jdk/test/sun/java2d/cmm/ProfileOp/ReadProfileTest.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 544 9e8d4d0c3d77
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 544
diff changeset
     2
 * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
544
9e8d4d0c3d77 6523403: Need to provide lcms library with PYCC and LINEAR_RGB OS ICC profiles
prr
parents: 2
diff changeset
    26
 * @bug 6476665 6523403
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Verifies reading profiles of the standard color spaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @run main ReadProfileTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.color.ColorSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.color.ICC_Profile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.nio.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public class ReadProfileTest implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /* Location of the tag sig counter in 4-byte words */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    final static int TAG_COUNT_OFFSET = 32;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /* Location of the tag sig table in 4-byte words */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    final static int TAG_ELEM_OFFSET = 33;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    static byte[][] profiles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static int [][] tagSigs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static Hashtable [] tags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    boolean status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static int [] cspaces = {ColorSpace.CS_sRGB, ColorSpace.CS_PYCC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                             ColorSpace.CS_LINEAR_RGB, ColorSpace.CS_CIEXYZ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                             ColorSpace.CS_GRAY};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    static String [] csNames = {"sRGB", "PYCC", "LINEAR_RGB", "CIEXYZ", "GRAY"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static void getProfileTags(byte [] data, Hashtable tags) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        ByteBuffer byteBuf = ByteBuffer.wrap(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        IntBuffer intBuf = byteBuf.asIntBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        int tagCount = intBuf.get(TAG_COUNT_OFFSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        intBuf.position(TAG_ELEM_OFFSET);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        for (int i = 0; i < tagCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            int tagSig = intBuf.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            int tagDataOff = intBuf.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            int tagSize = intBuf.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            byte [] tagData = new byte[tagSize];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            byteBuf.position(tagDataOff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            byteBuf.get(tagData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            tags.put(tagSig, tagData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        profiles = new byte[cspaces.length][];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        tags = new Hashtable[cspaces.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        for (int i = 0; i < cspaces.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            profiles[i] = pf.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            tags[i] = new Hashtable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            getProfileTags(profiles[i], tags[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public ReadProfileTest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        status = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        for (int i = 0; i < cspaces.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            byte [] data = pf.getData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (!Arrays.equals(data, profiles[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                status = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                System.err.println("Incorrect result of getData() " + "with " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                   csNames[i] + " profile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                throw new RuntimeException("Incorrect result of getData()");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            Iterator<Integer> iter = tags[i].keySet().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            while(iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                int tagSig = iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                byte [] tagData = pf.getData(tagSig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                if (!Arrays.equals(tagData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                                   (byte[]) tags[i].get(tagSig)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    status = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    System.err.println("Incorrect result of getData(int) with" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                       " tag " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                       Integer.toHexString(tagSig) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                       " of " + csNames[i] + " profile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                    throw new RuntimeException("Incorrect result of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                               "getData(int)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public boolean getStatus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return status;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public static void main(String [] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        ReadProfileTest test = new ReadProfileTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        test.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
}