From 04df6e3bf11c914d1521dab800f678a5af4946b5 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 9 Apr 2021 21:38:28 +1000 Subject: [PATCH] mapdepth is only 1 byte --- Tests/images/200x32_p_bl_raw_origin.tga | Bin 0 -> 7212 bytes Tests/test_file_tga.py | 10 +++++++++- src/PIL/TgaImagePlugin.py | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 Tests/images/200x32_p_bl_raw_origin.tga diff --git a/Tests/images/200x32_p_bl_raw_origin.tga b/Tests/images/200x32_p_bl_raw_origin.tga new file mode 100644 index 0000000000000000000000000000000000000000..329f0ca4d9e579bea5e1ade5783909eafde735c6 GIT binary patch literal 7212 zcmZvhdtA3pDrR7jyHr<~SW4hvyz zglzFlW|(1n5Gz?oqsDxJC=?0}1NyzJFj90@ zXj^J)T6fbP-a*5*ONY@Kim{zLj8`b^wY8=w6rXj}bW$i>G!*XInzIxgXKN_t>2zGI zrRCkTi(eO=rMevg`gUG1pj)t>R#^Xu?x~-+WsaM<;nSJx$GC2@^GKWOkv!Wi+0kQz ztH=7WE;~Ivl191Y2f3~v&?Ke0HH`Mr?(1?02paKRHKTa)~_d7CF@Z zzUk!KPaR`wTq5o|M?Q2}^M_Nk(S!z*iBF6tJ*;&OZ*Yoen;!FKMwD)(iGEDKCYP{w zm$gIe8wXB$-8sS7bn@$V&#<=7qxIICn@(>WMHny*d)7`SbFxRm? zbY0IK&O-zKZVgN9vwglno>zNBOt-wn7OP$u2RFW7m#km7pe-h0P=T+>mw$g)u>4(I zTHpOXefI?QKe(VZX@gnhi}sXw!+mQ9A6?v%nradE;==>+Z5c@>rQVhs8s255n;uLx zJd|#oR^OVPY;n@ZEd9mXZJ9<#vaQc7G|y^i*^y@Y)h_e%OGcdc8J6?>UBM=c;sYZq zmKc>BYTcLe@x_HUdC#pYeN4Xj=Iw#3j|%E+uPkjjywQA5gT?XF%}2Ld7S&rFuNZUP zx1}V*Pe|vKC@NeqOOP|}{_O&^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69a&jng(UHC0Kx-&eBJmI$kjFG8HQn5!FAAQOIp6c*;-v_)Pi*dkREhXZW zPg{VAqz5Og!$er;uU@~+2@!|rJi5GbVqq7c65U*N?Wd-167YGktUj2v;3&hKfPQlBJ{y!ZSCtfFZOWD~$ z57uF+5Edg|oVN2>hqYP|FLhX`8W{1aR1Fv`I&B{j@!qMb#)*E8h?h=upgZ}4Ho9zd zcG@z+;>5c|BHm<)cq@o_e<9+)c}vJ+k9 zw1q!p;?<^3QHQDqZgk!$!syuO(rL?2seiLh5qdDfl8JXI2#ek5>_QiWrCfyQ6wM4^ zbaaX`@k$*Q2usE2JH#mk;=O(U2@$Var&!H8EL1NI|&cqwB=-iE{+ctby#$P&?$xeq3jf?!y@8E)qo0%f|oj8 zCGmzMcsHO^6jj5w<=&?1yNMN82sPGf{cogywNCGiTQ3*x0tk)2Ya zQ$#naz6cS#DbPcWcx63MHLx2*Tp;YU-J(iZ=y;W#qGa@?1Sa&+LpbrWjXsGULY<=7 zKm(8>KW!QDqO3-TwOGAVq>fkpv?YV6c8Z*MOHK>I%1EZa(WH&ex(0Siu}+a0-HLaL zQB;oNwB65%_e#w*-YF`B7sMMVh!-1O?s(aa&IDnL(2xde@IQ2l3w*pmywvf6uqb$0 tISQkTPLX$5s-2?fOt1*E&|%>n?E8G?tZ833dOEtfT6;M-I#07v{1@pe>V*IR literal 0 HcmV?d00001 diff --git a/Tests/test_file_tga.py b/Tests/test_file_tga.py index 465e13316..d14f561c6 100644 --- a/Tests/test_file_tga.py +++ b/Tests/test_file_tga.py @@ -6,7 +6,7 @@ import pytest from PIL import Image -from .helper import assert_image_equal, hopper +from .helper import assert_image_equal, assert_image_equal_tofile, hopper _TGA_DIR = os.path.join("Tests", "images", "tga") _TGA_DIR_COMMON = os.path.join(_TGA_DIR, "common") @@ -112,6 +112,14 @@ def test_save_wrong_mode(tmp_path): im.save(out) +def test_save_mapdepth(): + # This image has been manually hexedited from 200x32_p_bl_raw.tga + # to include an origin + test_file = "Tests/images/200x32_p_bl_raw_origin.tga" + with Image.open(test_file) as im: + assert_image_equal_tofile(im, "Tests/images/tga/common/200x32_p.png") + + def test_save_id_section(tmp_path): test_file = "Tests/images/rgb32rle.tga" with Image.open(test_file) as im: diff --git a/src/PIL/TgaImagePlugin.py b/src/PIL/TgaImagePlugin.py index 2b936d687..97959ca4e 100644 --- a/src/PIL/TgaImagePlugin.py +++ b/src/PIL/TgaImagePlugin.py @@ -110,7 +110,7 @@ class TgaImageFile(ImageFile.ImageFile): if colormaptype: # read palette - start, size, mapdepth = i16(s, 3), i16(s, 5), i16(s, 7) + start, size, mapdepth = i16(s, 3), i16(s, 5), s[7] if mapdepth == 16: self.palette = ImagePalette.raw( "BGR;16", b"\0" * 2 * start + self.fp.read(2 * size)