fixed the bug concerning png-images with transparency palette#149
fixed the bug concerning png-images with transparency palette#149d-schmidt wants to merge 1 commit intopython-pillow:masterfrom d-schmidt:master
Conversation
There was a problem hiding this comment.
There is a + instead of *? This also removes the ability to store with limited palette size.
There was a problem hiding this comment.
you mean something like im.encoderinfo["transparency"][:2**bits]?
How would that work with a real image?
There was a problem hiding this comment.
For the bytes/string palette? Yes, but I would keep the alpha_bytes variable to make the code more readable.
For example, you need only 16 colors if you store a paletted image with 4 bits.
I would also swap the if statements and check for int instead of bytes (because transparency might be a string on Python 2).
PS: b'\xff' * 4 is b'\xff\xff\xff\xff'
There was a problem hiding this comment.
ah got it, reading http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.Anc-trns
There was a problem hiding this comment.
I agree with @olt. Looks like encoderinfo['transparency'] can be an int representing # of bytes, the output type of ImageFile._safe_read (bytes or string), or an int16, or a 3-tuple of int16. Line 557 should be a * instead of +.
If we're round tripping the transparency with no change, then it looks like line 554 should be:
chunk(fp, b"tRNS", im.encoderinfo["transparency"])Since we get a bytes/string when we don't find a \0 in the tRNS chunk. To roundtrip, we'd have to emit it as we got it.
(note that I have not checked the spec to see how well this is reflected in the proper format of a png image)
There was a problem hiding this comment.
Ah, wait, now I see it. It doesn't work when multiple colors at the end are fully transparent.
^\xff+\x00+$ should be ^\xff+\x00\xff*$. Good catch.
There was a problem hiding this comment.
Couldn't we discard it all together and always use all given bytes?
There was a problem hiding this comment.
On decoding? Yes, probably. But I would keep support for encoding for backwards compatibility (if a user sets transparency).
There was a problem hiding this comment.
This was probably originally added to make PNG transparency look like GIF transparency, which has just the one fully transparent color. I'd expect that it's expected behaviour from the users. I'd say keep it, but fix the regex as suggested by @olt.
There was a problem hiding this comment.
I've added the fixed pattern to the current open pull.
|
contains new error, will send another pull |
Compile libxcb on macOS
#95 (comment)