Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for PPM arbitrary maxval #6119

Merged
merged 4 commits into from Mar 18, 2022
Merged

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Mar 9, 2022

Resolves #5008
Resolves #5403

#5008 points out that the PPM maxval does not just indicate the bit depth of an image. It is an arbitrary number, that "Must be less than 65536 and more than zero."

The example from the issue has a maxval of 11 (not 2 ** 11, but just 11), and https://en.wikipedia.org/wiki/Netpbm#PGM_example shows an example where the maxval is 15. So when it is 15, the values range between 0 and 15, from black to white.

This PR

  • allows this value to be arbitrary for P5 (grayscale). That fixes the code example in PGM and PPM maximum grey/color value is ignored #5008, and 10 bit pgm file not read correctly #5403, which features a P5 image at 10-bit depth, or 1023 maxval (2 ** 10 - 1).
  • allows this value to be arbitrary for P6 (RGB). When the value is more than 255, that would require more than 16-bits of RGB data. As we do not have such a mode, this PR simply scales down the pixels to fit into 16-bit.

@radarhere radarhere force-pushed the ppm_maxval branch 2 times, most recently from fefce6a to 0cbeac6 Compare March 9, 2022 10:47
@radarhere radarhere changed the title Added support for PPM P5 maxval < 255 and P6 arbitrary maxval Added support for PPM arbitrary maxval Mar 9, 2022
assert im.get_format_mimetype() == "image/x-portable-pixmap"


def test_arbitrary_maxval():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these mode be parametrised? Looks like one input bytestring and two things to assert.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 bit pgm file not read correctly PGM and PPM maximum grey/color value is ignored
2 participants