import java.awt.image.BufferedImage;
import com.android.chimpchat.adb.AdbBackend;
import com.android.chimpchat.core.IChimpDevice;
import com.android.chimpchat.core.IChimpImage;
import com.android.chimpchat.adb.AdbChimpDevice;
import com.android.chimpchat.core.ChimpImageBase;
public class MonkeyTest {
public static void main(String[] args) {
IChimpDevice device = null;
try
{
// sdk/platform-tools has to be in PATH env variable in order to find adb
device = new AdbBackend().waitForConnection();
}
catch(java.lang.NullPointerException e)
{
System.out.println("Error");
System.exit(-1);
}
// Print Device Name
System.out.println(device.getProperty("build.model"));
// Take a snapshot and save to out.png
//device.takeSnapshot().writeToFile("out.png", "png");
IChimpImage deviceImage = device.takeSnapshot();
deviceImage.writeToFile("out_1.png", "png");
IChimpImage fileImage = ChimpImageBase.loadImageFromFile("out.png");
fileImage.writeToFile("out_2.png", "png");
sameAs(fileImage,deviceImage,0.9);
if(fileImage.sameAs(deviceImage, 0.75))
{
System.out.println("Sames");
}
else
{
System.out.println("Not");
}
device.dispose();
System.exit(0);
}
public static boolean sameAs(IChimpImage other, IChimpImage sames, double percent){
BufferedImage otherImage = other.getBufferedImage();
BufferedImage samesImage = sames.getBufferedImage();
//Easy size check
if(otherImage.getWidth()!= samesImage.getWidth()){
return false;
}
if(otherImage.getHeight()!=samesImage.getHeight()){
return false;
}
int[] otherPixel = new int[1];
int[] samesPixel = new int[1];
int width = samesImage.getWidth();
int height = samesImage.getHeight();
int numDiffPixels = 0;
// Now, go through pixel-by-pixel and check that the images are the same;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (samesImage.getRGB(x, y) != otherImage.getRGB(x, y)) {
System.out.println(samesImage.getRGB(x, y)+":"+otherImage.getRGB(x, y));
numDiffPixels++;
}
}
}
double numberPixels = (height * width);
double diffPercent = numDiffPixels / numberPixels;
return percent <= 1.0 - diffPercent;
}
}