test/jdk/java/awt/image/ConvolveOp/OpCompatibleImageTest.java
author jboes
Fri, 08 Nov 2019 11:15:16 +0000 (2019-11-08)
changeset 59029 3786a0962570
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232853: AuthenticationFilter.Cache::remove may throw ConcurrentModificationException Summary: Change implementation to use iterator instead of plain LinkedList Reviewed-by: dfuchs, vtewari
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2007, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug     6585922
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test verifies ConvolveOp creates compatible destination images
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *          of same type and this pair {src, dst} can be handled by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *          ConvolveOp filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run     main OpCompatibleImageTest
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.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.image.BufferedImageOp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.image.ConvolveOp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.image.ImagingOpException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.image.Kernel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class OpCompatibleImageTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        OpCompatibleImageTest t = new OpCompatibleImageTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        t.doTest(BufferedImage.TYPE_3BYTE_BGR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        t.doTest(BufferedImage.TYPE_4BYTE_ABGR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        t.doTest(BufferedImage.TYPE_BYTE_GRAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        t.doTest(BufferedImage.TYPE_INT_ARGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        t.doTest(BufferedImage.TYPE_INT_BGR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        t.doTest(BufferedImage.TYPE_INT_RGB);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        t.doTest(BufferedImage.TYPE_BYTE_INDEXED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private BufferedImageOp op;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public OpCompatibleImageTest() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        final Kernel kernel = new Kernel(3, 3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                new float[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            1f/9f, 1f/9f, 1f/9f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            1f/9f, 1f/9f, 1f/9f,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            1f/9f, 1f/9f, 1f/9f});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        op = new ConvolveOp(kernel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public void doTest(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        System.out.println("Test for type " + describeType(type));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        BufferedImage src = createTestImage(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        BufferedImage res = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        System.out.println("Testing null destination...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            res = op.filter(src, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        } catch (ImagingOpException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            throw new RuntimeException("Test FAILED!", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (res == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            ((src.getType() != BufferedImage.TYPE_BYTE_INDEXED) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
             (res.getType() != src.getType())))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            throw new RuntimeException("Test FAILED!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        System.out.println("Test PASSED.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    private BufferedImage createCompatible(ColorModel cm, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return new BufferedImage (cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                  cm.createCompatibleWritableRaster(w, h),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                                  cm.isAlphaPremultiplied(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private BufferedImage createTestImage(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        BufferedImage img = new BufferedImage(100, 100, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        Graphics g = img.createGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        g.setColor(Color.red);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        g.fillRect(0, 0, 100, 100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        return img;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private static String describeType(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        switch(type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        case BufferedImage.TYPE_3BYTE_BGR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            return "TYPE_3BYTE_BGR";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        case BufferedImage.TYPE_4BYTE_ABGR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            return "TYPE_4BYTE_ABGR";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        case BufferedImage.TYPE_BYTE_GRAY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            return "TYPE_BYTE_GRAY";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        case BufferedImage.TYPE_INT_ARGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            return "TYPE_INT_ARGB";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        case BufferedImage.TYPE_INT_BGR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            return  "TYPE_INT_BGR";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        case BufferedImage.TYPE_INT_RGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            return "TYPE_INT_RGB";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        case BufferedImage.TYPE_BYTE_INDEXED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            return "TYPE_BYTE_INDEXED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            throw new RuntimeException("Test FAILED: unknown type " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
}