IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
PixelFormatInfo.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
7
9
15
19public class PixelFormatInfo
20{
21 private readonly PixelFormatDefinition _pixelFormatInfo;
22
27 public PixelFormatInfo(PixelFormat pixelFormat)
28 {
29 _pixelFormatInfo = PixelFormatDefinition.FormatMap[pixelFormat];
30 }
31
36 public PixelFormatInfo(string name)
37 {
38 _pixelFormatInfo = PixelFormatDefinition.NameMap[name];
39 }
40
44 public uint StorageBitsPerPixel => _pixelFormatInfo.StorageBitsPerPixel;
45
50 {
51 // TODO: is this correct?
52 get
53 {
54 switch (PixelFormat)
55 {
56 case PixelFormat.YUV422_8_UYVY:
57 case PixelFormat.YUV420_8_YY_UV_SemiplanarIDS:
58 case PixelFormat.YUV420_8_YY_VU_SemiplanarIDS:
59 {
61 }
62
63 default:
65 }
66 }
67 }
68
72 public uint AllocatedBitsPerPixel => _pixelFormatInfo.AllocatedBitsPerPixel;
73
77 public string Name => _pixelFormatInfo.Name;
78
82 public Channel[] Channels => _pixelFormatInfo.Channels;
83
87 public bool HasIntensityChannel => HasChannel(Channel.Intensity);
88
92 public uint NumberOfChannels => (uint) Channels.Length;
93
97 public bool IsSingleChannel => NumberOfChannels == 1;
98
102 public PixelFormat PixelFormat => _pixelFormatInfo.Format;
103
107 public bool IsPacked => _pixelFormatInfo.IsPacked;
108
112 public bool IsFloat => _pixelFormatInfo.IsFloat;
113
171 public bool IsInterleaved => _pixelFormatInfo.IsInterleaved;
172
177 public PixelFormat UnpackedPixelFormat => _pixelFormatInfo.UnpackedFormat;
178
187 {
188 if (typeof(T) == typeof(float) && IsFloat)
189 {
190 return (T) (object) float.MinValue;
191 }
192
193 if (typeof(T) == typeof(int) && !IsFloat)
194 {
195 return (T) (object) 0;
196 }
197
198 var expectedType = IsFloat ? "float" : "int";
200 $"Minimum value type {expectedType} of format {Name} does not match requested type {typeof(T).Name}");
201 }
202
211 {
213 }
214
223 {
224 if (typeof(T) == typeof(float) && IsFloat)
225 {
226 return (T) (object) float.MaxValue;
227 }
228
229 if (typeof(T) == typeof(int) && !IsFloat)
230 {
231 return (T) (object) (int) (Math.Pow(2, StorageBitsPerChannel) - 1);
232 }
233
234 var expectedType = IsFloat ? "float" : "int";
236 $"Maximum value type {expectedType} of format {Name} does not match requested type {typeof(T).Name}");
237 }
238
247 {
249 }
250
256 public int GetChannelIndex(Channel channel)
257 {
258 return Array.IndexOf(Channels, channel);
259 }
260
266 public bool HasChannel(Channel channel)
267 {
268 return Channels.Contains(channel);
269 }
270
276 public ulong GetSizeInBytes(Size size)
277 {
278 return (size.Height * size.Width * AllocatedBitsPerPixel + 7) / 8;
279 }
280
286 public override bool Equals(object? obj)
287 {
288 if (obj is null)
289 {
290 return false;
291 }
292
293 if (ReferenceEquals(this, obj))
294 {
295 return true;
296 }
297
298 if (obj is not PixelFormatInfo other)
299 {
300 return false;
301 }
302
303 return Equals(other);
304 }
305
311 protected bool Equals(PixelFormatInfo other)
312 {
313 return PixelFormat.Equals(other.PixelFormat);
314 }
315
319 public override int GetHashCode()
320 {
321 return PixelFormat.GetHashCode();
322 }
323
328 public override string ToString()
329 {
330 return Formatting.Invariant($"{GetType().Name}{{ {nameof(PixelFormat)} = {PixelFormat} }}");
331 }
332}
Exception thrown when an invalid parameter is detected.
T Width
Gets the width of the size.
Definition Size.cs:37
T Height
Gets the height of the size.
Definition Size.cs:42
Represents a size with integer width and height values.
Definition Size.cs:107
Provides information and utility functions for pixel formats. The PixelFormatInfo class offers method...
PixelFormat PixelFormat
The underlying pixel format enumeration value.
uint AllocatedBitsPerPixel
The number of allocated bits per pixel.
bool IsPacked
Whether the pixel format is packed.
bool IsSingleChannel
Whether the pixel format contains only a single channel.
T MaximumValuePerChannel< T >()
Returns the maximum possible value per channel for the pixel format. Supports int (for integers) and ...
PixelFormatInfo(PixelFormat pixelFormat)
Constructs a PixelFormatInfo object for the specified pixel format.
uint NumberOfChannels
The total number of channels in the pixel format.
ulong GetSizeInBytes(Size size)
Calculates the memory size in bytes for a given image size.
bool IsInterleaved
Indicates whether the pixel format is interleaved.
uint StorageBitsPerPixel
The total number of bits used per pixel for storage.
bool IsFloat
Whether the pixel format uses floating points.
override int GetHashCode()
Returns a hash code for the current pixel format.
string Name
The human-readable name of the pixel format.
int MinimumValuePerChannel()
Returns the minimum possible value per channel for the pixel format. This defaults to int for the typ...
T MinimumValuePerChannel< T >()
Returns the minimum possible value per channel for the pixel format. Supports int (for integers) and ...
int MaximumValuePerChannel()
Returns the maximum possible value per channel for the pixel format. This defaults to int for the typ...
override bool Equals(object? obj)
Determines whether the specified object is equal to the current PixelFormatInfo.
bool HasIntensityChannel
Checks whether the pixel format includes an intensity channel.
override string ToString()
Returns a string representation of the pixel format info.
int GetChannelIndex(Channel channel)
Returns the index of a specific channel within the pixel format.
PixelFormat UnpackedPixelFormat
Returns the unpacked pixel format for a packed pixel format. If the pixel format is already unpacked,...
uint StorageBitsPerChannel
The number of bits used per channel for storage.
PixelFormatInfo(string name)
Constructs a PixelFormatInfo object from the name of a pixel format.
Channel[] Channels
The list of channels in the pixel format.
bool HasChannel(Channel channel)
Checks whether a specific channel is present in the pixel format.
Channel
Represents the various data channels in image or spatial data formats. /// This enumeration defines s...
Definition Channel.cs:13
PixelFormat
Each enumerator represents a specific pixel layout and bit-depth, used for interpreting raw image dat...