pub struct Color([u8; 4]);Expand description
An sRGBA color, 8 bits per channel, with premultiplied alpha — the
non-linear (“gamma”) values are the ones multiplied by the alpha, matching
ecolor’s Color32 byte for byte so the two convert without a color shift.
Every operation here works in gamma space. That is not physically correct, but it is what the palette and both render backends already assume, and it is perceptually more even than the linear-space alternative.
Tuple Fields§
§0: [u8; 4]Implementations§
Source§impl Color
impl Color
Sourcepub const TRANSPARENT: Self
pub const TRANSPARENT: Self
The absence of a color: a role mapped to nothing, a cell that draws no fill.
Sourcepub const PLACEHOLDER: Self
pub const PLACEHOLDER: Self
The “recolor me” sentinel a text layout carries until something paints it. Not a color, and not a valid premultiplied one either.
pub const BLACK: Self
pub const WHITE: Self
pub const GRAY: Self
pub const fn from_rgba_premultiplied(r: u8, g: u8, b: u8, a: u8) -> Self
Sourcepub const fn from_rgba_unmultiplied(r: u8, g: u8, b: u8, a: u8) -> Self
pub const fn from_rgba_unmultiplied(r: u8, g: u8, b: u8, a: u8) -> Self
From the “normal” RGBA a color picker hands out, with alpha kept
separate. Self::to_srgba_unmultiplied inverts it, up to rounding.
pub const fn a(self) -> u8
pub const fn is_opaque(self) -> bool
Sourcepub fn to_srgba_unmultiplied(self) -> [u8; 4]
pub fn to_srgba_unmultiplied(self) -> [u8; 4]
Back to separate alpha — the inverse of
Self::from_rgba_unmultiplied, up to rounding on transparent colors.
Sourcepub fn gamma_multiply(self, factor: f32) -> Self
pub fn gamma_multiply(self, factor: f32) -> Self
Scale every channel, alpha included, in gamma space: 0.5 makes the
color half as opaque, perceptually.
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>,
impl Copy for Color
impl Eq for Color
impl StructuralPartialEq 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 UnsafeUnpin 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.