@@ -114,6 +114,13 @@ def show(self):
114114 except AttributeError :
115115 pass
116116
117+ @staticmethod
118+ def rgb565_color (r , g , b ):
119+ """
120+ Convert red, green and blue values (0-255) into a 16-bit 565 encoding.
121+ """
122+ return (r & 0xf8 ) << 8 | (g & 0xfc ) << 3 | b >> 3
123+
117124 @staticmethod
118125 def _calculate_palette (color , bg_color ) -> tuple :
119126 """
@@ -506,7 +513,7 @@ def ppm(self, *args, **kwargs):
506513 self .pbm (* args , ** kwargs )
507514
508515 def pbm (self , file , x , y , key : int = - 1 , show : bool = None , clear : bool = None , invert : bool = False ,
509- color_type = "RGB565" , color : int = None , bg_color : int = None ):
516+ color_type = None , color : int = None , bg_color : int = None ):
510517 """
511518 显示 pbm / ppm 图片
512519
@@ -686,7 +693,7 @@ def pbm(self, file, x, y, key: int = -1, show: bool = None, clear: bool = None,
686693 raise TypeError ("Unsupported File Format Type." )
687694
688695 def bmp (self , file , x , y , key : int = - 1 , show : bool = None , clear : bool = None , invert : bool = False ,
689- color_type = "RGB565" , color : int = None , bg_color : int = None ):
696+ color_type = None , color : int = None , bg_color : int = None ):
690697 """
691698 显示 bmp 图片
692699
@@ -753,7 +760,7 @@ def bmp(self, file, x, y, key: int = -1, show: bool = None, clear: bool = None,
753760 try :
754761 dp_color = dp .color
755762 except AttributeError :
756- pass
763+ dp_color = self . rgb565_color
757764 dp_pixel = dp .pixel
758765 if f_read (2 ) == b'BM' : # 检查文件头
759766 dummy = f_read (8 ) # 文件大小占四个字节,文件作者占四个字节,file size(4), creator bytes(4)
0 commit comments