1
1
/*
2
- * Copyright (c) 2011, 2020 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2011, 2022 , 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
32
32
*/
33
33
34
34
import java .awt .BorderLayout ;
35
+ import java .awt .Color ;
35
36
import java .awt .Rectangle ;
36
37
import java .awt .Robot ;
37
38
import java .awt .image .BufferedImage ;
@@ -72,6 +73,7 @@ public class bug6796710 {
72
73
private static JFrame frame ;
73
74
74
75
private static JPanel pnBottom ;
76
+ private static final int COLOR_TOLERANCE = 5 ;
75
77
76
78
public static void main (String [] args ) throws Exception {
77
79
robot = new Robot ();
@@ -126,7 +128,7 @@ public void run() {
126
128
Thread .sleep (1000 );
127
129
128
130
BufferedImage pnBottomImage = getPnBottomImage ();
129
- if (!Util . compareBufferedImages (bufferedImage , pnBottomImage )) {
131
+ if (!compareBufferedImages (bufferedImage , pnBottomImage )) {
130
132
ImageIO .write (bufferedImage , "png" , new File ("bufferedImage.png" ));
131
133
ImageIO .write (pnBottomImage , "png" , new File ("pnBottomImage.png" ));
132
134
throw new RuntimeException ("The test failed" );
@@ -135,6 +137,41 @@ public void run() {
135
137
System .out .println ("The test bug6796710 passed." );
136
138
}
137
139
140
+ public static boolean compareBufferedImages (BufferedImage bufferedImage0 , BufferedImage bufferedImage1 ) {
141
+ int width = bufferedImage0 .getWidth ();
142
+ int height = bufferedImage0 .getHeight ();
143
+
144
+ if (width != bufferedImage1 .getWidth () || height != bufferedImage1 .getHeight ()) {
145
+ return false ;
146
+ }
147
+
148
+ for (int y = 0 ; y < height ; y ++) {
149
+ for (int x = 0 ; x < width ; x ++) {
150
+ Color bufCol0 = new Color (bufferedImage0 .getRGB (x , y ));
151
+ Color bufCol1 = new Color (bufferedImage1 .getRGB (x , y ));
152
+
153
+ int red1 = bufCol0 .getRed ();
154
+ int blue1 = bufCol0 .getBlue ();
155
+ int green1 = bufCol0 .getGreen ();
156
+
157
+ int red2 = bufCol1 .getRed ();
158
+ int blue2 = bufCol1 .getBlue ();
159
+ int green2 = bufCol1 .getGreen ();
160
+
161
+ if ((Math .abs (red1 - red2 ) > COLOR_TOLERANCE ) ||
162
+ (Math .abs (green1 - green2 ) > COLOR_TOLERANCE ) ||
163
+ (Math .abs (blue1 - blue2 ) > COLOR_TOLERANCE )) {
164
+ System .out .println ("x " + x + " y " + y +
165
+ " rgb1: " + bufCol0 +
166
+ " rgb2: " + bufCol1 );
167
+ return false ;
168
+ }
169
+ }
170
+ }
171
+
172
+ return true ;
173
+ }
174
+
138
175
private static BufferedImage getPnBottomImage () {
139
176
Rectangle rect = pnBottom .getBounds ();
140
177
0 commit comments