I have been trying to get the Galactic Unicorn to display various small, non-progressive jpeg files using the following code, but I can’t seem to get it to work. Any idea why ?
from picographics import PicoGraphics, PEN_RGB332, DISPLAY_GALACTIC_UNICORN as DISPLAY
from galactic import GalacticUnicorn
import jpegdec
galactic = GalacticUnicorn()
graphics = PicoGraphics(DISPLAY)
def pressed():
if galactic.is_pressed(GalacticUnicorn.SWITCH_A):
return GalacticUnicorn.SWITCH_A
if galactic.is_pressed(GalacticUnicorn.SWITCH_B):
return GalacticUnicorn.SWITCH_B
if galactic.is_pressed(GalacticUnicorn.SWITCH_C):
return GalacticUnicorn.SWITCH_C
if galactic.is_pressed(GalacticUnicorn.SWITCH_D):
return GalacticUnicorn.SWITCH_D
return None
display = PicoGraphics(display=DISPLAY, pen_type=PEN_RGB332, rotate=0)
# Create a new JPEG decoder for our PicoGraphics
j = jpegdec.JPEG(display)
# Open the JPEG file
j.open_file("testfile.jpg")
# Decode the JPEG
j.decode(0, 0, jpegdec.JPEG_SCALE_FULL)
# Display the result
galactic.update(graphics)
# wait
while True:
# if A, B, C, or D are pressed then reset
if pressed() != None:
machine.reset()
Yes, I had copied some code without noticing the double definition. The problem however doesn’t lie there.
I noticed that the issue is with “pen_type=PEN_RGB332”. If I use this when defining PicoGraphics, e.g. if I use : graphics = PicoGraphics(DISPLAY, pen_type=PEN_RGB332), nothing is displayed on the Unicorn’s screen.
If I omit the pen_type definition, I get an entirely blue screen (tried using different jpeg files).
The issue therefore seems to be with the decoding. I noticed that in the original library that has been ported to the Unicorn, the jpeg files are transcoded from jpeg to c arrays. Wondering if this is needed here also.
Has anyone managed to get the Unicorn display to show jpegs? If so, could you share your code?
Ahh yes; the Galactic Unicorn doesn’t play nicely with an RGB332 pen (which is also a problem with some of the sprite stuff) - I’ve got a PR to fix that sat in the queue (although I think the whole pico repo is in a bit of flux so I don’t know when it might get merged)
This works for me, running v1.19.12 MicroPython. Might be worth upgrading to the most recent firmware if you’ve not already - I think there have been fixes to jpegdec in the last few versions.
from picographics import PicoGraphics, DISPLAY_GALACTIC_UNICORN as DISPLAY
from galactic import GalacticUnicorn
import jpegdec
galactic = GalacticUnicorn()
graphics = PicoGraphics(DISPLAY)
# Create a new JPEG decoder for our PicoGraphics
j = jpegdec.JPEG(graphics)
# Open the JPEG file
j.open_file("gradient_pink_blue.jpg")
# Decode the JPEG
j.decode(0, 0, jpegdec.JPEG_SCALE_FULL)
# Display the result
galactic.update(graphics)
ENOENT means it can’t find the file - check the image filename and how it’s referenced in the code match? (look out for .jpg vs. .jpeg - I’ve been caught out by that before!)