-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8316497 : ColorConvertOp - typo for non-ICC conversions needs one-line fix #16895
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
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6910d9c
JDK-8316497 : ColorConvertOp - typo for non-ICC conversions needs one…
Renjithkannath b7faa3a
Added test case
Renjithkannath 71748d3
Integrated suggesions
Renjithkannath 1bf2cb3
Removed space
Renjithkannath 7962765
Removed unnecessary try block
Renjithkannath fdc1ce8
Removed unnecessary try block
Renjithkannath eb6b298
Review suggestions implemented
Renjithkannath f73dbb9
Copyright year updated
Renjithkannath 9fc84de
Included the review suggesion
Renjithkannath dbfadbe
Removed csRGB conversion call
Renjithkannath f6a435b
Copyright year updated
Renjithkannath 56ce5c5
Removed unwanted converion
Renjithkannath ac6b10f
8316497: Sergey's version of the non-ICC test
aivanov-jdk 8e85480
Improvements to Sergey's test
aivanov-jdk 1788ef6
Rename compareImages to areImagesEqual
aivanov-jdk 6d47f16
Fixed other two typos
Renjithkannath bec09a3
Included wrapper check
Renjithkannath 895de12
Updated the code with latest suggestion
Renjithkannath c0ac3b0
Fixed small typo
Renjithkannath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
import java.awt.Color; | ||
import java.awt.GradientPaint; | ||
import java.awt.Graphics2D; | ||
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; | ||
|
||
/* | ||
* @test | ||
* @bug 8316497 | ||
* @summary Verifies Color filter on non-ICC profile | ||
*/ | ||
public final class NonICCFilterTest { | ||
private static final int WIDTH = 100; | ||
private static final int HEIGHT = 100; | ||
|
||
private enum ColorSpaceSelector { | ||
GRAY, | ||
RGB, | ||
PYCC, | ||
WRAPPED_GRAY, | ||
WRAPPED_RGB, | ||
WRAPPED_PYCC | ||
} | ||
|
||
private static final class TestColorSpace extends ColorSpace { | ||
|
||
private final ColorSpace cs; | ||
|
||
TestColorSpace(ColorSpace cs) { | ||
super(cs.getType(), cs.getNumComponents()); | ||
this.cs = cs; | ||
} | ||
|
||
@Override | ||
public float[] toRGB(float[] colorvalue) { | ||
return cs.toRGB(colorvalue); | ||
} | ||
|
||
@Override | ||
public float[] fromRGB(float[] rgbvalue) { | ||
return cs.fromRGB(rgbvalue); | ||
} | ||
|
||
@Override | ||
public float[] toCIEXYZ(float[] colorvalue) { | ||
return cs.toCIEXYZ(colorvalue); | ||
} | ||
|
||
@Override | ||
public float[] fromCIEXYZ(float[] xyzvalue) { | ||
return cs.fromCIEXYZ(xyzvalue); | ||
} | ||
} | ||
|
||
private static BufferedImage createTestImage(final ColorSpace cs) { | ||
ComponentColorModel cm = new ComponentColorModel(cs, false, false, | ||
Transparency.OPAQUE, DataBuffer.TYPE_BYTE); | ||
WritableRaster raster = cm.createCompatibleWritableRaster(WIDTH, HEIGHT); | ||
BufferedImage img = new BufferedImage(cm, raster, false, null); | ||
|
||
Graphics2D g = img.createGraphics(); | ||
GradientPaint gp = new GradientPaint(0, 0, Color.GREEN, | ||
raster.getWidth(), raster.getHeight(), Color.BLUE); | ||
g.setPaint(gp); | ||
g.fillRect(0, 0, raster.getWidth(), raster.getHeight()); | ||
g.dispose(); | ||
|
||
return img; | ||
} | ||
|
||
private static ColorSpace createCS(ColorSpaceSelector selector) { | ||
return switch (selector) { | ||
case GRAY -> ColorSpace.getInstance(ColorSpace.CS_GRAY); | ||
case WRAPPED_GRAY -> new TestColorSpace(ColorSpace.getInstance(ColorSpace.CS_GRAY)); | ||
|
||
case RGB -> ColorSpace.getInstance(ColorSpace.CS_sRGB); | ||
case WRAPPED_RGB -> new TestColorSpace(ColorSpace.getInstance(ColorSpace.CS_sRGB)); | ||
|
||
case PYCC -> ColorSpace.getInstance(ColorSpace.CS_PYCC); | ||
case WRAPPED_PYCC -> new TestColorSpace(ColorSpace.getInstance(ColorSpace.CS_PYCC)); | ||
}; | ||
} | ||
|
||
private static boolean areImagesEqual(BufferedImage destTest, BufferedImage destGold) { | ||
for (int x = 0; x < destTest.getWidth(); x++) { | ||
for (int y = 0; y < destTest.getHeight(); y++) { | ||
int rgb1 = destTest.getRGB(x, y); | ||
int rgb2 = destGold.getRGB(x, y); | ||
if (rgb1 != rgb2) { | ||
System.err.println("x = " + x + ", y = " + y); | ||
System.err.println("rgb1 = " + Integer.toHexString(rgb1)); | ||
System.err.println("rgb2 = " + Integer.toHexString(rgb2)); | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public static void main(String[] args) { | ||
BufferedImage srcTest = createTestImage(createCS(ColorSpaceSelector.WRAPPED_GRAY)); | ||
BufferedImage destTest = createTestImage(createCS(ColorSpaceSelector.WRAPPED_RGB)); | ||
|
||
BufferedImage srcGold = createTestImage(createCS(ColorSpaceSelector.GRAY)); | ||
BufferedImage destGold = createTestImage(createCS(ColorSpaceSelector.RGB)); | ||
|
||
ColorConvertOp gold = new ColorConvertOp(createCS(ColorSpaceSelector.PYCC), null); | ||
gold.filter(srcTest, destTest); | ||
gold.filter(srcGold, destGold); | ||
|
||
if (!areImagesEqual(destTest, destGold)) { | ||
throw new RuntimeException("ICC test failed"); | ||
} | ||
|
||
ColorConvertOp test = new ColorConvertOp(createCS(ColorSpaceSelector.WRAPPED_PYCC), null); | ||
test.filter(srcTest, destTest); | ||
test.filter(srcGold, destGold); | ||
|
||
if (!areImagesEqual(destTest, destGold)) { | ||
throw new RuntimeException("Wrapper test failed"); | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "}" is missing in the latest version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oops, missed while integrating. |
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.
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.
Please add
@Override
annotations to the methods:toRGB
,fromRGB
,toCIEXYZ
,fromCIEXYZ
.