jdk/test/sun/java2d/cmm/ColorConvertOp/ColConvCCMTest.java
author bae
Fri, 07 Jun 2013 14:45:29 +0400
changeset 18114 8b16a9643b24
parent 9193 d5ad557f95dd
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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
18114
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 9193
diff changeset
    26
 * @bug 6476665 7033534 6830714
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Verifies color conversion of Component Color Model based images
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @run main ColConvCCMTest
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.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.image.ColorConvertOp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.image.DataBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.imageio.ImageIO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public class ColConvCCMTest extends ColConvTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    final static int [] dataTypes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        DataBuffer.TYPE_BYTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        DataBuffer.TYPE_DOUBLE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        DataBuffer.TYPE_FLOAT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        DataBuffer.TYPE_INT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        DataBuffer.TYPE_SHORT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        DataBuffer.TYPE_USHORT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    final static int [] cSpaces = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        ColorSpace.CS_sRGB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        ColorSpace.CS_LINEAR_RGB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        ColorSpace.CS_GRAY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        ColorSpace.CS_PYCC,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        ColorSpace.CS_CIEXYZ
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    final static double [] ACCURACY = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // Accuracy for color conversions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        2.5,        // sRGB
18114
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 9193
diff changeset
    60
        (isOpenProfile() ? 45.0 : 10.1), // LINEAR_RGB
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        10.5,       // GRAY
18114
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 9193
diff changeset
    62
        (isOpenProfile() ? 207 : 45.5), // PYCC
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        47.5        // CIEXYZ
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    final static String [] gldImgNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        "SRGB.png", "LRGB.png", "GRAY.png", "PYCC.png",  "CIEXYZ.png"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    static BufferedImage [] gldImages = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    static boolean testImage(int dataType, int rBits, int gBits, int bBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                              int cs, BufferedImage gldImage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                              double accuracy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        BufferedImage dst = ImageFactory.createDstImage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            BufferedImage.TYPE_INT_RGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        ColorConvertOp op = new ColorConvertOp(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        op.filter(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                                  bBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        boolean result = cmp.compare(gldImage, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (!result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            System.err.println(cmp.getStat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     static boolean testSubImage(int x0, int y0, int dx, int dy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                 int dataType, int rBits, int gBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                 int bBits, int cs, BufferedImage gldImage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                                 double accuracy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        BufferedImage src = ImageFactory.createCCMImage(cs, dataType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        BufferedImage dst = ImageFactory.createDstImage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            BufferedImage.TYPE_INT_RGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        ColorConvertOp op = new ColorConvertOp(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        op.filter(subSrc, subDst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                                                  bBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (!result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            System.err.println(cmp.getStat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     synchronized public static void initGoldenImages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (gldImages == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            gldImages = new BufferedImage[gldImgNames.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            for (int i = 0; i < gldImgNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    File gldFile = new File(System.getProperty("test.src", "."),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                            gldImgNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    gldImages[i] = ImageIO.read(gldFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    throw new RuntimeException("Cannot initialize golden " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                               "image: " + gldImgNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     public void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        initGoldenImages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     public void runTest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        for (int i = 0; i < cSpaces.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            BufferedImage gldImage = gldImages[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            for (int j = 0; j < dataTypes.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                if (!testImage(dataTypes[j], 8, 8, 8, cSpaces[i], gldImage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                               ACCURACY[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                     throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                        "Invalid result of the ColorConvertOp for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                        "ColorSpace:" + getCSName(cSpaces[i]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                        " Data type:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                        getDTName(dataTypes[j]) + ". Golden image:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                        gldImages[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                 if (!testSubImage(SI_X, SI_Y, SI_W, SI_H, dataTypes[j],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                   8, 8, 8, cSpaces[i], gldImage, ACCURACY[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                        "Invalid result of the ColorConvertOp for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                        "ColorSpace:" + getCSName(cSpaces[i]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                        " Data type:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                        getDTName(dataTypes[j]) + ". Golden image:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                        gldImages[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     public static void main(String [] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         ColConvCCMTest test = new ColConvCCMTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         test.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         test.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
}