Fix indexed image detection to prevent PDF size inflation#1479
Merged
andreasrosdal merged 5 commits intomasterfrom Feb 16, 2026
Merged
Fix indexed image detection to prevent PDF size inflation#1479andreasrosdal merged 5 commits intomasterfrom
andreasrosdal 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>
|
Copilot stopped work on behalf of
andreasrosdal due to an error
February 16, 2026 11:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



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.