-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Changed int conversion in ImagePalette to ord for Python 2 #1593
Conversation
I'm not convinced that this is the right approach yet. There's got to be something screwy with the palette, because if it was just an bytes/int conversion issue, then we'd likely have run across this before. The code's been in there since the conversion to py3. What's the character that's throwing it off? How is it encoded in the palette? |
The palette string is -
It looks to me like the '\x00' character is being rendered as '' in Python 2, but converted by int by Python 3. |
So, any palette that contains black (#000000) should error out in python 2.x with PIL from 2012 through current master. |
@wiredfool That's in line with what I'm seeing. I'm trying to draw black text and seeing this error on certain images. Since all tests have passed, are you still opposed to merging? |
A thought just popped into my head after reading the code for the fix. In the original issue, I wrote:
Does this fix have that problem? Is the image really unmodified, or will the palette still be incidentally converted to grayscale? The other concern I have is... won't this still break on Python 3? The image in the original issue breaks on Python 3 with the error So what's going on with that? Basically, will this fix 1) not lose palette data for images like the one in the original issue, and 2) make sure images like the one in the original issue work with Python 3 too? |
I've taken a look at this recently with the various people reporting issues with palette images, and apart from my opinion that the palette code is a type unsafe mess of the first order, we'd probably be better off having our internal representation of a mutable palette be a bytearray rather than a list. It's a simpler conversion from bytes or a list ( It looks like tests pass with the minimal changes in https://github.com/wiredfool/Pillow/tree/palette |
Okay, so the tests pass. Does the image pass through unharmed? |
It appears to. |
For the sake of anyone visiting this later, I've replied to the question @obskyr about RGBA;L with #1592 (comment) |
Error reported in #1592