Skip to main content

BitPacking

Enum BitPacking 

Source
#[non_exhaustive]
pub enum BitPacking { Full, Lsb { bits: NonZero<u8>, }, Msb { bits: NonZero<u8>, }, Shifted { bits: NonZero<u8>, shift: NonZero<u8>, }, Bitfields { bits: [u8; 4], shifts: [u8; 4], }, }
Expand description

Full re-export of zenpixels core types (zero module name collisions!). Bit-level packing of integer codes inside storage words.

Ordinary full-width samples use BitPacking::Full. Codec-native 10/12-bit codes inside U16 words (such as P010 or HEIF/AVIF 10-bit planes) and bitfield words such as RGB565 or RGB10A1 are first-class storage descriptions rather than a separate buffer universe.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Full

All bits of each SampleType word hold the channel value (0..=255 in U8, 0..=65535 in U16).

§

Lsb

Right-aligned bits-wide unsigned code in each U8/U16/U32 sample (unused high bits ignored on read).

Fields

§bits: NonZero<u8>

Significant bit depth (1..=8 for U8, 1..=16 for U16, 1..=31 for U32).

§

Msb

Left-aligned bits-wide unsigned code in each U8/U16/U32 sample (e.g., P010: 10-bit code shifted left by 6).

Fields

§bits: NonZero<u8>

Significant bit depth (1..=8 for U8, 1..=16 for U16, 1..=31 for U32).

§

Shifted

Strictly interior bit-shifted bits-wide unsigned code sitting at bit offset shift >= 1 in each U8/U16/U32 sample (bits + shift < sample.bits(); use Self::Lsb for shift == 0 and Self::Msb for bits + shift == sample.bits()).

Fields

§bits: NonZero<u8>

Significant bit depth (1..=8 for U8, 1..=16 for U16, 1..=31 for U32).

§shift: NonZero<u8>

Number of low padding bits below the code (>= 1).

§

Bitfields

Multiple channels bit-packed into a single SampleType word (e.g. RGB565 in U16, RGB10A1 in U32).

Fields

§bits: [u8; 4]

Bit widths per channel (0 for unused slots).

§shifts: [u8; 4]

Right-shift from bit 0 for each channel.

Implementations§

Source§

impl BitPacking

Source

pub const P010: BitPacking

P010 / 10-bit MSB-aligned code in U16 (code sits in bits 6..16).

Source

pub const U10_LSB: BitPacking

10-bit LSB-aligned code in U16 (code sits in bits 0..10).

Source

pub const U12_LSB: BitPacking

12-bit LSB-aligned code in U16 (code sits in bits 0..12).

Source

pub const RGB565: BitPacking

16-bit RGB565: R in 11..16, G in 5..11, B in 0..5.

Source

pub const RGB10A2: BitPacking

32-bit RGB10A2: R in 0..10, G in 10..20, B in 20..30, A in 30..32.

Source

pub const fn lsb(bits: u8) -> Option<BitPacking>

Construct Self::Lsb from a non-zero bit depth, returning None if bits == 0.

Source

pub const fn msb(bits: u8) -> Option<BitPacking>

Construct Self::Msb from a non-zero bit depth, returning None if bits == 0.

Source

pub const fn shifted(bits: u8, shift: u8) -> Option<BitPacking>

Construct Self::Shifted from non-zero bits and shift, returning None if either is 0.

Source

pub const fn canonicalize(self, sample: SampleType) -> BitPacking

Fold equivalent representations into canonical form for sample:

  • Lsb { bits == word_bits } and Msb { bits == word_bits } → Self::Full
  • Shifted { bits, shift } with bits + shift == word_bits → Self::Msb
Source

pub const fn is_full(self) -> bool

Whether every bit of every sample word is a full-width value.

Source

pub const fn is_packed_word(self) -> bool

Whether multiple channels share one storage word (Bitfields).

Source

pub const fn validate( self, sample: SampleType, channels: usize, ) -> Result<(), LayoutError>

Validate that this packing fits inside sample, is canonical, and matches channels.

Source

pub const fn extract_code( self, sample: SampleType, component: usize, word: u32, ) -> u32

Extract the unsigned integer code for component from a u32-widened word.

Source

pub const fn pack_code( self, sample: SampleType, component: usize, code: u32, ) -> u32

Pack an unsigned integer code into its bit position for component.

Source

pub const fn max_code(self, sample: SampleType, component: usize) -> u32

Maximum representable unsigned code for component under this packing.

Trait Implementations§

Source§

impl Clone for BitPacking

Source§

fn clone(&self) -> BitPacking

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for BitPacking

Source§

impl Debug for BitPacking

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for BitPacking

Source§

fn default() -> BitPacking

Returns the “default value” for a type. Read more
Source§

impl Eq for BitPacking

Source§

impl Hash for BitPacking

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for BitPacking

Source§

fn eq(&self, other: &BitPacking) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BitPacking

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.