pnm: Decode PAM format variants which have alpha #2432
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements the transparent tupltypes listed in the PAM spec, at https://netpbm.sourceforge.net/doc/pam.html.
I am submitting this PR to a) complete PAM format support so that image viewers based on
image
can read allreasonably constructable PAM images b) ensure that the
image
crate itself can read all the PAM tuple types that itwrites.
The format technically allows non-RGBA tuple types and depths > 4, but these should be rejected as they
have no clear interpretation as an image.
I've only added simple tests in-file for PAM, extending the existing ones, but if desired I can make regression test images.
Other than by using
image
itself, PAM images with alpha channels can be produced by NetPBM and ImageMagick.For example:
(Note:
pngtopam
does not produce BLACKANDWHITE_ALPHA;pamthreshold
can, but isn't general and appears to have bugs; so ImageMagick'sconvert
is the only standard converter which works. On the other hand, going from PAM to PNG, ImageMagick'sconvert
incorrectly flips the alpha channel, whilepamtopng
works correctly.)ColorType::Rgba16
are stored unpremultiplied, with native-endian channels in R,G,B,A memory order, and a linear alpha channel.