Open TecDroiD opened 2 years ago
After some trial-and-error experiments, I got images properly on the TFT-display. It is a kind of a fix for the IndexError - do not ask why it works and there might be a much better fix! (Note: colormap seems to be a B/W-array and might therefore be too small, c is a 16-bit color value)
Changes in method blit()
:
after the line: c = bitbuff.pixel(ix,iy)
self._buf[index*2] = c #self._colormap[c*2]
self._buf[index*2+1] = c #self._colormap[c*2+1]
add method draw_image()
to ili94xnew.py:
# draw_image - partial from rdagger/Rototron, and @TecDroID issue Blit bitbuffer #11
def draw_image(self, path, x=0, y=0, w=320, h=240):
""" Draw image from flash.
Args:
path (string): Image file path.
x (int): X coordinate of image left. Default is 0.
y (int): Y coordinate of image top. Default is 0.
w (int): Width of image. Default is 320.
h (int): Height of image. Default is 240.
"""
# read file contents in FrameBuffer
with open(path, "rb") as fp:
buf = framebuf.FrameBuffer(bytearray(fp.read()), w, h, framebuf.RGB565)
self.blit(buf, x, y, w, h)
test draw_image()
:
display.draw_image("RaspberryPiWB128x128.raw", 0, 0, 128, 128)
image dimensions: 128x128 pixels image(s) from Github @rdagger.
For details:
Hope someone would like this, and/or might do a proper fix.
PS. Thanks @Jeffmer for the driver, I like it due to the simple font handling (and uses Peter Hinch font_to_py).
Peter
After some more tests, it turns out text is not displayed on the TFT-display with above fix in blit()
.
Modification in blit()
:
if (c == 0 | c == 1) : # I'll assume text
self._buf[index*2] = self._colormap[c*2]
self._buf[index*2+1] = self._colormap[c*2+1]
else: # I'll assume an image
self._buf[index*2] = c
self._buf[index*2+1] = c
It would be interesting to see how it goes. Peter
Hi, i try to load a raw image (60x60 pixels, rgb565) using the following code:
and get this error:
is it my fault or some issue in the blit source?