Path: blob/master/test/jdk/sun/java2d/DirectX/OpaqueImageToSurfaceBlitTest/OpaqueImageToSurfaceBlitTest.java
41153 views
/*1* Copyright (c) 2007, 2018, 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*/2223/*24* @test25* @key headful26* @bug 6764257 819861327* @summary Tests that the alpha in opaque images doesn't affect result of alpha28* compositing29* @author [email protected]: area=Graphics30* @run main/othervm OpaqueImageToSurfaceBlitTest31* @run main/othervm -Dsun.java2d.noddraw=true OpaqueImageToSurfaceBlitTest32*/3334import java.awt.AlphaComposite;35import java.awt.Graphics2D;36import java.awt.GraphicsConfiguration;37import java.awt.GraphicsDevice;38import java.awt.GraphicsEnvironment;39import java.awt.image.BufferedImage;40import java.awt.image.DataBufferInt;41import java.awt.image.VolatileImage;4243public class OpaqueImageToSurfaceBlitTest {4445public static void main(String[] args) {4647GraphicsEnvironment ge =48GraphicsEnvironment.getLocalGraphicsEnvironment();49GraphicsDevice gd = ge.getDefaultScreenDevice();50GraphicsConfiguration gc = gd.getDefaultConfiguration();51VolatileImage vi = gc.createCompatibleVolatileImage(16, 16);52vi.validate(gc);5354BufferedImage bi =55new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);56int data[] = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();57data[0] = 0x0000007f;58data[1] = 0x0000007f;59data[2] = 0xff00007f;60data[3] = 0xff00007f;61Graphics2D g = vi.createGraphics();62g.setComposite(AlphaComposite.SrcOver.derive(0.999f));63g.drawImage(bi, 0, 0, null);6465bi = vi.getSnapshot();66if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) {67throw new RuntimeException("Test FAILED: color at 0x0 ="+68Integer.toHexString(bi.getRGB(0, 0))+" differs from 1x1 ="+69Integer.toHexString(bi.getRGB(1,1)));70}7172System.out.println("Test PASSED.");73}74}757677