JFLib

img_core/bits.rs#

Source: lib/img_core/bits.rs

bits -- the bit readers of the codecs (MSB-first and LSB-first)  [ASMLIB/inc/img_int.inc]

  BrM (MSB first: JPEG entropy data without stuffing, HEVC, AV1 headers, JXR)
  BrL (LSB first: deflate, VP8L, JPEG XL)
  r = BrX::new(data, pos); r.refill(); r.get(n) / r.peek(n) / r.skip(n); r.overrun()

The state of the assembly macros: a 64-bit buffer, a bit count and a byte position that
keeps counting past the end of the data (zero bytes are shifted in there, nothing is
read).  After refill() at least 56 bits are available.  overrun() is BRx_OVERRUN: more
zero padding bytes consumed than bits are left.  Values of n: 1..56 (get / peek / skip).
  • struct BrM<'a> MSB-first reader (BRM_*)
    • data: &'a [u8]
    • buf: u64
    • cnt: u32
    • pos: usize -- may pass data.len()

impl<'a> BrM<'a>

  • fn new(data: &'a [u8], pos: usize) -> Self BRM_INIT with the byte position pos

  • fn refill(&mut self) BRM_REFILL: at least 56 bits in the buffer

  • fn peek(&self, n: u32) -> u64 BRM_PEEK: the next n bits

  • fn skip(&mut self, n: u32) BRM_SKIP

  • fn get(&mut self, n: u32) -> u64 BRM_GET / BRM_GETV

  • fn overrun(&self) -> bool BRM_OVERRUN: true when more padding bytes were consumed than bits are left

  • struct BrL<'a> LSB-first reader (BRL_*)

    • data: &'a [u8]
    • buf: u64
    • cnt: u32
    • pos: usize -- may pass data.len()

impl<'a> BrL<'a>

  • fn new(data: &'a [u8], pos: usize) -> Self BRL_INIT with the byte position pos
  • fn refill(&mut self) BRL_REFILL: at least 56 bits in the buffer
  • fn peek(&self, n: u32) -> u64 BRL_PEEK: the next n bits
  • fn skip(&mut self, n: u32) BRL_SKIP
  • fn get(&mut self, n: u32) -> u64 BRL_GET / BRL_GETV
  • fn overrun(&self) -> bool BRL_OVERRUN

Source: docs/API.md in the JFLib repository.