JFLib

img_png#

PNG -- crate root lib/img_png/lib.rs

img_png -- the PNG codec                                  [src/img/png.s, imgcore.s PNG parts]

  CODEC                          the codec descriptor (probe / decode_ex / encode_opt; scan,
                                 decode_fl, save for the classic API and BMP's embedded PNG)
  dec::decode_fl(data, sf, jdf)  png_decode_fl (dec.rs: decoder)
  enc::encode_cfg(sf, cfg)       png_encode_cfg (enc.rs: encoder, PngCfg, put_chunk)
  glue::scan / probe / decode_ex / encode_opt   imgcore.s (glue.rs)
  encode(px, w, h, stride, grey) the screenshot writer of ui (--shot): rows of 32-bit
                                 B, G, R, x (RGB) or 8-bit grey -> png_encode's file
  decode_pargb(data)             png_decode: a FMT_PARGB surface or None (the hook of
                                 text::Text::png_decode, CBDT colour glyphs)

img_png API#

  • static CODEC: Codec the PNG codec (png_codec)

  • fn decode_pargb(data: &[u8]) -> Option<Surface> png_decode: the file as a new FMT_PARGB surface, None on any error

  • fn encode(px: &[u8], w: usize, h: usize, stride: usize, grey: bool) -> Vec<u8> the PNG file of w x h pixels: 32-bit B, G, R, x rows (RGB) or, with grey, 8-bit rows; stride = bytes per row (png_encode of an XRGB / A8 surface)

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

  • fn decode_fl(data: &[u8], out: &mut Surface, flags: u32) -> i32 decode a PNG file into a new surface: FMT_PARGB, or FMT_ARGB with JDF_STRAIGHT; on an error out is left as it is [png_decode_fl]

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

/// PngCfg::depth: png_encode's rule (A8 grey, XRGB RGB, else RGB when opaque / RGBA)
PNGD_CLASSIC: u32 = 0xFFFF_FFFF
  • struct PngCfg<'a> the options of encode_cfg (PNGCFG)

    • level: u32 -- deflate level 0..9
    • depth: u32 -- 0 auto / 32 / 24 / 8 / PNGD_CLASSIC
    • qcfg: u32 -- quantize_ex cfg for 8 bit (dither level | threshold << 8)
    • chunks: &'a [u8] -- complete chunks written after IHDR
    • cancel: Option<&'a AtomicU32>
  • fn put_chunk(out: &mut Vec<u8>, typ: &[u8; 4], data: &[u8]) append a chunk: length, type (4 bytes), data, CRC-32 of type + data [png_put_chunk]

  • fn encode_cfg(sf: &Surface, cfg: &PngCfg) -> Result<Vec<u8>, i32> encode sf (FMT_XRGB, PARGB, ARGB or A8) with a PngCfg [png_encode_cfg]

img_png modules#

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

ModuleContent
img_png::decthe PNG decoder
img_png::encthe PNG encoder
img_png::gluePNG behind the codec interface: metadata scanner, probe, decode_ex, encode_opt

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