OpCompatibleImageTest.java revision 0
0N/A/*
2362N/A * Copyright 2007 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
2362N/A * CA 95054 USA or visit www.sun.com if you need additional information or
2362N/A * have any 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
private BufferedImage createCompatible(ColorModel cm, int w, int h) {
return new BufferedImage (cm,
cm.createCompatibleWritableRaster(w, h),
cm.isAlphaPremultiplied(), null);
}
private BufferedImage createTestImage(int type) {
BufferedImage img = new BufferedImage(100, 100, type);
Graphics g = img.createGraphics();
g.setColor(Color.red);
g.fillRect(0, 0, 100, 100);
g.dispose();
return img;
}
private static String describeType(int type) {
switch(type) {
case BufferedImage.TYPE_3BYTE_BGR:
return "TYPE_3BYTE_BGR";
case BufferedImage.TYPE_4BYTE_ABGR:
return "TYPE_4BYTE_ABGR";
case BufferedImage.TYPE_BYTE_GRAY:
return "TYPE_BYTE_GRAY";
case BufferedImage.TYPE_INT_ARGB:
return "TYPE_INT_ARGB";
case BufferedImage.TYPE_INT_BGR:
return "TYPE_INT_BGR";
case BufferedImage.TYPE_INT_RGB:
return "TYPE_INT_RGB";
case BufferedImage.TYPE_BYTE_INDEXED:
return "TYPE_BYTE_INDEXED";
default:
throw new RuntimeException("Test FAILED: unknown type " + type);
}
}
}