Path: blob/master/test/jdk/sun/java2d/marlin/FlipBitTest.java
41149 views
/*1* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/222324import java.awt.BasicStroke;25import java.awt.Color;26import java.awt.Graphics2D;27import java.awt.Rectangle;28import java.awt.RenderingHints;29import java.awt.geom.AffineTransform;30import java.awt.geom.Ellipse2D;31import java.awt.image.BufferedImage;32import java.io.File;33import java.io.IOException;34import javax.imageio.ImageIO;353637/**38* Tests calculating user space line with a negative determinant (flip).39*40* @test41* @summary verify that flipped transformed lines are properly rasterized42* @bug 823072843*/44public class FlipBitTest {4546static final boolean SAVE_IMAGE = false;4748public static void main(final String[] args) {4950final int size = 100;5152// First display which renderer is tested:53// JDK9 only:54System.setProperty("sun.java2d.renderer.verbose", "true");5556System.out.println("FlipBitTest: size = " + size);5758final BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);5960final Graphics2D g2d = (Graphics2D) image.getGraphics();61try {62g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);63g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);64g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);6566final AffineTransform at = new AffineTransform();67at.setToScale(1, -1.01);68g2d.setTransform(at);6970g2d.translate(0, -image.getHeight());71g2d.setPaint(Color.WHITE);72g2d.fill(new Rectangle(image.getWidth(), image.getHeight()));7374g2d.setPaint(Color.BLACK);75g2d.setStroke(new BasicStroke(0.1f));76g2d.draw(new Ellipse2D.Double(25, 25, 50, 50));7778if (SAVE_IMAGE) {79try {80final File file = new File("FlipBitTest.png");8182System.out.println("Writing file: " + file.getAbsolutePath());83ImageIO.write(image, "PNG", file);84} catch (IOException ex) {85ex.printStackTrace();86}87}8889boolean nonWhitePixelFound = false;90for (int x = 0; x < image.getWidth(); ++x) {91if (image.getRGB(x, 50) != Color.WHITE.getRGB()) {92nonWhitePixelFound = true;93break;94}95}96if (!nonWhitePixelFound) {97throw new IllegalStateException("The ellipse was not drawn");98}99} finally {100g2d.dispose();101}102}103}104105106