#[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
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).
Msb
Left-aligned bits-wide unsigned code in each U8/U16/U32 sample (e.g., P010: 10-bit code shifted left by 6).
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
Bitfields
Multiple channels bit-packed into a single SampleType word (e.g. RGB565 in U16, RGB10A1 in U32).
Implementations§
Source§impl BitPacking
impl BitPacking
Sourcepub const P010: BitPacking
pub const P010: BitPacking
P010 / 10-bit MSB-aligned code in U16 (code sits in bits 6..16).
Sourcepub const U10_LSB: BitPacking
pub const U10_LSB: BitPacking
10-bit LSB-aligned code in U16 (code sits in bits 0..10).
Sourcepub const U12_LSB: BitPacking
pub const U12_LSB: BitPacking
12-bit LSB-aligned code in U16 (code sits in bits 0..12).
Sourcepub const RGB565: BitPacking
pub const RGB565: BitPacking
16-bit RGB565: R in 11..16, G in 5..11, B in 0..5.
Sourcepub const RGB10A2: BitPacking
pub const RGB10A2: BitPacking
32-bit RGB10A2: R in 0..10, G in 10..20, B in 20..30, A in 30..32.
Sourcepub const fn lsb(bits: u8) -> Option<BitPacking>
pub const fn lsb(bits: u8) -> Option<BitPacking>
Construct Self::Lsb from a non-zero bit depth, returning None if bits == 0.
Sourcepub const fn msb(bits: u8) -> Option<BitPacking>
pub const fn msb(bits: u8) -> Option<BitPacking>
Construct Self::Msb from a non-zero bit depth, returning None if bits == 0.
Sourcepub const fn shifted(bits: u8, shift: u8) -> Option<BitPacking>
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.
Sourcepub const fn canonicalize(self, sample: SampleType) -> BitPacking
pub const fn canonicalize(self, sample: SampleType) -> BitPacking
Fold equivalent representations into canonical form for sample:
Lsb { bits == word_bits }andMsb { bits == word_bits }→Self::FullShifted { bits, shift }withbits + shift == word_bits→Self::Msb
Sourcepub const fn is_full(self) -> bool
pub const fn is_full(self) -> bool
Whether every bit of every sample word is a full-width value.
Sourcepub const fn is_packed_word(self) -> bool
pub const fn is_packed_word(self) -> bool
Whether multiple channels share one storage word (Bitfields).
Sourcepub const fn validate(
self,
sample: SampleType,
channels: usize,
) -> Result<(), LayoutError>
pub const fn validate( self, sample: SampleType, channels: usize, ) -> Result<(), LayoutError>
Validate that this packing fits inside sample, is canonical, and matches channels.
Sourcepub const fn extract_code(
self,
sample: SampleType,
component: usize,
word: u32,
) -> u32
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.
Sourcepub const fn pack_code(
self,
sample: SampleType,
component: usize,
code: u32,
) -> u32
pub const fn pack_code( self, sample: SampleType, component: usize, code: u32, ) -> u32
Pack an unsigned integer code into its bit position for component.
Sourcepub const fn max_code(self, sample: SampleType, component: usize) -> u32
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
impl Clone for BitPacking
Source§fn clone(&self) -> BitPacking
fn clone(&self) -> BitPacking
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more