Struct PixelLayoutInfo
Describes the memory layout of a pixel type.
public readonly record struct PixelLayoutInfo : IEquatable<PixelLayoutInfo>
- Implements
- Inherited Members
Examples
// What a pixel type stores, for code that handles any TPixel.
PixelLayoutInfo layout = Rgba16.Layout;
Console.WriteLine($"{layout.ChannelOrder} {layout.ChannelType}: {layout.ChannelCount} channels, {layout.BitsPerChannel} bits each, {layout.BytesPerPixel} bytes");
bool needsAlpha = layout.Alpha != AlphaKind.None;
bool eightBit = layout.ChannelType == PixelChannelType.Unorm8;
bool bgrOrder = Bgr8.Layout.ChannelOrder is PixelChannelOrder.Bgr or PixelChannelOrder.Bgra;
Constructors
PixelLayoutInfo(PixelChannelOrder, PixelChannelType, AlphaKind)
Describes the memory layout of a pixel type.
public PixelLayoutInfo(PixelChannelOrder ChannelOrder, PixelChannelType ChannelType, AlphaKind Alpha)
Parameters
ChannelOrderPixelChannelOrderThe order of the channels in memory.
ChannelTypePixelChannelTypeThe storage type shared by every channel.
AlphaAlphaKindHow alpha is stored, if at all.
Examples
// What a pixel type stores, for code that handles any TPixel.
PixelLayoutInfo layout = Rgba16.Layout;
Console.WriteLine($"{layout.ChannelOrder} {layout.ChannelType}: {layout.ChannelCount} channels, {layout.BitsPerChannel} bits each, {layout.BytesPerPixel} bytes");
bool needsAlpha = layout.Alpha != AlphaKind.None;
bool eightBit = layout.ChannelType == PixelChannelType.Unorm8;
bool bgrOrder = Bgr8.Layout.ChannelOrder is PixelChannelOrder.Bgr or PixelChannelOrder.Bgra;
PixelLayoutInfo(PixelChannelOrder, PixelChannelType, AlphaKind, int, params ReadOnlySpan<int>)
Initializes a new instance of the PixelLayoutInfo struct for a packed layout, such as 5-6-5.
public PixelLayoutInfo(PixelChannelOrder channelOrder, PixelChannelType channelType, AlphaKind alpha, int bitsPerPixel, params ReadOnlySpan<int> channelBits)
Parameters
channelOrderPixelChannelOrderThe order of the channels, from the lowest bit up.
channelTypePixelChannelTypeThe storage type, usually Packed.
alphaAlphaKindHow alpha is stored, if at all.
bitsPerPixelintThe size of one pixel in bits.
channelBitsReadOnlySpan<int>The width of each channel in bits, in the order of
channelOrder.
Exceptions
- ArgumentOutOfRangeException
bitsPerPixelis not positive, or a channel width is negative.- ArgumentException
The channel widths add up to more than
bitsPerPixel.
Properties
Alpha
How alpha is stored, if at all.
public AlphaKind Alpha { get; init; }
Property Value
BitsPerChannel
Gets the number of bits in each channel; for a packed layout, the width its channels share, or 0 when they differ; 0 for Other.
public int BitsPerChannel { get; }
Property Value
BitsPerPixel
Gets the size of one pixel in bits: the size given for a packed layout, otherwise the channel count times the channel
size; 0 when the order or type is Other and no size was given.
public int BitsPerPixel { get; }
Property Value
BytesPerPixel
Gets the size of one pixel in bytes as the layout describes it, rounded up to whole bytes; 0 when the order or type is
Other and no size was given. Egami itself always uses the struct's size.
public int BytesPerPixel { get; }
Property Value
ChannelBits
Gets the width of each channel in bits, in channel order, for a layout created with them (packed layouts); empty otherwise, when every channel is BitsPerChannel wide.
public ReadOnlySpan<int> ChannelBits { get; }
Property Value
ChannelCount
Gets the number of channels, including alpha; for Other, the number of channel widths given, else 0.
public int ChannelCount { get; }
Property Value
ChannelOrder
The order of the channels in memory.
public PixelChannelOrder ChannelOrder { get; init; }
Property Value
ChannelType
The storage type shared by every channel.
public PixelChannelType ChannelType { get; init; }
Property Value
HasAlpha
Gets a value indicating whether the type has an alpha channel.
public bool HasAlpha { get; }
Property Value
Methods
Equals(PixelLayoutInfo)
Returns whether two layouts are the same, including the size and channel widths of packed layouts.
public bool Equals(PixelLayoutInfo other)
Parameters
otherPixelLayoutInfoThe other layout.
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.