27
27
display .init ()
28
28
display .fill (WHITE )
29
29
30
+ def color555 (self , rgb ):
31
+ return (rgb & 0x001F ) << 11 | (rgb & 0x0700 ) | (rgb & 0x0060 ) << 1 | 0x20 | (rgb & 0xF800 ) >> 11
32
+
30
33
class BMP (object ):
31
34
def __init__ (self , filename ):
32
35
self .filename = filename
@@ -53,8 +56,6 @@ def read_header(self):
53
56
self .data_size = int .from_bytes (f .read (4 ), 'little' )
54
57
f .seek (46 )
55
58
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
58
59
59
60
def draw (self , disp , x = 0 , y = 0 ):
60
61
print ("{:d}x{:d} image" .format (self .width , self .height ))
@@ -74,7 +75,7 @@ def draw(self, disp, x=0, y=0):
74
75
if (line_size - i ) < self .bpp // 8 :
75
76
break
76
77
if self .bpp == 16 :
77
- color = self . color555 (line_data [i ] << 8 | line_data [i + 1 ])
78
+ color = color555 (line_data [i ] << 8 | line_data [i + 1 ])
78
79
if self .bpp == 24 :
79
80
color = color565 (line_data [i + 2 ], line_data [i + 1 ], line_data [i ])
80
81
current_line_data = current_line_data + struct .pack (">H" , color )
@@ -83,4 +84,6 @@ def draw(self, disp, x=0, y=0):
83
84
disp .set_window (0 , 0 , disp .width , disp .height )
84
85
85
86
bitmap = BMP ("/ra8875_blinka.bmp" )
86
- bitmap .draw (display , (display .width // 2 ) - (bitmap .width // 2 ), (display .height // 2 ) - (bitmap .height // 2 ))
87
+ x_position = (display .width // 2 ) - (bitmap .width // 2 )
88
+ y_position = (display .height // 2 ) - (bitmap .height // 2 )
89
+ bitmap .draw (display , x_position , y_position )
0 commit comments