< prev index next >

test/jdk/java/awt/Graphics/DrawImageBG/SystemBgColorTest.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2013, 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     4614845
  27  * @summary Test drawImage(bgcolor) gets correct RGB from SystemColor objects.
  28  * @run     main SystemBgColorTest
  29  */
  30 
  31 import java.awt.*;
  32 import java.awt.image.*;






  33 
  34 public class SystemBgColorTest {
  35     public static final int TESTW = 10;
  36     public static final int TESTH = 10;
  37 
  38     static SystemColor systemColorObjects [] = {
  39         SystemColor.desktop,
  40         SystemColor.activeCaption,
  41         SystemColor.activeCaptionText,
  42         SystemColor.activeCaptionBorder,
  43         SystemColor.inactiveCaption,
  44         SystemColor.inactiveCaptionText,
  45         SystemColor.inactiveCaptionBorder,
  46         SystemColor.window,
  47         SystemColor.windowBorder,
  48         SystemColor.windowText,
  49         SystemColor.menu,
  50         SystemColor.menuText,
  51         SystemColor.text,
  52         SystemColor.textText,


  92     public static void test(int dsttype) {
  93         BufferedImage src =
  94             new BufferedImage(TESTW, TESTH, BufferedImage.TYPE_INT_ARGB);
  95         test(src, dsttype);
  96         IndexColorModel icm = new IndexColorModel(8, 2, cmap, 0, true, 0,
  97                                                   DataBuffer.TYPE_BYTE);
  98         src = new BufferedImage(TESTW, TESTH,
  99                                 BufferedImage.TYPE_BYTE_INDEXED, icm);
 100         test(src, dsttype);
 101     }
 102 
 103     public static void test(Image src, int dsttype) {
 104         BufferedImage dst =
 105             new BufferedImage(TESTW, TESTH, dsttype);
 106         for (int i = 0; i < systemColorObjects.length; i++) {
 107             test(src, dst, systemColorObjects[i]);
 108         }
 109     }
 110 
 111     public static void test(Image src, BufferedImage dst, Color bg) {
 112         Graphics g = dst.getGraphics();

 113         g.setColor(Color.white);
 114         g.fillRect(0, 0, TESTW, TESTH);
 115         g.drawImage(src, 0, 0, bg, null);
 116         if (dst.getRGB(0, 0) != bg.getRGB()) {
 117             error("bad bg pixel for: "+bg);







 118         }
 119     }
 120 }
   1 /*
   2  * Copyright (c) 2007, 2020, 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     4614845
  27  * @summary Test drawImage(bgcolor) gets correct RGB from SystemColor objects.
  28  * @run     main SystemBgColorTest
  29  */
  30 
  31 import java.awt.AlphaComposite;
  32 import java.awt.Color;
  33 import java.awt.Graphics2D;
  34 import java.awt.Image;
  35 import java.awt.SystemColor;
  36 import java.awt.image.BufferedImage;
  37 import java.awt.image.DataBuffer;
  38 import java.awt.image.IndexColorModel;
  39 
  40 public class SystemBgColorTest {
  41     public static final int TESTW = 10;
  42     public static final int TESTH = 10;
  43 
  44     static SystemColor systemColorObjects [] = {
  45         SystemColor.desktop,
  46         SystemColor.activeCaption,
  47         SystemColor.activeCaptionText,
  48         SystemColor.activeCaptionBorder,
  49         SystemColor.inactiveCaption,
  50         SystemColor.inactiveCaptionText,
  51         SystemColor.inactiveCaptionBorder,
  52         SystemColor.window,
  53         SystemColor.windowBorder,
  54         SystemColor.windowText,
  55         SystemColor.menu,
  56         SystemColor.menuText,
  57         SystemColor.text,
  58         SystemColor.textText,


  98     public static void test(int dsttype) {
  99         BufferedImage src =
 100             new BufferedImage(TESTW, TESTH, BufferedImage.TYPE_INT_ARGB);
 101         test(src, dsttype);
 102         IndexColorModel icm = new IndexColorModel(8, 2, cmap, 0, true, 0,
 103                                                   DataBuffer.TYPE_BYTE);
 104         src = new BufferedImage(TESTW, TESTH,
 105                                 BufferedImage.TYPE_BYTE_INDEXED, icm);
 106         test(src, dsttype);
 107     }
 108 
 109     public static void test(Image src, int dsttype) {
 110         BufferedImage dst =
 111             new BufferedImage(TESTW, TESTH, dsttype);
 112         for (int i = 0; i < systemColorObjects.length; i++) {
 113             test(src, dst, systemColorObjects[i]);
 114         }
 115     }
 116 
 117     public static void test(Image src, BufferedImage dst, Color bg) {
 118         Graphics2D g = (Graphics2D) dst.getGraphics();
 119         g.setComposite(AlphaComposite.Src);
 120         g.setColor(Color.white);
 121         g.fillRect(0, 0, TESTW, TESTH);
 122         g.drawImage(src, 0, 0, bg, null);
 123         int dstRGB = dst.getRGB(0, 0);
 124         int bgRGB = bg.getRGB();
 125         if (!dst.getColorModel().hasAlpha()) {
 126             bgRGB |= 0xFF000000;
 127         }
 128         if (dstRGB != bgRGB) {
 129             System.err.println("Actual: " + Integer.toHexString(dstRGB));
 130             System.err.println("Expected: " + Integer.toHexString(bgRGB));
 131             error("bad bg pixel for: " + bg);
 132         }
 133     }
 134 }
< prev index next >