From 3e8a9b2165ec271ade5096e6c59ad642f9f7fd86 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 20 Jun 2022 21:01:10 +1000 Subject: [PATCH] Fixed loading L mode RLE8 images --- Tests/images/hopper_rle8_greyscale.bmp | Bin 0 -> 6288 bytes Tests/test_file_bmp.py | 3 +++ src/PIL/BmpImagePlugin.py | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Tests/images/hopper_rle8_greyscale.bmp diff --git a/Tests/images/hopper_rle8_greyscale.bmp b/Tests/images/hopper_rle8_greyscale.bmp new file mode 100644 index 0000000000000000000000000000000000000000..ead32ff95a46d6fc5672974f96c639e680a69830 GIT binary patch literal 6288 zcmeI0_glza7{)(0A=#BAJCeN%SxLhvlD)EbW<=SWgzPOl6lL%1y_J={3k_tiS1#|5 z?_cnKpX;3KxzD-IkI#9Y`@UVgLaq4|K_=jrjs#|Zl4&}`$};`(Z=_$OZ+`u|{v2F9 zeEieF-*EmH{LcS{|2&aIh71|Vm@y+JCMIOcl!?rlGm|At7EDb|$(l7QW@ct&%a)Do z*|U=)M-Fo4%t@|XxyYS6H+k~p!Q9*&3kwS@EiK8LH!oIJR^-c<4{K{{^5@Twjg1Wj z3KXDV!GaVjREWZb3sa;>5sDTqO0iVC2Y=1O^5Y6cog$QKJ|=dNgCkjA889v5Xrxj`8EiGhxC6 zCQh8lq)C&QJb5xxrc7b#)TvCHHjU}ir!!;541$A$nK^SNAt52mnl+2rvu87B&KyER zLzz2wF7xKiWB&a4ELgCBg$oz5Xwf1TFJ8=&B}-VkbScZ0Eo1re<*Zn-f|V;*vTD^T z!otE>y?Qlk)~sRe+O@1(w~qDe*Rx^61~zWoNO*WSn>KA?^XAQL*|LR*hzKGhBiXuj zE8DhhBPuG2=;&y+Z{N<29Xr^$b0@oY?PB-t-R#-3hrN6EvTxr$_V3@%fddCPc<>;H z4jtm~;lsql#Bk)u5sn@`%CTd|IDY&%Cr+H;6<;oSVUcJh-YuC7b{W`I+vBbs2apT4fZr;4fty{Oaefu_d z?%W|hKAyXG?{e?nJ?`JX&w~dKc=+%kj~+eZ@#DuldGds(PoMJa*)yI$f6j{+FL?R# zB?$=$Bqk>E>eVY=zkbb|H*ZKvN+LNqnUs_iQd3iT`}QsG-o4}f`}d@!rSajz2R?rM z$fr-A`26`ZU%q_d>({S*`}U3R-@o(Y#}9t~{K>Chzkauo-@iYDGRj1mlv!D1s;n|o zHf2{1wl)s;(NUDJRuZZPig-)swU8%S8?3DmS^yLk-nPjnzb+@={YZlee17 zM=jJ+t<+j=)K=}(ULDj?o#d;|>Y}ddrta#Yp6aFE>Z88ur~dNO01eb24b~71mA{5* zxB@gnBNeD1jnZh1(O8YscumkmP10md(Ns;-bj?t(W-3IpG+T2Ns=1n{`C6cbTBOBV zqNQ4<W~gAMn`m1$8=mLbW*2uT4!`t=X72dbWxXdSyyyb*K}R6iqj3<)GgiC9mVUe?&-cB z=%F6zv7YFup6R(>=%o^rs8@QeH%d~nQk1H| wfKdTP4={RwF$Ih%VDJEg2N+DyV1kAgFtmW71`Rc6_yL9=U^qhmH%AEl0}b_zNB{r; literal 0 HcmV?d00001 diff --git a/Tests/test_file_bmp.py b/Tests/test_file_bmp.py index f214fd6bd..776b499e0 100644 --- a/Tests/test_file_bmp.py +++ b/Tests/test_file_bmp.py @@ -134,6 +134,9 @@ def test_rle8(): with Image.open("Tests/images/hopper_rle8.bmp") as im: assert_image_similar_tofile(im.convert("RGB"), "Tests/images/hopper.bmp", 12) + with Image.open("Tests/images/hopper_rle8_greyscale.bmp") as im: + assert_image_equal_tofile(im, "Tests/images/bw_gradient.png") + # This test image has been manually hexedited # to have rows with too much data with Image.open("Tests/images/hopper_rle8_row_overflow.bmp") as im: diff --git a/src/PIL/BmpImagePlugin.py b/src/PIL/BmpImagePlugin.py index 4dc2b93c3..5aacb10da 100644 --- a/src/PIL/BmpImagePlugin.py +++ b/src/PIL/BmpImagePlugin.py @@ -321,7 +321,8 @@ class BmpRleDecoder(ImageFile.PyDecoder): # align to 16-bit word boundary if self.fd.tell() % 2 != 0: self.fd.seek(1, os.SEEK_CUR) - self.set_as_raw(bytes(data), ("P", 0, self.args[-1])) + rawmode = "L" if self.mode == "L" else "P" + self.set_as_raw(bytes(data), (rawmode, 0, self.args[-1])) return -1, 0