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
6353N/A * @bug 6556332 8011992 8012112
0N/A * @summary Test verifies that on-demnad loading of medialib library does
0N/A * not break imageing ops based on this library.
0N/A * @run main MlibOpsTest
0N/A * @run main/othervm/policy=mlib.security.policy MlibOpsTest
0N/A */
0N/A
0N/A
0N/Aimport java.awt.Color;
0N/Aimport java.awt.Graphics2D;
0N/Aimport java.awt.RadialGradientPaint;
0N/Aimport java.awt.geom.AffineTransform;
0N/Aimport java.awt.geom.Point2D;
0N/Aimport java.awt.image.AffineTransformOp;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.BufferedImageOp;
0N/Aimport java.awt.image.ByteLookupTable;
0N/Aimport java.awt.image.ConvolveOp;
0N/Aimport java.awt.image.Kernel;
0N/Aimport java.awt.image.LookupOp;
0N/Aimport java.util.Arrays;
0N/A
0N/Aimport sun.awt.image.ImagingLib;
0N/A
0N/Apublic class MlibOpsTest {
0N/A
0N/A public static void main(String[] args) {
0N/A System.out.println("AffineTransformOp:");
0N/A BufferedImageOp op = getAffineTransformOp();
0N/A doTest(op);
0N/A
0N/A System.out.println("ConvolveOp:");
0N/A op = getConvolveOp();
0N/A doTest(op);
0N/A
0N/A System.out.println("LookupOp:");
0N/A op = getLookupOp();
0N/A doTest(op);
0N/A }
0N/A
0N/A public static void doTest(BufferedImageOp op) {
0N/A BufferedImage src = createSrcImage();
0N/A BufferedImage dst = createImage();
0N/A BufferedImage ret = null;
0N/A try {
0N/A ret = ImagingLib.filter(op, src, dst);
0N/A } catch (Exception e) {
0N/A throw new RuntimeException("Test FAILED.", e);
0N/A }
0N/A if (ret == null) {
0N/A throw new RuntimeException("Test FAILED: null output");
0N/A }
0N/A
0N/A System.out.println("ret: " + ret);
0N/A System.out.println("Test PASSED for " + op.getClass().getName());
0N/A }
0N/A
0N/A private static BufferedImageOp getAffineTransformOp() {
0N/A AffineTransform at = new AffineTransform();
0N/A return new AffineTransformOp(at,
0N/A AffineTransformOp.TYPE_BICUBIC);
0N/A }
0N/A
0N/A private static BufferedImageOp getConvolveOp() {
0N/A int kw = 3;
0N/A int kh = 3;
0N/A int size = kw * kh;
0N/A float[] kdata = new float[size];
0N/A Arrays.fill(kdata, 1.0f / size);
0N/A
0N/A Kernel k = new Kernel(kw, kh, kdata);
0N/A return new ConvolveOp(k);
0N/A }
0N/A
0N/A private static BufferedImageOp getLookupOp() {
0N/A byte[] inv = new byte[256];
0N/A for (int i = 0; i < 256; i++) {
0N/A inv[i] = (byte)(255 - i);
0N/A }
0N/A ByteLookupTable table = new ByteLookupTable(0, inv);
0N/A return new LookupOp(table, null);
0N/A }
0N/A
0N/A
0N/A private static int w = 100;
0N/A private static int h = 100;
0N/A
0N/A private static BufferedImage createImage() {
0N/A return new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
0N/A }
0N/A
0N/A private static BufferedImage createSrcImage() {
0N/A BufferedImage img = createImage();
0N/A
0N/A Graphics2D g = img.createGraphics();
0N/A Color[] colors = { Color.red, Color.green, Color.blue };
0N/A float[] dist = {0.0f, 0.5f, 1.0f };
0N/A Point2D center = new Point2D.Float(0.5f * w, 0.5f * h);
0N/A
0N/A RadialGradientPaint p =
0N/A new RadialGradientPaint(center, 0.5f * w, dist, colors);
0N/A g.setPaint(p);
0N/A g.fillRect(0, 0, w, h);
0N/A g.dispose();
0N/A
0N/A return img;
0N/A }
0N/A}