InvalidRenderIntentTest.java revision 9330:8b1f1c2a400f
1145256Sjkoshy/*
2180148Sjkoshy * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3174396Sjkoshy * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4145256Sjkoshy *
5145256Sjkoshy * This code is free software; you can redistribute it and/or modify it
6174396Sjkoshy * under the terms of the GNU General Public License version 2 only, as
7174396Sjkoshy * published by the Free Software Foundation.
8174396Sjkoshy *
9145256Sjkoshy * This code is distributed in the hope that it will be useful, but WITHOUT
10145256Sjkoshy * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11145256Sjkoshy * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12145256Sjkoshy * version 2 for more details (a copy is included in the LICENSE file that
13145256Sjkoshy * accompanied this code).
14145256Sjkoshy *
15145256Sjkoshy * You should have received a copy of the GNU General Public License version
16145256Sjkoshy * 2 along with this work; if not, write to the Free Software Foundation,
17145256Sjkoshy * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18145256Sjkoshy *
19145256Sjkoshy * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20145256Sjkoshy * or visit www.oracle.com if you need additional information or have any
21145256Sjkoshy * questions.
22145256Sjkoshy */
23145256Sjkoshy
24145256Sjkoshy/**
25145256Sjkoshy * @test
26145256Sjkoshy * @bug     7064516
27145256Sjkoshy * @summary Test verifies that incorrect profile rendering intent
28145256Sjkoshy *           does not cause an failure of color conversion op.
29145256Sjkoshy * @run     main InvalidRenderIntentTest
30145256Sjkoshy */
31145256Sjkoshy
32145256Sjkoshyimport java.awt.color.CMMException;
33145256Sjkoshyimport java.awt.color.ColorSpace;
34145256Sjkoshyimport java.awt.color.ICC_ColorSpace;
35145256Sjkoshyimport java.awt.color.ICC_Profile;
36169069Sjkoshyimport java.awt.image.ColorConvertOp;
37145256Sjkoshyimport java.awt.image.BufferedImage;
38147708Sjkoshy
39147708Sjkoshyimport static java.awt.color.ColorSpace.CS_sRGB;
40168949Sjkoshyimport static java.awt.image.BufferedImage.TYPE_3BYTE_BGR;
41145256Sjkoshy
42145256Sjkoshypublic class InvalidRenderIntentTest {
43169069Sjkoshy
44145256Sjkoshy    public static void main(String[] args) {
45145256Sjkoshy        ICC_Profile pSRGB = ICC_Profile.getInstance(CS_sRGB);
46145256Sjkoshy
47203790Sfabient        byte[] raw_data = pSRGB.getData();
48145256Sjkoshy
49145256Sjkoshy        setRenderingIntent(0x1000000, raw_data);
50145256Sjkoshy
51169069Sjkoshy        ICC_Profile p = ICC_Profile.getInstance(raw_data);
52157144Sjkoshy
53145256Sjkoshy        ICC_ColorSpace cs = new ICC_ColorSpace(p);
54145256Sjkoshy
55145256Sjkoshy        // perfrom test color conversion
56147191Sjkoshy        ColorConvertOp op = new ColorConvertOp(cs,
57169069Sjkoshy                ColorSpace.getInstance(CS_sRGB), null);
58145256Sjkoshy        BufferedImage src = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
59145256Sjkoshy        BufferedImage dst = new BufferedImage(1, 1, TYPE_3BYTE_BGR);
60147708Sjkoshy
61145256Sjkoshy        try {
62145256Sjkoshy            op.filter(src.getRaster(), dst.getRaster());
63145256Sjkoshy        } catch (CMMException e) {
64145256Sjkoshy            throw new RuntimeException("Test failed.", e);
65145256Sjkoshy        }
66145256Sjkoshy        System.out.println("Test passed.");
67147708Sjkoshy    }
68147708Sjkoshy
69147191Sjkoshy    private static void setRenderingIntent(int intent, byte[] data) {
70147191Sjkoshy        final int pos = ICC_Profile.icHdrRenderingIntent;
71147191Sjkoshy
72147191Sjkoshy        data[pos + 0] = (byte) (0xff & (intent >> 24));
73147191Sjkoshy        data[pos + 1] = (byte) (0xff & (intent >> 16));
74147191Sjkoshy        data[pos + 2] = (byte) (0xff & (intent >> 8));
75147191Sjkoshy        data[pos + 3] = (byte) (0xff & (intent));
76147191Sjkoshy    }
77147191Sjkoshy}
78147191Sjkoshy