0N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
295N/A * @bug 6476665 6523403
0N/A * @summary Verifies reading profiles of the standard color spaces
0N/A * @run main ReadProfileTest
0N/A */
0N/A
0N/Aimport java.awt.color.ColorSpace;
0N/Aimport java.awt.color.ICC_Profile;
0N/Aimport java.util.*;
0N/Aimport java.nio.*;
0N/Aimport java.util.Hashtable;
0N/A
0N/Apublic class ReadProfileTest implements Runnable {
0N/A /* Location of the tag sig counter in 4-byte words */
0N/A final static int TAG_COUNT_OFFSET = 32;
0N/A
0N/A /* Location of the tag sig table in 4-byte words */
0N/A final static int TAG_ELEM_OFFSET = 33;
0N/A
0N/A static byte[][] profiles;
0N/A static int [][] tagSigs;
0N/A static Hashtable [] tags;
0N/A boolean status;
0N/A
0N/A static int [] cspaces = {ColorSpace.CS_sRGB, ColorSpace.CS_PYCC,
0N/A ColorSpace.CS_LINEAR_RGB, ColorSpace.CS_CIEXYZ,
0N/A ColorSpace.CS_GRAY};
0N/A
0N/A static String [] csNames = {"sRGB", "PYCC", "LINEAR_RGB", "CIEXYZ", "GRAY"};
0N/A
0N/A static void getProfileTags(byte [] data, Hashtable tags) {
0N/A ByteBuffer byteBuf = ByteBuffer.wrap(data);
0N/A IntBuffer intBuf = byteBuf.asIntBuffer();
0N/A int tagCount = intBuf.get(TAG_COUNT_OFFSET);
0N/A intBuf.position(TAG_ELEM_OFFSET);
0N/A for (int i = 0; i < tagCount; i++) {
0N/A int tagSig = intBuf.get();
0N/A int tagDataOff = intBuf.get();
0N/A int tagSize = intBuf.get();
0N/A
0N/A byte [] tagData = new byte[tagSize];
0N/A byteBuf.position(tagDataOff);
0N/A byteBuf.get(tagData);
0N/A tags.put(tagSig, tagData);
0N/A }
0N/A }
0N/A
0N/A static {
0N/A profiles = new byte[cspaces.length][];
0N/A tags = new Hashtable[cspaces.length];
0N/A
0N/A for (int i = 0; i < cspaces.length; i++) {
0N/A ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]);
0N/A profiles[i] = pf.getData();
0N/A tags[i] = new Hashtable();
0N/A getProfileTags(profiles[i], tags[i]);
0N/A }
0N/A }
0N/A
0N/A public ReadProfileTest() {
0N/A status = true;
0N/A }
0N/A
0N/A public void run() {
0N/A for (int i = 0; i < cspaces.length; i++) {
0N/A ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]);
0N/A byte [] data = pf.getData();
0N/A if (!Arrays.equals(data, profiles[i])) {
0N/A status = false;
0N/A System.err.println("Incorrect result of getData() " + "with " +
0N/A csNames[i] + " profile");
0N/A throw new RuntimeException("Incorrect result of getData()");
0N/A }
0N/A
0N/A Iterator<Integer> iter = tags[i].keySet().iterator();
0N/A while(iter.hasNext()) {
0N/A int tagSig = iter.next();
0N/A byte [] tagData = pf.getData(tagSig);
0N/A if (!Arrays.equals(tagData,
0N/A (byte[]) tags[i].get(tagSig)))
0N/A {
0N/A status = false;
0N/A System.err.println("Incorrect result of getData(int) with" +
0N/A " tag " +
0N/A Integer.toHexString(tagSig) +
0N/A " of " + csNames[i] + " profile");
0N/A
0N/A throw new RuntimeException("Incorrect result of " +
0N/A "getData(int)");
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A public boolean getStatus() {
0N/A return status;
0N/A }
0N/A
0N/A public static void main(String [] args) {
0N/A ReadProfileTest test = new ReadProfileTest();
0N/A test.run();
0N/A }
0N/A}