Repository navigation
fix(latex): keep CMYK JPEG figures - #4696
Conversation
PNG can't store CMYK, so ImageRef.from_pil raised for a CMYK \includegraphics figure and the handler added the picture without an image, with only a debug log. Normalize the figure first, like the XLSX, OpenDocument, DOCX and PPTX backends do. Resolves docling-project#4695 Signed-off-by: usmanmateen <usmanmateen255@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
✅ DCO Check Passed Thanks @usmanmateen, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
AI triage (advisory)Checked commit This pull request normalizes CMYK JPEG figures before image conversion in the LaTeX backend. This change prevents dropped figures during document export. CI safety: no concern found. A maintainer must still approve CI. 1 related pull request(s) in the same code
The |
There was a problem hiding this comment.
AI first review (advisory): no blocking issue found
This review covers the full diff at 762d5019fb. It read the code only. It did not run tests or code from this pull request.
The PR fixes CMYK JPEG figures being silently dropped by the LaTeX backend. It applies normalize_image_for_png before ImageRef.from_pil, matching the pattern already used in the DOCX, PPTX, XLSX, and ODF backends. A regression test constructs a synthetic CMYK JPEG, converts it through the backend, and checks that the resulting picture has an RGB image. The change is small and low-risk; the main review points are the test robustness and one minor redundancy.
A maintainer makes the merge decision. This review never approves the pull request.
The CMYK colour decodes to exactly (255, 0, 0), so compare it directly, like the OpenDocument test does, instead of loose channel thresholds. Signed-off-by: usmanmateen <usmanmateen255@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
AI first review (advisory): no blocking issue found
This review covers the changes since 762d5019fb at 46d0517068. It read the code only. It did not run tests or code from this pull request.
This PR fixes a bug where CMYK JPEG figures in LaTeX documents were silently dropped because ImageRef.from_pil cannot write CMYK as PNG. The fix applies normalize_image_for_png before the ImageRef.from_pil call, matching the pattern already used in XLSX, ODF, DOCX, and PPTX backends. The incremental update addresses both nit findings from the previous review: it replaces the redundant isinstance guard and loose colour-threshold assertions with a single exact equality check.
A maintainer makes the merge decision. This review never approves the pull request.
|
cc @PeterStaar-IBM @DanielNg0729: same |
DanielNg0729
left a comment
There was a problem hiding this comment.
Hi @usmanmateen, thank you for the fix! I noticed there are a few other fixes addressing the same normalize_image_for_png issue. If there are any other cases where this issue still occurs, would you mind including those fixes in this PR as well? That way, we can hopefully address the issue comprehensively in one place. Thanks!
|
Thanks @DanielNg0729! I went through every Already normalized on Covered by open PRs:
Not affected, because the image is never in a mode PNG can't store: PDF, Tectonic and LibreOffice chart renders (pypdfium2 output), the HTML page screenshot and video frames (both One case I left alone: METS/GBS page scans are opened without conversion, but they are page images rather than pictures, and the test archives are 1-bit TIFFs, which PNG stores as is. I didn't find a real METS/GBS source in another mode, so I didn't change it. So this PR doesn't need more changes for now. If you'd rather have the #4683 / #4686 changes in one place, I'm happy to coordinate with their authors, but I didn't want to copy their work here. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
|
Issue resolved by this Pull Request:
Resolves #4695
The
includegraphicsbranch inhandlers/macros.pypassed the opened figure straight toImageRef.from_pil, which can't write CMYK as PNG. Theexcept Exceptionturned that into a debug log, so a CMYK JPEG figure was added as a picture without an image. This normalizes the figure withnormalize_image_for_pngfirst, the same way the XLSX (#4664), OpenDocument (#4666), DOCX and PPTX backends do. RGB, RGBA and other PNG-compatible figures pass through unchanged.Checklist:
Review evidence:
ConversionStatus.SUCCESS [True, False]onmainandConversionStatus.SUCCESS [True, True]with this change.test_latex_includegraphics_cmyk_jpegconverts a.texfile with one CMYK JPEG figure and checks that the picture has an RGB image with the expected colour. It fails onmain(picture.get_image(doc)isNone) and passes here.pytest tests/test_latex: 134 passed.ruff format --check,ruff checkandtach checkpass.ty checkreports no diagnostics on the changed lines.Not changed: a
strsource (convert("paper.tex")) still gives no figure an image, because the backend gets a stream and can't resolve relative files. That is #4694, which I'll fix in a separate PR.🤖 Generated with Claude Code