Expand description
Embed PNM images directly into Rust code.
This supports most PNM files in a mostly reasonable way. The idea here is that PNM is a very simple format that is also compressible enough to embed directly into version control repositories, and so, very suited to loading in at compile time.
Most PNM images are supported, with the primary exception applying to PPM images and 3-channel
PAM images: these must have a MAXVAL of 255 or 65535 in order to be loaded at all.
§Conversions
Similar to netpbm, all formats of PNM images are supported, and then converted to the result
depending on the mode requested. Color space is completely ignored when converting between
formats, and conversion is only allowed in the forward direction, where e.g. grayscale images
can be converted to RGB by duplicating values three times.
Similarly, conversion from 8-bit color to 16-bit color is done under the assumption that the scaling does not change, and all values get scaled by 65535/255.
§“Indexed” images
While PGM and 1-channel PAM images may have any allowed MAXVAL, images without a MAXVAL of
1, 255, or 65535 may not be converted into any other color format, under the assumption that
they were intended to reference palette indices instead of colors.
§Tracking included images
On stable Rust, you must add a build script and output cargo:rerun-if-changed=path for each
included image to ensure that your crate recompiles whenever the image files change. However,
on nightly Rust with the nightly feature enabled, the unstable track_path feature will be
used so this happens automatically.
Macros§
- include_
pbm - Include a PBM image as a 2D array of
bool. - include_
pbma - Include a “PBMA” image as a 2D array of
[bool; 2]. - include_
pgm - Include a PGM image as a 2D array of
u8. - include_
pgm16 - Include a PGM image as a 2D array of
u16. - include_
pgma - Include a “PGMA” image as a 2D array of
[u8; 2]. - include_
pgma16 - Include a “PGMA” image as a 2D array of
[u16; 2]. - include_
pnm - Include a PAM image as a 2D array of the specified type and number of channels.
- include_
ppm - Include a PPM image as a 2D array of
[u8; 3]. - include_
ppm16 - Include a PPM image as a 2D array of
[u16; 3]. - include_
ppma - Include a “PPMA” image as a 2D array of
[u8; 4]. - include_
ppma16 - Include a “PPMA” image as a 2D array of
[u16; 4].