Struct palette::Packed [−][src]
#[repr(C)]pub struct Packed<C = Argb> { pub color: u32, pub channel_order: PhantomData<C>, }
Expand description
RGBA color packed into a 32-bit unsigned integer. Defaults to ARGB
ordering for Rgb
types and RGBA ordering for Rgba
types.
Packed integer type represented in u32
. Two hexadecimal digits (8-bits)
express each value of the Red, Green, Blue, and Alpha components in the
RGBA color.
Note that conversion from float to integer component types in palette
rounds to nearest even: an Rgb
component of 0.5
will convert to
0x80
/128
, not 0x7F
/127
.
use approx::assert_relative_eq; use palette::{Packed, Srgb, Srgba}; use palette::rgb::channels::{Argb, Rgba}; let packed: Packed = Srgb::new(0.5, 0.0, 0.5).into_format().into(); assert_eq!(0xFF80_0080, packed.color); let unpacked: Srgba<u8> = Packed::<Rgba>::from(0xFFFF_FF80).into(); assert_relative_eq!( Srgba::new(1.0, 1.0, 1.0, 0.5), unpacked.into_format(), epsilon = 0.01 ); // By default, `Packed` uses `Argb` order for creating `Rgb` colors to make // entering 6-digit hex numbers more convenient let rgb = Srgb::from(0xFF8000); assert_eq!(Srgb::new(0xFF, 0x80, 0x00), rgb); let rgba = Srgba::from(0xFF80007F); assert_eq!(Srgba::new(0xFF, 0x80, 0x00, 0x7F), rgba);
When an Rgb
type is packed, the alpha value will be 0xFF
in the
corresponding u32
. Converting from a packed color type back to an Rgb
type will disregard the alpha value.
Packed
implements Pixel and can be
constructed from a slice of &[u32]
.
use palette::{Packed, Pixel}; use palette::rgb::channels::Argb; let raw = &[0x7F0080u32, 0x60BBCC]; let colors = Packed::<Argb>::from_raw_slice(raw); assert_eq!(colors.len(), 2); assert_eq!(colors[0].color, 0x7F0080); assert_eq!(colors[1].color, 0x60BBCC);
Fields
color: u32
The sRGB color packed into a u32
.
channel_order: PhantomData<C>
The channel ordering for red, green, blue, and alpha components in the
packed integer; can be Abgr
, Argb
, Bgra
, or Rgba
. See
RgbChannels.
Trait Implementations
Cast as a mutable reference to raw color components.
Convert into raw color components.
Cast from a reference to raw color components.
Cast from a mutable reference to raw color components.
Cast a slice of raw color components to a slice of colors. Read more
Cast a mutable slice of raw color components to a mutable slice of colors. Read more
Cast a slice of colors to a slice of raw color components. Read more
Cast a mutable slice of colors to a mutable slice of raw color components. Read more
Auto Trait Implementations
impl<C> RefUnwindSafe for Packed<C> where
C: RefUnwindSafe,
impl<C> UnwindSafe for Packed<C> where
C: UnwindSafe,
Blanket Implementations
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
T: FloatComponent,
Swp: WhitePoint,
Dwp: WhitePoint,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
T: FloatComponent,
Swp: WhitePoint,
Dwp: WhitePoint,
D: AdaptFrom<S, Swp, Dwp, T>,
Mutably borrows from an owned value. Read more
Convert into T with values clamped to the color defined bounds Read more
Convert into T. The resulting color might be invalid in its color space Read more
Convert into T, returning ok if the color is inside of its defined
range, otherwise an OutOfBounds
error is returned which contains
the unclamped color. Read more