Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions examples/ra8875_bmptest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
display.init()
display.fill(WHITE)

def color555(self, rgb):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be renamed something like cast_to_565 or something similar. Compared to color565 the name suggests that it's converting to 555.

Alternatively you could import color565 as color_565_from_24bpp and then make your own color565 that does the appropriate conversion based on bpp? Not a deal breaker either way

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just went with convert_555_to_565()

return (rgb & 0x001F) << 11 | (rgb & 0x0700) | (rgb & 0x0060) << 1 | 0x20 | (rgb & 0xF800) >> 11

class BMP(object):
def __init__(self, filename):
self.filename = filename
Expand All @@ -35,7 +38,8 @@ def __init__(self, filename):
self.data_size = 0
self.bpp = 0
self.width = 0
self.height=0
self.height = 0
self.read_header()

def read_header(self):
if self.colors:
Expand All @@ -54,7 +58,6 @@ def read_header(self):
self.colors = int.from_bytes(f.read(4), 'little')

def draw(self, disp, x=0, y=0):
self.read_header()
print("{:d}x{:d} image".format(self.width, self.height))
print("{:d}-bit encoding detected".format(self.bpp))
line = 0
Expand All @@ -72,12 +75,15 @@ def draw(self, disp, x=0, y=0):
if (line_size-i) < self.bpp//8:
break
if self.bpp == 16:
color = line_data[i] << 8 | line_data[i+1]
color = color555(line_data[i] << 8 | line_data[i+1])
if self.bpp == 24:
color = color565(line_data[i], line_data[i+1], line_data[i+2])
color = color565(line_data[i+2], line_data[i+1], line_data[i])
current_line_data = current_line_data + struct.pack(">H", color)
disp.setxy(x, self.height - line + y)
disp.push_pixels(current_line_data)
disp.set_window(0, 0, disp.width, disp.height)

BMP("/ra8875_blinka.bmp").draw(display, 287, 127)
bitmap = BMP("/ra8875_blinka.bmp")
x_position = (display.width // 2) - (bitmap.width // 2)
y_position = (display.height // 2) - (bitmap.height // 2)
bitmap.draw(display, x_position, y_position)
6 changes: 4 additions & 2 deletions examples/ra8875_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
display.curve(50, 100, 80, 40, 2, BLACK)
display.fill_curve(50, 100, 78, 38, 2, WHITE)

display.txt_set_cursor(240, 240)
display.txt_set_cursor(display.width // 2 - 200, display.height // 2 - 20)
print(display.width)
print(display.height)
display.txt_trans(WHITE)
display.txt_size(2)
testvar = 99
Expand All @@ -77,7 +79,7 @@
coords = display.touch_read()
display.fill_circle(int(coords[0]/x_scale), int(coords[1]/y_scale), 4, MAGENTA)
display.txt_color(WHITE, BLACK)
display.txt_set_cursor(240, 240)
display.txt_set_cursor(display.width // 2 - 220, display.height // 2 - 20)
display.txt_size(2)
display.txt_write("Position (" + str(int(coords[0]/x_scale)) + ", " +
str(int(coords[1]/y_scale)) + ")")