1115N/A/*
2365N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
1115N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1115N/A *
1115N/A * This code is free software; you can redistribute it and/or modify it
1115N/A * under the terms of the GNU General Public License version 2 only, as
1115N/A * published by the Free Software Foundation.
1115N/A *
1115N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1115N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1115N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1115N/A * version 2 for more details (a copy is included in the LICENSE file that
1115N/A * accompanied this code).
1115N/A *
1115N/A * You should have received a copy of the GNU General Public License version
1115N/A * 2 along with this work; if not, write to the Free Software Foundation,
1115N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1115N/A *
2365N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2365N/A * or visit www.oracle.com if you need additional information or have any
2365N/A * questions.
1115N/A */
1115N/A
1115N/A/*
1115N/A * @test
1115N/A * @bug 6726779
1115N/A * @summary Test verifies that ConvolveOp with the EDGE_NO_OP edge condition
1115N/A * does not cause JVM crash if size of source raster elements is
1115N/A * greather than size of the destination raster element.
1115N/A *
1115N/A * @run main EdgeNoOpCrash
1115N/A */
1115N/Aimport java.awt.Point;
1115N/Aimport java.awt.image.ConvolveOp;
1115N/Aimport java.awt.image.DataBuffer;
1115N/Aimport java.awt.image.ImagingOpException;
1115N/Aimport java.awt.image.Kernel;
1115N/Aimport java.awt.image.Raster;
1115N/Aimport java.awt.image.WritableRaster;
1115N/Aimport java.util.Arrays;
1115N/A
1115N/Apublic class EdgeNoOpCrash {
1115N/A private static final int w = 3000;
1115N/A private static final int h = 200;
1115N/A
1115N/A public static void main(String[] args) {
1115N/A crashTest();
1115N/A }
1115N/A
1115N/A private static void crashTest() {
1115N/A Raster src = createSrcRaster();
1115N/A WritableRaster dst = createDstRaster();
1115N/A ConvolveOp op = createConvolveOp(ConvolveOp.EDGE_NO_OP);
1115N/A try {
1115N/A op.filter(src, dst);
1115N/A } catch (ImagingOpException e) {
1115N/A /*
1115N/A * The test pair of source and destination rasters
1115N/A * may cause failure of the medialib convolution routine,
1115N/A * so this exception is expected.
1115N/A *
1115N/A * The JVM crash is the only manifestation of this
1115N/A * test failure.
1115N/A */
1115N/A }
1115N/A System.out.println("Test PASSED.");
1115N/A }
1115N/A
1115N/A private static Raster createSrcRaster() {
1115N/A WritableRaster r = Raster.createInterleavedRaster(DataBuffer.TYPE_USHORT,
1115N/A w, h, 4, new Point(0, 0));
1115N/A
1115N/A return r;
1115N/A }
1115N/A
1115N/A private static WritableRaster createDstRaster() {
1115N/A WritableRaster r = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE,
1115N/A w, h, 4, new Point(0, 0));
1115N/A
1115N/A return r;
1115N/A }
1115N/A
1115N/A private static ConvolveOp createConvolveOp(int edgeHint) {
1115N/A final int kw = 3;
1115N/A final int kh = 3;
1115N/A float[] kdata = new float[kw * kh];
1115N/A float v = 1f / kdata.length;
1115N/A Arrays.fill(kdata, v);
1115N/A
1115N/A Kernel k = new Kernel(kw, kh, kdata);
1115N/A ConvolveOp op = new ConvolveOp(k, edgeHint, null);
1115N/A
1115N/A return op;
1115N/A }
2365N/A}