Struct smol_rgb::EncodedRgb[][src]

#[repr(C)]pub struct EncodedRgb {
    pub r: u8,
    pub g: u8,
    pub b: u8,
    pub a: u8,
}

A color used in linear applications. On a technical level, this color is in sRGB; however, this name is not very clear.

In code, we will say that this Color is encoded. This is generally the same colorspace that texels in a texture are in. This color space is not valid to perform mixing operations between colors in, so we must convert this color space into a different color, LinearRgb, with to_linear before we do such operations.

Fields

r: u8

The red component of the color.

g: u8

The green component of the color.

b: u8

The blue component of the color.

a: u8

The alpha component of the color, normally the opacity in blending operations.

Implementations

impl EncodedRgb[src]

pub const WHITE: EncodedRgb[src]

A basic white (255, 255, 255, 255) with full opacity.

pub const BLACK: EncodedRgb[src]

A basic black (0, 0, 0, 255) with full opacity.

pub const CLEAR: EncodedRgb[src]

A black (0, 0, 0, 0) with zero opacity.

pub const FUCHSIA: EncodedRgb[src]

God’s color (255, 0, 255, 255). The color of choice for graphics testing.

pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self[src]

Creates a new encoded 32bit color.

pub fn to_linear(self) -> LinearRgb[src]

Transforms this color into the Linear color space.

pub fn to_encoded_f32s(self) -> [f32; 4][src]

Converts this color to an [f32; 4] array. This is still in encoded space but they are converted to an f32. This is mostly for compatability with other libraries which sometimes need to f32s even while in encoded sRGB.

We use this dedicated function, rather than a From or Into because this is an unusual use of f32s, and in general, this module acts as if f32 == Linear and u8 == Encoded, though this is not technically true.

pub fn from_encoded_f32s(input: [f32; 4]) -> Self[src]

Converts this color to an [f32; 4] array. This is still in encoded space but they are converted to an f32. This is mostly for compatability with other libraries which sometimes need to f32s even while in encoded sRGB.

We use this dedicated function, rather than a From or Into because this is an unusual use of f32s, and in general, this module acts as if f32 == Linear and u8 == Encoded, though this is not technically true.

pub const fn from_rgba_u32(input: u32) -> Self[src]

Converts a packed u32 to an encoded rgba struct.

Note, your colors must be in order of red, green, blue, alpha. For bgra support, use from_bgra_u32.

This function might also has issues on non-little endian platforms, but look, you’re not on one of those.

pub const fn to_rgba_u32(self) -> u32[src]

Converts the encoded rgba struct to a packed u32 in rgba encoding.

This will output your colors in order of red, green, blue, alpha. For bgra support, use to_bgra_u32.

This function might also have issues on non-little endian platforms, but look, you’re not on one of those.

pub const fn from_bgra_u32(input: u32) -> Self[src]

Converts a packed u32 to an encoded rgba struct. On little endian platforms, this is a no-op.

Note, your colors must be in order of blue, green, red, alpha.

This function might also has issues on non-little endian platforms, but look, you’re not on one of those probably.

pub const fn to_bgra_u32(self) -> u32[src]

Converts the encoded rgba struct to a packed u32 in bgra encoding.

This will output your colors in order of red, green, blue, alpha. For bgra support, use to_bgra_u32.

This function might also have issues on non-little endian platforms, but look, you’re not on one of those.

Trait Implementations

impl Clone for EncodedRgb[src]

impl Copy for EncodedRgb[src]

impl Debug for EncodedRgb[src]

impl Default for EncodedRgb[src]

impl Display for EncodedRgb[src]

impl Eq for EncodedRgb[src]

impl From<(u8, u8, u8, u8)> for EncodedRgb[src]

impl From<EncodedRgb> for LinearRgb[src]

impl From<LinearRgb> for EncodedRgb[src]

impl Hash for EncodedRgb[src]

impl Into<(u8, u8, u8, u8)> for EncodedRgb[src]

impl LowerHex for EncodedRgb[src]

impl Ord for EncodedRgb[src]

impl PartialEq<EncodedRgb> for EncodedRgb[src]

impl PartialOrd<EncodedRgb> for EncodedRgb[src]

impl StructuralEq for EncodedRgb[src]

impl StructuralPartialEq for EncodedRgb[src]

impl UpperHex for EncodedRgb[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.