771N/A/*
2362N/A * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
771N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
771N/A *
771N/A * This code is free software; you can redistribute it and/or modify it
771N/A * under the terms of the GNU General Public License version 2 only, as
771N/A * published by the Free Software Foundation.
771N/A *
771N/A * This code is distributed in the hope that it will be useful, but WITHOUT
771N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
771N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
771N/A * version 2 for more details (a copy is included in the LICENSE file that
771N/A * accompanied this code).
771N/A *
771N/A * You should have received a copy of the GNU General Public License version
771N/A * 2 along with this work; if not, write to the Free Software Foundation,
771N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
771N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
771N/A */
771N/A
771N/A/*
771N/A * @test
771N/A * @bug 6764257
771N/A * @summary Tests that the alpha in opaque images doesn't affect result of alpha
771N/A * compositing
771N/A * @author Dmitri.Trembovetski@sun.com: area=Graphics
771N/A * @run main/othervm OpaqueImageToSurfaceBlitTest
771N/A * @run main/othervm -Dsun.java2d.noddraw=true OpaqueImageToSurfaceBlitTest
771N/A * @run main/othervm -Dsun.java2d.opengl=True OpaqueImageToSurfaceBlitTest
771N/A */
771N/A
771N/Aimport java.awt.AlphaComposite;
771N/Aimport java.awt.Graphics2D;
771N/Aimport java.awt.GraphicsConfiguration;
771N/Aimport java.awt.GraphicsDevice;
771N/Aimport java.awt.GraphicsEnvironment;
771N/Aimport java.awt.image.BufferedImage;
771N/Aimport java.awt.image.DataBufferInt;
771N/Aimport java.awt.image.VolatileImage;
771N/A
771N/Apublic class OpaqueImageToSurfaceBlitTest {
771N/A
771N/A public static void main(String[] args) {
771N/A
771N/A GraphicsEnvironment ge =
771N/A GraphicsEnvironment.getLocalGraphicsEnvironment();
771N/A GraphicsDevice gd = ge.getDefaultScreenDevice();
771N/A GraphicsConfiguration gc = gd.getDefaultConfiguration();
771N/A VolatileImage vi = gc.createCompatibleVolatileImage(16, 16);
771N/A vi.validate(gc);
771N/A
771N/A BufferedImage bi =
771N/A new BufferedImage(2, 2, BufferedImage.TYPE_INT_RGB);
771N/A int data[] = ((DataBufferInt)bi.getRaster().getDataBuffer()).getData();
771N/A data[0] = 0x0000007f;
771N/A data[1] = 0x0000007f;
771N/A data[2] = 0xff00007f;
771N/A data[3] = 0xff00007f;
771N/A Graphics2D g = vi.createGraphics();
771N/A g.setComposite(AlphaComposite.SrcOver.derive(0.999f));
771N/A g.drawImage(bi, 0, 0, null);
771N/A
771N/A bi = vi.getSnapshot();
771N/A if (bi.getRGB(0, 0) != bi.getRGB(1, 1)) {
771N/A throw new RuntimeException("Test FAILED: color at 0x0 ="+
771N/A Integer.toHexString(bi.getRGB(0, 0))+" differs from 1x1 ="+
771N/A Integer.toHexString(bi.getRGB(1,1)));
771N/A }
771N/A
771N/A System.out.println("Test PASSED.");
771N/A }
771N/A}