Struct smol_rgb::LinearColor
source · pub struct LinearColor {
pub r: f32,
pub g: f32,
pub b: f32,
pub a: f32,
}
Expand description
This is a Color in the linear
space. This represents
“linear sRGB”. You should use this color space when blending colors on the CPU
or when sending uniforms to a linear card.
Colors on disc are EncodedColor, but to blend them correctly, you need to move them
into the linear
color space with to_linear.
You can directly create this struct, but you probably don’t want to. You’d need already linear sRGB to correctly make this struct – that’s possible to have, but generally, textures, color pickers (like photoshop), and outputted surface (like if you use a Color Picker on a game) will all be in the encoded sRGBA space. Exceptions abound though, so it is possible to directly create this color.
Fields§
§r: f32
The red component of the color.
g: f32
The green component of the color.
b: f32
The blue component of the color.
a: f32
The alpha component of the color, normally the opacity in blending operations.
Implementations§
source§impl LinearColor
impl LinearColor
sourcepub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self
pub const fn new(r: f32, g: f32, b: f32, a: f32) -> Self
You probably don’t want to use this function. This creates a color in the LinearColor space directly. For this function to be valid, the colors given to this function must be in the linear space already.
sourcepub fn to_encoded_space(self) -> EncodedColor
pub fn to_encoded_space(self) -> EncodedColor
Transforms this color into the Encoded color space. Use this space to serialize colors.
sourcepub fn to_array(self) -> [f32; 4]
pub fn to_array(self) -> [f32; 4]
Creates an array representation of the color. This is useful for sending the color
to a uniform, but is the same memory representation as Self
. LinearColor also implements
Into, but this function is often more convenient.
Trait Implementations§
source§impl Clone for LinearColor
impl Clone for LinearColor
source§fn clone(&self) -> LinearColor
fn clone(&self) -> LinearColor
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for LinearColor
impl Debug for LinearColor
source§impl Default for LinearColor
impl Default for LinearColor
source§fn default() -> LinearColor
fn default() -> LinearColor
source§impl Display for LinearColor
impl Display for LinearColor
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 [f32; 4]
impl From<LinearColor> for [f32; 4]
source§fn from(o: LinearColor) -> Self
fn from(o: LinearColor) -> Self
source§impl From<LinearColor> for (f32, f32, f32, f32)
impl From<LinearColor> for (f32, f32, f32, f32)
source§fn from(o: LinearColor) -> Self
fn from(o: LinearColor) -> 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 PartialEq<LinearColor> for LinearColor
impl PartialEq<LinearColor> for LinearColor
source§fn eq(&self, other: &LinearColor) -> bool
fn eq(&self, other: &LinearColor) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<LinearColor> for LinearColor
impl PartialOrd<LinearColor> for LinearColor
source§fn partial_cmp(&self, other: &LinearColor) -> Option<Ordering>
fn partial_cmp(&self, other: &LinearColor) -> 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