Skip to content

Conversation

@prrace
Copy link
Contributor

@prrace prrace commented Oct 14, 2025

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

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8364583: ColorConvertOp fails for CMYK → RGB conversion (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27785/head:pull/27785
$ git checkout pull/27785

Update a local copy of the PR:
$ git checkout pull/27785
$ git pull https://git.openjdk.org/jdk.git pull/27785/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27785

View PR using the GUI difftool:
$ git pr show -t 27785

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27785.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 14, 2025

👋 Welcome back prr! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Oct 14, 2025

@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:

8364583: ColorConvertOp fails for CMYK → RGB conversion

Reviewed-by: serb, psadhukhan, honkar

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 master branch:

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot changed the title 8364583 8364583: ColorConvertOp fails for CMYK → RGB conversion Oct 14, 2025
@openjdk openjdk bot added the client client-libs-dev@openjdk.org label Oct 14, 2025
@openjdk
Copy link

openjdk bot commented Oct 14, 2025

@prrace The following label will be automatically applied to this pull request:

  • client

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 14, 2025
@mlbridge
Copy link

mlbridge bot commented Oct 14, 2025

Webrevs

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);
Copy link
Member

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.

Copy link
Contributor Author

@prrace prrace Oct 23, 2025

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.

Copy link
Member

@mrserb mrserb Oct 24, 2025

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?

Copy link
Contributor Author

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.

Copy link
Member

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);
    }
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrserb @prrace

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.

@prrace
Copy link
Contributor Author

prrace commented Nov 2, 2025

@prsadhuk @honkar-jdk please review

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 3, 2025
@honkar-jdk
Copy link
Contributor

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);
Copy link
Contributor

@prsadhuk prsadhuk Nov 4, 2025

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...

Copy link
Contributor

@honkar-jdk honkar-jdk left a 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

@prrace
Copy link
Contributor Author

prrace commented Nov 4, 2025

/integrate

@openjdk
Copy link

openjdk bot commented Nov 4, 2025

Going to push as commit 8585b46.
Since your change was applied there have been 348 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 4, 2025
@openjdk openjdk bot closed this Nov 4, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 4, 2025
@openjdk
Copy link

openjdk bot commented Nov 4, 2025

@prrace Pushed as commit 8585b46.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client client-libs-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

4 participants