0N/A/*
2362N/A * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 6476665
0N/A * @summary Verifies MT safety of color conversions
0N/A * @run main MTSafetyTest
0N/A */
0N/A
0N/Aimport java.util.Vector;
0N/Aimport java.awt.*;
0N/Aimport java.awt.color.*;
0N/Aimport java.awt.image.*;
0N/A
0N/Apublic class MTSafetyTest {
0N/A
0N/A static boolean failed = false;
0N/A
0N/A static int[] colorSpaceType = {
0N/A ColorSpace.CS_CIEXYZ,
0N/A ColorSpace.CS_GRAY,
0N/A ColorSpace.CS_LINEAR_RGB,
0N/A ColorSpace.CS_PYCC,
0N/A ColorSpace.CS_sRGB
0N/A };
0N/A
0N/A static private final int[] imageTypes = new int[] {
0N/A BufferedImage.TYPE_INT_RGB,
0N/A BufferedImage.TYPE_INT_ARGB,
0N/A BufferedImage.TYPE_INT_ARGB_PRE,
0N/A BufferedImage.TYPE_INT_BGR,
0N/A BufferedImage.TYPE_3BYTE_BGR,
0N/A BufferedImage.TYPE_4BYTE_ABGR,
0N/A BufferedImage.TYPE_4BYTE_ABGR_PRE,
0N/A BufferedImage.TYPE_USHORT_565_RGB,
0N/A BufferedImage.TYPE_USHORT_555_RGB,
0N/A BufferedImage.TYPE_BYTE_GRAY,
0N/A BufferedImage.TYPE_USHORT_GRAY,
0N/A BufferedImage.TYPE_BYTE_BINARY,
0N/A BufferedImage.TYPE_BYTE_INDEXED
0N/A };
0N/A
0N/A
0N/A public static void main(String[] args) {
0N/A int nImgTypes = imageTypes.length;
0N/A int nCSTypes = colorSpaceType.length;
0N/A Vector<Thread> threads =
0N/A new Vector<Thread>(nImgTypes*nCSTypes*nCSTypes);
0N/A
0N/A for (int i = 0; i < nImgTypes; i++) {
0N/A BufferedImage origImage =
0N/A new BufferedImage(300, 300, imageTypes[i]);
0N/A
0N/A for (int j = 0; j < nCSTypes; j++) {
0N/A for (int k = 0; k < nCSTypes; k++) {
0N/A
0N/A Graphics2D g2 = (Graphics2D) origImage.getGraphics();
0N/A g2.fillRect(0, 0, 300, 150);
0N/A
0N/A ColorConvertOp colorOp = getColorConvertOp(j,k);
0N/A ColorConvert cc = new ColorConvert(origImage, colorOp);
0N/A
0N/A Thread colorThread = new Thread(cc);
0N/A threads.add(colorThread);
0N/A colorThread.start();
0N/A }
0N/A }
0N/A }
0N/A
0N/A try {
0N/A for (Thread thread : threads) {
0N/A thread.join();
0N/A }
0N/A } catch (InterruptedException e) {
0N/A throw new RuntimeException("Unexpected exception" + e);
0N/A }
0N/A
0N/A if (failed) {
0N/A throw new RuntimeException("Unexpected exception");
0N/A }
0N/A }
0N/A
0N/A private static ColorConvertOp getColorConvertOp(int srcIndex,
0N/A int destIndex)
0N/A {
0N/A ColorSpace srcColorSpace = ColorSpace.getInstance(
0N/A colorSpaceType[srcIndex]);
0N/A ColorSpace destColorSpace = ColorSpace.getInstance(
0N/A colorSpaceType[destIndex]);
0N/A return new ColorConvertOp(srcColorSpace, destColorSpace, null);
0N/A }
0N/A
0N/A
0N/A static class ColorConvert implements Runnable {
0N/A
0N/A BufferedImage original = null;
0N/A ColorConvertOp colorOp = null;
0N/A
0N/A public ColorConvert(BufferedImage orig, ColorConvertOp ccOp) {
0N/A original = orig;
0N/A colorOp = ccOp;
0N/A }
0N/A
0N/A public void run() {
0N/A try {
0N/A colorOp.filter(original, null);
0N/A } catch (OutOfMemoryError e) {
0N/A /* Skipping OOM exception. We cannot just enlarge stack and heap
0N/A * because it causes problem to disappear
0N/A */
0N/A
0N/A e.printStackTrace();
0N/A
0N/A } catch (Exception e) {
0N/A e.printStackTrace();
0N/A failed = true;
0N/A }
0N/A }
0N/A }
0N/A}