From 6cff2931e4be19d7e7d2ef31c2f054b6b9554beb Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Tue, 18 Jan 2022 16:33:37 +0100 Subject: [PATCH] ensure that gif test input uses the same palette for all frames --- src/img2pdf_test.py | 52 +++++++++++++++-------------- src/tests/input/animation.gif | Bin 1930 -> 1962 bytes src/tests/output/animation.gif.pdf | Bin 6070 -> 6101 bytes 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/img2pdf_test.py b/src/img2pdf_test.py index 4253929..39cd0c4 100755 --- a/src/img2pdf_test.py +++ b/src/img2pdf_test.py @@ -2190,15 +2190,37 @@ def gif_palette8_img(tmp_path_factory, tmp_palette8_png): @pytest.fixture(scope="session") def gif_animation_img(tmp_path_factory, tmp_normal_png, tmp_inverse_png): in_img = tmp_path_factory.mktemp("gif_animation_img") / "in.gif" + pal_img = tmp_path_factory.mktemp("gif_animation_img") / "pal.gif" + tmp_img = tmp_path_factory.mktemp("gif_animation_img") / "tmp.gif" subprocess.check_call( CONVERT + [ str(tmp_normal_png), str(tmp_inverse_png), - "-strip", - str(in_img), + str(tmp_img), ] ) + # create palette image with all unique colors + subprocess.check_call( + CONVERT + + [ + str(tmp_img), + "-unique-colors", + str(pal_img), + ] + ) + # make sure all frames have the same palette by using -remap + subprocess.check_call( + CONVERT + + [ + str(tmp_img), + "-strip", + "-remap", str(pal_img), + str(in_img) + ] + ) + pal_img.unlink() + tmp_img.unlink() identify = json.loads( subprocess.check_output(CONVERT + [str(in_img) + "[0]", "json:"]) ) @@ -2228,6 +2250,7 @@ def gif_animation_img(tmp_path_factory, tmp_normal_png, tmp_inverse_png): "y": 0, }, str(identify) assert identify[0]["image"].get("compression") == "LZW", str(identify) + colormap_frame0 = identify[0]["image"].get("colormap") identify = json.loads( subprocess.check_output(CONVERT + [str(in_img) + "[1]", "json:"]) ) @@ -2258,6 +2281,8 @@ def gif_animation_img(tmp_path_factory, tmp_normal_png, tmp_inverse_png): }, str(identify) assert identify[0]["image"].get("compression") == "LZW", str(identify) assert identify[0]["image"].get("scene") == 1, str(identify) + colormap_frame1 = identify[0]["image"].get("colormap") + assert colormap_frame0 == colormap_frame1 yield in_img in_img.unlink() @@ -6712,29 +6737,6 @@ def test_general(general_input, engine): y = pikepdf.open(out) pydictx = rec(x.Root) pydicty = rec(y.Root) - if f.endswith(os.path.sep + "animation.gif"): - # starting with PIL 8.2.0 the palette is half the size when encoding - # our test GIF image as PNG - # - # to still compare successfully, we truncate the expected palette - import PIL - - if PIL.__version__ >= "8.2.0": - assert len(pydictx["/Pages"]["/Kids"]) == 2 - for p in pydictx["/Pages"]["/Kids"]: - assert p["/Resources"]["/XObject"]["/Im0"]["/ColorSpace"][2] == 127 - assert len(pydicty["/Pages"]["/Kids"]) == 2 - for p in pydicty["/Pages"]["/Kids"]: - cs = p["/Resources"]["/XObject"]["/Im0"]["/ColorSpace"] - cs[2] = decimal.Decimal("127") - cs[3] = cs[3][:384] - else: - assert ( - pydictx["/Pages"]["/Kids"][0]["/Resources"]["/XObject"]["/Im0"][ - "/ColorSpace" - ][2] - == 255 - ) assert pydictx == pydicty # the python-pil version 2.3.0-1ubuntu3 in Ubuntu does not have the # close() method diff --git a/src/tests/input/animation.gif b/src/tests/input/animation.gif index af4b278972b7a1817b1cf38cc8763774a00be4e4..d60a2370b21c32c7ee8283b42e9f65098c702e91 100644 GIT binary patch delta 1697 zcmb`_*;|r{0)X)k6}MzDL2*Gg4MkK^TSjw(5ZoGaDKs;o^fAVI#L+plF$`TU%Ra zXJ=PeS8s1`UteE;f4@ef866!RA0O9hwUd*R&+VQ+fAQkQ;^N}U%F62M>e|}c+qZAm z*VjRBC|dOKB+L$HyN(emo%|;lzm(Nl8g*X=$06nL?p3D=RBMKVKq|fFM{?Q*-_L^@fIqrlzLm z=H{C>Z+3KasMYG8o}Ph$fhSL%Jbn6fYHDg)G(D}?>lYRlUcGwt=FOXT@7`^0ZoYs2 z9tMLU5C|j^iAJNbSS${QBauk%?(P%{g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>F8+7ppj6oZm1^YT6P=WLC^3TNO47Q*UnAAf`@0T#f~SQ>Dt|>PHF1qp@&QGP zm#v8&l3?u~zAAN{j5&nY7klALy+2ER>P0MpOI%%l)JUb_<`j_BMJiXQkt)t@)Y3?; za#3v3NR1Q8iJzqI5(#jhq{134{I+n>7`R4i#aGG!K+dUQ4HQ86;IK1RNo$y=YDVB$Z0D+3=07rCp{*DnFExuAQA+kikSiQg5S- zw-u$zwY7mR2HGFMqs^)RNWH)iYNT>ya1&LfmguuoZH9rz*K(v;YP;aB>7IGhcI_`q Gb^jZ{q*Yr0 diff --git a/src/tests/output/animation.gif.pdf b/src/tests/output/animation.gif.pdf index fdfd460d3d6f8d858db7315699eb8c662455020a..2af1ba4ec9f6a578dbd35129ac28fb5ba8c55234 100644 GIT binary patch literal 6101 zcmeI03vg8B700It9lW5tq~THEACVw1Wbb?LlJJ-$L;?vU;hBKI-Fv?qR+7DOv*96A zkOG1T2*iMpXlERSRERJNBEq1BGKE4xc@(sbB4tvZwuoYND)gRjS6HCVbf(jGI+O1= zvv>CF_c-6V=ezg6r&oSfc7G{V5qh2d)6wIC1QBlV2_ZdQfY*Ha5!bG?SOkxT%1Y#N z+ku#>rYe1eL4yPqwyCRp_Ykv$RY38qg|Rut%r0l}Wtvg5)GbLENL>=w%5*EkQOL1D zBSLlsCPJlY;OC!@Cr+17t0YWD9q*hh9A)8X1vDBP8=1%KkeT7m^5zvi3_VrWpy-HC zoNq?F5s97`vI@5{VtLz%$AiaY!l>XA%!(%3xIL##gnnx^GI>EtxcFj$AkPyVC;t*1 z&t>6~=rpJX^{I$Pm{}$~DR5s!@>=vfP8Gf8-HF7DRVMhzgDh7lpj#6k8ox>8SK=xe zp=d=ui)6ZG6W^Y(dDMayde2_C_w^>O+aA;6o-K7C!kscG?9SD2xtxgT_&KL1bBZHevN=(5-@@U0vdsUO@MDt zgeeg)9Rl1H1-!ojzGo4ZM8J{>a931Vyuoq^*dhVGOBpsJU^@huN`UzZFoOUK5MV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