test/jdk/sun/java2d/marlin/FlipBitTest.java
changeset 58321 7f55aad34ac4
equal deleted inserted replaced
58320:3020baa4efa4 58321:7f55aad34ac4
       
     1 /*
       
     2  * Copyright (c) 2019, 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 import java.awt.BasicStroke;
       
    26 import java.awt.Color;
       
    27 import java.awt.Graphics2D;
       
    28 import java.awt.Rectangle;
       
    29 import java.awt.RenderingHints;
       
    30 import java.awt.geom.AffineTransform;
       
    31 import java.awt.geom.Ellipse2D;
       
    32 import java.awt.image.BufferedImage;
       
    33 import java.io.File;
       
    34 import java.io.IOException;
       
    35 import javax.imageio.ImageIO;
       
    36 
       
    37 
       
    38 /**
       
    39  * Tests calculating user space line with a negative determinant (flip).
       
    40  *
       
    41  * @test
       
    42  * @summary verify that flipped transformed lines are properly rasterized
       
    43  * @bug 8230728
       
    44  */
       
    45 public class FlipBitTest {
       
    46 
       
    47     static final boolean SAVE_IMAGE = false;
       
    48 
       
    49     public static void main(final String[] args) {
       
    50 
       
    51         final int size = 100;
       
    52 
       
    53         // First display which renderer is tested:
       
    54         // JDK9 only:
       
    55         System.setProperty("sun.java2d.renderer.verbose", "true");
       
    56 
       
    57         System.out.println("FlipBitTest: size = " + size);
       
    58 
       
    59         final BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
       
    60 
       
    61         final Graphics2D g2d = (Graphics2D) image.getGraphics();
       
    62         try {
       
    63             g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
       
    64             g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
       
    65             g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
       
    66 
       
    67             final AffineTransform at = new AffineTransform();
       
    68             at.setToScale(1, -1.01);
       
    69             g2d.setTransform(at);
       
    70 
       
    71             g2d.translate(0, -image.getHeight());
       
    72             g2d.setPaint(Color.WHITE);
       
    73             g2d.fill(new Rectangle(image.getWidth(), image.getHeight()));
       
    74 
       
    75             g2d.setPaint(Color.BLACK);
       
    76             g2d.setStroke(new BasicStroke(0.1f));
       
    77             g2d.draw(new Ellipse2D.Double(25, 25, 50, 50));
       
    78 
       
    79             if (SAVE_IMAGE) {
       
    80                 try {
       
    81                     final File file = new File("FlipBitTest.png");
       
    82 
       
    83                     System.out.println("Writing file: " + file.getAbsolutePath());
       
    84                     ImageIO.write(image, "PNG", file);
       
    85                 } catch (IOException ex) {
       
    86                     ex.printStackTrace();
       
    87                 }
       
    88             }
       
    89 
       
    90             boolean nonWhitePixelFound = false;
       
    91             for (int x = 0; x < image.getWidth(); ++x) {
       
    92                 if (image.getRGB(x, 50) != Color.WHITE.getRGB()) {
       
    93                     nonWhitePixelFound = true;
       
    94                     break;
       
    95                 }
       
    96             }
       
    97             if (!nonWhitePixelFound) {
       
    98                 throw new IllegalStateException("The ellipse was not drawn");
       
    99             }
       
   100         } finally {
       
   101             g2d.dispose();
       
   102         }
       
   103     }
       
   104 }