|
1 /* |
|
2 * Copyright 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 * have any questions. |
|
22 */ |
|
23 |
|
24 /** |
|
25 * @test |
|
26 * @bug 6476665 |
|
27 * @summary Verifies reading profiles of the standard color spaces |
|
28 * @run main ReadProfileTest |
|
29 */ |
|
30 |
|
31 import java.awt.color.ColorSpace; |
|
32 import java.awt.color.ICC_Profile; |
|
33 import java.util.*; |
|
34 import java.nio.*; |
|
35 import java.util.Hashtable; |
|
36 |
|
37 public class ReadProfileTest implements Runnable { |
|
38 /* Location of the tag sig counter in 4-byte words */ |
|
39 final static int TAG_COUNT_OFFSET = 32; |
|
40 |
|
41 /* Location of the tag sig table in 4-byte words */ |
|
42 final static int TAG_ELEM_OFFSET = 33; |
|
43 |
|
44 static byte[][] profiles; |
|
45 static int [][] tagSigs; |
|
46 static Hashtable [] tags; |
|
47 boolean status; |
|
48 |
|
49 static int [] cspaces = {ColorSpace.CS_sRGB, ColorSpace.CS_PYCC, |
|
50 ColorSpace.CS_LINEAR_RGB, ColorSpace.CS_CIEXYZ, |
|
51 ColorSpace.CS_GRAY}; |
|
52 |
|
53 static String [] csNames = {"sRGB", "PYCC", "LINEAR_RGB", "CIEXYZ", "GRAY"}; |
|
54 |
|
55 static void getProfileTags(byte [] data, Hashtable tags) { |
|
56 ByteBuffer byteBuf = ByteBuffer.wrap(data); |
|
57 IntBuffer intBuf = byteBuf.asIntBuffer(); |
|
58 int tagCount = intBuf.get(TAG_COUNT_OFFSET); |
|
59 intBuf.position(TAG_ELEM_OFFSET); |
|
60 for (int i = 0; i < tagCount; i++) { |
|
61 int tagSig = intBuf.get(); |
|
62 int tagDataOff = intBuf.get(); |
|
63 int tagSize = intBuf.get(); |
|
64 |
|
65 byte [] tagData = new byte[tagSize]; |
|
66 byteBuf.position(tagDataOff); |
|
67 byteBuf.get(tagData); |
|
68 tags.put(tagSig, tagData); |
|
69 } |
|
70 } |
|
71 |
|
72 static { |
|
73 profiles = new byte[cspaces.length][]; |
|
74 tags = new Hashtable[cspaces.length]; |
|
75 |
|
76 for (int i = 0; i < cspaces.length; i++) { |
|
77 ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]); |
|
78 profiles[i] = pf.getData(); |
|
79 tags[i] = new Hashtable(); |
|
80 getProfileTags(profiles[i], tags[i]); |
|
81 } |
|
82 } |
|
83 |
|
84 public ReadProfileTest() { |
|
85 status = true; |
|
86 } |
|
87 |
|
88 public void run() { |
|
89 for (int i = 0; i < cspaces.length; i++) { |
|
90 ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]); |
|
91 byte [] data = pf.getData(); |
|
92 if (!Arrays.equals(data, profiles[i])) { |
|
93 status = false; |
|
94 System.err.println("Incorrect result of getData() " + "with " + |
|
95 csNames[i] + " profile"); |
|
96 throw new RuntimeException("Incorrect result of getData()"); |
|
97 } |
|
98 |
|
99 Iterator<Integer> iter = tags[i].keySet().iterator(); |
|
100 while(iter.hasNext()) { |
|
101 int tagSig = iter.next(); |
|
102 byte [] tagData = pf.getData(tagSig); |
|
103 if (!Arrays.equals(tagData, |
|
104 (byte[]) tags[i].get(tagSig))) |
|
105 { |
|
106 status = false; |
|
107 System.err.println("Incorrect result of getData(int) with" + |
|
108 " tag " + |
|
109 Integer.toHexString(tagSig) + |
|
110 " of " + csNames[i] + " profile"); |
|
111 |
|
112 throw new RuntimeException("Incorrect result of " + |
|
113 "getData(int)"); |
|
114 } |
|
115 } |
|
116 } |
|
117 } |
|
118 |
|
119 public boolean getStatus() { |
|
120 return status; |
|
121 } |
|
122 |
|
123 public static void main(String [] args) { |
|
124 ReadProfileTest test = new ReadProfileTest(); |
|
125 test.run(); |
|
126 } |
|
127 } |