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