Repository navigation
fix(xlsx): keep CMYK pictures instead of dropping or re-rendering them - #4664
Conversation
Unlike the Word and PowerPoint backends since docling-project#4598, the Excel backend did not normalize pictures before PNG serialization. A CMYK picture loaded by openpyxl failed in ImageRef.from_pil and was dropped, and the PNG probe in the unsupported-image scan took the same picture for an EMF/WMF image and rendered it through LibreOffice. Normalize the picture in both paths, so it is kept once, as stored, with or without LibreOffice. Resolves docling-project#4658 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 The PR applies Topic labels added: 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 f96dfd18bf. It read the code only. It did not run tests or code from this pull request.
The PR fixes CMYK picture handling in the Excel backend, which had two failure paths: _find_images_in_sheet dropped CMYK pictures because ImageRef.from_pil could not write CMYK as PNG, and _process_drawing_for_unsupported_images re-routed them to LibreOffice because the PNG probe also failed on CMYK. The fix applies normalize_image_for_png on both paths and adds ValueError to the probe's exception handler, mirroring the Word and PowerPoint backends. Tests are targeted and would catch both regressions.
A maintainer makes the merge decision. This review never approves the pull request.
|
cc @PeterStaar-IBM since you reviewed #4598, this applies the same fix to the Excel backend. Happy to adjust anything. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Resolves #4658
Unlike the Word and PowerPoint backends since #4598, the Excel backend didn't run
normalize_image_for_pngon pictures. A CMYK picture failed on both of its paths:_find_images_in_sheet:ImageRef.from_pilcan't write CMYK as PNG, so the picture was dropped withcould not extract the image from excel sheets._process_drawing_for_unsupported_images: the PNG probe failed on the same picture, so it was treated as EMF/WMF and, when LibreOffice is available, rendered through it instead of kept as stored.This normalizes the picture on both paths. Normalizing only the first one would return the picture twice, because the probe would still send it to LibreOffice. The probe now also catches
ValueError, like the PowerPoint backend does, because the RGB conversion can raise it and that would otherwise stop the scan of the whole drawing.Checklist:
Review evidence:
With the reproduction from the issue:
Tests in
tests/test_office_image_modes.py:test_cmyk_office_picture_without_libreofficenow also runs forxlsx, with and without an invalid ICC profile.test_cmyk_xlsx_picture_is_not_rendered_by_libreofficestands in for an installed LibreOffice by patching_convert_emf_to_pil, and checks that the picture is kept once at its stored size. With only the first path fixed, it fails with 2 pictures.Commands run (WSL2 Ubuntu, Python 3.12):
pytest tests/test_office_image_modes.py: 11 passed. The 3 new xlsx cases fail onmain(0 pictures, 0 pictures, 401×201).pytest tests/test_backend_msexcel.py: 28 passed, 2 skipped, same as onmain.make validate: all hooks pass.Not run: a real LibreOffice conversion (not installed here, so the second test patches it), and the full test suite.