From 6596e31605b7916610a69c491d76114f2058fede Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 5 Aug 2021 01:06:01 +1000 Subject: [PATCH] Determine mode purely from ihdr header box --- Tests/images/balloon_eciRGBv2_aware.jp2 | Bin 0 -> 7419 bytes Tests/test_file_jpeg2k.py | 10 +++++ src/PIL/Jpeg2KImagePlugin.py | 49 ++++++------------------ 3 files changed, 21 insertions(+), 38 deletions(-) create mode 100644 Tests/images/balloon_eciRGBv2_aware.jp2 diff --git a/Tests/images/balloon_eciRGBv2_aware.jp2 b/Tests/images/balloon_eciRGBv2_aware.jp2 new file mode 100644 index 0000000000000000000000000000000000000000..18fd1e1723de3237802ecf53839ac530d5321822 GIT binary patch literal 7419 zcmeHM3w#q**1waaO`5*w3(9-i0%>vD%;Y_38)=i2R{EkXPf<)W({yN(iIeFILD^LS zc?flZWfepPSw9p7c`SaQ!unVcKUZJ{RKN$|DvPV)iux_uy?63x3dLR5Z-3wZzTek0 zXYM`sf6hH~?wNDX+yDTQ=G5bOvU-sk0Fc=tb_eDJbU18-&{dTPudT2Ampd3h$m{%J z09-x}AO+x9VRMz;zRqWOeCsCXCu)mq7n%#$`9Qb8 zd0It0-(G<0NYacqcjI>6%L{lT?`;=3-XA3JGOrhJK(HX*zy?{NgJp{FYR=92gDlRl zqKoqeaktBlH?w#P-|lB{-fzWQMKNI2YCAhSi&!^T#0wrRylPoLxcnNpS}8zCDfBW1-hr>tH!Q^v{yvO8o8 zWj(TWvL|FaWG~7N%TCD7%081_k*nlc@?5!AULvoOPn9!rL4KEfx%?sd7Wp3etMa$x z=j2~1WQsIJj)GK7P}D1KQv?(X6g`SZ70)VOQv5-2Uh#FDDsEUD5oe35k8{Vh$1RR~ zDDLUF195M~eH?cseo*|FcuRauyeqyVerfz8@w?&=$G;zcS(&8FQ_{*hWs7pYa+UHa z4nwx#x@?oK^5NH!>cP~D)8LF)&-Jm_Lt zMp|(ileR2vSK66$Wjd8UGyR_Qr_ip*x2D zaoC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Z8|e$4hvj8)L&*spN!s2Qn4~ILq92a1FgKs2V42Tz!4lBjtS!^ zFBG&jJj2@bCE9`5=yv+}m0VEdg>GAASz~2B*+n%|mS);eK;V50BMiL$41=HB*;|WPN?VQ zY?e@(fh~mjaqN(2SY?Tn!mgdSL^8+D`vP!Vkb(_H%{4rn;nl3)BevQ?5q1r` zKXw|&Kxim{`=B9i6xr`7`2W21@13`#RqVH7(RHj7IJl3(O$g?!NEpTPqQH8TL|}O! zaPBI<$Oy97J$Z{a-cLjPIo2N;VA!dLb1EBq8cC)y%YUd4{W zLk}r>T&3iTQkUd|tNDEbe2duW5?EUqs)TUqR#3*o?TrR}8s}&D&R|4G1R52d-e-nQ zPm-qBw3=p3W@F{%Hjo777pMweV^B^21gXszyM-gqANTyE>8(cEYOvfu z>Z0@a!$uYG4A;_qJ@Js?aOa9(ev(&%qO$`Qrr{#DUj-QPYp|(1z-rO*whM07*#V!c zyuLy(1|rQKRmzB7p_4iEUa?{SXnX^0`HSb>wrrLvdF|zO~gj2 zaK=j{)2s~dZbvnBmBZHF&M{UK3<;;vm&NdqyP`OEtIO|U8Jji&iZJ@2Vx0YB)(K4-Bic`8Fq|OEJTRIDNDVOw zHDrB%fquF=TUl63ll^jo#cDJ~azjXggp%Y2ti67mW8J*JgB8Rdb}oFFTyQgFg`lkk zJz$|%&N%_rgNuB)hjyHZ?_==)Q+6_;=Q}b(I4t^kFJ{*0UE%**_Wlb4mj3&R<^OQN z{tF#j_V4Z3*ec-%Gr?8wRiP{$laNtC150Grm|b-^{F@DU8_gN5`zxo3rx4j?~Z z5fi#Scpe8&=Csk{J=lpJ5VC%FD%c5+|KMpN`Z>|vTh}`oXi*RTged)#h}!569xqB? zsRQ88ix?LA?`;6-N*PdLaS8CK0(s?pw*LbB?DGH*X!&qIIHBBBB") + height, width, nc, bpc = header.read_fields(">IIHB") size = (width, height) - if unkc: - if nc == 1 and (bpc & 0x7F) > 8: - mode = "I;16" - elif nc == 1: - mode = "L" - elif nc == 2: - mode = "LA" - elif nc == 3: - mode = "RGB" - elif nc == 4: - mode = "RGBA" - elif tbox == b"colr": - meth, prec, approx = header.read_fields(">BBB") - if meth == 1 and unkc == 0: - cs = header.read_fields(">I")[0] - if cs == 16: # sRGB - if nc == 1 and (bpc & 0x7F) > 8: - mode = "I;16" - elif nc == 1: - mode = "L" - elif nc == 3: - mode = "RGB" - elif nc == 4: - mode = "RGBA" - elif cs == 17: # grayscale - if nc == 1 and (bpc & 0x7F) > 8: - mode = "I;16" - elif nc == 1: - mode = "L" - elif nc == 2: - mode = "LA" - elif cs == 18: # sYCC - if nc == 3: - mode = "RGB" - elif nc == 4: - mode = "RGBA" + if nc == 1 and (bpc & 0x7F) > 8: + mode = "I;16" + elif nc == 1: + mode = "L" + elif nc == 2: + mode = "LA" + elif nc == 3: + mode = "RGB" + elif nc == 4: + mode = "RGBA" elif tbox == b"res ": res = header.read_boxes() while res.has_next_box():