ReadWriteProfileTest.java revision 2362
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
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/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 *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2362N/A */
2362N/A
0N/A/**
0N/A * @test
0N/A * @bug 6476665 6523403 6733501
0N/A * @summary Verifies reading and writing profiles and tags of the standard color
0N/A * spaces
0N/A * @run main ReadWriteProfileTest
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 ReadWriteProfileTest 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<Integer,byte[]> [] tags;
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
static {
profiles = new byte[cspaces.length][];
tags = new Hashtable[cspaces.length];
for (int i = 0; i < cspaces.length; i++) {
ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]);
profiles[i] = pf.getData();
tags[i] = new Hashtable();
getProfileTags(profiles[i], tags[i]);
}
}
public void run() {
for (int i = 0; i < cspaces.length; i++) {
ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]);
byte [] data = pf.getData();
pf = ICC_Profile.getInstance(data);
if (!Arrays.equals(data, profiles[i])) {
System.err.println("Incorrect result of getData() " + "with " +
csNames[i] + " profile");
throw new RuntimeException("Incorrect result of getData()");
}
for (int tagSig : tags[i].keySet()) {
byte [] tagData = pf.getData(tagSig);
byte [] empty = new byte[tagData.length];
pf.setData(tagSig, empty);
pf.setData(tagSig, tagData);
byte [] tagData1 = pf.getData(tagSig);
if (!Arrays.equals(tagData1, tags[i].get(tagSig)))
{
System.err.println("Incorrect result of getData(int) with" +
" tag " +
Integer.toHexString(tagSig) +
" of " + csNames[i] + " profile");
throw new RuntimeException("Incorrect result of " +
"getData(int)");
}
}
}
}
public static void main(String [] args) {
ReadWriteProfileTest test = new ReadWriteProfileTest();
test.run();
}
}