Skip to content

Commit e9715b2

Browse files
authored
Merge pull request #6384 from radarhere/bmp_rle8
Fixed loading L mode BMP RLE8 images
2 parents 5fc3b6e + 3e8a9b2 commit e9715b2

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed
6.14 KB
Binary file not shown.

Tests/test_file_bmp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ def test_rle8():
134134
with Image.open("Tests/images/hopper_rle8.bmp") as im:
135135
assert_image_similar_tofile(im.convert("RGB"), "Tests/images/hopper.bmp", 12)
136136

137+
with Image.open("Tests/images/hopper_rle8_greyscale.bmp") as im:
138+
assert_image_equal_tofile(im, "Tests/images/bw_gradient.png")
139+
137140
# This test image has been manually hexedited
138141
# to have rows with too much data
139142
with Image.open("Tests/images/hopper_rle8_row_overflow.bmp") as im:

src/PIL/BmpImagePlugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ def decode(self, buffer):
321321
# align to 16-bit word boundary
322322
if self.fd.tell() % 2 != 0:
323323
self.fd.seek(1, os.SEEK_CUR)
324-
self.set_as_raw(bytes(data), ("P", 0, self.args[-1]))
324+
rawmode = "L" if self.mode == "L" else "P"
325+
self.set_as_raw(bytes(data), (rawmode, 0, self.args[-1]))
325326
return -1, 0
326327

327328

0 commit comments

Comments
 (0)