JFLib

img_jpeg#

JPEG -- crate root lib/img_jpeg/lib.rs

img_jpeg -- JPEG decoder and encoder  [src/img/jpeg_dec.s, jpeg_enc.s, jpeg_dsp.s,
                                       imgcore.s (JPEG parts)]

  decode(data) -> Surface / ERR_*                        jpeg_decode (FMT_PARGB, opaque)
  decode_fl(data, flags) -> Surface / ERR_*              jpeg_decode_fl, JDF_* flags
  decode_abbrev(tables, data, flags) -> Surface / ERR_*  jpeg_decode_abbrev (JPEG-in-TIFF)
  encode(sf, quality) -> file / None                     jpeg_encode
  encode_ex(sf, quality, cfg) -> file / None             jpeg_encode_ex (EncCfg = JENCCFG)
  meta(data, m, flags) -> 0 / ERR_*                      jpeg_meta (also used for BMP's
                                                         embedded JPEG)
  probe / decode_ex / encode_opt                         the codec interface (CODEC)

Modules: dec (jpeg_dec.s), enc (jpeg_enc.s), dsp (jpeg_dsp.s: IDCT / FDCT / colour
conversion / resampling kernels and the tables), glue (imgcore.s: metadata scan, IMGDEC /
IMGOPT glue).

img_jpeg API#

Re-exports: img_core::{JDF_CMYK, JDF_NO_ORIENT, JDF_RAW_CMYK, JDF_RGB, JDF_STRAIGHT, JDF_YCC, JPEG_IOM}

  • fn decode(data: &[u8]) -> Result<Surface, i32> jpeg_decode: decode a JPEG file into a new FMT_PARGB surface

  • static CODEC: Codec the codec descriptor (jpeg_codec); scan / decode_fl / save serve img_core::io's classic paths (img_decode, img_save) and the BMP / TIFF embeddings

From lib/img_jpeg/dec.rs (img_jpeg::dec):

  • fn decode_fl(data: &[u8], flags: u32) -> Result<Surface, i32> jpeg_decode_fl

  • fn decode_fl_max(data: &[u8], flags: u32, maxw: u32, maxh: u32) -> Result<Surface, i32> decode_fl with a limit on the frame size: a larger SOF is ERR_DIMS before any allocation

  • fn decode_abbrev(tables: &[u8], data: &[u8], flags: u32) -> Result<Surface, i32> jpeg_decode_abbrev: an abbreviated image stream (JPEG-in-TIFF strip / tile) with the tables of a tables-only stream (TIFF JPEGTables; empty = none); the orientation is never applied

  • fn decode_abbrev_max(tables: &[u8], data: &[u8], flags: u32, maxw: u32, maxh: u32) -> Result<Surface, i32> decode_abbrev with a limit on the frame size (see decode_fl_max)

From lib/img_jpeg/enc.rs (img_jpeg::enc):

  • struct EncCfg JENCCFG: chroma subsampling 0 (4:4:4 from quality 90, else 4:2:0) / 444 / 422 / 420 / 400; JFIF density unit 0 = keep 96 x 96 dpi, 1 dpi, 2 dots per cm; x / y density 1..65535

    • chroma: u32
    • unit: u32
    • xd: u32
    • yd: u32
  • fn encode(sf: &Surface, quality: i32) -> Option<Vec<u8>> jpeg_encode

  • fn encode_ex(sf: &Surface, quality: i32, cfg: Option<&EncCfg>) -> Option<Vec<u8>> jpeg_encode_ex: jpeg_encode with an EncCfg (None = defaults)

From lib/img_jpeg/glue.rs (img_jpeg::glue):

  • fn meta(data: &[u8], m: &mut ImgMeta, flags: u32) -> i32 jpeg_meta: scan the marker segments up to the first SOS (see the file header)

  • fn probe(data: &[u8], m: &mut ImgMeta) -> bool jpeg_probe: header + metadata scan, no pixels

  • fn decode_ex(data: &[u8], out: &mut Surface, d: &ImgDec, m: &mut ImgMeta) -> i32 jpeg_decode_ex: JPEG through decode_fl, which applies the EXIF orientation itself unless IMGD_NO_ORIENT: IMF_ORIENT_APPLIED is set when it did

  • fn encode_opt(sf: &Surface, opt: &ImgOpt, out: &mut Vec<u8>) -> i32 jpeg_encode_opt: encode_ex with the IMGOPT options and metadata segments (see the file header)

img_jpeg modules#

The codec's building blocks (public for the codec test app codectest; see their source headers):

ModuleContent
img_jpeg::decJPEG decoder
img_jpeg::dspJPEG signal processing kernels and tables (shared by dec / enc)
img_jpeg::encJPEG encoder (baseline JFIF)
img_jpeg::glueJPEG behind the codec interface: metadata scan, IMGDEC / IMGOPT glue

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