Struct Rgb8
A pixel with 8-bit red, green and blue channels, in that order, and no alpha.
public struct Rgb8 : IPixelType<Rgb8>, IEquatable<Rgb8>
- Implements
- Inherited Members
Examples
using Raster image = Raster.Load("duck.png");
switch (image)
{
case Raster<Rgb8> rgb:
Console.WriteLine($"8-bit color, {rgb.Width} × {rgb.Height}");
break;
case Raster<Rgba8> rgba:
Console.WriteLine($"8-bit color with alpha, {rgba.Width} × {rgba.Height}");
break;
default:
Console.WriteLine($"{image.Layout.ChannelOrder}, {image.Layout.ChannelType}");
break;
}
Constructors
Rgb8(byte, byte, byte)
Initializes a new instance of the Rgb8 struct.
public Rgb8(byte r, byte g, byte b)
Parameters
Fields
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
Layout
Gets the memory layout of this pixel type.
public static PixelLayoutInfo Layout { get; }
Property Value
Methods
Equals(Rgb8)
Indicates whether the current object is equal to another object of the same type.
public readonly bool Equals(Rgb8 other)
Parameters
otherRgb8An 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.
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 Rgb8 FromRgba8(Rgba8 value)
Parameters
valueRgba8The color.
Returns
- Rgb8
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 Rgb8 FromScaled(Vector4 rgba)
Parameters
rgbaVector4The color, with each channel scaled to 0..1.
Returns
- Rgb8
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.
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.
Operators
operator ==(Rgb8, Rgb8)
Returns a value indicating whether two pixels are equal.
public static bool operator ==(Rgb8 left, Rgb8 right)
Parameters
Returns
operator !=(Rgb8, Rgb8)
Returns a value indicating whether two pixels differ.
public static bool operator !=(Rgb8 left, Rgb8 right)