Fix indexed image detection to prevent PDF size inflation#1479
Fix indexed image detection to prevent PDF size inflation#1479andreasrosdal merged 5 commits intomasterfrom
Conversation
Co-authored-by: andreasrosdal <259156774+andreasrosdal@users.noreply.github.com>
Co-authored-by: andreasrosdal <259156774+andreasrosdal@users.noreply.github.com>
Co-authored-by: andreasrosdal <259156774+andreasrosdal@users.noreply.github.com>
|
)" This reverts commit 7c04f66.
)" This reverts commit 7c04f66.
|
I noticed you started using copilot to automatically "fix" issues with the code about two weeks ago. This led to this regression, where png and gif images were garbled in the produced pdf. If this is how you maintain the code now, it's hard to place any confidence in new releases of openpdf. |
|
I would say that it was an in good-faith attempt at using Copilot AI to help fix bugs in OpenPDF, because "everyone" is saying that AI is now smart enough to program, and to see how well Copilot now can be used to fix bugs in OpenPDF. |
|
Thank you, that's reassuring. Thankfully, the bug was noticed before it made it into our production environment. Openpdf-3.0.1 was pulled in transitively when updating Flying Saucer from 10.0.6 to 10.0.7, which is still the latest version. https://mvnrepository.com/artifact/org.xhtmlrenderer/flying-saucer-pdf/10.0.7/dependencies |
|
Flying saucer 10.1.0 has been released, with latest OpenPDF version. |
|
Thanks :) |



Fix indexed image detection to prevent PDF size inflation
Fixes #1289
Problem
Indexed images (GIFs and PNGs with indexed colors) were incorrectly detected as RGB images, causing significant PDF size inflation (100%+ in some cases as reported in the issue).
Root Cause
When loading GIF/PNG via ImageIO, BufferedImage with IndexColorModel was converted to RGB using PixelGrabber, which:
Solution Implemented
Modified
Image.getInstance(java.awt.Image, java.awt.Color, boolean)to:[/Indexed /DeviceRGB maxIndex palette]Changes Made
shouldDetectIndexedColorGif: Tests loading indexed GIF from fileshouldDetectIndexedColorFromBufferedImage: Tests programmatically created indexed BufferedImageTesting Results
Verification
Tested with H.gif (indexed GIF from test resources):
This fix ensures that indexed images maintain their compact representation in PDFs, preventing the size inflation reported in issue #1289.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.