Repository navigation
Add CmykColorConverter for print production (RGB to CMYK with ICC profiles) - #1811
Merged
andreasrosdalw merged 1 commit intoDec 2, 2026
Merged
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 70 |
| Duplication | 1 |
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.
Print production formats such as PDF/X-4 with a CMYK output intent, for example for newspapers (ISOnewspaper26v4) or offset printing (FOGRA39), expect the content in the CMYK colour space of the printing condition. OpenPDF could only write RGB colours and images as RGB. CmykColorConverter converts with the ICC profile of the printing condition and the colour management of the JDK: - toCmyk(Color) returns a CMYKColor for text, lines and fills. - toCmykImage(java.awt.Image) and toCmykImage(byte[]) return a DeviceCMYK image. Transparency becomes a soft mask. - setOutputIntent(PdfWriter, String, String) sets the profile as the output intent of the document. The tests create a small CMYK ICC profile in code, so they need no profile file with license restrictions. A PDF/A-2b document with that profile as output intent and converted text and images passes veraPDF. Co-Authored-By: Claude Opus 5.5 <[email protected]>
andreasrosdal
force-pushed
the
cmyk-colour-conversion
branch
from
December 2, 2026 21:57
14bb73f to
e058ae6
Compare
|
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.



Description of the new Feature/Bugfix
Adds
CmykColorConverter, which converts RGB colours and images to the CMYK colour space of a printing condition using its ICC profile, for example ISOnewspaper26v4 (newspapers, WAN-IFRA) or Coated FOGRA39 (offset on coated paper).Print production expects CMYK content that matches the output intent: PDF/X-4 (#1809), PDF/X-1a and PDF/A with a CMYK output intent, and the Ghent Workgroup specifications that newspapers use to check ads. Until now OpenPDF could only write RGB images and colours as RGB, so users had to convert them with another tool first.
Usage
CmykColorConverter(ICC_Profile)rejects a profile that is not CMYK.toCmyk(Color)returns aCMYKColorand keeps the alpha value. ACMYKColoris returned unchanged.toCmykImage(java.awt.Image)andtoCmykImage(byte[] imageFile)(PNG, JPEG, GIF, BMP through ImageIO) return a DeviceCMYKImagewith 8 bits per component. An alpha channel becomes a soft mask, which PDF/X-4 and PDF/A-2/3 allow. The colours are first converted to sRGB, so images with an embedded profile such as Adobe RGB are converted correctly.setOutputIntent(PdfWriter, String, String)sets the same profile as the output intent (GTS_PDFX, orGTS_PDFA1for PDF/A).The conversion uses the colour management of the JDK (Little CMS, through
ColorConvertOp) with the default rendering intent of the profile, usually perceptual. The new class adds no dependency.Not in this PR
Unit-Tests for the new Feature/Bugfix
CmykColorConverterTest(10 tests). The tests useTestCmykProfile, which creates a small valid CMYK ICC profile (v2, Lab lookup tables) in code, so the repository needs no press profile with unclear distribution terms.I also checked the converter locally with a real press profile, the Microsoft SWOP profile that comes with Windows. Gray 128 became C25 M21 Y20 K36 and red became M100 Y100. That profile is not part of the PR.
./mvnw -B installpasses locally on Java 25 for all modules, andcheckstyle:checkreports nothing on the new files. The changelog for 4.0.1 is updated.