#[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
sourceimpl<S, C> From<Alpha<Rgb<S, u8>, u8>> for Packed<C> where
S: RgbStandard,
C: RgbChannels,
impl<S, C> From<Alpha<Rgb<S, u8>, u8>> for Packed<C> where
S: RgbStandard,
C: RgbChannels,
sourceimpl<S, C> From<Packed<C>> for Rgb<S, u8> where
S: RgbStandard,
C: RgbChannels,
impl<S, C> From<Packed<C>> for Rgb<S, u8> where
S: RgbStandard,
C: RgbChannels,
sourceimpl<S, C> From<Packed<C>> for Rgba<S, u8> where
S: RgbStandard,
C: RgbChannels,
impl<S, C> From<Packed<C>> for Rgba<S, u8> where
S: RgbStandard,
C: RgbChannels,
sourceimpl<S, C> From<Rgb<S, u8>> for Packed<C> where
S: RgbStandard,
C: RgbChannels,
impl<S, C> From<Rgb<S, u8>> for Packed<C> where
S: RgbStandard,
C: RgbChannels,
sourceimpl<C: RgbChannels> From<u32> for Packed<C>
impl<C: RgbChannels> From<u32> for Packed<C>
sourceimpl<C> Pixel<u32> for Packed<C>
impl<C> Pixel<u32> for Packed<C>
sourcefn as_raw_mut<P: RawPixel<T> + ?Sized>(&mut self) -> &mut P
fn as_raw_mut<P: RawPixel<T> + ?Sized>(&mut self) -> &mut P
Cast as a mutable reference to raw color components.
sourcefn into_raw<P: RawPixelSized<T>>(self) -> P
fn into_raw<P: RawPixelSized<T>>(self) -> P
Convert into raw color components.
sourcefn from_raw<P: RawPixel<T> + ?Sized>(pixel: &P) -> &Self
fn from_raw<P: RawPixel<T> + ?Sized>(pixel: &P) -> &Self
Cast from a reference to raw color components.
sourcefn from_raw_mut<P: RawPixel<T> + ?Sized>(pixel: &mut P) -> &mut Self
fn from_raw_mut<P: RawPixel<T> + ?Sized>(pixel: &mut P) -> &mut Self
Cast from a mutable reference to raw color components.
sourcefn from_raw_slice(slice: &[T]) -> &[Self]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
fn from_raw_slice(slice: &[T]) -> &[Self]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
Cast a slice of raw color components to a slice of colors. Read more
sourcefn from_raw_slice_mut(slice: &mut [T]) -> &mut [Self]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
fn from_raw_slice_mut(slice: &mut [T]) -> &mut [Self]ⓘNotable traits for &[u8]impl<'_> Read for &[u8]impl<'_> Write for &mut [u8]
Cast a mutable slice of raw color components to a mutable slice of colors. Read more
impl<C> Copy for Packed<C>
impl<C: Eq> Eq for Packed<C>
impl<C> StructuralEq for Packed<C>
impl<C> StructuralPartialEq for Packed<C>
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
sourceimpl<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>,
sourcefn adapt_into_using<M>(self, method: M) -> D where
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into_using<M>(self, method: M) -> D where
M: TransformMatrix<Swp, Dwp, T>,
Convert the source color to the destination color using the specified method Read more
sourcefn adapt_into(self) -> D
fn adapt_into(self) -> D
Convert the source color to the destination color using the bradford method by default Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T, U> IntoColor<U> for T where
U: FromColor<T>,
impl<T, U> IntoColor<U> for T where
U: FromColor<T>,
sourcefn into_color(self) -> U
fn into_color(self) -> U
Convert into T with values clamped to the color defined bounds Read more
sourceimpl<T, U> IntoColorUnclamped<U> for T where
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for T where
U: FromColorUnclamped<T>,
sourcefn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Convert into T. The resulting color might be invalid in its color space Read more
sourceimpl<T, U> TryIntoColor<U> for T where
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for T where
U: TryFromColor<T>,
sourcefn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
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