jdk/test/sun/java2d/cmm/ColorConvertOp/ColConvTest.java
author bae
Fri, 07 Jun 2013 14:45:29 +0400
changeset 18114 8b16a9643b24
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
6830714: cmm test failures with OpenJDK Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2007, Oracle and/or its affiliates. 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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
import java.awt.color.ColorSpace;
18114
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
    25
import java.awt.color.ICC_Profile;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.image.DataBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
public abstract class ColConvTest implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
    /* Parameters of the testing subimage */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
    static final int SI_X = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    static final int SI_Y = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    static final int SI_W = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    static final int SI_H = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private boolean passed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    static String getCSName(int cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        switch(cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
            case ColorSpace.CS_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
                return "CS_GRAY";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            case ColorSpace.CS_CIEXYZ:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                return "CS_CIEXYZ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
            case ColorSpace.CS_LINEAR_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                return "CS_LINEAR_RGB";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            case ColorSpace.CS_PYCC:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                return "CS_PYCC";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            case ColorSpace.CS_sRGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                return "CS_sRGB";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        return "UNKNOWN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static String getDTName(int dType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        switch(dType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            case DataBuffer.TYPE_BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                return "TYPE_BYTE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            case DataBuffer.TYPE_DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                return "TYPE_DOUBLE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            case DataBuffer.TYPE_FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                return "TYPE_FLOAT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            case DataBuffer.TYPE_INT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                return "TYPE_INT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            case DataBuffer.TYPE_SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                return "TYPE_SHORT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            case DataBuffer.TYPE_USHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                return "TYPE_USHORT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            case DataBuffer.TYPE_UNDEFINED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                return "TYPE_UNDEFINED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return "UNKNOWN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static String getImageTypeName(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        switch(type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            case BufferedImage.TYPE_INT_ARGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                return "TYPE_INT_ARGB";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            case BufferedImage.TYPE_INT_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                return "TYPE_INT_RGB";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            case BufferedImage.TYPE_INT_BGR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                return "TYPE_INT_BGR";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            case BufferedImage.TYPE_INT_ARGB_PRE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                return "TYPE_INT_ARGB_PRE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            case BufferedImage.TYPE_3BYTE_BGR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                return "TYPE_3BYTE_BGR";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            case BufferedImage.TYPE_4BYTE_ABGR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                return "TYPE_4BYTE_ABGR";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            case BufferedImage.TYPE_4BYTE_ABGR_PRE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                return "TYPE_4BYTE_ABGR_PRE";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            case BufferedImage.TYPE_BYTE_BINARY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                return "TYPE_BYTE_BINARY";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            case BufferedImage.TYPE_BYTE_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                return "TYPE_BYTE_GRAY";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            case BufferedImage.TYPE_BYTE_INDEXED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                return "TYPE_BYTE_INDEXED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            case BufferedImage.TYPE_USHORT_555_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                return "TYPE_USHORT_555_RGB";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            case BufferedImage.TYPE_USHORT_565_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                return "TYPE_USHORT_565_RGB";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            case BufferedImage.TYPE_USHORT_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                return "TYPE_USHORT_GRAY";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        return "UNKNOWN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /* Actual tests should override this method and put initialization logic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * into it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public abstract void init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /* Actual tests should override this method and put test logic into it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public abstract void runTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public final void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            runTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            passed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        } catch (Throwable ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            passed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            throw new RuntimeException(ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /* returns result of the test */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public boolean isPassed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return passed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
18114
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   130
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   131
    private static Boolean isOpenProfile = null;
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   132
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   133
    public static boolean isOpenProfile() {
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   134
        if (isOpenProfile == null) {
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   135
            ICC_Profile p = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   136
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   137
            byte[] h = p.getData(ICC_Profile.icSigHead);
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   138
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   139
            if (h == null || h.length < 128) {
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   140
                throw new RuntimeException("Test failed: invalid sRGB header");
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   141
            }
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   142
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   143
            final byte[] lcmsID = new byte[] {
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   144
                (byte)0x6c, // l
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   145
                (byte)0x63, // c
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   146
                (byte)0x6d, // m
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   147
                (byte)0x73, // s
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   148
            };
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   149
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   150
            int off = ICC_Profile.icHdrCmmId;
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   151
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   152
            isOpenProfile = ((h[off + 0] == lcmsID[0])
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   153
                    && (h[off + 1] == lcmsID[1])
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   154
                    && (h[off + 2] == lcmsID[2])
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   155
                    && (h[off + 3] == lcmsID[3]));
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   156
        }
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   157
        return isOpenProfile;
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   158
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
}