jdk/test/sun/java2d/cmm/ColorConvertOp/ColConvDCMTest.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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6476665
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Verifies color conversion of Direct Color Model based images
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @run main ColConvDCMTest
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.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.imageio.ImageIO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public class ColConvDCMTest extends ColConvTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * Test case descriptors: <imgType> <rBits> <gBits> <bBits> <csNum> <gldNum>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    final static int [][] imgTypes = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        {BufferedImage.TYPE_INT_ARGB, 8, 8, 8, 0, 0},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        {BufferedImage.TYPE_INT_ARGB, 8, 8, 8, 1, 3},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        {BufferedImage.TYPE_INT_RGB, 8, 8, 8, 0, 0},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        {BufferedImage.TYPE_INT_RGB, 8, 8, 8, 1, 3},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        {BufferedImage.TYPE_INT_BGR, 8, 8, 8, 0, 0},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        {BufferedImage.TYPE_INT_BGR, 8, 8, 8, 1, 3},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        {BufferedImage.TYPE_USHORT_555_RGB, 5, 5, 5, 0, 1},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        {BufferedImage.TYPE_USHORT_555_RGB, 5, 5, 5, 1, 4},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        {BufferedImage.TYPE_USHORT_565_RGB, 5, 6, 5, 0, 2},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        {BufferedImage.TYPE_USHORT_565_RGB, 5, 6, 5, 1, 5}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    final static int [] cSpaces = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        ColorSpace.CS_sRGB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        ColorSpace.CS_LINEAR_RGB,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
18114
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
    65
    final static double [] ACCURACY = {
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
    66
        // Accuracy for color conversions
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
    67
        2.5, // sRGB
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
    68
        (isOpenProfile() ? 45.0 : 2.5), // LINEAR_RGB
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
    69
    };
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    final static String [] gldImgNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        "SRGB.png", "SRGB555.png", "SRGB565.png", "LRGB.png", "LRGB555.png",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        "LRGB565.png"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    static BufferedImage [] gldImages = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    static boolean testImage(int type, int rBits, int gBits, int bBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                              int cs, BufferedImage gldImage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                              double accuracy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        BufferedImage src = ImageFactory.createDCMImage(type, cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        BufferedImage dst = ImageFactory.createDstImage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            BufferedImage.TYPE_INT_RGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        ColorConvertOp op = new ColorConvertOp(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        op.filter(src, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                                  bBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        boolean result = cmp.compare(gldImage, dst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (!result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            System.err.println(cmp.getStat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     static boolean testSubImage(int x0, int y0, int dx, int dy, int type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                 int rBits, int gBits, int bBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                 int cs, BufferedImage gldImage,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                                 double accuracy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        BufferedImage src = ImageFactory.createDCMImage(type, cs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        BufferedImage subSrc = src.getSubimage(x0, y0, dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        BufferedImage dst = ImageFactory.createDstImage(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            BufferedImage.TYPE_INT_RGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        BufferedImage subDst = dst.getSubimage(x0, y0, dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        ColorConvertOp op = new ColorConvertOp(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        op.filter(subSrc, subDst);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        ImageComparator cmp = new ImageComparator(accuracy, rBits, gBits,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                                  bBits);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        boolean result = cmp.compare(subDst, gldImage, x0, y0, dx, dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (!result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            System.err.println(cmp.getStat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     synchronized public static void initGoldenImages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (gldImages == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            gldImages = new BufferedImage[gldImgNames.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            for (int i = 0; i < gldImgNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    File gldFile = new File(System.getProperty("test.src", "."),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                            gldImgNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    gldImages[i] = ImageIO.read(gldFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    throw new RuntimeException("Cannot initialize golden " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                               "image: " + gldImgNames[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     public void init() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        initGoldenImages();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     public void runTest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        for (int i = 0; i < imgTypes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            BufferedImage gldImage = gldImages[imgTypes[i][5]];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (!testImage(imgTypes[i][0], imgTypes[i][1], imgTypes[i][2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                           imgTypes[i][3], cSpaces[imgTypes[i][4]], gldImage,
18114
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   149
                           ACCURACY[imgTypes[i][4]]))
2
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[imgTypes[i][4]]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    " Image type:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                    getImageTypeName(imgTypes[i][0]) + ". Golden image:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    gldImgNames[imgTypes[i][5]]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            if (!testSubImage(SI_X, SI_Y, SI_W, SI_H, imgTypes[i][0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                              imgTypes[i][1], imgTypes[i][2], imgTypes[i][3],
18114
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   161
                              cSpaces[imgTypes[i][4]], gldImage,
8b16a9643b24 6830714: cmm test failures with OpenJDK
bae
parents: 5506
diff changeset
   162
                              ACCURACY[imgTypes[i][4]]))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                throw new RuntimeException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    "Invalid result of the ColorConvertOp for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                     "ColorSpace:" + getCSName(cSpaces[imgTypes[i][4]]) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                     " Image type:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                     getImageTypeName(imgTypes[i][0]) + ". Golden image:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                     gldImgNames[imgTypes[i][5]]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     public static void main(String [] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         ColConvDCMTest test = new ColConvDCMTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         test.init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         test.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
}