5252__version__ = "0.0.0-auto.0"
5353__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BitmapSaver.git"
5454
55- #pylint:disable=line-too-long,broad-except,redefined-outer-name,invalid-name
5655
5756def _write_bmp_header (output_file , filesize ):
5857 output_file .write (bytes ('BM' , 'ascii' ))
@@ -61,26 +60,25 @@ def _write_bmp_header(output_file, filesize):
6160 output_file .write (b'\00 \x00 ' )
6261 output_file .write (struct .pack ('<I' , 54 ))
6362
64- def _write_dib_header (output_file , w , h ):
63+ def _write_dib_header (output_file , width , height ):
6564 output_file .write (struct .pack ('<I' , 40 ))
66- output_file .write (struct .pack ('<I' , w ))
67- output_file .write (struct .pack ('<I' , h ))
65+ output_file .write (struct .pack ('<I' , width ))
66+ output_file .write (struct .pack ('<I' , height ))
6867 output_file .write (struct .pack ('<H' , 1 ))
6968 output_file .write (struct .pack ('<H' , 24 ))
70- output_file .write (b'\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 ' )
69+ for _ in range (24 ):
70+ output_file .write (b'\x00 ' )
7171
7272def _bytes_per_row (source_width ):
7373 pixel_bytes = 3 * source_width
7474 padding_bytes = (4 - (pixel_bytes % 4 )) % 4
7575 return pixel_bytes + padding_bytes
7676
7777def _rotated_height_and_width (pixel_source ):
78- w = pixel_source .width
79- h = pixel_source .height
8078 # flip axis if the display is rotated
8179 if isinstance (pixel_source , Display ) and (pixel_source .rotation % 180 != 0 ):
82- return (h , w )
83- return (w , h )
80+ return (pixel_source . height , pixel_source . width )
81+ return (pixel_source . width , pixel_source . height )
8482
8583def _rgb565_to_bgr_tuple (color ):
8684 blue = (color << 3 ) & 0x00F8 # extract each of the RGB tripple into it's own byte
@@ -91,21 +89,21 @@ def _rgb565_to_bgr_tuple(color):
9189#pylint:disable=too-many-locals
9290def _write_pixels (output_file , pixel_source , palette ):
9391 saving_bitmap = isinstance (pixel_source , Bitmap )
94- w , h = _rotated_height_and_width (pixel_source )
95- row_buffer = bytearray (_bytes_per_row (w ))
96- for y in range (h , 0 , - 1 ):
92+ width , height = _rotated_height_and_width (pixel_source )
93+ row_buffer = bytearray (_bytes_per_row (width ))
94+ for y in range (height , 0 , - 1 ):
9795 buffer_index = 0
9896 if saving_bitmap :
99- for x in range (w ):
97+ for x in range (width ):
10098 pixel = pixel_source [x , y - 1 ]
10199 color = palette [pixel ]
102100 for _ in range (3 ):
103101 row_buffer [buffer_index ] = color & 0xFF
104102 color >>= 8
105103 buffer_index += 1
106104 else :
107- data = pixel_source .fill_area (x = 0 , y = y - 1 , width = w , height = 1 )
108- for i in range (w ):
105+ data = pixel_source .fill_area (x = 0 , y = y - 1 , width = width , height = 1 )
106+ for i in range (width ):
109107 pixel565 = (data [i * 2 ] << 8 ) + data [i * 2 + 1 ]
110108 for b in _rgb565_to_bgr_tuple (pixel565 ):
111109 row_buffer [buffer_index ] = b & 0xFF
@@ -134,10 +132,10 @@ def save_pixels(file_or_filename, pixel_source=board.DISPLAY, palette=None):
134132 else :
135133 output_file = file_or_filename
136134
137- w , h = _rotated_height_and_width (pixel_source )
138- filesize = 54 + h * _bytes_per_row (w )
135+ width , height = _rotated_height_and_width (pixel_source )
136+ filesize = 54 + height * _bytes_per_row (width )
139137 _write_bmp_header (output_file , filesize )
140- _write_dib_header (output_file , w , h )
138+ _write_dib_header (output_file , width , height )
141139 _write_pixels (output_file , pixel_source , palette )
142140 except Exception :
143141 raise
0 commit comments