1 /*
2  * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 /**
25  * @test
26  * @bug 6279846
27  * @summary Verifies that transform between the same ICC color spaces does not
28  * change pixels
29  * @run main ColorConvertTest
30  */
31 
32 import java.awt.image.*;
33 import java.awt.color.ColorSpace;
34 
35 public class RGBColorConvertTest {
36 
main(String [] args)37     public static void main(String [] args) {
38         BufferedImage src =
39             new BufferedImage(256,3,BufferedImage.TYPE_INT_RGB);
40         BufferedImage dst =
41             new BufferedImage(256,3,BufferedImage.TYPE_INT_RGB);
42 
43         for (int i = 0; i < 256; i++) {
44             src.setRGB(i,0,i);
45             src.setRGB(i,1,i << 8);
46             src.setRGB(i,2,i << 16);
47         }
48 
49         ColorSpace srcColorSpace = src.getColorModel().getColorSpace();
50 
51         ColorConvertOp op = new ColorConvertOp(srcColorSpace, srcColorSpace,
52                                                null);
53         op.filter(src, dst);
54 
55         int errCount = 0;
56         for (int i = 0; i < src.getWidth(); i++) {
57             for (int j = 0; j < src.getHeight(); j++) {
58                 int scol = src.getRGB(i,j);
59                 int dcol = dst.getRGB(i,j);
60                 if (scol != dcol) {
61                     System.err.println("(" + i + "," + j + ") : " +
62                                        Integer.toHexString(scol) + "!=" +
63                                        Integer.toHexString(dcol));
64                     errCount++;
65                 }
66             }
67         }
68 
69         if (errCount > 0) {
70             throw new RuntimeException(errCount + " pixels are changed by " +
71                                        "transform between the same ICC color " +
72                                        "spaces");
73         }
74     }
75 }
76