Table of Contents

Struct Rgba8

Namespace
Egami.Pixels
Assembly
Egami.dll

A pixel with 8-bit red, green, blue and straight alpha channels, in that order. Egami's default working type.

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

Examples

// Decode straight into the type you want to work in.
using Raster<Rgba8> rgba = Raster.Load<Rgba8>("duck.png");

// Pixels are a row at a time: each row is a Span<Rgba8>.
for (int y = 0; y < rgba.Height; y++)
{
    Span<Rgba8> row = rgba.Row(y);
    for (int x = 0; x < row.Length; x++)
    {
        row[x].A = 128;
    }
}

// Convert a whole raster; the result is a new raster you dispose too.
using Raster<Gray8> gray = rgba.As<Gray8>();
gray.Save("duck-gray.png");

Constructors

Rgba8(byte, byte, byte, byte)

Initializes a new instance of the Rgba8 struct.

public Rgba8(byte r, byte g, byte b, byte a)

Parameters

r byte

The red channel.

g byte

The green channel.

b byte

The blue channel.

a byte

The alpha channel.

Fields

A

The alpha channel.

public byte A

Field Value

byte

B

The blue channel.

public byte B

Field Value

byte

G

The green channel.

public byte G

Field Value

byte

R

The red channel.

public byte R

Field Value

byte

Properties

Black

Gets black, #000000.

public static Rgba8 Black { get; }

Property Value

Rgba8

Blue

Gets blue, #0000FF.

public static Rgba8 Blue { get; }

Property Value

Rgba8

Cyan

Gets cyan, #00FFFF.

public static Rgba8 Cyan { get; }

Property Value

Rgba8

Gray

Gets gray, #808080.

public static Rgba8 Gray { get; }

Property Value

Rgba8

Green

Gets green, #008000.

public static Rgba8 Green { get; }

Property Value

Rgba8

Layout

Gets the memory layout of this pixel type.

public static PixelLayoutInfo Layout { get; }

Property Value

PixelLayoutInfo

Lime

Gets lime, #00FF00.

public static Rgba8 Lime { get; }

Property Value

Rgba8

Magenta

Gets magenta, #FF00FF.

public static Rgba8 Magenta { get; }

Property Value

Rgba8

Maroon

Gets maroon, #800000.

public static Rgba8 Maroon { get; }

Property Value

Rgba8

Navy

Gets navy, #000080.

public static Rgba8 Navy { get; }

Property Value

Rgba8

Olive

Gets olive, #808000.

public static Rgba8 Olive { get; }

Property Value

Rgba8

Purple

Gets purple, #800080.

public static Rgba8 Purple { get; }

Property Value

Rgba8

Red

Gets red, #FF0000.

public static Rgba8 Red { get; }

Property Value

Rgba8

Silver

Gets silver, #C0C0C0.

public static Rgba8 Silver { get; }

Property Value

Rgba8

Teal

Gets teal, #008080.

public static Rgba8 Teal { get; }

Property Value

Rgba8

Transparent

Gets fully transparent black.

public static Rgba8 Transparent { get; }

Property Value

Rgba8

White

Gets white, #FFFFFF.

public static Rgba8 White { get; }

Property Value

Rgba8

Yellow

Gets yellow, #FFFF00.

public static Rgba8 Yellow { get; }

Property Value

Rgba8

Methods

Equals(Rgba8)

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

public readonly bool Equals(Rgba8 other)

Parameters

other Rgba8

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.

FromHex(ReadOnlySpan<char>)

Parses a hex color: RGB, RGBA, RRGGBB or RRGGBBAA, with or without a leading #. Single digits are doubled, so #F80 is #FF8800. Missing alpha means opaque.

public static Rgba8 FromHex(ReadOnlySpan<char> hex)

Parameters

hex ReadOnlySpan<char>

The hex string.

Returns

Rgba8

The color.

Exceptions

FormatException

hex is not a valid hex color.

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 Rgba8 FromRgba8(Rgba8 value)

Parameters

value Rgba8

The color.

Returns

Rgba8

The pixel.

FromScaled(Vector4)

Creates a pixel from red, green, blue and alpha scaled to 0..1, with straight alpha. Values outside 0..1 are clamped and NaN becomes 0. Gray types take the Rec. 709 luma of the color, weighted in linear light. Types without alpha drop it.

public static Rgba8 FromScaled(Vector4 rgba)

Parameters

rgba Vector4

The color, with each channel scaled to 0..1.

Returns

Rgba8

The nearest pixel of this type.

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.

ToHex()

Returns the color as #RRGGBBAA in uppercase hex.

public readonly string ToHex()

Returns

string

The hex string.

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 red, green, blue and alpha scaled to 0..1. Types without alpha return an alpha of 1.

public readonly Vector4 ToScaled()

Returns

Vector4

The scaled color.

ToString()

Returns the fully qualified type name of this instance.

public override readonly string ToString()

Returns

string

The fully qualified type name.

TryFromHex(ReadOnlySpan<char>, out Rgba8)

Tries to parse a hex color in the forms that FromHex(ReadOnlySpan<char>) accepts.

public static bool TryFromHex(ReadOnlySpan<char> hex, out Rgba8 color)

Parameters

hex ReadOnlySpan<char>

The hex string.

color Rgba8

The color, or Transparent if parsing failed.

Returns

bool

true if hex was a valid hex color.

Operators

operator ==(Rgba8, Rgba8)

Returns a value indicating whether two pixels are equal.

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

Parameters

left Rgba8

The first pixel.

right Rgba8

The second pixel.

Returns

bool

true if every channel is equal.

operator !=(Rgba8, Rgba8)

Returns a value indicating whether two pixels differ.

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

Parameters

left Rgba8

The first pixel.

right Rgba8

The second pixel.

Returns

bool

true if any channel differs.