author | lana |
Thu, 26 Dec 2013 12:04:16 -0800 | |
changeset 23010 | 6dadb192ad81 |
parent 18114 | 8b16a9643b24 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
18114
diff
changeset
|
2 |
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* @bug 6476665 |
|
27 |
* @summary Verifies color conversion of Direct Color Model based images |
|
28 |
* @run main ColConvDCMTest |
|
29 |
*/ |
|
30 |
||
31 |
import java.awt.color.ColorSpace; |
|
32 |
import java.awt.image.BufferedImage; |
|
33 |
import java.awt.image.ColorConvertOp; |
|
34 |
import java.io.File; |
|
35 |
import java.io.IOException; |
|
36 |
import javax.imageio.ImageIO; |
|
37 |
||
38 |
public class ColConvDCMTest extends ColConvTest { |
|
39 |
||
40 |
/* |
|
41 |
* Test case descriptors: <imgType> <rBits> <gBits> <bBits> <csNum> <gldNum> |
|
42 |
*/ |
|
43 |
final static int [][] imgTypes = { |
|
44 |
{BufferedImage.TYPE_INT_ARGB, 8, 8, 8, 0, 0}, |
|
45 |
{BufferedImage.TYPE_INT_ARGB, 8, 8, 8, 1, 3}, |
|
46 |
||
47 |
{BufferedImage.TYPE_INT_RGB, 8, 8, 8, 0, 0}, |
|
48 |
{BufferedImage.TYPE_INT_RGB, 8, 8, 8, 1, 3}, |
|
49 |
||
50 |
{BufferedImage.TYPE_INT_BGR, 8, 8, 8, 0, 0}, |
|
51 |
{BufferedImage.TYPE_INT_BGR, 8, 8, 8, 1, 3}, |
|
52 |
||
53 |
{BufferedImage.TYPE_USHORT_555_RGB, 5, 5, 5, 0, 1}, |
|
54 |
{BufferedImage.TYPE_USHORT_555_RGB, 5, 5, 5, 1, 4}, |
|
55 |
||
56 |
{BufferedImage.TYPE_USHORT_565_RGB, 5, 6, 5, 0, 2}, |
|
57 |
{BufferedImage.TYPE_USHORT_565_RGB, 5, 6, 5, 1, 5} |
|
58 |
}; |
|
59 |
||
60 |
final static int [] cSpaces = { |
|
61 |
ColorSpace.CS_sRGB, |
|
62 |
ColorSpace.CS_LINEAR_RGB, |
|
63 |
}; |
|
64 |
||
18114 | 65 |
final static double [] ACCURACY = { |
66 |
// Accuracy for color conversions |
|
67 |
2.5, // sRGB |
|
68 |
(isOpenProfile() ? 45.0 : 2.5), // LINEAR_RGB |
|
69 |
}; |
|
2 | 70 |
|
71 |
final static String [] gldImgNames = { |
|
72 |
"SRGB.png", "SRGB555.png", "SRGB565.png", "LRGB.png", "LRGB555.png", |
|
73 |
"LRGB565.png" |
|
74 |
}; |
|
75 |
||
76 |
static BufferedImage [] gldImages = null; |
|
77 |
||
78 |
static boolean testImage(int type, int rBits, int gBits, int bBits, |
|
79 |
int cs, BufferedImage gldImage, |
|
80 |
double accuracy) |
|
81 |
{ |
|
82 |
BufferedImage src = ImageFactory.createDCMImage(type, cs); |
|
83 |
BufferedImage dst = ImageFactory.createDstImage( |
|
84 |
BufferedImage.TYPE_INT_RGB); |
|
85 |
ColorConvertOp op = new ColorConvertOp(null); |
|
86 |
||
87 |
op.filter(src, dst); |
|
88 |
||
89 |
ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits, |
|
90 |
bBits); |
|
91 |
boolean result = cmp.compare(gldImage, dst); |
|
92 |
if (!result) { |
|
93 |
System.err.println(cmp.getStat()); |
|
94 |
} |
|
95 |
return result; |
|
96 |
} |
|
97 |
||
98 |
static boolean testSubImage(int x0, int y0, int dx, int dy, int type, |
|
99 |
int rBits, int gBits, int bBits, |
|
100 |
int cs, BufferedImage gldImage, |
|
101 |
double accuracy) |
|
102 |
{ |
|
103 |
BufferedImage src = ImageFactory.createDCMImage(type, cs); |
|
104 |
BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy); |
|
105 |
BufferedImage dst = ImageFactory.createDstImage( |
|
106 |
BufferedImage.TYPE_INT_RGB); |
|
107 |
BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy); |
|
108 |
||
109 |
ColorConvertOp op = new ColorConvertOp(null); |
|
110 |
||
111 |
op.filter(subSrc, subDst); |
|
112 |
||
113 |
ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits, |
|
114 |
bBits); |
|
115 |
boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy); |
|
116 |
if (!result) { |
|
117 |
System.err.println(cmp.getStat()); |
|
118 |
} |
|
119 |
return result; |
|
120 |
} |
|
121 |
||
122 |
synchronized public static void initGoldenImages() { |
|
123 |
if (gldImages == null) { |
|
124 |
gldImages = new BufferedImage[gldImgNames.length]; |
|
125 |
for (int i = 0; i < gldImgNames.length; i++) { |
|
126 |
try { |
|
127 |
File gldFile = new File(System.getProperty("test.src", "."), |
|
128 |
gldImgNames[i]); |
|
129 |
||
130 |
gldImages[i] = ImageIO.read(gldFile); |
|
131 |
} catch (IOException e) { |
|
132 |
throw new RuntimeException("Cannot initialize golden " + |
|
133 |
"image: " + gldImgNames[i]); |
|
134 |
} |
|
135 |
} |
|
136 |
} |
|
137 |
} |
|
138 |
||
139 |
public void init() { |
|
140 |
initGoldenImages(); |
|
141 |
} |
|
142 |
||
143 |
public void runTest() { |
|
144 |
for (int i = 0; i < imgTypes.length; i++) { |
|
145 |
BufferedImage gldImage = gldImages[imgTypes[i][5]]; |
|
146 |
||
147 |
if (!testImage(imgTypes[i][0], imgTypes[i][1], imgTypes[i][2], |
|
148 |
imgTypes[i][3], cSpaces[imgTypes[i][4]], gldImage, |
|
18114 | 149 |
ACCURACY[imgTypes[i][4]])) |
2 | 150 |
{ |
151 |
throw new RuntimeException( |
|
152 |
"Invalid result of the ColorConvertOp for " + |
|
153 |
"ColorSpace:" + getCSName(cSpaces[imgTypes[i][4]]) + |
|
154 |
" Image type:" + |
|
155 |
getImageTypeName(imgTypes[i][0]) + ". Golden image:" + |
|
156 |
gldImgNames[imgTypes[i][5]]); |
|
157 |
} |
|
158 |
||
159 |
if (!testSubImage(SI_X, SI_Y, SI_W, SI_H, imgTypes[i][0], |
|
160 |
imgTypes[i][1], imgTypes[i][2], imgTypes[i][3], |
|
18114 | 161 |
cSpaces[imgTypes[i][4]], gldImage, |
162 |
ACCURACY[imgTypes[i][4]])) |
|
2 | 163 |
{ |
164 |
throw new RuntimeException( |
|
165 |
"Invalid result of the ColorConvertOp for " + |
|
166 |
"ColorSpace:" + getCSName(cSpaces[imgTypes[i][4]]) + |
|
167 |
" Image type:" + |
|
168 |
getImageTypeName(imgTypes[i][0]) + ". Golden image:" + |
|
169 |
gldImgNames[imgTypes[i][5]]); |
|
170 |
} |
|
171 |
} |
|
172 |
} |
|
173 |
||
174 |
public static void main(String [] args) throws Exception { |
|
175 |
ColConvDCMTest test = new ColConvDCMTest(); |
|
176 |
test.init(); |
|
177 |
test.run(); |
|
178 |
} |
|
179 |
} |