#image-format #codec #format #decoding #image #encoding #graphics

nightly pnm

portable anymap format encoding and decoding

1 unstable release

0.1.0 Mar 15, 2024

#107 in #image-format

MIT license

47KB
1K SLoC

PNM

provides encoders and decoders for the portable anymap formats.

Warning 16 bit images are not supported.

pnm format depth support table

PBM PGM PPM PAM
Y
YA
RGB
RGBA

lib.rs:

crate for decoding/encoding the portable anymap format.

a quick guide to the various functions for everyday use

  • [decode()]: your go-to for all PNM image decoding. If you have a specific format you need to support, use its module directly. Note that this function reads both plain and raw formats.
  • [encode()]: this function is a little tricky. It supports the "older" PNM formats, and, due to their age they do not support the alpha channels existence. If possible, use pam::encode instead.
  • encode_plain: The PAM format doesnt actually support read-age-by-humans, so this is still useful at times. Outputs data in decimal digits.

functions in action

let data = include_bytes!("../tdata/fimg-rainbowR.ppm");
let out = pnm::decode(data).unwrap();

assert_eq!(pnm::encode(out), data);

Dependencies

~335KB