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
10 bit pgm file not read correctly #5403
Comments
Could you provide a copy of the input image? |
Yeah sure! Here is an example of a 10 bit pgm image. |
Just for the record, the rawmode of this image is detected as I;16B |
Pillow does not auto-scale image values, even when converting between 8 bit and 16 bit formats. This is a longstanding issue with expectations, but changing it at this point would be a breaking change. |
Considering that this unexpected behavior is undocumented (correct me if I am wrong) and violates the PNG specification, such a breaking change would maybe be acceptable? |
I've created PR #6107 to resolve this. Just to be clear - there is no problem with how the PNG is saved in the original post here. The problem is just in how a 10-bit PGM file is read by Pillow. |
Why stop at 10-bit? There are 12-bit pixel formats as well, e.g. used in very high quality HDR production. FFmpeg also defines 14-bit, and even 9-bit... 12 and 14 are also common bit depths for camera sensors, and raw data is sometimes dumped/converted to PGM(-like) files. |
Ok, I've added 9, 12 and 14 to the PR as well. |
What did you do?
Load 10 bit pgm image and saved it as png image
What did you expect to happen?
Pixel values scaled to use the 16 bit range
(http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html)
What actually happened?
pixel values stored in the least significant bytes and hence the image is too dark
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: