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

source

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.

source

pub fn to_encoded_space(self) -> EncodedColor

Transforms this color into the Encoded color space. Use this space to serialize colors.

source

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.

source

pub fn to_bits(self) -> [u8; 16]

Encodes the 4 floats as 16 u8s. This is useful for sending the color to a uniform, but is the same memory representation as Self – ie, the bits have just been reinterpreted as 16 u8s, but they’re still secret floats.

source

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

Recasts four u8s into floats. Note: these floats could be subnormal if these u8s were produced incorrectly.

Trait Implementations§

source§

impl Clone for LinearColor

source§

fn clone(&self) -> LinearColor

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 LinearColor

source§

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

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

impl Default for LinearColor

source§

fn default() -> LinearColor

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

impl Display for LinearColor

source§

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

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

impl From<[f32; 4]> for LinearColor

source§

fn from(o: [f32; 4]) -> Self

Converts to this type from the input type.
source§

impl From<(f32, f32, f32, f32)> for LinearColor

source§

fn from(o: (f32, f32, f32, f32)) -> 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 [f32; 4]

source§

fn from(o: LinearColor) -> Self

Converts to this type from the input type.
source§

impl From<LinearColor> for (f32, f32, f32, f32)

source§

fn from(o: LinearColor) -> 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 PartialEq<LinearColor> for LinearColor

source§

fn eq(&self, other: &LinearColor) -> 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<LinearColor> for LinearColor

source§

fn partial_cmp(&self, other: &LinearColor) -> 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 Copy for LinearColor

source§

impl StructuralPartialEq for LinearColor

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.