Fix/simplify equal_pixels

Luckily without maxDiff, we can completely remove the buggy
implementation of diff().

Bug: skia:
Change-Id: I365fb6e595e3b670950a016bcb8ee553d85a8b75
Reviewed-on: https://skia-review.googlesource.com/155844
Commit-Queue: Brian Osman <brianosman@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
Auto-Submit: Brian Osman <brianosman@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp
index 9bff574..a0b57e5 100644
--- a/tools/sk_tool_utils.cpp
+++ b/tools/sk_tool_utils.cpp
@@ -13,7 +13,6 @@
 #include "SkFloatingPoint.h"
 #include "SkImage.h"
 #include "SkMatrix.h"
-#include "SkPM4f.h"
 #include "SkPaint.h"
 #include "SkPath.h"
 #include "SkPixelRef.h"
@@ -524,68 +523,10 @@
 
     //////////////////////////////////////////////////////////////////////////////////////////////
 
-    static int scale255(float x) {
-        return sk_float_round2int(x * 255);
-    }
-
-    static unsigned diff(const SkColorType ct, const void* a, const void* b) {
-        int dr = 0,
-            dg = 0,
-            db = 0,
-            da = 0;
-        switch (ct) {
-            case kRGBA_8888_SkColorType:
-            case kBGRA_8888_SkColorType: {
-                SkPMColor c0 = *(const SkPMColor*)a;
-                SkPMColor c1 = *(const SkPMColor*)b;
-                dr = SkGetPackedR32(c0) - SkGetPackedR32(c1);
-                dg = SkGetPackedG32(c0) - SkGetPackedG32(c1);
-                db = SkGetPackedB32(c0) - SkGetPackedB32(c1);
-                da = SkGetPackedA32(c0) - SkGetPackedA32(c1);
-            } break;
-            case kRGB_565_SkColorType: {
-                uint16_t c0 = *(const uint16_t*)a;
-                uint16_t c1 = *(const uint16_t*)b;
-                dr = SkGetPackedR16(c0) - SkGetPackedR16(c1);
-                dg = SkGetPackedG16(c0) - SkGetPackedG16(c1);
-                db = SkGetPackedB16(c0) - SkGetPackedB16(c1);
-            } break;
-            case kARGB_4444_SkColorType: {
-                uint16_t c0 = *(const uint16_t*)a;
-                uint16_t c1 = *(const uint16_t*)b;
-                dr = SkGetPackedR4444(c0) - SkGetPackedR4444(c1);
-                dg = SkGetPackedG4444(c0) - SkGetPackedG4444(c1);
-                db = SkGetPackedB4444(c0) - SkGetPackedB4444(c1);
-                da = SkGetPackedA4444(c0) - SkGetPackedA4444(c1);
-            } break;
-            case kAlpha_8_SkColorType:
-            case kGray_8_SkColorType:
-                da = (const uint8_t*)a - (const uint8_t*)b;
-                break;
-            case kRGBA_F16_SkColorType: {
-                const SkPM4f* c0 = (const SkPM4f*)a;
-                const SkPM4f* c1 = (const SkPM4f*)b;
-                dr = scale255(c0->r() - c1->r());
-                dg = scale255(c0->g() - c1->g());
-                db = scale255(c0->b() - c1->b());
-                da = scale255(c0->a() - c1->a());
-            } break;
-            default:
-                return 0;
-        }
-        dr = SkAbs32(dr);
-        dg = SkAbs32(dg);
-        db = SkAbs32(db);
-        da = SkAbs32(da);
-        return SkMax32(dr, SkMax32(dg, SkMax32(db, da)));
-    }
-
-    bool equal_pixels(const SkPixmap& a, const SkPixmap& b, unsigned maxDiff,
-                      bool respectColorSpace) {
+    bool equal_pixels(const SkPixmap& a, const SkPixmap& b) {
         if (a.width() != b.width() ||
             a.height() != b.height() ||
-            a.colorType() != b.colorType() ||
-            (respectColorSpace && (a.colorSpace() != b.colorSpace())))
+            a.colorType() != b.colorType())
         {
             return false;
         }
@@ -594,11 +535,7 @@
             const char* aptr = (const char*)a.addr(0, y);
             const char* bptr = (const char*)b.addr(0, y);
             if (memcmp(aptr, bptr, a.width() * a.info().bytesPerPixel())) {
-                for (int x = 0; x < a.width(); ++x) {
-                    if (diff(a.colorType(), a.addr(x, y), b.addr(x, y)) > maxDiff) {
-                        return false;
-                    }
-                }
+                return false;
             }
             aptr += a.rowBytes();
             bptr += b.rowBytes();
@@ -606,24 +543,18 @@
         return true;
     }
 
-    bool equal_pixels(const SkBitmap& bm0, const SkBitmap& bm1, unsigned maxDiff,
-                      bool respectColorSpaces) {
+    bool equal_pixels(const SkBitmap& bm0, const SkBitmap& bm1) {
         SkPixmap pm0, pm1;
-        return bm0.peekPixels(&pm0) && bm1.peekPixels(&pm1) &&
-               equal_pixels(pm0, pm1, maxDiff, respectColorSpaces);
+        return bm0.peekPixels(&pm0) && bm1.peekPixels(&pm1) && equal_pixels(pm0, pm1);
     }
 
-    bool equal_pixels(const SkImage* a, const SkImage* b, unsigned maxDiff,
-                      bool respectColorSpaces) {
+    bool equal_pixels(const SkImage* a, const SkImage* b) {
         // ensure that peekPixels will succeed
         auto imga = a->makeRasterImage();
         auto imgb = b->makeRasterImage();
-        a = imga.get();
-        b = imgb.get();
 
         SkPixmap pm0, pm1;
-        return a->peekPixels(&pm0) && b->peekPixels(&pm1) &&
-               equal_pixels(pm0, pm1, maxDiff, respectColorSpaces);
+        return imga->peekPixels(&pm0) && imgb->peekPixels(&pm1) && equal_pixels(pm0, pm1);
     }
 
     sk_sp<SkSurface> makeSurface(SkCanvas* canvas, const SkImageInfo& info,