!752 lib 1003153 // magic.jar import prophecy.common.image.ImageSurface; import prophecy.common.image.RGBImage; import prophecy.common.image.BWImage; static new HashMap images; sclass FoundImg { Rectangle r; S imageID; *() {} *(Rectangle *r, S *imageID) {} } static new L found; p { BWImage big = shootScreenBW(); S patID = "#1004153"; // Search Button BWImage pat = loadBWImage(patID); int wp = pat.getWidth(), hp = pat.getHeight(); int w = big.getWidth(), h = big.getHeight(); for (int y = 0; y < h-hp; y++) for (int x = 0; x < w-wp; x++) if (imagesSimilar(big, pat, x, y)) { print("Found at " + x + "/" + y); found.add(new FoundImg(new Rectangle(x, y, wp, hp), patID)); x += wp-1; } } static bool imagesSimilar(BWImage big, BWImage pat, int x, int y) { int wp = pat.getWidth(), hp = pat.getHeight(); int w = big.getWidth(), h = big.getHeight(); for (int yy = 0; yy < hp; yy++) for (int xx = 0; xx < wp; xx++) if (big.getPixel(x+xx, y+yy) != pat.getPixel(xx, yy)) false; true; } static float imageSimilarity(BWImage big, BWImage pat, int x, int y, float max) { int wp = pat.getWidth(), hp = pat.getHeight(); int w = big.getWidth(), h = big.getHeight(); float diff = 0; for (int yy = 0; yy < hp; yy++) for (int xx = 0; xx < wp; xx++) { diff += abs(big.getPixel(x+xx, y+yy)-pat.getPixel(xx, yy)); if (diff >= max) ret diff; } ret diff; }