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 Errorwhy a file could not be decodedNotJpeg2000-- neither a JP2 file nor a codestreamTruncated-- the headers end earlyCorrupt-- a header that breaks the standardUnsupported-- valid, but not decoded here (Part 2, more than 24 bits)Limit-- larger than the limits allow
struct Optionswhat to decodereduce: 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, withColor::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 beyondmax_pixels; the structures of a tile then stay within the size of the samples, at least 64 MB)
enum Colorthe colour space the JP2 header names (Unknown for a raw codestream)UnknownGraySrgb-- sRGB (also sYCC after the conversion here)CmykLab-- CIELab (the enumerated space of JPX)Icc(Vec<u8>)-- an ICC profile
struct Componentone component (channel) of the imagewidth: u32height: u32dx: u32-- its sub-sampling on the image griddy: u32precision: u8signed: booldata: Vec<i32>-- width * height samples, row by row (unsigned: 0 .. 2^precision - 1)
struct Imagea decoded image: the colour channels first, in their order, then the opacity channelwidth: u32height: u32components: Vec<Component>color: Coloralpha: Option<usize>-- the index of the opacity channelpremultiplied: bool-- the colour channels are premultiplied by the opacity
fn probe(d: &[u8]) -> boola JP2 file or a raw codestreamfn decode(d: &[u8], opt: &Options) -> Result<Image, Error>decode a JP2 / JPX file or a raw codestreamstatic CODEC: Codecjp2_codec: JP2, JPX and raw codestreams as 8-bit ARGB