jdk/test/sun/java2d/cmm/ProfileOp/ReadWriteProfileTest.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2392 738be5224b3f
child 9784 3a0ebf0b855d
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2392
diff changeset
     2
 * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
     4
 *
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
     7
 * published by the Free Software Foundation.
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
     8
 *
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    13
 * accompanied this code).
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    14
 *
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2392
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2392
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2392
diff changeset
    21
 * questions.
2392
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    22
 */
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    23
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    24
/**
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    25
 * @test
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    26
 * @bug 6476665 6523403 6733501
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    27
 * @summary Verifies reading and writing profiles and tags of the standard color
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    28
 * spaces
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    29
 * @run main ReadWriteProfileTest
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    30
 */
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    31
import java.awt.color.ColorSpace;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    32
import java.awt.color.ICC_Profile;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    33
import java.util.*;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    34
import java.nio.*;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    35
import java.util.Hashtable;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    36
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    37
public class ReadWriteProfileTest implements Runnable {
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    38
    /* Location of the tag sig counter in 4-byte words */
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    39
    final static int TAG_COUNT_OFFSET = 32;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    40
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    41
    /* Location of the tag sig table in 4-byte words */
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    42
    final static int TAG_ELEM_OFFSET = 33;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    43
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    44
    static byte[][] profiles;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    45
    static int [][] tagSigs;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    46
    static Hashtable<Integer,byte[]> [] tags;
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    47
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    48
    static int [] cspaces = {ColorSpace.CS_sRGB, ColorSpace.CS_PYCC,
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    49
                             ColorSpace.CS_LINEAR_RGB, ColorSpace.CS_CIEXYZ,
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    50
                             ColorSpace.CS_GRAY};
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    51
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    52
    static String [] csNames = {"sRGB", "PYCC", "LINEAR_RGB", "CIEXYZ", "GRAY"};
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    53
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    54
    static void getProfileTags(byte [] data, Hashtable tags) {
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    55
        ByteBuffer byteBuf = ByteBuffer.wrap(data);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    56
        IntBuffer intBuf = byteBuf.asIntBuffer();
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    57
        int tagCount = intBuf.get(TAG_COUNT_OFFSET);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    58
        intBuf.position(TAG_ELEM_OFFSET);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    59
        for (int i = 0; i < tagCount; i++) {
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    60
            int tagSig = intBuf.get();
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    61
            int tagDataOff = intBuf.get();
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    62
            int tagSize = intBuf.get();
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    63
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    64
            byte [] tagData = new byte[tagSize];
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    65
            byteBuf.position(tagDataOff);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    66
            byteBuf.get(tagData);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    67
            tags.put(tagSig, tagData);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    68
        }
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    69
    }
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    70
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    71
    static {
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    72
        profiles = new byte[cspaces.length][];
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    73
        tags = new Hashtable[cspaces.length];
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    74
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    75
        for (int i = 0; i < cspaces.length; i++) {
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    76
            ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    77
            profiles[i] = pf.getData();
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    78
            tags[i] = new Hashtable();
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    79
            getProfileTags(profiles[i], tags[i]);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    80
        }
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    81
    }
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    82
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    83
    public void run() {
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    84
        for (int i = 0; i < cspaces.length; i++) {
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    85
            ICC_Profile pf = ICC_Profile.getInstance(cspaces[i]);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    86
            byte [] data = pf.getData();
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    87
            pf = ICC_Profile.getInstance(data);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    88
            if (!Arrays.equals(data, profiles[i])) {
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    89
                System.err.println("Incorrect result of getData() " + "with " +
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    90
                                   csNames[i] + " profile");
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    91
                throw new RuntimeException("Incorrect result of getData()");
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    92
            }
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    93
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    94
            for (int tagSig : tags[i].keySet()) {
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    95
                byte [] tagData = pf.getData(tagSig);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    96
                byte [] empty = new byte[tagData.length];
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    97
                pf.setData(tagSig, empty);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    98
                pf.setData(tagSig, tagData);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
    99
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   100
                byte [] tagData1 = pf.getData(tagSig);
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   101
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   102
                if (!Arrays.equals(tagData1, tags[i].get(tagSig)))
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   103
                {
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   104
                    System.err.println("Incorrect result of getData(int) with" +
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   105
                                       " tag " +
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   106
                                       Integer.toHexString(tagSig) +
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   107
                                       " of " + csNames[i] + " profile");
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   108
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   109
                    throw new RuntimeException("Incorrect result of " +
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   110
                                               "getData(int)");
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   111
                }
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   112
            }
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   113
        }
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   114
    }
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   115
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   116
    public static void main(String [] args) {
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   117
        ReadWriteProfileTest test = new ReadWriteProfileTest();
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   118
        test.run();
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   119
    }
738be5224b3f 6733501: Apply IcedTea little cms patches
avu
parents:
diff changeset
   120
}