Skip to content

Commit

Permalink
BUG: Handle single element ColorSpace list (#2026)
Browse files Browse the repository at this point in the history
Fixes #2023
  • Loading branch information
pubpub-zz authored Jul 27, 2023
1 parent 0b85bce commit 0a9055d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pypdf/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,8 @@ def _handle_jpx(
data = data.encode()
colors = x_object_obj.get("/Colors", 1)
color_space: Any = x_object_obj.get("/ColorSpace", NullObject()).get_object()
if isinstance(color_space, list) and len(color_space) == 1:
color_space = color_space[0].get_object()
if (
IA.COLOR_SPACE in x_object_obj
and x_object_obj[IA.COLOR_SPACE] == ColorSpaces.DEVICE_RGB
Expand Down
9 changes: 9 additions & 0 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,3 +553,12 @@ def test_gray_devicen_cmyk():
diff = ImageChops.difference(data.image, refimg)
d = sqrt(sum([(a * a) for a in diff.getdata()])) / (diff.size[0] * diff.size[1])
assert d < 0.001


@pytest.mark.enable_socket()
def test_singleton_device():
"""From #2023"""
url = "https://github.com/py-pdf/pypdf/files/12177287/tt.pdf"
name = "pypdf_with_arr_deviceRGB.pdf"
reader = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
reader.pages[0].images[0]

0 comments on commit 0a9055d

Please sign in to comment.