EABlitTest.java revision 8729:0242fce0f717
1192067Snwhitehorn/* 2192067Snwhitehorn * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3192067Snwhitehorn * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4192067Snwhitehorn * 5192067Snwhitehorn * This code is free software; you can redistribute it and/or modify it 6192067Snwhitehorn * under the terms of the GNU General Public License version 2 only, as 7192067Snwhitehorn * published by the Free Software Foundation. 8192067Snwhitehorn * 9192067Snwhitehorn * This code is distributed in the hope that it will be useful, but WITHOUT 10192067Snwhitehorn * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11192067Snwhitehorn * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12192067Snwhitehorn * version 2 for more details (a copy is included in the LICENSE file that 13192067Snwhitehorn * accompanied this code). 14192067Snwhitehorn * 15192067Snwhitehorn * You should have received a copy of the GNU General Public License version 16192067Snwhitehorn * 2 along with this work; if not, write to the Free Software Foundation, 17192067Snwhitehorn * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18192067Snwhitehorn * 19192067Snwhitehorn * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20192067Snwhitehorn * or visit www.oracle.com if you need additional information or have any 21192067Snwhitehorn * questions. 22192067Snwhitehorn */ 23192067Snwhitehorn 24192067Snwhitehornimport java.awt.*; 25192067Snwhitehornimport java.awt.image.*; 26192067Snwhitehornimport java.util.*; 27192067Snwhitehornimport javax.swing.*; 28192067Snwhitehorn 29192067Snwhitehorn/** 30192067Snwhitehorn * @test 31192067Snwhitehorn * @bug 8024895 32192067Snwhitehorn * @summary tests if changing extra alpha values are honored for transformed blits 33192067Snwhitehorn * @author ceisserer 34192067Snwhitehorn */ 35192067Snwhitehornpublic class EABlitTest extends Frame { 36192067Snwhitehorn protected void test() { 37192067Snwhitehorn BufferedImage srcImg = createSrcImage(); 38192067Snwhitehorn Image dstImg = getGraphicsConfiguration().createCompatibleVolatileImage(20, 50); 39192067Snwhitehorn 40192067Snwhitehorn //be over-cautious and render twice to avoid BI caching issues 41192067Snwhitehorn renderToVI(srcImg, dstImg); 42192067Snwhitehorn renderToVI(srcImg, dstImg); 43192067Snwhitehorn 44192067Snwhitehorn BufferedImage validationImg = new BufferedImage(20, 50, BufferedImage.TYPE_INT_RGB); 45192067Snwhitehorn Graphics2D valG = (Graphics2D) validationImg.getGraphics(); 46192067Snwhitehorn valG.drawImage(dstImg, 0, 0, null); 47209908Sraj 48209908Sraj //Loop over all pixel, and count the different pixel values encountered. 49209908Sraj TreeSet<Integer> colorCntSet = new TreeSet<>(); 50209908Sraj for (int x=0; x < validationImg.getWidth(); x++) { 51209908Sraj for (int y=0; y < validationImg.getHeight(); y++) { 52192067Snwhitehorn int rgb = validationImg.getRGB(x, y); 53192067Snwhitehorn colorCntSet.add(rgb); 54192067Snwhitehorn } 55192067Snwhitehorn } 56192532Sraj 57192532Sraj //Check if we encountered 3 different color values in total 58192532Sraj if (colorCntSet.size() == 3) { 59224611Smarcel System.out.println("Passed!"); 60192532Sraj } else { 61192532Sraj throw new RuntimeException("Test FAILED!"); 62217523Smarcel } 63217523Smarcel } 64193492Sraj 65192067Snwhitehorn protected void renderToVI(BufferedImage src, Image dst) { 66192067Snwhitehorn Graphics2D g = (Graphics2D) dst.getGraphics(); 67192067Snwhitehorn 68192067Snwhitehorn g.setColor(Color.WHITE); 69192067Snwhitehorn g.fillRect(0, 0, 50, 50); 70192067Snwhitehorn g.rotate(0.5f); 71192067Snwhitehorn g.setRenderingHint(RenderingHints.KEY_RENDERING, 72192067Snwhitehorn RenderingHints.VALUE_RENDER_QUALITY); 73192067Snwhitehorn 74192067Snwhitehorn g.setComposite(AlphaComposite.SrcOver.derive(1f)); 75212054Snwhitehorn g.drawImage(src, 10, 10, null); 76212054Snwhitehorn 77192067Snwhitehorn g.setComposite(AlphaComposite.SrcOver.derive(0.5f)); 78192067Snwhitehorn g.drawImage(src, 20, 20, null); 79192067Snwhitehorn } 80192067Snwhitehorn 81192067Snwhitehorn protected BufferedImage createSrcImage() { 82192067Snwhitehorn BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); 83192067Snwhitehorn Graphics2D g = (Graphics2D) bi.getGraphics(); 84192067Snwhitehorn g.setColor(Color.YELLOW); 85192067Snwhitehorn g.fillRect(0, 0, 10, 10); 86192067Snwhitehorn return bi; 87212453Smav } 88212054Snwhitehorn 89192067Snwhitehorn public static void main(String[] args) { 90192067Snwhitehorn new EABlitTest().test(); 91192067Snwhitehorn } 92192067Snwhitehorn} 93192067Snwhitehorn