Open mmalina opened 8 years ago
I have some comments from Dominik: It's possible that the image read is asynchronous. In that case you would need to call getWidth(ImageObserver observer) and if it returns -1, you need to wait for notification from the observer. Image is in general asynchronous. So there could be just one half of the image loaded. But the problem could be somewhere else also.
In dummy job, we have a test if the vnc screen is empty or not: https://github.com/jbosstools/jbosstools-integration-https://github.com/jbosstools/jbosstools-integration-tests/blob/master/tests/org.jboss.tools.dummy.ui.bot.test/src/org/jboss/tools/dummy/ui/bot/test/DummyTest.java#L39
ScreenshotCapturer sc = ScreenshotCapturer.getInstance(); try { screenshotTaken = true; String path = sc.captureScreenshot("dummyOK.png"); ImageTool it = ImageTool.getInstance(); boolean isScreenshotBlank = it.isImageBlank(path); if (isScreenshotBlank) log.error("Screenshot " + path + " is blank"); else log.info("Screenshot " + path + " has visible content"); assertTrue("Screenshot " + path + " should not be blank", !isScreenshotBlank ); } catch (CaptureScreenshotException e) { log.error("Cannot capture screenshot:" + e.getMessage(), e); }
This uses ImageTool's isImageBlank: https://github.com/jboss-reddeer/reddeer/blob/master/plugins/org.jboss.reddeer.junit/src/org/jboss/reddeer/junit/screenshot/ImageTool.java#L54
It works in most cases, but for some reason, on our new slave xerus64, this returns true even if the image is actually not blank: http://machydra.brq.redhat.com:8080/job/jbt.dummy.bot.tests/jdk=sunjdk1.7,label=matrix-u16.04-64-xerus64/314/artifact/tests/org.jboss.tools.dummy.ui.bot.test/target/custom-screenshots/dummyOK.png
The isImageBlank method checks the first pixel and then goes pixel by pixel until there is a pixel of different color. When this happens, false is returned. Otherwise true is returned.
The color is saved as an integer: https://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html#getRGB(int,%20int) Returns an integer pixel in the default RGB color model (TYPE_INT_ARGB) and default sRGB colorspace. Color conversion takes place if this default model does not match the image ColorModel. There are only 8-bits of precision for each color component in the returned data when using this method.
I'm not sure I fully understand this. Perhaps there could be a problem that the color is somehow converted and all pixels are treated as the same color?