< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -26,12 +26,18 @@
  * @bug     4614845
  * @summary Test drawImage(bgcolor) gets correct RGB from SystemColor objects.
  * @run     main SystemBgColorTest
  */
 
-import java.awt.*;
-import java.awt.image.*;
+import java.awt.AlphaComposite;
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.SystemColor;
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBuffer;
+import java.awt.image.IndexColorModel;
 
 public class SystemBgColorTest {
     public static final int TESTW = 10;
     public static final int TESTH = 10;
 

@@ -107,14 +113,22 @@
             test(src, dst, systemColorObjects[i]);
         }
     }
 
     public static void test(Image src, BufferedImage dst, Color bg) {
-        Graphics g = dst.getGraphics();
+        Graphics2D g = (Graphics2D) dst.getGraphics();
+        g.setComposite(AlphaComposite.Src);
         g.setColor(Color.white);
         g.fillRect(0, 0, TESTW, TESTH);
         g.drawImage(src, 0, 0, bg, null);
-        if (dst.getRGB(0, 0) != bg.getRGB()) {
-            error("bad bg pixel for: "+bg);
+        int dstRGB = dst.getRGB(0, 0);
+        int bgRGB = bg.getRGB();
+        if (!dst.getColorModel().hasAlpha()) {
+            bgRGB |= 0xFF000000;
+        }
+        if (dstRGB != bgRGB) {
+            System.err.println("Actual: " + Integer.toHexString(dstRGB));
+            System.err.println("Expected: " + Integer.toHexString(bgRGB));
+            error("bad bg pixel for: " + bg);
         }
     }
 }
< prev index next >