Path: blob/master/test/jdk/sun/java2d/loops/Bug7049339.java
41149 views
/*1* Copyright 2011 Red Hat, Inc. All Rights Reserved.2* Copyright (c) 2011, 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 it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 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 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25@test26@bug 704933927@summary Copying images with a non-rectangular clip and a custom composite28fails29@author Denis Lila <[email protected]>30@run main Bug704933931*/3233import java.awt.Composite;34import java.awt.CompositeContext;35import java.awt.Graphics2D;36import java.awt.RenderingHints;37import java.awt.Shape;38import java.awt.geom.Ellipse2D;39import java.awt.image.BufferedImage;40import java.awt.image.ColorModel;41import java.awt.image.Raster;42import java.awt.image.WritableRaster;4344public class Bug7049339 {45public static void main(String[] argv) {46int x = 100, y = 100;47BufferedImage src = new BufferedImage(x, y, BufferedImage.TYPE_INT_ARGB);48BufferedImage dst = new BufferedImage(x, y, BufferedImage.TYPE_3BYTE_BGR);4950Graphics2D dstg2d = dst.createGraphics();51dstg2d.setComposite(new Composite() {52@Override53public CompositeContext createContext(54ColorModel srcColorModel,55ColorModel dstColorModel,56RenderingHints hints)57{58return new CompositeContext() {59@Override60public void compose(Raster src, Raster dstIn,61WritableRaster dstOut)62{63// do nothing64}65@Override66public void dispose() {67}68};69}70});71Shape clip = new Ellipse2D.Double(x/4, y/4, x/2, y/2);72dstg2d.setClip(clip);73// This will throw a RasterFormatException if the bug is present.74dstg2d.drawImage(src, 0, 0, null);75}76}777879