1
1
/*
2
- * Copyright (c) 2007, 2013 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2007, 2020 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
28
28
* @run main SystemBgColorTest
29
29
*/
30
30
31
- import java .awt .*;
32
- import java .awt .image .*;
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 ;
33
39
34
40
public class SystemBgColorTest {
35
41
public static final int TESTW = 10 ;
@@ -109,12 +115,20 @@ public static void test(Image src, int dsttype) {
109
115
}
110
116
111
117
public static void test (Image src , BufferedImage dst , Color bg ) {
112
- Graphics g = dst .getGraphics ();
118
+ Graphics2D g = (Graphics2D ) dst .getGraphics ();
119
+ g .setComposite (AlphaComposite .Src );
113
120
g .setColor (Color .white );
114
121
g .fillRect (0 , 0 , TESTW , TESTH );
115
122
g .drawImage (src , 0 , 0 , bg , null );
116
- if (dst .getRGB (0 , 0 ) != bg .getRGB ()) {
117
- error ("bad bg pixel for: " +bg );
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 );
118
132
}
119
133
}
120
- }
134
+ }
0 commit comments