2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2007, 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 |
import java.awt.color.ColorSpace;
|
18114
|
25 |
import java.awt.color.ICC_Profile;
|
2
|
26 |
import java.awt.image.BufferedImage;
|
|
27 |
import java.awt.image.DataBuffer;
|
|
28 |
|
|
29 |
public abstract class ColConvTest implements Runnable {
|
|
30 |
|
|
31 |
/* Parameters of the testing subimage */
|
|
32 |
static final int SI_X = 10;
|
|
33 |
static final int SI_Y = 10;
|
|
34 |
static final int SI_W = 100;
|
|
35 |
static final int SI_H = 100;
|
|
36 |
|
|
37 |
private boolean passed = false;
|
|
38 |
|
|
39 |
static String getCSName(int cs) {
|
|
40 |
switch(cs) {
|
|
41 |
case ColorSpace.CS_GRAY:
|
|
42 |
return "CS_GRAY";
|
|
43 |
case ColorSpace.CS_CIEXYZ:
|
|
44 |
return "CS_CIEXYZ";
|
|
45 |
case ColorSpace.CS_LINEAR_RGB:
|
|
46 |
return "CS_LINEAR_RGB";
|
|
47 |
case ColorSpace.CS_PYCC:
|
|
48 |
return "CS_PYCC";
|
|
49 |
case ColorSpace.CS_sRGB:
|
|
50 |
return "CS_sRGB";
|
|
51 |
}
|
|
52 |
return "UNKNOWN";
|
|
53 |
}
|
|
54 |
|
|
55 |
static String getDTName(int dType) {
|
|
56 |
switch(dType) {
|
|
57 |
case DataBuffer.TYPE_BYTE:
|
|
58 |
return "TYPE_BYTE";
|
|
59 |
case DataBuffer.TYPE_DOUBLE:
|
|
60 |
return "TYPE_DOUBLE";
|
|
61 |
case DataBuffer.TYPE_FLOAT:
|
|
62 |
return "TYPE_FLOAT";
|
|
63 |
case DataBuffer.TYPE_INT:
|
|
64 |
return "TYPE_INT";
|
|
65 |
case DataBuffer.TYPE_SHORT:
|
|
66 |
return "TYPE_SHORT";
|
|
67 |
case DataBuffer.TYPE_USHORT:
|
|
68 |
return "TYPE_USHORT";
|
|
69 |
case DataBuffer.TYPE_UNDEFINED:
|
|
70 |
return "TYPE_UNDEFINED";
|
|
71 |
}
|
|
72 |
return "UNKNOWN";
|
|
73 |
}
|
|
74 |
|
|
75 |
static String getImageTypeName(int type) {
|
|
76 |
switch(type) {
|
|
77 |
case BufferedImage.TYPE_INT_ARGB:
|
|
78 |
return "TYPE_INT_ARGB";
|
|
79 |
case BufferedImage.TYPE_INT_RGB:
|
|
80 |
return "TYPE_INT_RGB";
|
|
81 |
case BufferedImage.TYPE_INT_BGR:
|
|
82 |
return "TYPE_INT_BGR";
|
|
83 |
case BufferedImage.TYPE_INT_ARGB_PRE:
|
|
84 |
return "TYPE_INT_ARGB_PRE";
|
|
85 |
case BufferedImage.TYPE_3BYTE_BGR:
|
|
86 |
return "TYPE_3BYTE_BGR";
|
|
87 |
case BufferedImage.TYPE_4BYTE_ABGR:
|
|
88 |
return "TYPE_4BYTE_ABGR";
|
|
89 |
case BufferedImage.TYPE_4BYTE_ABGR_PRE:
|
|
90 |
return "TYPE_4BYTE_ABGR_PRE";
|
|
91 |
case BufferedImage.TYPE_BYTE_BINARY:
|
|
92 |
return "TYPE_BYTE_BINARY";
|
|
93 |
case BufferedImage.TYPE_BYTE_GRAY:
|
|
94 |
return "TYPE_BYTE_GRAY";
|
|
95 |
case BufferedImage.TYPE_BYTE_INDEXED:
|
|
96 |
return "TYPE_BYTE_INDEXED";
|
|
97 |
case BufferedImage.TYPE_USHORT_555_RGB:
|
|
98 |
return "TYPE_USHORT_555_RGB";
|
|
99 |
case BufferedImage.TYPE_USHORT_565_RGB:
|
|
100 |
return "TYPE_USHORT_565_RGB";
|
|
101 |
case BufferedImage.TYPE_USHORT_GRAY:
|
|
102 |
return "TYPE_USHORT_GRAY";
|
|
103 |
}
|
|
104 |
return "UNKNOWN";
|
|
105 |
}
|
|
106 |
|
|
107 |
/* Actual tests should override this method and put initialization logic
|
|
108 |
* into it
|
|
109 |
*/
|
|
110 |
public abstract void init();
|
|
111 |
|
|
112 |
/* Actual tests should override this method and put test logic into it */
|
|
113 |
public abstract void runTest();
|
|
114 |
|
|
115 |
public final void run() {
|
|
116 |
try {
|
|
117 |
runTest();
|
|
118 |
passed = true;
|
|
119 |
} catch (Throwable ex) {
|
|
120 |
ex.printStackTrace();
|
|
121 |
passed = false;
|
|
122 |
throw new RuntimeException(ex);
|
|
123 |
}
|
|
124 |
}
|
|
125 |
|
|
126 |
/* returns result of the test */
|
|
127 |
public boolean isPassed() {
|
|
128 |
return passed;
|
|
129 |
}
|
18114
|
130 |
|
|
131 |
private static Boolean isOpenProfile = null;
|
|
132 |
|
|
133 |
public static boolean isOpenProfile() {
|
|
134 |
if (isOpenProfile == null) {
|
|
135 |
ICC_Profile p = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
|
|
136 |
|
|
137 |
byte[] h = p.getData(ICC_Profile.icSigHead);
|
|
138 |
|
|
139 |
if (h == null || h.length < 128) {
|
|
140 |
throw new RuntimeException("Test failed: invalid sRGB header");
|
|
141 |
}
|
|
142 |
|
|
143 |
final byte[] lcmsID = new byte[] {
|
|
144 |
(byte)0x6c, // l
|
|
145 |
(byte)0x63, // c
|
|
146 |
(byte)0x6d, // m
|
|
147 |
(byte)0x73, // s
|
|
148 |
};
|
|
149 |
|
|
150 |
int off = ICC_Profile.icHdrCmmId;
|
|
151 |
|
|
152 |
isOpenProfile = ((h[off + 0] == lcmsID[0])
|
|
153 |
&& (h[off + 1] == lcmsID[1])
|
|
154 |
&& (h[off + 2] == lcmsID[2])
|
|
155 |
&& (h[off + 3] == lcmsID[3]));
|
|
156 |
}
|
|
157 |
return isOpenProfile;
|
|
158 |
}
|
2
|
159 |
}
|