2222import time
2323from enum import Enum
2424from math import ceil
25- from typing import Optional
25+ from typing import Optional , Tuple
2626
2727import serial
2828from PIL import Image
@@ -293,25 +293,23 @@ def DisplayPILImage(
293293 self ._send_command (Command .START_DISPLAY_BITMAP , padding = Padding .START_DISPLAY_BITMAP )
294294 self ._send_command (Command .DISPLAY_BITMAP )
295295 self ._send_command (Command .SEND_PAYLOAD ,
296- payload = bytearray (self ._generate_full_image (image , self . orientation )),
296+ payload = bytearray (self ._generate_full_image (image )),
297297 readsize = 1024 )
298298 self ._send_command (Command .QUERY_STATUS , readsize = 1024 )
299299 else :
300300 with self .update_queue_mutex :
301- img , pyd = self ._generate_update_image (image , x , y , Count .Start , Command .UPDATE_BITMAP ,
302- self .orientation )
301+ img , pyd = self ._generate_update_image (image , x , y , Count .Start , Command .UPDATE_BITMAP )
303302 self ._send_command (Command .SEND_PAYLOAD , payload = pyd )
304303 self ._send_command (Command .SEND_PAYLOAD , payload = img )
305304 self ._send_command (Command .QUERY_STATUS , readsize = 1024 )
306305 Count .Start += 1
307306
308- @staticmethod
309- def _generate_full_image (image : Image .Image , orientation : Orientation = Orientation .PORTRAIT ):
310- if orientation == Orientation .PORTRAIT :
307+ def _generate_full_image (self , image : Image .Image ) -> bytes :
308+ if self .orientation == Orientation .PORTRAIT :
311309 image = image .rotate (90 , expand = True )
312- elif orientation == Orientation .REVERSE_PORTRAIT :
310+ elif self . orientation == Orientation .REVERSE_PORTRAIT :
313311 image = image .rotate (270 , expand = True )
314- elif orientation == Orientation .REVERSE_LANDSCAPE :
312+ elif self . orientation == Orientation .REVERSE_LANDSCAPE :
315313 image = image .rotate (180 )
316314
317315 image_data = image .convert ("RGBA" ).load ()
@@ -324,21 +322,22 @@ def _generate_full_image(image: Image.Image, orientation: Orientation = Orientat
324322 hex_data = bytearray .fromhex (image_ret )
325323 return b'\x00 ' .join (hex_data [i :i + 249 ] for i in range (0 , len (hex_data ), 249 ))
326324
327- def _generate_update_image (self , image , x , y , count , cmd : Optional [Command ] = None ,
328- orientation : Orientation = Orientation .PORTRAIT ):
325+ def _generate_update_image (
326+ self , image : Image .Image , x : int , y : int , count : int , cmd : Optional [Command ] = None
327+ ) -> Tuple [bytearray , bytearray ]:
329328 x0 , y0 = x , y
330329
331- if orientation == Orientation .PORTRAIT :
330+ if self . orientation == Orientation .PORTRAIT :
332331 image = image .rotate (90 , expand = True )
333332 x0 = self .get_width () - x - image .height
334- elif orientation == Orientation .REVERSE_PORTRAIT :
333+ elif self . orientation == Orientation .REVERSE_PORTRAIT :
335334 image = image .rotate (270 , expand = True )
336335 y0 = self .get_height () - y - image .width
337- elif orientation == Orientation .REVERSE_LANDSCAPE :
336+ elif self . orientation == Orientation .REVERSE_LANDSCAPE :
338337 image = image .rotate (180 , expand = True )
339338 y0 = self .get_width () - x - image .width
340339 x0 = self .get_height () - y - image .height
341- elif orientation == Orientation .LANDSCAPE :
340+ elif self . orientation == Orientation .LANDSCAPE :
342341 x0 , y0 = y , x
343342
344343 img_raw_data = []
0 commit comments