Path: blob/master/test/jdk/sun/java2d/cmm/ProfileOp/ReadProfileTest.java
41153 views
/*1* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 6476665 652340326* @summary Verifies reading profiles of the standard color spaces27* @run main ReadProfileTest28*/2930import java.awt.color.ColorSpace;31import java.awt.color.ICC_Profile;32import java.util.*;33import java.nio.*;34import java.util.Hashtable;3536public class ReadProfileTest implements Runnable {37/* Location of the tag sig counter in 4-byte words */38final static int TAG_COUNT_OFFSET = 32;3940/* Location of the tag sig table in 4-byte words */41final static int TAG_ELEM_OFFSET = 33;4243static byte[][] profiles;44static int [][] tagSigs;45static Hashtable [] tags;46boolean status;4748static int [] cspaces = {ColorSpace.CS_sRGB, ColorSpace.CS_PYCC,49ColorSpace.CS_LINEAR_RGB, ColorSpace.CS_CIEXYZ,50ColorSpace.CS_GRAY};5152static String [] csNames = {"sRGB", "PYCC", "LINEAR_RGB", "CIEXYZ", "GRAY"};5354static void getProfileTags(byte [] data, Hashtable tags) {55ByteBuffer byteBuf = ByteBuffer.wrap(data);56IntBuffer intBuf = byteBuf.asIntBuffer();57int tagCount = intBuf.get(TAG_COUNT_OFFSET);58intBuf.position(TAG_ELEM_OFFSET);59for (int i = 0; i < tagCount; i++) {60int tagSig = intBuf.get();61int tagDataOff = intBuf.get();62int tagSize = intBuf.get();6364byte [] tagData = new byte[tagSize];65byteBuf.position(tagDataOff);66byteBuf.get(tagData);67tags.put(tagSig, tagData);68}69}7071static {72profiles = new byte[cspaces.length][];73tags = new Hashtable[cspaces.length];7475for (int i = 0; i < cspaces.length; i++) {76ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]);77profiles[i] = pf.getData();78tags[i] = new Hashtable();79getProfileTags(profiles[i], tags[i]);80}81}8283public ReadProfileTest() {84status = true;85}8687public void run() {88for (int i = 0; i < cspaces.length; i++) {89ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]);90byte [] data = pf.getData();91if (!Arrays.equals(data, profiles[i])) {92status = false;93System.err.println("Incorrect result of getData() " + "with " +94csNames[i] + " profile");95throw new RuntimeException("Incorrect result of getData()");96}9798Iterator<Integer> iter = tags[i].keySet().iterator();99while(iter.hasNext()) {100int tagSig = iter.next();101byte [] tagData = pf.getData(tagSig);102if (!Arrays.equals(tagData,103(byte[]) tags[i].get(tagSig)))104{105status = false;106System.err.println("Incorrect result of getData(int) with" +107" tag " +108Integer.toHexString(tagSig) +109" of " + csNames[i] + " profile");110111throw new RuntimeException("Incorrect result of " +112"getData(int)");113}114}115}116}117118public boolean getStatus() {119return status;120}121122public static void main(String [] args) {123ReadProfileTest test = new ReadProfileTest();124test.run();125}126}127128129