-
Notifications
You must be signed in to change notification settings - Fork 21
Incorrect (skewed?) image displayed by image recorded by adafruit_imageload.load() #88
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
Comments
@todbot |
@todbot, The solution you proposed did not work. Here is the shortest and simplest code I could write to reproduce this error. try: from board_definitions import m5stack_cardputer as board
except: import board
import displayio
import digitalio
import adafruit_imageload # type: ignore
# Device: M5Stack Cardputer
display = board.DISPLAY
bitmap, pallete = adafruit_imageload.load('/untitled_app.png')
image = displayio.TileGrid(bitmap, pixel_shader=pallete, x=5, y=5)
root_group = displayio.Group()
display.root_group = root_group
root_group.append(image)
G0_btn = digitalio.DigitalInOut(board.BUTTON)
G0_btn.direction = digitalio.Direction.INPUT
# Forever loop to see what is happening.
while 1:
pass The device I am using is the M5Stack Cardputer if that helps. In this case, I get this output on the screen: Here is the image (/untitled_app.png) I am trying to use in a zip file (so that no platform can put their hands on it :D): |
Using the PNG in that zip, I am seeing the same skewing are you are. This reminds me of #74 and it looks like the main way this PNG differs from the one at the top of this issue (recompressed by github) is that it's not palette-based but RGB. Here's what PNG check shows for your original skewed image and the github one:
So a workaround would be to recompress your images until you find a setting that works with I tried re-encoding the PNG using ImageMagick with: magick untitled_app_orig.png -type palette -colors 64 untitled_app_new.png And that provokes a new bug in Traceback (most recent call last):
File "code.py", line 9, in <module>
File "adafruit_imageload/__init__.py", line 92, in load
File "adafruit_imageload/png.py", line 121, in load
IndexError: x must be 0-49 which is the same codeblock that was to fix #74. So I think we're in the right ballpark. Looks like |
For more data points here are the working/not working images I've been using:
|
Also replacing the < with a <= in the following line of png.py makes the untitled_app.png from the attached zip display properly... Edit: If like me you're trying to figure the work-around out from this screen shot, I chopped line 120, it should be: |
Is it possible there's a bug in the Circuitpython memoryview/array copy functions? I haven't stared at the work-around long enough to be sure but it looks to me like at a depth of 8, it's just performing a manual copy of data_bytes directly to bmp, rather than using the memoryview technique. |
I don't understand exactly how the memoryview function works but I don't think it's working as expected. I was able to get the untitled_app.png file from the attached zip to display properly by modifying the target memory location from I may try and dig in and figure out exactly how the memoryview function works but until then I think we should just enable the #74 work around for 8 bit images as well. This slows down the image display but moving the data into the bitmap object one byte at a time at least displays the images correctly. |
Thew problem is that displayio uses uint32_t arrays internally, but the memoryview exposes that as uint8_t array. In hindsight, and after reading the docs for https://docs.circuitpython.org/projects/imageload/en/latest/api.html#adafruit_imageload.load I think we should have never used memoryview in imageload in the first place, we should be using |
I think I worked out the adjustment needed to get the memoryview to work. I've tested on 2, 4 & 8 bit mode 8 images and it seems to be working. https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad/pull/87/files |
The original code used |
The |
Why dont you create a pull request then? Also, I had created this image using getpaint.net if anyone is wondering, its a great, lightweight image editor :) |
#87 resolves the issue. The <= change was one of the first commits to the PR but after working on it for many hours I was able to get the code to work without the work around which is noticeably faster for larger image files. |
Expected Behavior
Python logo displays correctly.

Python logo in a ZIP archive
Behavior shown
Skewed python logo.

Please feel free to ask me any further questions!
Code
P.S. Original code in old version of this message.
The text was updated successfully, but these errors were encountered: