pub struct Color { /* private fields */ }
Expand description
A color.
When specifying RGBA values of a color, the RGB values can either be specified straight or premultiplied. Premultiplied means that the RGB values have already been multiplied by the alpha value.
Given a color, to reduce its opacity by half,
- if you’re working with premultiplied values, you would multiply each component by
0.5
; - if you’re working with straight values, you would multiply only the alpha component by
0.5
.
When using hexadecimal notation, #RRGGBBAA
, the RGB values are usually straight.
Implementations§
Source§impl Color
impl Color
Sourcepub fn new_straight(r: u8, g: u8, b: u8, a: u8) -> Self
pub fn new_straight(r: u8, g: u8, b: u8, a: u8) -> Self
Creates a new color from straight u8
RGBA values.
Sourcepub fn new_f32_premultiplied(r: f32, g: f32, b: f32, a: f32) -> Self
pub fn new_f32_premultiplied(r: f32, g: f32, b: f32, a: f32) -> Self
Creates a new color from premultiplied f32
RGBA values.
Sourcepub fn new_f32_straight(r: f32, g: f32, b: f32, a: f32) -> Self
pub fn new_f32_straight(r: f32, g: f32, b: f32, a: f32) -> Self
Creates a new color from straight f32
RGBA values.
Sourcepub fn to_f32_premultiplied(&self) -> [f32; 4]
pub fn to_f32_premultiplied(&self) -> [f32; 4]
Converts the color to its premultiplied f32
RGBA values.
Sourcepub fn to_f32_straight(&self) -> [f32; 4]
pub fn to_f32_straight(&self) -> [f32; 4]
Converts the color to its straight f32
RGBA values.
Sourcepub fn to_u8_straight(&self) -> [u8; 4]
pub fn to_u8_straight(&self) -> [u8; 4]
Converts the color to its straight u8
RGBA values.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Color
Auto Trait Implementations§
impl Freeze for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more