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