pypdf icon indicating copy to clipboard operation
pypdf copied to clipboard

Check some code in _image_xobject.py and update comments

Open j-t-1 opened this issue 5 months ago • 4 comments

Explanation

Check some comments in_image_xobject.py.

https://github.com/py-pdf/pypdf/blob/d5cd26622a871635cb8bc6ae0552c843681b5a6e/pypdf/generic/_image_xobject.py#L290-L291

The PR is closed, check whether the TODO comment can be removed? Check if Pillow can process CYMK; if not add to the comment the version checked.

https://github.com/py-pdf/pypdf/blob/d5cd26622a871635cb8bc6ae0552c843681b5a6e/pypdf/generic/_image_xobject.py#L308-L310

This needs checking.

https://github.com/py-pdf/pypdf/blob/d5cd26622a871635cb8bc6ae0552c843681b5a6e/pypdf/generic/_image_xobject.py#L528-L541

I agree with the comment, but needs checking, and comment updating.

j-t-1 avatar Jun 17 '26 11:06 j-t-1

I am not sure how you want to check and update this, but I will leave this up to you.

This needs checking.

This is unresolved.

stefan6419846 avatar Jun 17 '26 11:06 stefan6419846

For the unresolved part (last above), I think doing the try/except first, and then using img.format to determine if it is a TIFF or PNG may be better.

img = Image.open(BytesIO(data), formats=("TIFF", "PNG"))
if img.format == "TIFF"
         extension = ".tiff"

What would have been better is if the format was obtained, and then at the very end the extension can be calculated by lookup, there is no need to carry the extension around. The image_format is contained in img.format for most paths. The code is more complicated than necessary.

j-t-1 avatar Jun 18 '26 19:06 j-t-1

@BiswasNehaa the PR you have done solves this issue nicely. Will you be able to update it and finish the coverage?

j-t-1 avatar Oct 14 '26 21:10 j-t-1

Thanks for the nudge, @j-t-1, and sorry for the delay. Yes, I’ll finish it. Where it stands: the branch has conflicts with main, and the 2 uncovered lines are in the UnidentifiedImageError fallback. Looking again, that branch should keep the _expand_low_bit_samples call that main has, which my version dropped. I’ll rebase, fix that, add a test that hits the fallback, and follow up on @stefan6419846’s question about raising the minimum Pillow version.

BiswasNehaa avatar Oct 15 '26 17:10 BiswasNehaa