Skip to content

Commit d603f8a

Browse files
committed
8312191: ColorConvertOp.filter for the default destination is too slow
Backport-of: e5f05b5a963774914751d9c241dd5693ed06af0b
1 parent 245885b commit d603f8a

File tree

2 files changed

+82
-2
lines changed

2 files changed

+82
-2
lines changed

src/java.desktop/share/classes/java/awt/image/ColorConvertOp.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -560,7 +560,7 @@ public BufferedImage createCompatibleDestImage (BufferedImage src,
560560
"Destination ColorSpace is undefined");
561561
}
562562
ICC_Profile destProfile = profileList[nProfiles - 1];
563-
cs = new ICC_ColorSpace(destProfile);
563+
cs = createCompatibleColorSpace(destProfile);
564564
} else {
565565
/* non-ICC case */
566566
int nSpaces = CSList.length;
@@ -570,6 +570,25 @@ public BufferedImage createCompatibleDestImage (BufferedImage src,
570570
return createCompatibleDestImage(src, destCM, cs);
571571
}
572572

573+
private static ColorSpace createCompatibleColorSpace(ICC_Profile profile) {
574+
if (profile == ICC_Profile.getInstance(ColorSpace.CS_sRGB)) {
575+
return ColorSpace.getInstance(ColorSpace.CS_sRGB);
576+
}
577+
if (profile == ICC_Profile.getInstance(ColorSpace.CS_LINEAR_RGB)) {
578+
return ColorSpace.getInstance(ColorSpace.CS_LINEAR_RGB);
579+
}
580+
if (profile == ICC_Profile.getInstance(ColorSpace.CS_CIEXYZ)) {
581+
return ColorSpace.getInstance(ColorSpace.CS_CIEXYZ);
582+
}
583+
if (profile == ICC_Profile.getInstance(ColorSpace.CS_PYCC)) {
584+
return ColorSpace.getInstance(ColorSpace.CS_PYCC);
585+
}
586+
if (profile == ICC_Profile.getInstance(ColorSpace.CS_GRAY)) {
587+
return ColorSpace.getInstance(ColorSpace.CS_GRAY);
588+
}
589+
return new ICC_ColorSpace(profile);
590+
}
591+
573592
private BufferedImage createCompatibleDestImage(BufferedImage src,
574593
ColorModel destCM,
575594
ColorSpace destCS) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.awt.color.ColorSpace;
25+
import java.awt.image.BufferedImage;
26+
import java.awt.image.ColorConvertOp;
27+
28+
/**
29+
* @test
30+
* @bug 8312191
31+
* @summary Standard color spaces should be reused for CompatibleDestImage
32+
*/
33+
public final class CompatibleColorSpace {
34+
35+
private static final int[] spaces = {
36+
ColorSpace.CS_CIEXYZ, ColorSpace.CS_GRAY, ColorSpace.CS_LINEAR_RGB,
37+
ColorSpace.CS_PYCC, ColorSpace.CS_sRGB
38+
};
39+
40+
public static void main(String[] args) {
41+
for (int from : spaces) {
42+
for (int to : spaces) {
43+
test(from, to);
44+
}
45+
}
46+
}
47+
48+
private static void test(int from, int to) {
49+
ColorSpace srcCS = ColorSpace.getInstance(from);
50+
ColorSpace dstCS = ColorSpace.getInstance(to);
51+
ColorConvertOp op = new ColorConvertOp(srcCS, dstCS, null);
52+
BufferedImage src = new BufferedImage(10, 10,
53+
BufferedImage.TYPE_INT_ARGB);
54+
BufferedImage dst = op.filter(src, null);
55+
// dst image is not set and will be created automatically, the dstCS
56+
// should be reused
57+
if (dst.getColorModel().getColorSpace() != dstCS) {
58+
throw new RuntimeException("Wrong color space");
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)