test/jdk/java/awt/image/LookupOp/IntImageReverseTest.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 15502 jdk/test/java/awt/image/LookupOp/IntImageReverseTest.java@6aad6647696c
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15502
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
     1
/*
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
     4
 *
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
     8
 *
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    13
 * accompanied this code).
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    14
 *
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    18
 *
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    21
 * questions.
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    22
 */
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    23
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    24
/*
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    25
 * @test
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    26
 * @bug     8004801
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    27
 * @summary Test verifies that byte lookup table with single lookup
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    28
 *          affects only color components in buffered images with
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    29
 *          integer data type, and that this operation does not distort
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    30
 *          colors in the destination image.
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    31
 * @run     main IntImageReverseTest
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    32
 */
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    33
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    34
import java.awt.image.BufferedImage;
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    35
import java.awt.image.ByteLookupTable;
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    36
import java.awt.image.LookupOp;
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    37
import java.awt.image.LookupTable;
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    38
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    39
public class IntImageReverseTest {
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    40
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    41
    public static void main(String[] args) {
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    42
        LookupTable tbl = createReverseTable();
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    43
        LookupOp op = new LookupOp(tbl, null);
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    44
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    45
        for (ImageType t : ImageType.values()) {
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    46
            System.out.print(t);
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    47
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    48
            BufferedImage src = createSourceImage(t);
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    49
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    50
            BufferedImage dst = op.filter(src, null);
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    51
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    52
            int rgb = dst.getRGB(0, 0);
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    53
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    54
            System.out.printf(" Result: 0x%X ", rgb);
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    55
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    56
            if (rgb != argbReverse) {
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    57
                throw new RuntimeException("Test failed.");
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    58
            }
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    59
            System.out.println("Passed.");
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    60
        }
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    61
    }
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    62
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    63
    /**
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    64
     * Reverse image color components, leave alpha unchanged.
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    65
     */
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    66
    private static LookupTable createReverseTable() {
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    67
        byte[] data = new byte[256];
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    68
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    69
        for (int i = 0; i < 256; i++) {
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    70
            data[i] = (byte) (255 - i);
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    71
        }
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    72
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    73
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    74
        return new ByteLookupTable(0, data);
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    75
    }
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    76
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    77
    private static BufferedImage createSourceImage(ImageType type) {
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    78
        BufferedImage img = new BufferedImage(1, 1, type.bi_type);
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    79
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    80
        img.setRGB(0, 0, argbTest);
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    81
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    82
        return img;
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    83
    }
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    84
    private static final int argbTest = 0xFFDDAA77;
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    85
    private static final int argbReverse = 0xFF225588;
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    86
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    87
    private static enum ImageType {
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    88
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    89
        INT_ARGB(BufferedImage.TYPE_INT_ARGB),
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    90
        INT_ARGB_PRE(BufferedImage.TYPE_INT_ARGB_PRE),
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    91
        INT_RGB(BufferedImage.TYPE_INT_BGR),
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    92
        INT_BGR(BufferedImage.TYPE_INT_BGR);
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    93
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    94
        private ImageType(int bi_type) {
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    95
            this.bi_type = bi_type;
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    96
        }
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    97
        public final int bi_type;
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    98
    }
6aad6647696c 8004801: The image of BufferedImage.TYPE_INT_ARGB is blank.
bae
parents:
diff changeset
    99
}