!7 p { RGBImage a = loadRGBImage(#1006818), b = loadRGBImage(#1006819); compare(a, b); } svoid compare(RGBImage a, RGBImage b) { //new HashSet deltas; new Best best; repeat { Rect r = randomScreenRect(50, 50); RGBImage clip = a.clip(r); if (rgbInnerPrecision(clip) >= 0.5f) { Rect r2 = rgbSearchPrecise(b, clip); if (r2 != null && neq(r, r2)) { Pt delta = new Pt(r2.x-r.x, r2.y-r.y); Rect match = expandMatch(a, b, r, r2); if (best.put(match, match.w*match.h)) { print("New best. Movement: " + delta + ". Match size: " + match.w + "/" + match.h); packFrameInTopRightCorner(quickShowImage(rgbScale(a.clip(match), 1))); } } } } } static Rect expandMatch(RGBImage a, RGBImage b, Rect r1, Rect r2) { assertEquals(r1.w, r2.w); assertEquals(r1.h, r2.h); int w = a.w(), h = a.h(); print("Comparing " + r1 + " and " + r2); repeat { Rect r = r1; // left if (r2.x > 0 && r1.x > 0 && rgbImageSectionsIdentical(a, new Rect(r1.x-1, r1.y, 1, r1.h), b, new Rect(r2.x-1, r2.y, 1, r2.h))) { r1 = growRectLeft(r1, 1); r2 = growRectLeft(r2, 1); } // right if (r2.x2() < w && r2.x2() < w && rgbImageSectionsIdentical(a, new Rect(r1.x2(), r1.y, 1, r1.h), b, new Rect(r2.x2(), r2.y, 1, r2.h))) { r1 = growRectRight(r1, 1); r2 = growRectRight(r2, 1); } // top if (r2.y > 0 && r1.y > 0 && rgbImageSectionsIdentical(a, new Rect(r1.x, r1.y-1, r1.w, 1), b, new Rect(r2.x, r2.y-1, r2.w, 1))) { r1 = growRectTop(r1, 1); r2 = growRectTop(r2, 1); } // bottom if (r2.y2() < h && r2.y2() < h && rgbImageSectionsIdentical(a, new Rect(r1.x, r1.y2(), r1.w, 1), b, new Rect(r2.x, r2.y2(), r2.w, 1))) { r1 = growRectBottom(r1, 1); r2 = growRectBottom(r2, 1); } if (eq(r, r1)) break; ret r1; }