1
1
# SPDX-FileCopyrightText: 2019 Dave Astels for Adafruit Industries
2
+ # SPDX-FileCopyrightText: 2022 Matt Land
2
3
#
3
4
# SPDX-License-Identifier: MIT
4
5
10
11
Make a screenshot (the contents of a displayio.Display) and save in a BMP file.
11
12
12
13
13
- * Author(s): Dave Astels
14
+ * Author(s): Dave Astels, Matt Land
14
15
15
16
Implementation Notes
16
17
--------------------
38
39
39
40
def _write_bmp_header (output_file , filesize ):
40
41
output_file .write (bytes ("BM" , "ascii" ))
41
- output_file .write (struct .pack ("<I" , filesize ))
42
+ output_file .write (struct .pack ("<I" , filesize )) # pylint: disable=no-member
42
43
output_file .write (b"\00 \x00 " )
43
44
output_file .write (b"\00 \x00 " )
44
- output_file .write (struct .pack ("<I" , 54 ))
45
+ output_file .write (struct .pack ("<I" , 54 )) # pylint: disable=no-member
45
46
46
47
47
48
def _write_dib_header (output_file , width , height ):
48
- output_file .write (struct .pack ("<I" , 40 ))
49
- output_file .write (struct .pack ("<I" , width ))
50
- output_file .write (struct .pack ("<I" , height ))
51
- output_file .write (struct .pack ("<H" , 1 ))
52
- output_file .write (struct .pack ("<H" , 24 ))
49
+ output_file .write (struct .pack ("<I" , 40 )) # pylint: disable=no-member
50
+ output_file .write (struct .pack ("<I" , width )) # pylint: disable=no-member
51
+ output_file .write (struct .pack ("<I" , height )) # pylint: disable=no-member
52
+ output_file .write (struct .pack ("<H" , 1 )) # pylint: disable=no-member
53
+ output_file .write (struct .pack ("<H" , 24 )) # pylint: disable=no-member
53
54
for _ in range (24 ):
54
55
output_file .write (b"\x00 " )
55
56
@@ -79,6 +80,7 @@ def _write_pixels(output_file, pixel_source, palette):
79
80
saving_bitmap = isinstance (pixel_source , Bitmap )
80
81
width , height = _rotated_height_and_width (pixel_source )
81
82
row_buffer = bytearray (_bytes_per_row (width ))
83
+ result_buffer = False
82
84
for y in range (height , 0 , - 1 ):
83
85
buffer_index = 0
84
86
if saving_bitmap :
@@ -98,8 +100,9 @@ def _write_pixels(output_file, pixel_source, palette):
98
100
row_buffer [buffer_index ] = b & 0xFF
99
101
buffer_index += 1
100
102
output_file .write (row_buffer )
101
- for i in range (width * 2 ):
102
- result_buffer [i ] = 0
103
+ if result_buffer :
104
+ for i in range (width * 2 ):
105
+ result_buffer [i ] = 0
103
106
gc .collect ()
104
107
105
108
0 commit comments