1 /* 2 * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 6556332 8011992 8012112 27 * @summary Test verifies that on-demnad loading of medialib library does 28 * not break imageing ops based on this library. 29 * @modules java.desktop/sun.awt.image 30 * @run main MlibOpsTest 31 * @run main/othervm/policy=mlib.security.policy MlibOpsTest 32 */ 33 34 35 import java.awt.Color; 36 import java.awt.Graphics2D; 37 import java.awt.RadialGradientPaint; 38 import java.awt.geom.AffineTransform; 39 import java.awt.geom.Point2D; 40 import java.awt.image.AffineTransformOp; 41 import java.awt.image.BufferedImage; 42 import java.awt.image.BufferedImageOp; 43 import java.awt.image.ByteLookupTable; 44 import java.awt.image.ConvolveOp; 45 import java.awt.image.Kernel; 46 import java.awt.image.LookupOp; 47 import java.util.Arrays; 48 49 import sun.awt.image.ImagingLib; 50 51 public class MlibOpsTest { 52 53 public static void main(String[] args) { 54 System.out.println("AffineTransformOp:"); 55 BufferedImageOp op = getAffineTransformOp(); 56 doTest(op); 57 58 System.out.println("ConvolveOp:"); 59 op = getConvolveOp(); 60 doTest(op); 61 62 System.out.println("LookupOp:"); 63 op = getLookupOp(); 64 doTest(op); 65 } 66 67 public static void doTest(BufferedImageOp op) { 68 BufferedImage src = createSrcImage(); 69 BufferedImage dst = createImage(); 70 BufferedImage ret = null; 71 try { 72 ret = ImagingLib.filter(op, src, dst); 73 } catch (Exception e) { 74 throw new RuntimeException("Test FAILED.", e); 75 } 76 if (ret == null) { 77 throw new RuntimeException("Test FAILED: null output"); 78 } 79 80 System.out.println("ret: " + ret); 81 System.out.println("Test PASSED for " + op.getClass().getName()); 82 } 83 84 private static BufferedImageOp getAffineTransformOp() { 85 AffineTransform at = new AffineTransform(); 86 return new AffineTransformOp(at, 87 AffineTransformOp.TYPE_BICUBIC); 88 } 89 90 private static BufferedImageOp getConvolveOp() { 91 int kw = 3; 92 int kh = 3; 93 int size = kw * kh; 94 float[] kdata = new float[size]; 95 Arrays.fill(kdata, 1.0f / size); 96 97 Kernel k = new Kernel(kw, kh, kdata); 98 return new ConvolveOp(k); 99 } 100 101 private static BufferedImageOp getLookupOp() { 102 byte[] inv = new byte[256]; 103 for (int i = 0; i < 256; i++) { 104 inv[i] = (byte)(255 - i); 105 } 106 ByteLookupTable table = new ByteLookupTable(0, inv); 107 return new LookupOp(table, null); 108 } 109 110 111 private static int w = 100; 112 private static int h = 100; 113 114 private static BufferedImage createImage() { 115 return new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); 116 } 117 118 private static BufferedImage createSrcImage() { 119 BufferedImage img = createImage(); 120 121 Graphics2D g = img.createGraphics(); 122 Color[] colors = { Color.red, Color.green, Color.blue }; 123 float[] dist = {0.0f, 0.5f, 1.0f }; 124 Point2D center = new Point2D.Float(0.5f * w, 0.5f * h); 125 126 RadialGradientPaint p = 127 new RadialGradientPaint(center, 0.5f * w, dist, colors); 128 g.setPaint(p); 129 g.fillRect(0, 0, w, h); 130 g.dispose(); 131 132 return img; 133 } 134 }