Table of Contents

Struct PixelLayoutInfo

Namespace
Egami.Pixels
Assembly
Egami.dll

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

ChannelOrder PixelChannelOrder

The order of the channels in memory.

ChannelType PixelChannelType

The storage type shared by every channel.

Alpha AlphaKind

How 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

channelOrder PixelChannelOrder

The order of the channels, from the lowest bit up.

channelType PixelChannelType

The storage type, usually Packed.

alpha AlphaKind

How alpha is stored, if at all.

bitsPerPixel int

The size of one pixel in bits.

channelBits ReadOnlySpan<int>

The width of each channel in bits, in the order of channelOrder.

Exceptions

ArgumentOutOfRangeException

bitsPerPixel is 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

AlphaKind

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

int

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

int

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

int

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

ReadOnlySpan<int>

ChannelCount

Gets the number of channels, including alpha; for Other, the number of channel widths given, else 0.

public int ChannelCount { get; }

Property Value

int

ChannelOrder

The order of the channels in memory.

public PixelChannelOrder ChannelOrder { get; init; }

Property Value

PixelChannelOrder

ChannelType

The storage type shared by every channel.

public PixelChannelType ChannelType { get; init; }

Property Value

PixelChannelType

HasAlpha

Gets a value indicating whether the type has an alpha channel.

public bool HasAlpha { get; }

Property Value

bool

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

other PixelLayoutInfo

The other layout.

Returns

bool

true if they describe the same memory.

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.