Expand description
Image encoding — write a raster::Bitmap<P> to PPM, PGM, PBM, and PNG.
§Supported formats
| Function | Format | Accepted pixel types |
|---|---|---|
write_ppm | Netpbm P6 binary | Rgb8, Bgr8, Rgba8 (Xbgr8), Cmyk8, DeviceN8 |
write_pgm | Netpbm P5 binary | Gray8 |
write_pbm | Netpbm P4 binary | Gray8 (0 = white, non-zero = black) |
write_png | PNG | Rgb8, Gray8, Rgba8 |
All functions consume the output sink (W: Write). Wrap in
std::io::BufWriter at the call site if buffering is needed.
§CMYK handling
Neither PPM nor PNG natively supports CMYK. write_ppm converts
CMYK/DeviceN to RGB via the naïve subtractive ink-density formula
R = 255 − C − K (PDF §10.3.3). For ICC-accurate colour, convert to
Rgb8 before encoding.
Re-exports§
Modules§
- pbm
- Netpbm P4 (binary PBM) encoder.
- pgm
- Netpbm P5 (binary PGM) encoder.
- png
- PNG encoder (via the
pngcrate). - ppm
- Netpbm P6 (binary PPM) encoder.
Enums§
- Encode
Error - Errors that can occur during encoding.