Struct palette::rgb::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> Clone for Packed<C>
[src]fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<S, C> From<Alpha<Rgb<S, u8>, u8>> for Packed<C> where
S: RgbStandard,
C: RgbChannels,
[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 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<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<S, C> From<Rgb<S, u8>> for Packed<C> where
S: RgbStandard,
C: RgbChannels,
[src]impl<C> Pixel<u32> for Packed<C>
[src]
impl<C> Pixel<u32> for Packed<C>
[src]const CHANNELS: usize
[src]
fn as_raw<P: RawPixel<T> + ?Sized>(&self) -> &P
[src]
fn as_raw_mut<P: RawPixel<T> + ?Sized>(&mut self) -> &mut P
[src]
fn into_raw<P: RawPixelSized<T>>(self) -> P
[src]
fn from_raw<P: RawPixel<T> + ?Sized>(pixel: &P) -> &Self
[src]
fn from_raw_mut<P: RawPixel<T> + ?Sized>(pixel: &mut P) -> &mut Self
[src]
fn from_raw_slice(slice: &[T]) -> &[Self]
[src]
fn from_raw_slice_mut(slice: &mut [T]) -> &mut [Self]
[src]
fn into_raw_slice(slice: &[Self]) -> &[T]
[src]
fn into_raw_slice_mut(slice: &mut [Self]) -> &mut [T]
[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,
C: RefUnwindSafe,
impl<C> Send for Packed<C> where
C: Send,
C: Send,
impl<C> Sync for Packed<C> where
C: Sync,
C: Sync,
impl<C> Unpin for Packed<C> where
C: Unpin,
C: Unpin,
impl<C> UnwindSafe for Packed<C> where
C: UnwindSafe,
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<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]pub fn adapt_into_using<M>(Self, M) -> D where
M: TransformMatrix<Swp, Dwp, T>,
[src]
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into(self) -> D
[src]
impl<T, U> IntoColor<U> for T where
U: FromColor<T>,
[src]
impl<T, U> IntoColor<U> for T where
U: FromColor<T>,
[src]pub fn into_color(Self) -> U
[src]
impl<T, U> IntoColorUnclamped<U> for T where
U: FromColorUnclamped<T>,
[src]
impl<T, U> IntoColorUnclamped<U> for T where
U: FromColorUnclamped<T>,
[src]pub fn into_color_unclamped(Self) -> U
[src]
impl<T, U> TryIntoColor<U> for T where
U: TryFromColor<T>,
[src]
impl<T, U> TryIntoColor<U> for T where
U: TryFromColor<T>,
[src]