From 329fd00d3fe2709c043c73e075da03b6d9729a2b Mon Sep 17 00:00:00 2001 From: hugovk Date: Mon, 14 Apr 2014 13:49:29 +0300 Subject: [PATCH] Test j2k --- Tests/images/rgb_trns_ycbc.j2k | Bin 0 -> 5365 bytes Tests/images/rgb_trns_ycbc.jp2 | Bin 0 -> 5450 bytes Tests/test_file_jpeg2k.py | 36 ++++++++++++++++++++++++++++----- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 Tests/images/rgb_trns_ycbc.j2k create mode 100644 Tests/images/rgb_trns_ycbc.jp2 diff --git a/Tests/images/rgb_trns_ycbc.j2k b/Tests/images/rgb_trns_ycbc.j2k new file mode 100644 index 0000000000000000000000000000000000000000..462729501e184f82e36a5dc9ea9548c9dca6a4ea GIT binary patch literal 5365 zcmZXWWl$W9kH&E*?(PdLP~4rx-6>F9N^z&SwPXV%wLN1|0(kSQsnDEzaDPgXHHyC&(TZ9TP8L@BxqUcv`&%aPgX`O)%hnKg7dNhoFucGJ&l5KNvaph= zn}!({SQoyYGEgScr#V?y{1p=|I91wZ`do{+{u1%y=*Y8Jsw%xE!&m0PLxsrT3r0yJ`>{g2ky^s>rem@1~q8E97vbYarJ#X z1CeMmIpS%!_zoisFnrjNs;Qo%&`5rU!Xvzd9Cz6Yvs5Vf7^(0+sw8aoLYlrR(k>JF z{Kg%vU+4B60FQ1nIsIw4^qc@NjQg0rzFi4B&$SuXlb>x3rCd_$bTORGvz8`2#PnUe zzTu`X^WeNp31;CbG`=h30k?Av9h%Tt1<|R2DAq#=#%Yn7`?&q6^aq%_G?;L9K{;1# zr2`;ImQGQ3W0$~Y!d&ksh~IW{zoB(o+E7c)lo<*u6FUWnM;hFjTkK^|a|ORPGJhg? zFO!rbm{)cbmNS<;H+pr(fGXOA{}eKBQwxiVg|ZiOZ46efu!#d7~q`JN+v zG=u*>#xmxtwTg?S~ z%ggt1!G-h{H398bQd}Rfl;NW->P!P+T3W%25@8_K!Jvgr)z#WA)mt4Snt4nFqmiHX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4%_iq~~jk^9zPqFEKx zabO6)G0Zbnca#=sZdh$Wa=dgI)TE(^wb-E@TcW6lb2%v(D%n}V6cSMQG1!=Q z7>Ol_#ZtujDn-QIS0(E(t>LYPE->;PG^-}G5q381!^d-8G3{)V9on{q;#^;JKRRS|J2AhP@g3K}X;jZSr#ye9@0OQ9WhF}HCrD*R$zXBh zn(eVf@k`1rOio_rxtVaJkp`juZfwGoX zOM$!XSTQy~q%!!e%2_+E4VUZvXeaMN4=Sg-m)~$ssl+dka7k6B?JcOAqET0Uc|#ec zPeh8gqpl+SGw6oUyxox>cllK}`k~`yPDM`7R94s@%+;`r^-%8C(q2&SPKZmm(Lk7& ze)B=X(A6>l_te$+CNL;cosVIU7^_2I%Y_Ps&Hi4Y2N^>u1GB> zyYF2;!GHL;|7J!kOS?~ErTfwUf=OZVH6XE13-#j8L+iB z=GB$zNc=|NW+XR){H@8B9MH;@18d-iqO%z|9y^{#gqSt=Iu6Vfq#qyG6O!rK{b%4R zNZ*WW_Z85vWrmp{y(xVuxsj4MV%j4YrOirWKoW|UGlO!$z753zfXkQ%C}h@V(%2){ zMaFDzR#{@FgY-D}zU&x-Rw@t4ms}M>$t#-HYq!Eb?p);e6!S%rP6l?Wd{J-^gX?S; z3RQo6>yS-rN_+ytU z!K9^H4%U2f%lm0-X|R$x}fa;K|0qpe}XMJecf z%-d#ox?`(xzPbT4A0e_Bs##=}mtZ$lH+G8Q@3AlLrn<4~E_MLsaS zNpZFIZUx{NgSPznUPT)%&CXf>Y%B*^{?>XUkTkl>!{%#9!D4ImP>*)56lpSd|+SN;oYTsHRr literal 0 HcmV?d00001 diff --git a/Tests/images/rgb_trns_ycbc.jp2 b/Tests/images/rgb_trns_ycbc.jp2 new file mode 100644 index 0000000000000000000000000000000000000000..dea77c6dab27083254984681d6b79ff2ce73619b GIT binary patch literal 5450 zcmZWrWmFr?woUNjlHwj9w8h;C6n87o;!uh^#jQn)dvPhnp%g7na0!`_{VetaE0c*?Z5dv*yFa9m%E$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4Dn(Ckl~dNk;$qRrOn2WP2D zVx0E#dcUmC;|dALfA6Wy*$KxJ#A7R9e~=>M?ktnF8&mgG#TMxQ2Axn9S`IlJ^Wx(< zD(UmSQuWBAalo>rGOLmf<(oIe2=&G+pe-t4SAk%$iGQ@_HNzE%x2=oV4Kbtfjf&z@ z@x;4wJrV(C=w(r0o09sfFpFKJTX}VZ<~l_JI6EfxSb>wkwZ86Wj{0R!rF>L9sClV^c{IsqjYL2_fM!J^vKAu*431Se+HbBn*OloC!BlGiM(z;pHzOSYb-153*)Mp z!@DkaY50*>?Mg~Wx?Dq=lY0JE!ob-)j_|K_-JzUymJg;ZsavXC4SlzM zoZDW=7fwFn-=h3c-cAgqy_PRj{_cfcCcQCeAEBi>nl{O$8L__zImdBb$G46BbK2O_ z5WUI*uMtqWVx1~1hzifb&k3H%en}Y{3EI0lGwVK2^l`aaHJpgR67>m%G0FWbrGYz6 zW(-4Dw48l-cZzAACFmAj#%mz%AqBleBi`4ceJ#9^VDq*D15Ir-h!Z24`|T*TC5~U@ z?|tN}N#YR%xkR)dFwm8+4)`}!H%P+L6vFd_4F1ogak)dT&O_>CJ6fI2J8tY+57q^ypk&w6A#}zEuJ?H9tNm^ETov$jf zAHVNGfxG;tl1&`gQ$I&jTGW_~8p>ZH>-R5s-#%yCaUYL4*&>PR`>@*T>MX71wIOjZ zllx}XKO=3f#aWHn+MwpR2zoT=Y1KDYvgI!0X(!fT81ROlaWO96viHwqCK}3Wm_v$_ z^2Y!w2ycyLtuP@yJCyvZ73UEh2^q8d78P7 t7H=z97fCe$i*Th&JHFoG?Sc4K*NpO+zPV=9hf7#zHpEYT;O2Ok{~w$!MHB!4 literal 0 HcmV?d00001 diff --git a/Tests/test_file_jpeg2k.py b/Tests/test_file_jpeg2k.py index b11e5e6ab..628c53437 100644 --- a/Tests/test_file_jpeg2k.py +++ b/Tests/test_file_jpeg2k.py @@ -1,7 +1,6 @@ from tester import * from PIL import Image -from PIL import ImageFile codecs = dir(Image.core) @@ -15,18 +14,20 @@ ignore('Not enough memory to handle tile data') test_card = Image.open('Tests/images/test-card.png') test_card.load() + def roundtrip(im, **options): out = BytesIO() im.save(out, "JPEG2000", **options) bytes = out.tell() out.seek(0) im = Image.open(out) - im.bytes = bytes # for testing only + im.bytes = bytes # for testing only im.load() return im # ---------------------------------------------------------------------- + def test_sanity(): # Internal version number assert_match(Image.core.jp2klib_version, '\d+\.\d+\.\d+$') @@ -36,9 +37,10 @@ def test_sanity(): assert_equal(im.mode, 'RGB') assert_equal(im.size, (640, 480)) assert_equal(im.format, 'JPEG2000') - + # ---------------------------------------------------------------------- + # These two test pre-written JPEG 2000 files that were not written with # PIL (they were made using Adobe Photoshop) @@ -48,6 +50,7 @@ def test_lossless(): im.save('/tmp/test-card.png') assert_image_similar(im, test_card, 1.0e-3) + def test_lossy_tiled(): im = Image.open('Tests/images/test-card-lossy-tiled.jp2') im.load() @@ -55,49 +58,58 @@ def test_lossy_tiled(): # ---------------------------------------------------------------------- + def test_lossless_rt(): im = roundtrip(test_card) assert_image_equal(im, test_card) + def test_lossy_rt(): im = roundtrip(test_card, quality_layers=[20]) assert_image_similar(im, test_card, 2.0) + def test_tiled_rt(): im = roundtrip(test_card, tile_size=(128, 128)) assert_image_equal(im, test_card) + def test_tiled_offset_rt(): im = roundtrip(test_card, tile_size=(128, 128), tile_offset=(0, 0), offset=(32, 32)) assert_image_equal(im, test_card) - + + def test_irreversible_rt(): im = roundtrip(test_card, irreversible=True, quality_layers=[20]) assert_image_similar(im, test_card, 2.0) + def test_prog_qual_rt(): im = roundtrip(test_card, quality_layers=[60, 40, 20], progression='LRCP') assert_image_similar(im, test_card, 2.0) + def test_prog_res_rt(): im = roundtrip(test_card, num_resolutions=8, progression='RLCP') assert_image_equal(im, test_card) # ---------------------------------------------------------------------- + def test_reduce(): im = Image.open('Tests/images/test-card-lossless.jp2') im.reduce = 2 im.load() assert_equal(im.size, (160, 120)) + def test_layers(): out = BytesIO() test_card.save(out, 'JPEG2000', quality_layers=[100, 50, 10], progression='LRCP') out.seek(0) - + im = Image.open(out) im.layers = 1 im.load() @@ -108,3 +120,17 @@ def test_layers(): im.layers = 3 im.load() assert_image_similar(im, test_card, 0.4) + + +def test_rgba(): + # Arrange + j2k = Image.open('Tests/images/rgb_trns_ycbc.j2k') + jp2 = Image.open('Tests/images/rgb_trns_ycbc.jp2') + + # Act + j2k.load() + jp2.load() + + # Assert + assert_equal(j2k.mode, 'RGBA') + assert_equal(jp2.mode, 'RGBA')