Skip to content

Commit e9d7a49

Browse files
author
Melissa LeBlanc-Williams
committed
Made 16-bit color handling a little better
1 parent 498676b commit e9d7a49

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

examples/ra8875_bmptest.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def read_header(self):
5353
self.data_size = int.from_bytes(f.read(4), 'little')
5454
f.seek(46)
5555
self.colors = int.from_bytes(f.read(4), 'little')
56+
def color555(self, rgb):
57+
return (rgb & 0x001F) << 11 | (rgb & 0x0700) | (rgb & 0x0060) << 1 | 0x20 | (rgb & 0xF800) >> 11
5658

5759
def draw(self, disp, x=0, y=0):
5860
print("{:d}x{:d} image".format(self.width, self.height))
@@ -72,7 +74,7 @@ def draw(self, disp, x=0, y=0):
7274
if (line_size-i) < self.bpp//8:
7375
break
7476
if self.bpp == 16:
75-
color = line_data[i] << 8 | line_data[i+1]
77+
color = self.color555(line_data[i] << 8 | line_data[i+1])
7678
if self.bpp == 24:
7779
color = color565(line_data[i+2], line_data[i+1], line_data[i])
7880
current_line_data = current_line_data + struct.pack(">H", color)
@@ -81,9 +83,4 @@ def draw(self, disp, x=0, y=0):
8183
disp.set_window(0, 0, disp.width, disp.height)
8284

8385
bitmap = BMP("/ra8875_blinka.bmp")
84-
print(display.width)
85-
print(display.height)
86-
print(bitmap.width)
87-
print(bitmap.height)
88-
bitmap.draw(display, (display.width // 2) - (bitmap.width // 2),
89-
(display.height // 2) - (bitmap.height // 2))
86+
bitmap.draw(display, (display.width // 2) - (bitmap.width // 2), (display.height // 2) - (bitmap.height // 2))

0 commit comments

Comments
 (0)