Struct smol_rgb::EncodedColor

source ·
#[repr(C)]
pub struct EncodedColor { pub r: u8, pub g: u8, pub b: u8, pub a: u8, }
Expand description

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, LinearColor, 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§

source§

impl EncodedColor

source

pub const WHITE: EncodedColor = _

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

source

pub const BLACK: EncodedColor = _

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

source

pub const CLEAR: EncodedColor = _

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

source

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

Creates a new encoded 32bit color.

source

pub fn to_linear(self) -> LinearColor

Transforms this color into the Linear color space.

source

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

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.

source

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

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.

source

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

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.

source

pub const fn to_rgba_u32(self) -> u32

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.

source

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

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.

source

pub const fn to_bgra_u32(self) -> u32

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.

source

pub const fn from_bits_u32(value: u32) -> Self

Recasts four u8s into EncodedColor

source

pub const fn from_bits(value: [u8; 4]) -> Self

Recasts four u8s into EncodedColor

source§

impl EncodedColor

source

pub const RED: EncodedColor = _

Full alpha Red (255, 0, 0, 255)

source

pub const RED_CLEAR: EncodedColor = _

Zero alpha Red (255, 0, 0, 255)

source

pub const GREEN: EncodedColor = _

Full alpha green (255, 0, 0, 255)

source

pub const GREEN_CLEAR: EncodedColor = _

Zero alpha green (255, 0, 0, 255)

source

pub const BLUE: EncodedColor = _

Full alpha blue (255, 0, 0, 255)

source

pub const BLUE_CLEAR: EncodedColor = _

Zero alpha blue (255, 0, 0, 255)

source

pub const YELLOW: EncodedColor = _

Full alpha Yellow (255, 255, 0, 255).

source

pub const YELLOW_CLEAR: EncodedColor = _

Zero alpha Yellow (255, 255, 0, 0).

source

pub const FUCHSIA: EncodedColor = _

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

source

pub const FUCHSIA_CLEAR: EncodedColor = _

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

source

pub const TEAL: EncodedColor = _

Full alpha Teal (0, 255, 255, 255).

source

pub const TEAL_CLEAR: EncodedColor = _

Zero alpha Teal (0, 255, 255, 0).

Trait Implementations§

source§

impl Clone for EncodedColor

source§

fn clone(&self) -> EncodedColor

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for EncodedColor

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for EncodedColor

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for EncodedColor

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<[u8; 4]> for EncodedColor

source§

fn from([r, g, b, a]: [u8; 4]) -> Self

Converts to this type from the input type.
source§

impl From<(u8, u8, u8, u8)> for EncodedColor

source§

fn from(o: (u8, u8, u8, u8)) -> Self

Converts to this type from the input type.
source§

impl From<EncodedColor> for [u8; 4]

source§

fn from(o: EncodedColor) -> Self

Converts to this type from the input type.
source§

impl From<EncodedColor> for (u8, u8, u8, u8)

source§

fn from(o: EncodedColor) -> Self

Converts to this type from the input type.
source§

impl From<EncodedColor> for LinearColor

source§

fn from(o: EncodedColor) -> Self

Converts to this type from the input type.
source§

impl From<LinearColor> for EncodedColor

source§

fn from(o: LinearColor) -> Self

Converts to this type from the input type.
source§

impl Hash for EncodedColor

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl LowerHex for EncodedColor

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Ord for EncodedColor

source§

fn cmp(&self, other: &EncodedColor) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<EncodedColor> for EncodedColor

source§

fn eq(&self, other: &EncodedColor) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<EncodedColor> for EncodedColor

source§

fn partial_cmp(&self, other: &EncodedColor) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl UpperHex for EncodedColor

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Copy for EncodedColor

source§

impl Eq for EncodedColor

source§

impl StructuralEq for EncodedColor

source§

impl StructuralPartialEq for EncodedColor

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.