Expand description
A JPEG decoder that reproduces libjpeg(-turbo)’s output byte for byte —
what pdfium’s DCTDecode produces (core/fxcodec/jpeg, libjpeg at its
defaults: the JDCT_ISLOW integer IDCT, “fancy” triangle-filter chroma
upsampling, the 16.16 fixed-point YCbCr→RGB tables of jdcolor.c).
Neither pure-Rust decoder in the dependency tree matches those bytes:
zune-jpeg (the image crate’s) rounds its upsampler and colour
conversion differently, jpeg-decoder carries stb_image’s +8/+8 h2v2
filter where libjpeg alternates +8/+7 and a float-derived colour
conversion. The pixel differences are ±1, invisible — and exactly what a
byte-for-byte oracle against pdfium’s raster cannot tolerate. So this is a
deliberately small decoder: baseline and progressive Huffman, 8-bit,
1 or 3 components, restart intervals, and libjpeg’s 1/2, 1/4, 1/8
DCT-scaled output (jidctred.c’s 4×4/2×2/1×1 transforms with
jdmaster.c’s per-component scaling and the scaled upsampler rules);
everything else (arithmetic coding, 12-bit, lossless, CMYK/YCCK, DNL) is
reported as unsupported and the page stays with pdfium. Checked against
Pillow’s libjpeg-turbo on docling-pdf’s tests/data/jpeg/ fixtures
(raster::jpeg_tests::matches_libjpeg_on_the_fixtures).
It lives in docling-core because Pillow decodes with the same libjpeg:
besides docling-pdf’s raster/renderer (which re-export it), the DocLang
serializer hashes a JPEG picture’s decoded pixels to name its asset the
way docling does (pixel_digest.rs).
Structs§
- Image
- A decoded image:
channelsis 1 (gray) or 3 (RGB, or the raw component triplets when no colour transform applies), rows ofwidthpixels. - Info
- Header facts the caller needs before decoding.
Enums§
Functions§
- decode
- Decode
dataat1/scale_denom(1, 2, 4 or 8 — libjpeg’s DCT scaling, which pdfium requests for an image at least twice the bitmap’s size:resolution_levels_to_skip); the output isceil(w/scale_denom)×ceil(h/scale_denom).color_transformis the PDF’s/ColorTransformdecode parameter (default 1), which pdfium forces on when an Adobe marker is present and otherwise uses to decide whether a 3-component image is converted from YCbCr or handed over raw. - info
- Read the frame header only.