openpdf-renderer: resolve named /ColorSpace resources (ICCBased, CalGray, CalRGB, Lab) for cs/CS/scn/SCN - #1605
Open
andreasrosdalw wants to merge 4 commits into
Conversation
…for cs/CS/scn/SCN cs/CS previously only recognized literal device color space names (/DeviceGray, /DeviceRGB, /DeviceCMYK); any other name -- most commonly a named ICCBased profile like /CS0 declared in the page's /ColorSpace resource dictionary -- fell back to ColorSpaceKind.UNKNOWN, and colorFromOperands guessed gray/RGB/CMYK from the sc/scn operand count. That heuristic happens to match ICCBased/CalGray/CalRGB by coincidence (operand count equals component count), but is a real correctness bug for Lab: L*a*b* values (L 0-100, a/b roughly -100..100) fed straight into rgb() after clamping collapse to solid white/black instead of the intended color. Add resolveColorSpaceResource()/classifyColorSpaceDefinition(), reusing the same array-classification approach imageComponents() already uses for images, plus a proper Lab -> XYZ -> sRGB conversion (using the color space's own /WhitePoint when present, D50 otherwise). Update the README to document the new capability.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 9 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
- Reduce colorFromOperands's cognitive complexity below the required threshold by extracting the numeric-operand counting loop and the unknown-color-space operand-count heuristic into their own methods, and using ternaries for the direct GRAY/RGB/CMYK/LAB cases instead of if+break. - labWhitePointFrom() and every ColorSpaceInfo/GState call site now use a shared NO_LAB_WHITE_POINT empty-array sentinel instead of returning/ storing null for "no white point", per S1168. - ColorSpaceInfo now overrides equals/hashCode/toString itself (via Arrays.equals/hashCode/toString) since a record's generated versions compare an array component by reference rather than content (S6218).
- Move NO_LAB_WHITE_POINT / DEFAULT_LAB_WHITE_POINT / CIE_SRGB next to the other color-space constant fields at the top of the class instead of declaring them inline next to their first use. - Wrap the README's Colors operator-table row under the 120-char line length limit.
andreasrosdalw
added a commit
to andreasrosdalw/OpenPDF
that referenced
this pull request
Jul 28, 2026
Consolidated into LibrePDF#1607 along with the README updates for LibrePDF#1604, LibrePDF#1605, and LibrePDF#1606, so these four independent PRs (all based on master) don't each carry their own overlapping README.md diff and risk merge conflicts with each other depending on merge order.
andreasrosdalw
added a commit
to andreasrosdalw/OpenPDF
that referenced
this pull request
Jul 28, 2026
Consolidated into LibrePDF#1607 along with the README updates for LibrePDF#1603, LibrePDF#1605, and LibrePDF#1606, so these four independent PRs (all based on master) don't each carry their own overlapping README.md diff and risk merge conflicts with each other depending on merge order.
Consolidated into LibrePDF#1607 along with the README updates for LibrePDF#1603, LibrePDF#1604, and LibrePDF#1606, so these four independent PRs (all based on master) don't each carry their own overlapping README.md diff and risk merge conflicts with each other depending on merge order.
andreasrosdalw
added a commit
to andreasrosdalw/OpenPDF
that referenced
this pull request
Jul 28, 2026
Consolidated into LibrePDF#1607 along with the README updates for LibrePDF#1603, LibrePDF#1604, and LibrePDF#1605, so these four independent PRs (all based on master) don't each carry their own overlapping README.md diff and risk merge conflicts with each other depending on merge order.
|
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.



Summary
cs/CSinOpenPdfCorePageRendererpreviously only recognized literal device color-space names (/DeviceGray,/DeviceRGB,/DeviceCMYKand abbreviations). Any other name — most commonly a named ICCBased profile like/CS0declared in the page's/ColorSpaceresource dictionary, which is how most real-world PDF producers actually declare RGB/CMYK color spaces — fell intoColorSpaceKind.UNKNOWN, andcolorFromOperandsfell back to guessing gray/RGB/CMYK purely from thesc/scnoperand count.Lin 0-100,a/broughly -100..100) fed straight intorgb()afterclamp01collapse almost every Lab color to solid white or black instead of the intended color, since raw Lab values aren't RGB values.resolveColorSpaceResource()/classifyColorSpaceDefinition(), reusing the same array-classification approachimageComponents()already uses for Image XObjects (ICCBased-by-/N, CalGray, CalRGB), plus a new correct Lab → CIEXYZ → sRGB conversion (labToRgb), using the color space's own/WhitePointwhen present and D50 otherwise. Verified the conversion against known reference values (Lab D50 encodings of pure red/green/black/white round-trip to the expected sRGB) before locking in test assertions.openpdf-renderer/README.md's color-space coverage section and the class-level Javadoc.