diff options
-rw-r--r-- | tools/sk_tool_utils.cpp | 25 | ||||
-rw-r--r-- | tools/sk_tool_utils.h | 9 |
2 files changed, 28 insertions, 6 deletions
diff --git a/tools/sk_tool_utils.cpp b/tools/sk_tool_utils.cpp index 5321513a17..a025209166 100644 --- a/tools/sk_tool_utils.cpp +++ b/tools/sk_tool_utils.cpp @@ -13,6 +13,7 @@ #include "SkCommonFlags.h" #include "SkFontMgr.h" #include "SkFontStyle.h" +#include "SkImage.h" #include "SkPixelRef.h" #include "SkPM4f.h" #include "SkPoint3.h" @@ -513,11 +514,12 @@ void copy_to_g8(SkBitmap* dst, const SkBitmap& src) { return SkMax32(dr, SkMax32(dg, SkMax32(db, da))); } - bool equal_pixels(const SkPixmap& a, const SkPixmap& b, unsigned maxDiff) { + bool equal_pixels(const SkPixmap& a, const SkPixmap& b, unsigned maxDiff, + bool respectColorSpace) { if (a.width() != b.width() || a.height() != b.height() || a.colorType() != b.colorType() || - a.colorSpace() != b.colorSpace()) + (respectColorSpace && (a.colorSpace() != b.colorSpace()))) { return false; } @@ -538,8 +540,23 @@ void copy_to_g8(SkBitmap* dst, const SkBitmap& src) { return true; } - bool equal_pixels(const SkBitmap& bm0, const SkBitmap& bm1, unsigned maxDiff) { + bool equal_pixels(const SkBitmap& bm0, const SkBitmap& bm1, unsigned maxDiff, + bool respectColorSpaces) { SkPixmap pm0, pm1; - return bm0.peekPixels(&pm0) && bm1.peekPixels(&pm1) && equal_pixels(pm0, pm1, maxDiff); + return bm0.peekPixels(&pm0) && bm1.peekPixels(&pm1) && + equal_pixels(pm0, pm1, maxDiff, respectColorSpaces); + } + + bool equal_pixels(const SkImage* a, const SkImage* b, unsigned maxDiff, + bool respectColorSpaces) { + // 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); } } // namespace sk_tool_utils diff --git a/tools/sk_tool_utils.h b/tools/sk_tool_utils.h index abf43323c5..db7aa3ee43 100644 --- a/tools/sk_tool_utils.h +++ b/tools/sk_tool_utils.h @@ -20,6 +20,7 @@ class SkBitmap; class SkCanvas; class SkColorFilter; +class SkImage; class SkPaint; class SkPath; class SkRRect; @@ -79,8 +80,12 @@ namespace sk_tool_utils { * * If the colorType is half-float, then maxDiff is interpreted as 0..255 --> 0..1 */ - bool equal_pixels(const SkPixmap&, const SkPixmap&, unsigned maxDiff = 0); - bool equal_pixels(const SkBitmap&, const SkBitmap&, unsigned maxDiff = 0); + bool equal_pixels(const SkPixmap&, const SkPixmap&, unsigned maxDiff = 0, + bool respectColorSpaces = false); + bool equal_pixels(const SkBitmap&, const SkBitmap&, unsigned maxDiff = 0, + bool respectColorSpaces = false); + bool equal_pixels(const SkImage* a, const SkImage* b, unsigned maxDiff, + bool respectColorSpaces = false); // private to sk_tool_utils sk_sp<SkTypeface> create_font(const char* name, SkFontStyle); |