RFR: 8326027: Comparing buffered images of white background frame fails in Mac
Alexey Ivanov
aivanov at openjdk.org
Thu Aug 29 13:00:20 UTC 2024
On Thu, 29 Aug 2024 04:38:29 GMT, Tejesh R <tr at openjdk.org> wrote:
> On analysis of captured image, it is observed that there are few pixels which vary slightly w.r.t to expected color. Hence tolerance is included in color comparison.
> Tested in mach5 multiple time and its green.
I wonder whether the tolerance wouldn't be required if `Robot.createMultiResolutionScreenCapture` was used to create the screenshot and then analysing the original image which didn't go through down-scaling in High DPI environment.
test/jdk/javax/swing/JFrame/JFrameBackgroundRefreshTest.java line 140:
> 138:
> 139: private static boolean compareImages(BufferedImage bufferedImage) {
> 140: Color firstPixel = new Color(bufferedImage.getRGB(0,0));
Suggestion:
final Color firstPixel = new Color(bufferedImage.getRGB(0, 0));
test/jdk/javax/swing/JFrame/JFrameBackgroundRefreshTest.java line 151:
> 149: }
> 150:
> 151: private static boolean compareColor(Color c1, Color c2) {
Shall we move such a method into `Util`?
More and more test cases add tolerance to color comparison. Yeah, it's simple enough… and adding a library makes it somewhat harder to run a test in stand-alone mode, without jtreg.
test/jdk/javax/swing/JFrame/JFrameBackgroundRefreshTest.java line 155:
> 153: Math.abs(c1.getGreen() - c2.getGreen()) < TOLERANCE &&
> 154: Math.abs(c1.getBlue() - c2.getBlue()) < TOLERANCE;
> 155: }
Suggestion:
private static boolean compareColor(Color c1, Color c2) {
return Math.abs(c1.getRed() - c2.getRed()) < TOLERANCE
&& Math.abs(c1.getGreen() - c2.getGreen()) < TOLERANCE
&& Math.abs(c1.getBlue() - c2.getBlue()) < TOLERANCE;
}
Java Coding Style recommends putting operators on the continuation line, it makes it obvious to the reader it is a continuation of an expression.
-------------
PR Review: https://git.openjdk.org/jdk/pull/20760#pullrequestreview-2268640859
PR Review Comment: https://git.openjdk.org/jdk/pull/20760#discussion_r1736144750
PR Review Comment: https://git.openjdk.org/jdk/pull/20760#discussion_r1736154776
PR Review Comment: https://git.openjdk.org/jdk/pull/20760#discussion_r1736145854
More information about the client-libs-dev
mailing list