Path: blob/master/test/jdk/sun/java2d/cmm/ColorConvertOp/InvalidRenderIntentTest.java
43305 views
/*1* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 706451626* @summary Test verifies that incorrect profile rendering intent27* does not cause an failure of color conversion op.28* @run main InvalidRenderIntentTest29*/3031import java.awt.color.CMMException;32import java.awt.color.ColorSpace;33import java.awt.color.ICC_ColorSpace;34import java.awt.color.ICC_Profile;35import java.awt.image.ColorConvertOp;36import java.awt.image.BufferedImage;3738import static java.awt.color.ColorSpace.CS_sRGB;39import static java.awt.image.BufferedImage.TYPE_3BYTE_BGR;4041public class InvalidRenderIntentTest {4243public static void main(String[] args) {44ICC_Profile pSRGB = ICC_Profile.getInstance(CS_sRGB);4546byte[] raw_data = pSRGB.getData();4748setRenderingIntent(0x1000000, raw_data);4950ICC_Profile p = ICC_Profile.getInstance(raw_data);5152ICC_ColorSpace cs = new ICC_ColorSpace(p);5354// perfrom test color conversion55ColorConvertOp op = new ColorConvertOp(cs,56ColorSpace.getInstance(CS_sRGB), null);57BufferedImage src = new BufferedImage(1, 1, TYPE_3BYTE_BGR);58BufferedImage dst = new BufferedImage(1, 1, TYPE_3BYTE_BGR);5960try {61op.filter(src.getRaster(), dst.getRaster());62} catch (CMMException e) {63throw new RuntimeException("Test failed.", e);64}65System.out.println("Test passed.");66}6768private static void setRenderingIntent(int intent, byte[] data) {69final int pos = ICC_Profile.icHdrRenderingIntent;7071data[pos + 0] = (byte) (0xff & (intent >> 24));72data[pos + 1] = (byte) (0xff & (intent >> 16));73data[pos + 2] = (byte) (0xff & (intent >> 8));74data[pos + 3] = (byte) (0xff & (intent));75}76}777879