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
impl EncodedColor
sourcepub const WHITE: EncodedColor = _
pub const WHITE: EncodedColor = _
A basic white (255, 255, 255, 255) with full opacity.
sourcepub const BLACK: EncodedColor = _
pub const BLACK: EncodedColor = _
A basic black (0, 0, 0, 255) with full opacity.
sourcepub const CLEAR: EncodedColor = _
pub const CLEAR: EncodedColor = _
A black (0, 0, 0, 0) with zero opacity.
sourcepub fn to_linear(self) -> LinearColor
pub fn to_linear(self) -> LinearColor
Transforms this color into the Linear color space.
sourcepub fn to_encoded_f32s(self) -> [f32; 4]
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.
sourcepub fn from_encoded_f32s(input: [f32; 4]) -> Self
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.
sourcepub const fn from_rgba_u32(input: u32) -> Self
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.
sourcepub const fn to_rgba_u32(self) -> u32
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.
sourcepub const fn from_bgra_u32(input: u32) -> Self
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.
sourcepub const fn to_bgra_u32(self) -> u32
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.
sourcepub const fn from_bits_u32(value: u32) -> Self
pub const fn from_bits_u32(value: u32) -> Self
Recasts four u8s into EncodedColor
source§impl EncodedColor
impl EncodedColor
sourcepub const RED: EncodedColor = _
pub const RED: EncodedColor = _
Full alpha Red (255, 0, 0, 255)
sourcepub const RED_CLEAR: EncodedColor = _
pub const RED_CLEAR: EncodedColor = _
Zero alpha Red (255, 0, 0, 255)
sourcepub const GREEN: EncodedColor = _
pub const GREEN: EncodedColor = _
Full alpha green (255, 0, 0, 255)
sourcepub const GREEN_CLEAR: EncodedColor = _
pub const GREEN_CLEAR: EncodedColor = _
Zero alpha green (255, 0, 0, 255)
sourcepub const BLUE: EncodedColor = _
pub const BLUE: EncodedColor = _
Full alpha blue (255, 0, 0, 255)
sourcepub const BLUE_CLEAR: EncodedColor = _
pub const BLUE_CLEAR: EncodedColor = _
Zero alpha blue (255, 0, 0, 255)
sourcepub const YELLOW: EncodedColor = _
pub const YELLOW: EncodedColor = _
Full alpha Yellow (255, 255, 0, 255).
sourcepub const YELLOW_CLEAR: EncodedColor = _
pub const YELLOW_CLEAR: EncodedColor = _
Zero alpha Yellow (255, 255, 0, 0).
sourcepub const FUCHSIA: EncodedColor = _
pub const FUCHSIA: EncodedColor = _
God’s color (255, 0, 255, 255). The color of choice for graphics testing.
sourcepub const FUCHSIA_CLEAR: EncodedColor = _
pub const FUCHSIA_CLEAR: EncodedColor = _
God’s color but clear (255, 0, 255, 255). The color of choice for graphics testing.
sourcepub const TEAL: EncodedColor = _
pub const TEAL: EncodedColor = _
Full alpha Teal (0, 255, 255, 255).
sourcepub const TEAL_CLEAR: EncodedColor = _
pub const TEAL_CLEAR: EncodedColor = _
Zero alpha Teal (0, 255, 255, 0).
Trait Implementations§
source§impl Clone for EncodedColor
impl Clone for EncodedColor
source§fn clone(&self) -> EncodedColor
fn clone(&self) -> EncodedColor
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for EncodedColor
impl Debug for EncodedColor
source§impl Default for EncodedColor
impl Default for EncodedColor
source§impl Display for EncodedColor
impl Display for EncodedColor
source§impl From<EncodedColor> for [u8; 4]
impl From<EncodedColor> for [u8; 4]
source§fn from(o: EncodedColor) -> Self
fn from(o: EncodedColor) -> Self
source§impl From<EncodedColor> for (u8, u8, u8, u8)
impl From<EncodedColor> for (u8, u8, u8, u8)
source§fn from(o: EncodedColor) -> Self
fn from(o: EncodedColor) -> Self
source§impl From<EncodedColor> for LinearColor
impl From<EncodedColor> for LinearColor
source§fn from(o: EncodedColor) -> Self
fn from(o: EncodedColor) -> Self
source§impl From<LinearColor> for EncodedColor
impl From<LinearColor> for EncodedColor
source§fn from(o: LinearColor) -> Self
fn from(o: LinearColor) -> Self
source§impl Hash for EncodedColor
impl Hash for EncodedColor
source§impl LowerHex for EncodedColor
impl LowerHex for EncodedColor
source§impl Ord for EncodedColor
impl Ord for EncodedColor
source§fn cmp(&self, other: &EncodedColor) -> Ordering
fn cmp(&self, other: &EncodedColor) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere Self: Sized,
source§impl PartialEq<EncodedColor> for EncodedColor
impl PartialEq<EncodedColor> for EncodedColor
source§fn eq(&self, other: &EncodedColor) -> bool
fn eq(&self, other: &EncodedColor) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<EncodedColor> for EncodedColor
impl PartialOrd<EncodedColor> for EncodedColor
source§fn partial_cmp(&self, other: &EncodedColor) -> Option<Ordering>
fn partial_cmp(&self, other: &EncodedColor) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more