-
Notifications
You must be signed in to change notification settings - Fork 21
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
Some Indexed PNGs Rendering Improperly #97
Comments
I think I have a lead on the cause of this. If google AI is to be trusted (sometimes I guess?) then all PNGs including indexed PNGs use filtering. It seems to me that our implementation does not handle any filtering for indexed images. For RGB images the code here reads the filter byte per scanline and then decides what to do about it immediately after Adafruit_CircuitPython_ImageLoad/adafruit_imageload/png.py Lines 135 to 155 in c5e3b7e
As far as I can tell for indexed images this code is basically ignoring the filter byte by the way it's adding an "extra" 1.
With the blue heart image the filter byte seems to always be |
Medium sized brain dump about this issue.
With these two images:
blue heart image:
pink heart image:
The blue one renders properly and looks correct.
The pink one looks to be mostly corrupted or distorted. Here is it decoded with this library and put into a scaled Group to enlarge it
The 3 rows of pixels above the last row that contains pink pixels look correct to my eye, but the rest of the rows are mostly messed up in a way that doesn't seem to have a discernible pattern.
In comparing the two images to try to understand what is different about them I noticed the blue one has an
sRGB
chunk with value set to0
and the pink one does not. But our code seems to be ignoring that chunk anyhow. I confirmed it was getting skipped by adding a print statement here: https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad/blob/main/adafruit_imageload/png.py#L101I also tried modifying the pink image to add the sRGB chunk and get the same results when decoded and rendered by this library. I can provide that file if someone else is working on that and thinks it may help.
The other main difference between the two images is that the blue one has 3 colors in its palette: black, dark blue, light blue. The black is set to transparent with the
tRNS
chunk having size 1 and value0x00
The pink one has 4 colors in its palette: grey, black, light pink, dark pink. The grey and black are set to transparent with the
tRNS
chunk having size 2 and value0x00
,0x00
They both render correctly inside of gimp, so I believe there must be something our implementation is doing wrong or missing, but I haven't figured out what. I guess the 4th color in the palette could be some how related to it not working, but I don't see any clear mechanism for it cause trouble in the code.
My suspicion was on the decompression of the data, but as far as I can tell it seems to be going fine. I've tested
zlib.decompress()
on the same 49 IDAT bytes on PC and MCU and verified the ouput results are the same in both cases.If I use this to "undo" the automatic transparency setting I can see that some of the "empty" pixels are actually the grey (color index 0), and others are black (color index 1)
I've printed out the raw bits of the decompressed data and confirmed that the seem to align with the visual appearance of this.
The text was updated successfully, but these errors were encountered: