/* * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @bug 8146042 * @run main RenderRectTest */ import java.awt.*; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; import java.awt.image.VolatileImage; public class RenderRectTest { public static void main(String[] args) throws Exception { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice().getDefaultConfiguration(); AffineTransform transform = gc.getDefaultTransform(); if(transform.getScaleX() == 1 && transform.getScaleY() == 1) { VolatileImage vi = gc.createCompatibleVolatileImage(12, 12); Graphics2D g = vi.createGraphics(); g.setColor(Color.black); g.drawRect(1, 1, 9, 9); g.dispose(); BufferedImage capture = vi.getSnapshot(); int w = capture.getWidth(); int h = capture.getHeight(); for (int y = 0; y < h >> 1; y++) { for (int x = 0; x < w >> 1; x++) { if (x > 0 && y > 0 && (x == 1 || y == 1)) { if ((capture.getRGB(x, y) | capture.getRGB(x, h - 1 - y) | capture.getRGB(w - 1 - x, y) | capture.getRGB(w - 1 - x, h - 1 - y)) != Color.black.getRGB()) { throw new RuntimeException("Wrong rectangle"); } } else { if ((capture.getRGB(x, y) & capture.getRGB(x, h - 1 - y) & capture.getRGB(w - 1 - x, y) & capture.getRGB(w - 1 - x, h - 1 - y)) != Color.white.getRGB()) { throw new RuntimeException("Wrong rectangle"); } } } } } else { VolatileImage vi = gc.createCompatibleVolatileImage(12, 12); Graphics2D g = vi.createGraphics(); g.setColor(Color.black); g.drawRect(1, 1, 9, 9); g.dispose(); BufferedImage i1 = new BufferedImage((int)(12 * transform.getScaleX()), (int)(12 * transform.getScaleY()), BufferedImage.TYPE_4BYTE_ABGR_PRE); g = i1.createGraphics(); g.drawImage(vi, 0, 0, i1.getWidth(), i1.getHeight(), null); g.dispose(); BufferedImage i2 = gc.createCompatibleImage(i1.getWidth(), i1.getHeight()); g = i2.createGraphics(); g.setBackground(Color.white); g.clearRect(0, 0, i2.getWidth(), i2.getHeight()); g.setTransform(transform); g.setColor(Color.black); g.drawRect(1, 1, 9, 9); g.dispose(); int w = i1.getWidth(); int h = i1.getHeight(); for (int y = 0; y < h; y++) { for (int x = 0; x < w ; x++) { if (i1.getRGB(x, y) != i2.getRGB(x, y)) { throw new RuntimeException("Rectangles are different"); } } } } } }