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 6585922
0N/A * @summary Test verifies ConvolveOp creates compatible destination images
0N/A * of same type and this pair {src, dst} can be handled by the
0N/A * ConvolveOp filter.
0N/A *
0N/A * @run main OpCompatibleImageTest
0N/A */
0N/A
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Graphics;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.BufferedImageOp;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.image.ConvolveOp;
0N/Aimport java.awt.image.ImagingOpException;
0N/Aimport java.awt.image.Kernel;
0N/A
0N/Apublic class OpCompatibleImageTest {
0N/A
0N/A public static void main(String[] args) {
0N/A OpCompatibleImageTest t = new OpCompatibleImageTest();
0N/A t.doTest(BufferedImage.TYPE_3BYTE_BGR);
0N/A t.doTest(BufferedImage.TYPE_4BYTE_ABGR);
0N/A t.doTest(BufferedImage.TYPE_BYTE_GRAY);
0N/A t.doTest(BufferedImage.TYPE_INT_ARGB);
0N/A t.doTest(BufferedImage.TYPE_INT_BGR);
0N/A t.doTest(BufferedImage.TYPE_INT_RGB);
0N/A t.doTest(BufferedImage.TYPE_BYTE_INDEXED);
0N/A }
0N/A
0N/A private BufferedImageOp op;
0N/A
0N/A public OpCompatibleImageTest() {
0N/A final Kernel kernel = new Kernel(3, 3,
0N/A new float[] {
0N/A 1f/9f, 1f/9f, 1f/9f,
0N/A 1f/9f, 1f/9f, 1f/9f,
0N/A 1f/9f, 1f/9f, 1f/9f});
0N/A op = new ConvolveOp(kernel);
0N/A }
0N/A
0N/A public void doTest(int type) {
0N/A System.out.println("Test for type " + describeType(type));
0N/A
0N/A BufferedImage src = createTestImage(type);
0N/A
0N/A BufferedImage res = null;
0N/A
0N/A System.out.println("Testing null destination...");
0N/A try {
0N/A res = op.filter(src, null);
0N/A } catch (ImagingOpException e) {
0N/A throw new RuntimeException("Test FAILED!", e);
0N/A }
0N/A
0N/A if (res == null ||
0N/A ((src.getType() != BufferedImage.TYPE_BYTE_INDEXED) &&
0N/A (res.getType() != src.getType())))
0N/A {
0N/A throw new RuntimeException("Test FAILED!");
0N/A }
0N/A System.out.println("Test PASSED.");
0N/A }
0N/A
0N/A private BufferedImage createCompatible(ColorModel cm, int w, int h) {
0N/A return new BufferedImage (cm,
0N/A cm.createCompatibleWritableRaster(w, h),
0N/A cm.isAlphaPremultiplied(), null);
0N/A }
0N/A
0N/A private BufferedImage createTestImage(int type) {
0N/A BufferedImage img = new BufferedImage(100, 100, type);
0N/A Graphics g = img.createGraphics();
0N/A g.setColor(Color.red);
0N/A g.fillRect(0, 0, 100, 100);
0N/A g.dispose();
0N/A
0N/A return img;
0N/A }
0N/A
0N/A private static String describeType(int type) {
0N/A switch(type) {
0N/A case BufferedImage.TYPE_3BYTE_BGR:
0N/A return "TYPE_3BYTE_BGR";
0N/A case BufferedImage.TYPE_4BYTE_ABGR:
0N/A return "TYPE_4BYTE_ABGR";
0N/A case BufferedImage.TYPE_BYTE_GRAY:
0N/A return "TYPE_BYTE_GRAY";
0N/A case BufferedImage.TYPE_INT_ARGB:
0N/A return "TYPE_INT_ARGB";
0N/A case BufferedImage.TYPE_INT_BGR:
0N/A return "TYPE_INT_BGR";
0N/A case BufferedImage.TYPE_INT_RGB:
0N/A return "TYPE_INT_RGB";
0N/A case BufferedImage.TYPE_BYTE_INDEXED:
0N/A return "TYPE_BYTE_INDEXED";
0N/A default:
0N/A throw new RuntimeException("Test FAILED: unknown type " + type);
0N/A }
0N/A }
0N/A}