#[repr(C, align(4))]pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
pub a: u8,
}Expand description
An RGBA8 color with premultiplied alpha.
Every color the renderer accepts or stores is premultiplied: r, g, and b have already
been scaled by a / 255. Opaque colors are the same either way; for translucent ones, use
Color::from_rgba_unmultiplied to convert straight-alpha input. A channel above a is
allowed and blends additively, as in egui.
It is four bytes with four-byte alignment, so the rasterizer compares and moves a color as one 32-bit word.
Fields§
§r: u8Red, premultiplied.
g: u8Green, premultiplied.
b: u8Blue, premultiplied.
a: u8Alpha: 0 is transparent, 255 is opaque.
Implementations§
Source§impl Color
impl Color
Sourcepub const TRANSPARENT: Self
pub const TRANSPARENT: Self
Fully transparent (all channels 0).
Sourcepub const fn from_rgba_premultiplied(r: u8, g: u8, b: u8, a: u8) -> Self
pub const fn from_rgba_premultiplied(r: u8, g: u8, b: u8, a: u8) -> Self
A color from channels that are already premultiplied.
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
A color from straight (unmultiplied) channels, premultiplying each of r, g, b by
a with round-to-nearest: (channel * a + 127) / 255.
Sourcepub const fn to_array(self) -> [u8; 4]
pub const fn to_array(self) -> [u8; 4]
The channels as [r, g, b, a], the same order as surface and texture bytes.
Sourcepub const fn to_packed(self) -> u32
pub const fn to_packed(self) -> u32
Packs the color into a u32 with a fixed layout that does not depend on host byte
order: bits 0-7 red, 8-15 green, 16-23 blue, 24-31 alpha.
Sourcepub const fn from_packed(packed: u32) -> Self
pub const fn from_packed(packed: u32) -> Self
Unpacks a color from the Color::to_packed layout. Every u32 is a valid color.
Trait Implementations§
impl Copy for Color
impl Eq 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§
impl<T> AsId for T
impl<T> AsIdSalt for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more