Skip to main content

encode_context_map

Function encode_context_map 

Source
pub fn encode_context_map(
    context_map: &[u8],
    num_histograms: usize,
    writer: &mut BitWriter,
) -> Result<()>
Expand description

Encode context map to bitstream.

The context map maps context indices to histogram indices.

§Current Implementation

Uses simple encoding only, which supports up to 8 histograms (3 bits per entry). This is sufficient for reasonable clustering without the complexity of implementing the full ANS entropy bundle format for context maps.

§Encoding Format

  • If num_histograms == 1: write (1, 0) → no actual entries needed
  • Simple mode: write (1, entry_bits) then each entry with entry_bits bits

§Future Work

To support >8 histograms with efficient encoding, implement the full JXL entropy bundle format for context maps (is_simple=0 path). This requires:

  • lz77.enabled flag
  • Full histogram bundle with ANS/prefix codes
  • HybridUint encoding for symbols

Reference: libjxl lib/jxl/enc_context_map.cc