Skip to content

MAINT: Remove duplicate CCITT processing#3415

Merged
stefan6419846 merged 6 commits intopy-pdf:mainfrom
j-t-1:_xobj_to_image
Aug 4, 2025
Merged

MAINT: Remove duplicate CCITT processing#3415
stefan6419846 merged 6 commits intopy-pdf:mainfrom
j-t-1:_xobj_to_image

Conversation

@j-t-1
Copy link
Copy Markdown
Contributor

@j-t-1 j-t-1 commented Jul 30, 2025

Also rename a variable for readability.

@stefan6419846
Copy link
Copy Markdown
Collaborator

Could you please elaborate where we can see the unnecessary second processing?

@j-t-1
Copy link
Copy Markdown
Contributor Author

j-t-1 commented Jul 30, 2025

pypdf/pypdf/filters.py

Lines 899 to 926 in 6e617af

elif lfilters in (FT.LZW_DECODE, FT.ASCII_85_DECODE, FT.CCITT_FAX_DECODE):
# I'm not sure if the following logic is correct.
# There might not be any relationship between the filters and the
# extension
if lfilters in (FT.LZW_DECODE, FT.CCITT_FAX_DECODE):
extension = ".tiff" # mime_type = "image/tiff"
image_format = "TIFF"
else:
extension = ".png" # mime_type = "image/png"
image_format = "PNG"
try:
img = Image.open(BytesIO(data), formats=("TIFF", "PNG"))
except UnidentifiedImageError:
img = _extended_image_frombytes(mode, size, data)
elif lfilters == FT.DCT_DECODE:
img, image_format, extension = Image.open(BytesIO(data)), "JPEG", ".jpg"
# invert_color kept unchanged
elif lfilters == FT.JPX_DECODE:
img, image_format, extension, invert_color = _handle_jpx(
size, data, mode, color_space, colors
)
elif lfilters == FT.CCITT_FAX_DECODE:
img, image_format, extension, invert_color = (
Image.open(BytesIO(data), formats=("TIFF",)),
"TIFF",
".tiff",
False,
)

Lines 899 and 920.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.98%. Comparing base (01c98a5) to head (57020a2).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3415      +/-   ##
==========================================
+ Coverage   96.96%   96.98%   +0.02%     
==========================================
  Files          55       55              
  Lines        9343     9340       -3     
  Branches     1708     1708              
==========================================
- Hits         9059     9058       -1     
+ Misses        169      168       -1     
+ Partials      115      114       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread pypdf/filters.py Outdated
@stefan6419846 stefan6419846 merged commit 8000cbe into py-pdf:main Aug 4, 2025
14 checks passed
@j-t-1 j-t-1 deleted the _xobj_to_image branch August 4, 2025 10:27
j-t-1 added a commit to j-t-1/pypdf that referenced this pull request Aug 5, 2025
OpenNingia pushed a commit to OpenNingia/pypdf that referenced this pull request Oct 23, 2025
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

Successfully merging this pull request may close these issues.

2 participants