1 /* 2 * Copyright (c) 2014, 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 * @test 26 * @bug 8028539 27 * @summary Test that drawing a scaled image terminates. 28 * @run main/othervm/timeout=60 DrawImageCoordsTest 29 */ 30 31 import java.awt.Color; 32 import java.awt.Graphics; 33 import java.awt.Graphics2D; 34 import java.awt.geom.AffineTransform; 35 import java.awt.image.BufferedImage; 36 37 public class DrawImageCoordsTest { 38 39 public static void main(String[] args) { 40 41 /* Create an image to draw, filled in solid red. */ 42 BufferedImage srcImg = 43 new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB); 44 Graphics srcG = srcImg.createGraphics(); 45 srcG.setColor(Color.red); 46 int w = srcImg.getWidth(null); 47 int h = srcImg.getHeight(null); 48 srcG.fillRect(0, 0, w, h); 49 50 /* Create a destination image */ 51 BufferedImage dstImage = 52 new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB); 53 Graphics2D dstG = dstImage.createGraphics(); 54 /* draw image under a scaling transform that overflows int */ 55 AffineTransform tx = new AffineTransform(0.5, 0, 0, 0.5, 56 0, 5.8658460197478485E9); 57 dstG.setTransform(tx); 58 dstG.drawImage(srcImg, 0, 0, null ); 59 /* draw image under the same overflowing transform, cancelling 60 * out the 0.5 scale on the graphics 61 */ 62 dstG.drawImage(srcImg, 0, 0, 2*w, 2*h, null); 63 if (Color.red.getRGB() == dstImage.getRGB(w/2, h/2)) { 64 throw new RuntimeException("Unexpected color: clipping failed."); 65 } 66 System.out.println("Test Thread Completed"); 67 } 68 }