Skip to content

Commit d84e967

Browse files
committed
Fix lint complaints
1 parent 51d8efa commit d84e967

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

adafruit_bitmapsaver.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
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

5756
def _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

7272
def _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

7777
def _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

8583
def _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
9290
def _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

Comments
 (0)