jxl_bitstream/lib.rs
1//! This crate provides a JPEG XL bitstream reader and container format parser.
2//!
3//! # Bitstream reader
4//!
5//! [`Bitstream`] reads all the raw bits needed to decode JPEG XL codestream. It provides methods
6//! to read data types that appear on the JPEG XL specification.
7//!
8//! # Container parser
9//!
10//! [`ContainerParser`] tries to parse the bytes fed into it, and emits various parser events
11//! including codestream data and auxiliary box data.
12
13mod bitstream;
14pub mod consts;
15pub mod container;
16mod error;
17
18pub use bitstream::{Bitstream, U, U32Specifier};
19pub use container::{BitstreamKind, ContainerParser, ParseEvent};
20pub use error::{BitstreamResult, Error};
21
22/// Perform `UnpackSigned` for `u32`, as specified in the JPEG XL specification.
23#[inline]
24pub fn unpack_signed(x: u32) -> i32 {
25 let bit = x & 1;
26 let base = x >> 1;
27 let flip = 0u32.wrapping_sub(bit);
28 (base ^ flip) as i32
29}
30
31/// Perform `UnpackSigned` for `u64`, as specified in the JPEG XL specification.
32#[inline]
33pub fn unpack_signed_u64(x: u64) -> i64 {
34 let bit = x & 1;
35 let base = x >> 1;
36 let flip = 0u64.wrapping_sub(bit);
37 (base ^ flip) as i64
38}