Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_image_palette fails with Pillow 9.1.0 #328

Closed
dotlambda opened this issue Apr 9, 2022 · 2 comments
Closed

test_image_palette fails with Pillow 9.1.0 #328

dotlambda opened this issue Apr 9, 2022 · 2 comments

Comments

@dotlambda
Copy link

============================= test session starts ==============================
platform linux -- Python 3.10.3, pytest-7.0.1, pluggy-1.0.0
rootdir: /build/source, configfile: pyproject.toml, testpaths: tests
plugins: hypothesis-6.38.0, xdist-2.5.0, forked-1.4.0
gw0 [510] / gw1 [510]m
....................................................................x... [ 14%]
..........................F.................s........................... [ 28%]
....................................................s................... [ 42%]
........................................................................ [ 56%]
........................................................................ [ 70%]
....................................s................................... [ 84%]
...................................ssss................................. [ 98%]
......                                                                   [100%]
=================================== FAILURES ===================================
_________________ test_image_palette[pal-1bit-rgb.pdf-1-rgb2] __________________
[gw0] linux -- Python 3.10.3 /nix/store/443qk9752l44kfp8pzsrp0m9jyq6jz2p-python3-3.10.3/bin/python3.10

resources = PosixPath('/build/source/tests/resources')
filename = 'pal-1bit-rgb.pdf', bpc = 1, rgb = (255, 128, 0)

    @pytest.mark.parametrize(
        'filename,bpc,rgb',
        [
            ('pal.pdf', 8, (0, 0, 255)),
            ('pal-1bit-trivial.pdf', 1, (255, 255, 255)),
            ('pal-1bit-rgb.pdf', 1, (255, 128, 0)),
        ],
    )
    def test_image_palette(resources, filename, bpc, rgb):
        pdf = Pdf.open(resources / filename)
        pim = PdfImage(next(iter(pdf.pages[0].images.values())))

        assert pim.palette[0] == 'RGB'
        assert pim.colorspace == '/DeviceRGB'
        assert not pim.is_inline
        assert pim.mode == 'P'
        assert pim.bits_per_component == bpc

        outstream = BytesIO()
        pim.extract_to(stream=outstream)

        im = pim.as_pil_image().convert('RGB')
>       assert im.getpixel((1, 1)) == rgb
E       assert (255, 255, 255) == (255, 128, 0)
E         At index 1 diff: 255 != 128
E         Use -v to get the full diff

tests/test_image_access.py:520: AssertionError
=============================== warnings summary ===============================
tests/test_pages.py:220
tests/test_pages.py:220
  /build/source/tests/test_pages.py:220: PytestUnknownMarkWarning: Unknown pytest.mark.timeout - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
    @pytest.mark.timeout(1)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED tests/test_image_access.py::test_image_palette[pal-1bit-rgb.pdf-1-rgb2]
======= 1 failed, 501 passed, 7 skipped, 1 xfailed, 2 warnings in 16.94s =======
@jbarlow83
Copy link
Member

Looks like this new release of Pillow is disregarding the image's palette.

@jbarlow83
Copy link
Member

Fixed in v5.1.2.

Notes: did not fully investigate if this was a Pillow problem or just a behavior quirk. Regardless the fix works with new and old Pillow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants