jxl_bitstream/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! This crate provides a JPEG XL bitstream reader. The bitstream reader supports both bare codestream
//! and container format, and it can detect which format to read.

mod bitstream;
pub mod container;
mod error;

pub use bitstream::{Bitstream, U32Specifier, U};
pub use container::{BitstreamKind, ContainerDetectingReader, ParseEvent};
pub use error::{Error, Result};

/// Perform `UnpackSigned` for `u32`, as specified in the JPEG XL specification.
#[inline]
pub fn unpack_signed(x: u32) -> i32 {
    let bit = x & 1;
    let base = x >> 1;
    let flip = 0u32.wrapping_sub(bit);
    (base ^ flip) as i32
}

/// Perform `UnpackSigned` for `u64`, as specified in the JPEG XL specification.
#[inline]
pub fn unpack_signed_u64(x: u64) -> i64 {
    let bit = x & 1;
    let base = x >> 1;
    let flip = 0u64.wrapping_sub(bit);
    (base ^ flip) as i64
}