-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8364583: ColorConvertOp fails for CMYK → RGB conversion #27785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
👋 Welcome back prr! A progress list of the required criteria for merging this PR into |
|
@prrace This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 348 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
| for (int x = 0; x < w; x++) { | ||
| pixel = srcRas.getDataElements(x, y, pixel); | ||
| color = srcCM.getNormalizedComponents(pixel, color, 0); | ||
| color = srcCM.getNormalizedComponents(pixel, null, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is executed for each pixel, it will generate garbage equal to the image size. Maybe we can cleanly split the usage of the two vars here? Note that the bug only occurs when the source image does not use an ICC profile, but this change would increase garbage for both ICC and non-ICC profiles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean keep the original returned float[] color separate from the one that's later over-written.
I'd thought about that but I don't think it is worth it.
It can also be over-written at line 835. There's just too much state tracking needed to save
the GC a tiny bit of effort freeing small transient objects.
Also it already is re-initialised for each scanline. See line 807, so it isn't (quite) the same array for the entire image anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can also be over-written at line 835.
Interesting, is it possible that that line has the same bug?
color = dstColorSpace.fromCIEXYZ(dstColor);
Does dstColor always have the same number of components as CIEXYZ?
Is the logic of using CIEXYZ for mix of non-/ICC source and non-/ICC destination actually correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fromCIEXYZ is defined on ColorSpace, not ICC_ColorSpace.
It requires 3 (or more) components, and then dstColorSpace will return an array of colors in its own colorspace.
The dstColor parameter is always created with at least 3 components based on the dstNumComp
And if there's no bug in dstColorSpace it should return an array of the right length for itself.
So if there's a bug it isn't obvious to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the destination handles it properly; I tested it with the following example:
import java.awt.Transparency;
import java.awt.color.ColorSpace;
import java.awt.image.BufferedImage;
import java.awt.image.ColorConvertOp;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.WritableRaster;
import static java.awt.color.ColorSpace.TYPE_2CLR;
import static java.awt.color.ColorSpace.TYPE_FCLR;
import static java.awt.color.ColorSpace.TYPE_GRAY;
public final class TestCCP {
private static final int WIDTH = 10;
private static final int HEIGHT = 10;
private static class CustomColorSpace extends ColorSpace {
private final int numComponents;
private CustomColorSpace(int type, int numComponents) {
super(type, numComponents);
this.numComponents = numComponents;
}
@Override
public float[] toRGB(float[] colorvalue) {
return new float[3];
}
@Override
public float[] fromRGB(float[] rgbvalue) {
return new float[numComponents];
}
@Override
public float[] toCIEXYZ(float[] colorvalue) {
return new float[3];
}
@Override
public float[] fromCIEXYZ(float[] colorvalue) {
return new float[numComponents];
}
}
private static final ColorSpace[] CS = {
ColorSpace.getInstance(ColorSpace.CS_CIEXYZ),
ColorSpace.getInstance(ColorSpace.CS_GRAY),
ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB),
ColorSpace.getInstance(ColorSpace.CS_PYCC),
ColorSpace.getInstance(ColorSpace.CS_sRGB),
new CustomColorSpace(TYPE_GRAY, 1),
new CustomColorSpace(TYPE_2CLR, 2),
new CustomColorSpace(TYPE_FCLR, 15)
};
public static void main(String[] args) {
for (ColorSpace srcCS : CS) {
for (ColorSpace fromCS : CS) {
for (ColorSpace toCS : CS) {
for (ColorSpace dstCS : CS) {
BufferedImage src = createTestImage(srcCS);
BufferedImage dst = createTestImage(dstCS);
new ColorConvertOp(fromCS, toCS, null).filter(src, dst);
}
}
}
}
}
private static BufferedImage createTestImage(ColorSpace cs) {
ComponentColorModel cm = new ComponentColorModel(cs, false, false,
Transparency.OPAQUE,
DataBuffer.TYPE_BYTE);
WritableRaster raster = cm.createCompatibleWritableRaster(WIDTH,
HEIGHT);
return new BufferedImage(cm, raster, cm.isAlphaPremultiplied(), null);
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we testing the else block - the one for "possible non-ICC src, possible CSList, possible non-ICC dst" with the test provided by Sergey?
Ln#872 in the else block has a similar line color = srcCM.getNormalizedComponents(spixel, color, 0); and the above test runs fine if normComponents is set to either color or null.
|
@prsadhuk @honkar-jdk please review |
|
In the process of reviewing the PR |
| ColorModel sourceModel = source.getColorModel(); | ||
| ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); | ||
| ColorConvertOp convertOp = new ColorConvertOp(cs, null); | ||
| BufferedImage rgb = convertOp.filter(source, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rgb variable can be removed...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix LGTM for the case demonstrated by the regression test although I'm not clear on the case described by @mrserb in this thread - https://github.com/openjdk/jdk/pull/27785/files#r2487547644
|
/integrate |
|
Going to push as commit 8585b46.
Your commit was automatically rebased without conflicts. |
color is initially returned as 4 element array but we over-write with 3 element and so next time through the loop it is used by but is too short.
More details in JBS.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27785/head:pull/27785$ git checkout pull/27785Update a local copy of the PR:
$ git checkout pull/27785$ git pull https://git.openjdk.org/jdk.git pull/27785/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 27785View PR using the GUI difftool:
$ git pr show -t 27785Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27785.diff
Using Webrev
Link to Webrev Comment