Struct Rgba8
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
rbyteThe red channel.
gbyteThe green channel.
bbyteThe blue channel.
abyteThe alpha channel.
Fields
A
The alpha channel.
public byte A
Field Value
B
The blue channel.
public byte B
Field Value
G
The green channel.
public byte G
Field Value
R
The red channel.
public byte R
Field Value
Properties
Black
Gets black, #000000.
public static Rgba8 Black { get; }
Property Value
Blue
Gets blue, #0000FF.
public static Rgba8 Blue { get; }
Property Value
Cyan
Gets cyan, #00FFFF.
public static Rgba8 Cyan { get; }
Property Value
Gray
Gets gray, #808080.
public static Rgba8 Gray { get; }
Property Value
Green
Gets green, #008000.
public static Rgba8 Green { get; }
Property Value
Layout
Gets the memory layout of this pixel type.
public static PixelLayoutInfo Layout { get; }
Property Value
Lime
Gets lime, #00FF00.
public static Rgba8 Lime { get; }
Property Value
Magenta
Gets magenta, #FF00FF.
public static Rgba8 Magenta { get; }
Property Value
Maroon
Gets maroon, #800000.
public static Rgba8 Maroon { get; }
Property Value
Navy
Gets navy, #000080.
public static Rgba8 Navy { get; }
Property Value
Olive
Gets olive, #808000.
public static Rgba8 Olive { get; }
Property Value
Purple
Gets purple, #800080.
public static Rgba8 Purple { get; }
Property Value
Red
Gets red, #FF0000.
public static Rgba8 Red { get; }
Property Value
Silver
Gets silver, #C0C0C0.
public static Rgba8 Silver { get; }
Property Value
Teal
Gets teal, #008080.
public static Rgba8 Teal { get; }
Property Value
Transparent
Gets fully transparent black.
public static Rgba8 Transparent { get; }
Property Value
White
Gets white, #FFFFFF.
public static Rgba8 White { get; }
Property Value
Yellow
Gets yellow, #FFFF00.
public static Rgba8 Yellow { get; }
Property Value
Methods
Equals(Rgba8)
Indicates whether the current object is equal to another object of the same type.
public readonly bool Equals(Rgba8 other)
Parameters
otherRgba8An object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override readonly bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand 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
hexReadOnlySpan<char>The hex string.
Returns
- Rgba8
The color.
Exceptions
- FormatException
hexis 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
valueRgba8The 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
rgbaVector4The 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
hexReadOnlySpan<char>The hex string.
colorRgba8The color, or Transparent if parsing failed.
Returns
Operators
operator ==(Rgba8, Rgba8)
Returns a value indicating whether two pixels are equal.
public static bool operator ==(Rgba8 left, Rgba8 right)
Parameters
Returns
operator !=(Rgba8, Rgba8)
Returns a value indicating whether two pixels differ.
public static bool operator !=(Rgba8 left, Rgba8 right)