-
Notifications
You must be signed in to change notification settings - Fork 22
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
fix skewed PNG images caused by 'memoryview' bitmap filling #87
Conversation
#88 displays this same skew issue on an image that's only 50x50 |
This should probably be closed until the associated issue is understood. |
At least until the memoryview issue is understood, I believe this fixes #88 now. |
If the The patch in question is adafruit/circuitpython@2c7b11b |
The bitmap[x, y] code wasn't wrong and worked fine, it's just much slower to copy a single byte at a time. |
I realized that without figuring out how the workaround code worked, I never would have come up with the memoryview adjustment so I put the code block in as a comment for documentation and in case it's needed in the future for additional workarounds. |
That is true, but we need the workaround for the stable versions, because the bit alignment was only fixed recently. |
Ah, good point. Is there a reason not to use the circuitpython release in sys.implementation[1] to select the workaround code or do we just have to wait until 9.1 is no longer supported? Something like: if (sys.implementation[1][0] == 9 and sys.implementation[1][1] < 2) or sys.implementation[1][0] < 9:
# Use workaround
else:
mem[dst : dst + scanline] = data_bytes[src : src + scanline] |
This version reverts to the workaround for CircuitPython 9.1 and earlier. I tested on 8.2.10 as well as 9.2. Edit: I guess testing 8.x was overkill since technically there's an 8.x library bundle so this update shouldn't impact CP 8.x. Since it worked with 8.x I would think 9.1 should also be fine though 😁 |
Thanks! Good catch, for all my staring at this section of code, I missed that one 😁 |
Okay, so I ran some benchmarks on the code section being updated. Pico2: ESP32-S3: All 8 bit images. I have no idea why the workaround runs so much faster on the larger files and I couldn't really confirm the findings on the Pico2 since even a 420x420 image wouldn't load into memory. Based on these results, I'm inclined to suggest we dump the Memoryview method and use the workaround in all cases. A 20 second difference for larger files on the S3 is going to be a lot more noticeable than a 1 second difference on the Pico2. |
Probably because I wrote it that way originally, and I wasn't thinking about speed at all. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this successfully with the reproducer code and image from the issue.
Thanks for the fix @RetiredWizard and to @deshipu for looking into this.
Updating https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad to 1.23.3 from 1.23.2: > Merge pull request adafruit/Adafruit_CircuitPython_ImageLoad#87 from RetiredWizard/main Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
This PR implements the fix #74 workaround on images that have a width greater than 128 pixels.I don't know if the PNG image format changes when the image width gets larger than 128 pixels or if there's some decoding error in the library but this workaround seems to resolve the problem I'm seeing for PNG files with a width > 128 pixels.This PR adjust the memoryview copy used for mode 3 PNG images to avoid the skewing that occurred when the image width was not an even multiple of either 4 pixels (for 8 bit color), 8 pixels (for 4 bit color), 16 pixels (for 2 bit color) or 32 pixels (for 1 bit color).
128x128:

129x129:

fixes #88