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
Image.putalpha should handle 16/32-bit to RGBA conversion #4926
Comments
I don't agree that there should be an automatic conversion, as we currently don't do implicit conversions that would lose data, which would be the case going from I;16 or F to an 8 bit image format. The multiple errors are something that should probably be cleaned up though. |
Not necessarily – 16-bit grayscale content could well be preserved in a 24-bit color image without too much loss in precision. But I agree that it would be unexpected (and need some form of color management to get back to an equivalent luminance in the end). And since reporting this, I have also learned that Pillow does not even convert correctly (loosing only precision), but clips off the significant part of the dynamic range – without warning. See:
Given that, I am actually glad Pillow does raise an exception here at least. |
I've created #5090 to reduce the chain from three errors to two. |
That PR has now been merged. So the exception would now be >>> from PIL import Image
>>> img = Image.new('F', (200,100), 1.0)
>>> img.putalpha(Image.new('L', (200,100), 255))
Traceback (most recent call last):
File "PIL/Image.py", line 1620, in putalpha
ValueError: image has wrong mode
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "PIL/Image.py", line 1623, in putalpha
ValueError: conversion from F to LA not supported Is that enough to resolve this? |
Thanks @radarhere! Yes, I guess we can close – as long as the other conversion-related issues are not resolved, it does not make sense attempting anything out of the ordinary here. |
This is similar to #2705 (which covered P→PA conversion):
IMHO images in 16-bit (
I;16
) or 32-bit (I
/F
) modes should be automatically converted to RGBA whenputalpha
is attempted on them.Current (7.2.0) behaviour:
If this is too difficult or unwise for other reasons (like quantization), then at least the documentation should state which base modes are supported.
In the very least, the above ugly multi-catch error message should be avoided.
The text was updated successfully, but these errors were encountered: