JFLib

img_jp2#

JPEG 2000 decoder -- crate root lib/img_jp2/src/lib.rs

img_jp2 -- JPEG 2000 decoder (ITU-T T.800 | ISO/IEC 15444-1, the JP2 file format and the parts
of JPX that JP2 readers meet)

  decode(data, &Options) -> Result<Image, Error>   a JP2 / JPX file or a raw codestream (J2K, J2C)
  probe(data) -> bool                         the JP2 signature or the start of a codestream
  Image { width, height, components, color, alpha, premultiplied }
  Component { width, height, dx, dy, precision, signed, data }   samples, row by row
  CODEC                                       img_core's codec (8-bit ARGB surfaces) for img_all;
                                              CIELab files are ERR_UNSUPPORTED there

Modules: boxes (the JP2 boxes), codestream (the markers), tile (geometry, packets, progression,
dequantisation, assembly), t1 (the code-blocks), mq (the arithmetic decoder), dwt (the wavelets).

What it decodes: every progression order and POC, tiles and tile-parts in any order, precincts,
layers, SOP / EPH, PPM / PPT, every code-block style (bypass, reset, terminate-all, vertically
causal, predictable termination, segmentation symbols), ROI max-shift, the 5/3 and 9/7 wavelets
with any image and tile offsets, RCT and ICT, sub-sampled components, precision 1 to 24 bits,
signed and unsigned.  From the JP2 header: the colour space (enumerated sRGB, greyscale, sYCC,
CMYK, CIELab; an ICC profile), the palette with its component mapping (applied here) and the
channel definitions (colour channels in their order, the opacity channel).  sYCC is converted to
RGB here (unless `Options::convert_sycc` is false).  `Options::reduce` decodes a lower
resolution (each level halves the size).

Not here: Part 2 (other wavelets, multiple-component transforms beyond RCT / ICT, trellis
quantisation), precision above 24 bits.  A file that is cut short gives what was decoded up to
there (like the common readers); limits (`Options::max_pixels` also for the channels a palette
makes, tiles times components, code-blocks, precincts, the packets and the layer-resolution
passes the progression looks at, the bytes a tile's structures hold, `Options::max_mem` for all
of it) refuse hostile files before they cost memory or time.

img_jp2 crate root#

  • enum Error why a file could not be decoded

    • NotJpeg2000 -- neither a JP2 file nor a codestream
    • Truncated -- the headers end early
    • Corrupt -- a header that breaks the standard
    • Unsupported -- valid, but not decoded here (Part 2, more than 24 bits)
    • Limit -- larger than the limits allow
  • struct Options what to decode

    • reduce: u8 -- resolution levels to leave out (each halves width and height)
    • max_pixels: u64 -- the largest width * height (the default: img_core's IMG_MAXPX_DEF)
    • convert_sycc: bool -- convert sYCC to sRGB (the default); false leaves the components as they are coded, with Color::Unknown (a reader that takes the colour space from elsewhere, like PDF)
    • max_mem: u64 -- the most bytes the decode may hold at once: the samples, a tile's planes and its structures (0, the default: no limit beyond max_pixels; the structures of a tile then stay within the size of the samples, at least 64 MB)
  • enum Color the colour space the JP2 header names (Unknown for a raw codestream)

    • Unknown
    • Gray
    • Srgb -- sRGB (also sYCC after the conversion here)
    • Cmyk
    • Lab -- CIELab (the enumerated space of JPX)
    • Icc(Vec<u8>) -- an ICC profile
  • struct Component one component (channel) of the image

    • width: u32
    • height: u32
    • dx: u32 -- its sub-sampling on the image grid
    • dy: u32
    • precision: u8
    • signed: bool
    • data: Vec<i32> -- width * height samples, row by row (unsigned: 0 .. 2^precision - 1)
  • struct Image a decoded image: the colour channels first, in their order, then the opacity channel

    • width: u32
    • height: u32
    • components: Vec<Component>
    • color: Color
    • alpha: Option<usize> -- the index of the opacity channel
    • premultiplied: bool -- the colour channels are premultiplied by the opacity
  • fn probe(d: &[u8]) -> bool a JP2 file or a raw codestream

  • fn decode(d: &[u8], opt: &Options) -> Result<Image, Error> decode a JP2 / JPX file or a raw codestream

  • static CODEC: Codec jp2_codec: JP2, JPX and raw codestreams as 8-bit ARGB

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