JFLib

img_bmp#

BMP -- crate root lib/img_bmp/lib.rs

img_bmp -- Windows bitmap (BMP) decoder and encoder, and the BMP parts of the core-format
glue                                             [src/img/bmp.s, src/img/imgcore.s]

  decode(data, sf) -> 0 / ERR_*                  bmp_decode: FMT_PARGB
  decode_fl(data, sf, flags) -> 0 / ERR_*        bmp_decode_fl: JDF_STRAIGHT -> FMT_ARGB
  encode(sf) -> Some(file) / None                bmp_encode (the classic rule)
  encode_cfg(sf, cfg, out) -> 0 / ERR_*          bmp_encode_cfg (BmpCfg = BMPCFG)
  meta(data, meta, flags) -> 0 / ERR_*           bmp_meta (imgcore.s)
  probe(data, meta) -> recognised                bmp_probe
  decode_ex(data, sf, dec, meta) -> 0 / ERR_*    bmp_decode_ex
  encode_opt(sf, opt, out) -> 0 / ERR_*          bmp_encode_opt
  CODEC                                          bmp_codec

Decoder: BITMAPCOREHEADER (12) and BITMAPINFOHEADER..V5 (40..124) headers; 1/4/8-bit palette,
16-bit (default 5-5-5 or bit fields), 24-bit, 32-bit (BI_RGB = opaque, BI_BITFIELDS /
BI_ALPHABITFIELDS with any masks and an optional alpha mask); bottom-up and top-down rows.
Channels narrower than 8 bits are scaled with rounding (v * 255 / max), wider ones keep their
top 8 bits.  Palette indices past the palette give opaque black.
BI_RLE8 / BI_RLE4: encoded runs, absolute runs (word aligned), end of line, end of bitmap,
delta; pixels the stream skips (delta, early end of line / bitmap, data that ends early) stay
transparent; runs past the right edge are clipped, everything is bounds-checked.  BI_JPEG /
BI_PNG: the embedded file (bfOffBits, biSizeImage bytes or up to the end of the data) is
decoded by img_jpeg / img_png (the flags are passed on).  OS/2 2.x (64-byte header) Huffman
1D and RLE24, CMYK and other compressions: ERR_UNSUPPORTED.  Result: FMT_PARGB surface, or
FMT_ARGB with JDF_STRAIGHT (the file's straight values: colour kept at alpha 0).

Encoder (encode): 24-bit BI_RGB when the surface is opaque (XRGB, all-opaque PARGB / ARGB,
A8 as grey), else 32-bit BITMAPV4HEADER with BI_BITFIELDS and an alpha mask (straight alpha).
Rows bottom-up, 72 dpi.  encode_cfg with a BmpCfg: depth 0 auto (not opaque -> 32; opaque
with <= 256 colours -> exact 8-bit palette; else 24), 32, 24 (colour composited over white),
8 (quantize_ex with qcfg's dither level, over white: BMP palettes have no alpha),
BMPD_CLASSIC (encode's rule); ppmx / ppmy pixels per metre (0 = 2835, 72 dpi).

Metadata (bmp_meta): header (size, depth, compression, alpha mask), pels per metre -> dpi,
V4/V5 colour space (sRGB flag, embedded profile for IMGD_ICC); BI_JPEG / BI_PNG: the embedded
file's own header (size, depth, model, channels, alpha / lossless / interlace / HDR flags).

img_bmp API#

BMPD_CLASSIC: u32 = 0xFFFF_FFFF  // BmpCfg::depth: encode's rule
  • static CODEC: Codec bmp_codec

  • struct BmpCfg<'a> encoder options (BMPCFG)

    • depth: u32 -- 0 auto / 32 / 24 / 8 / BMPD_CLASSIC
    • qcfg: u32 -- quantize_ex cfg for 8 bit (IQF_WHITE is added)
    • ppmx: u32 -- pixels per metre (0 = 2835, 72 dpi)
    • ppmy: u32
    • cancel: Option<&'a AtomicU32>
  • fn decode(data: &[u8], sf: &mut Surface) -> i32 bmp_decode: a BMP file as a new FMT_PARGB surface (sf is replaced; untouched on error)

  • fn decode_fl(d: &[u8], sf: &mut Surface, flags: u32) -> i32 bmp_decode_fl: bmp_decode with JDF_* flags (JDF_STRAIGHT: FMT_ARGB output; passed on to an embedded JPEG / PNG)

  • fn encode(sf: &Surface) -> Option<Vec<u8>> bmp_encode: BMP file, 24-bit when opaque, else 32-bit BITMAPV4HEADER with alpha (straight)

  • fn encode_cfg(sf: &Surface, cfg: &BmpCfg, out: &mut Vec<u8>) -> i32 bmp_encode_cfg: encode sf (FMT_XRGB, FMT_PARGB, FMT_ARGB or FMT_A8) with a BmpCfg (see the module header); out is empty on error. Errors: ERR_DIMS, ERR_UNSUPPORTED (surface format), ERR_NOMEM (8-bit quantization failed), ERR_CANCEL

  • fn meta(d: &[u8], m: &mut ImgMeta, flags: u32) -> i32 bmp_meta: file and info header -> 0 / ERR_TRUNC / ERR_HDR (see the module header)

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

  • fn decode_ex(data: &[u8], sf: &mut Surface, dec: &ImgDec, m: &mut ImgMeta) -> i32 bmp_decode_ex: BMP through decode_fl (core_decode: the metadata scan, IMGD_PROBE, frame 0 only, the size check, the cancel flag)

  • fn encode_opt(sf: &Surface, opt: &ImgOpt, out: &mut Vec<u8>) -> i32 bmp_encode_opt: encode_cfg with ImgOpt::bitdepth (0 / 32 / 24 / 8), ImgOpt::dither (8 bit) and the pixels per metre of ImgOpt::meta's dpi (none: 72 dpi)

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