Repository navigation
fix(odf): keep CMYK pictures instead of dropping them - #4666
Conversation
PNG can't store CMYK, so ImageRef.from_pil raised for a CMYK picture in an ODT, ODP or ODS file, and _add_odf_images skipped the picture with only a debug log. Normalize the picture first, like the Word and PowerPoint backends do since docling-project#4598. Resolves docling-project#4665 Signed-off-by: usmanmateen <usmanmateen255@gmail.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 Normalize CMYK images with normalize_image_for_png in the OpenDocument backend to prevent dropped pictures. Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 2 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 cad3d0c998. It read the code only. It did not run tests or code from this pull request.
The PR fixes CMYK image loss in ODF (ODT, ODP, ODS) conversion. _image_ref_from_odf_image passed the raw PIL image to ImageRef.from_pil, which cannot write CMYK as PNG and therefore raised an exception that _add_odf_images silently swallowed. The fix normalizes the image with the same normalize_image_for_png helper used by the Word and PowerPoint backends. Three parametrized tests verify the fix for all three ODF types. The only remaining risk is the untouched _find_images_in_sheet path in OdsDocumentBackend, which has the same ImageRef.from_pil call without normalization, but the PR body explains why that path is currently unreachable.
Findings outside the diff lines
-
minor
docling/backend/opendocument_backend.py:2317:_find_images_in_sheetstill callsImageRef.from_pilwithout normalization
_find_images_in_sheet(line 2317) has the exact same missing normalization as the one fixed in_image_ref_from_odf_image. The PR body explains thatimg.get_data()does not currently return data for odfdo 3.26.3DrawImageobjects, so the bug cannot trigger today. However, if odfdo ever adds that method, or if a different image object type reaches this path, CMYK images will silently fail again with no indication that the root cause is the same as #4665.Consider adding
normalize_image_for_png(pil_image)here as a defensive fix alongside this PR, or file a follow-up issue so the gap is tracked.
A maintainer makes the merge decision. This review never approves the pull request.
|
On the review's cc @PeterStaar-IBM since you added the OpenDocument backend in #3480 and reviewed #4598. Happy to adjust anything. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Resolves #4665
_image_ref_from_odf_imagepassed pictures straight toImageRef.from_pil, which can't write CMYK as PNG, so_add_odf_imagesdropped any CMYK picture in an ODT, ODP or ODS file with only a debug log. This normalizes the picture withnormalize_image_for_pngfirst, the same way the Word and PowerPoint backends do since #4598 (#4664 does the same for Excel).Checklist:
Review evidence:
ConversionStatus.SUCCESS 0onmainandConversionStatus.SUCCESS 1with this change.test_cmyk_picture_is_keptbuilds an ODT, ODP and ODS file with one CMYK picture (in a paragraph, on a draw page and in a cell) and checks that the picture is kept at its size and colour. All 3 cases fail onmain(0 pictures) and pass here. With an RGB picture, the same files keep it onmain, so CMYK is the only cause.pytest tests/test_backend_opendocument.py tests/test_office_image_modes.py: 63 passed (60 onmainplus the 3 new cases), with the same 3 warnings asmain.make validate: all hooks pass.Not changed:
OdsDocumentBackend._find_images_in_sheetalso callsImageRef.from_pilwithout normalizing, but it reads the picture withimg.get_data(), which odfdo'sDrawImagedoesn't have (odfdo 3.26.3), so that path can't add a picture today. That looks like a separate issue, so I left it out of this PR.