Struct palette::Packed[][src]

#[repr(C)]
pub struct Packed<C = Argb> { pub color: u32, pub channel_order: PhantomData<C>, }

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

impl<C> Clone for Packed<C>[src]

impl<C: Debug> Debug for Packed<C>[src]

impl<S, C> From<Alpha<Rgb<S, u8>, u8>> for Packed<C> where
    S: RgbStandard,
    C: RgbChannels
[src]

impl<S, C> From<Packed<C>> for Rgb<S, u8> where
    S: RgbStandard,
    C: RgbChannels
[src]

impl<S, C> From<Packed<C>> for Rgba<S, u8> where
    S: RgbStandard,
    C: RgbChannels
[src]

impl<S, C> From<Rgb<S, u8>> for Packed<C> where
    S: RgbStandard,
    C: RgbChannels
[src]

impl<C: RgbChannels> From<u32> for Packed<C>[src]

impl<C: PartialEq> PartialEq<Packed<C>> for Packed<C>[src]

impl<C> Pixel<u32> for Packed<C>[src]

impl<C> Copy for Packed<C>[src]

impl<C: Eq> Eq for Packed<C>[src]

impl<C> StructuralEq for Packed<C>[src]

impl<C> StructuralPartialEq for Packed<C>[src]

Auto Trait Implementations

impl<C> RefUnwindSafe for Packed<C> where
    C: RefUnwindSafe

impl<C> Send for Packed<C> where
    C: Send

impl<C> Sync for Packed<C> where
    C: Sync

impl<C> Unpin for Packed<C> where
    C: Unpin

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>, 
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> IntoColor<U> for T where
    U: FromColor<T>, 
[src]

impl<T, U> IntoColorUnclamped<U> for T where
    U: FromColorUnclamped<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T, U> TryIntoColor<U> for T where
    U: TryFromColor<T>, 
[src]