Skip to content

Commit

Permalink
BUG: Handle chained colorspace for inline images when no filter is set
Browse files Browse the repository at this point in the history
Closes #2998.
  • Loading branch information
stefan6419846 committed Dec 19, 2024
1 parent 17f6e35 commit 3c28ea7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pypdf/generic/_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,8 @@ def _read_inline_image(self, stream: StreamType) -> Dict[str, Any]:
data = extract_inline_DCT(stream)
elif filtr == "not set":
cs = settings.get("/CS", "")
if isinstance(cs, list):
cs = cs[0]
if "RGB" in cs:
lcs = 3
elif "CMYK" in cs:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,14 @@ def test_4bits_images(caplog):
name = "iss2411.png"
img = Image.open(BytesIO(get_data_from_url(url, name=name)))
assert image_similarity(reader.pages[0].images[1].image, img) == 1.0


@pytest.mark.enable_socket
def test_no_filter_with_colorspace_as_list():
"""Tests for #2998"""
url = "https://github.com/user-attachments/files/18058571/9bf7a2e2-72c8-4ac1-b8ae-164df16c8cef.pdf"
name = "iss2998.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))

page = reader.pages[0]
page.images.items()

0 comments on commit 3c28ea7

Please sign in to comment.