Table of Contents

Struct PremulRgbaF32

Namespace
Egami.Pixels
Assembly
Egami.dll

A pixel with 32-bit float red, green and blue channels premultiplied by the alpha channel, in that order, for float compositing and blending. The conversions take and return straight colors; values are not clamped, except that a premultiplied pixel with zero alpha has no color.

public struct PremulRgbaF32 : IPixelType<PremulRgbaF32>, IEquatable<PremulRgbaF32>
Implements
Inherited Members

Examples

// Eight-bit, sixteen-bit and float pixels; every type converts to every other through PixelConvert.
Rgba8 orange = new(255, 128, 0, 255);
Bgr8 bgr = Bgr8.FromRgba8(orange);
Gray8 gray = Gray8.FromRgba8(orange);
GrayAlpha8 grayAlpha = new(gray.L, 128);
Gray16 deep = Gray16.FromRgba8(orange);
Rgba16 wide = new(65535, 32896, 0, 65535);
Rgb16 wideOpaque = Rgb16.FromRgba16(wide);           // exact: 16-bit to 16-bit never rounds
GrayAlpha16 deepMask = new(deep.L, 32768);
Argb8 alphaFirst = Argb8.FromRgba8(orange);             // bytes A, R, G, B
Alpha8 mask = Alpha8.FromRgba8(orange);                 // alpha only; reads back as black
RgbaF16 hdr = RgbaF16.FromScaled(new Vector4(4f, 2f, 0.5f, 1f)); // half floats keep values above 1
GrayF32 depth = new(12.5f);                              // floats hold any value until written to an integer type
Bgr565 packed = Bgr565.FromRgba8(orange);                // 5-6-5 levels in one ushort; rounds to the nearest level
Bgra5551 gdi16 = Bgra5551.FromRgba8(orange);             // 5-5-5 levels and a 1-bit alpha, the GDI+ 16-bit ARGB layout
Cmyk8 ink = Cmyk8.FromRgba8(orange);                     // inks by the plain formula: (0, 127, 255, 0)
PremulRgba8 glass = PremulRgba8.FromRgba8(new Rgba8(255, 128, 0, 128)); // stored (128, 64, 0, 128); converts back straight
RgbaF32 linear = RgbaF32.FromScaled(orange.ToScaled());

Rgba8[] row = [orange, Rgba8.Transparent];
Bgra8[] converted = new Bgra8[row.Length];
PixelConvert.Convert<Rgba8, Bgra8>(row, converted);

Constructors

PremulRgbaF32(float, float, float, float)

Initializes a new instance of the PremulRgbaF32 struct from premultiplied channels.

public PremulRgbaF32(float r, float g, float b, float a)

Parameters

r float

The red channel, already premultiplied.

g float

The green channel, already premultiplied.

b float

The blue channel, already premultiplied.

a float

The alpha channel.

Fields

A

The alpha channel.

public float A

Field Value

float

B

The blue channel, premultiplied.

public float B

Field Value

float

G

The green channel, premultiplied.

public float G

Field Value

float

R

The red channel, premultiplied.

public float R

Field Value

float

Properties

Layout

Gets the memory layout of this pixel type.

public static PixelLayoutInfo Layout { get; }

Property Value

PixelLayoutInfo

Methods

Equals(PremulRgbaF32)

Indicates whether the current object is equal to another object of the same type.

public readonly bool Equals(PremulRgbaF32 other)

Parameters

other PremulRgbaF32

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override readonly bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

FromRgba8(Rgba8)

Creates a pixel from an 8-bit color. The conversion is exact wherever the type can hold the color. Gray types take the Rec. 709 luma, weighted in linear light. Types without alpha drop it.

public static PremulRgbaF32 FromRgba8(Rgba8 value)

Parameters

value Rgba8

The color.

Returns

PremulRgbaF32

The pixel.

FromScaled(Vector4)

Creates a pixel from a straight color by multiplying red, green and blue by alpha. Values are not clamped.

public static PremulRgbaF32 FromScaled(Vector4 rgba)

Parameters

rgba Vector4

The straight color.

Returns

PremulRgbaF32

The pixel.

GetHashCode()

Returns the hash code for this instance.

public override readonly int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToRgba8()

Returns the pixel as an 8-bit color. 16-bit channels are rounded to the nearest 8-bit value, and gray is copied to red, green and blue.

public readonly Rgba8 ToRgba8()

Returns

Rgba8

The 8-bit color.

ToScaled()

Returns the straight color: red, green and blue divided by alpha, or transparent black when alpha is 0.

public readonly Vector4 ToScaled()

Returns

Vector4

The straight color.

ToString()

Returns the fully qualified type name of this instance.

public override readonly string ToString()

Returns

string

The fully qualified type name.

Operators

operator ==(PremulRgbaF32, PremulRgbaF32)

Returns a value indicating whether two pixels are equal.

public static bool operator ==(PremulRgbaF32 left, PremulRgbaF32 right)

Parameters

left PremulRgbaF32

The first pixel.

right PremulRgbaF32

The second pixel.

Returns

bool

true if every stored channel is equal.

operator !=(PremulRgbaF32, PremulRgbaF32)

Returns a value indicating whether two pixels differ.

public static bool operator !=(PremulRgbaF32 left, PremulRgbaF32 right)

Parameters

left PremulRgbaF32

The first pixel.

right PremulRgbaF32

The second pixel.

Returns

bool

true if any stored channel differs.