From 31114c69f39befd50d2b755b7d0dd1cda2c6d2ab Mon Sep 17 00:00:00 2001 From: "epoger@google.com" Date: Wed, 12 Dec 2012 17:22:23 +0000 Subject: Create SkBitmapChecksummer and associated SkBitmapTransformer As needed to start capturing gm image checksums. Review URL: https://codereview.appspot.com/6920050 git-svn-id: http://skia.googlecode.com/svn/trunk@6759 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/ChecksumTest.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/ChecksumTest.cpp') diff --git a/tests/ChecksumTest.cpp b/tests/ChecksumTest.cpp index e8a2f253b0..03194907f5 100644 --- a/tests/ChecksumTest.cpp +++ b/tests/ChecksumTest.cpp @@ -6,8 +6,12 @@ * found in the LICENSE file. */ #include "Test.h" + +#include "SkBitmap.h" +#include "SkBitmapChecksummer.h" #include "SkChecksum.h" #include "SkCityHash.h" +#include "SkColor.h" // Word size that is large enough to hold results of any checksum type. typedef uint64_t checksum_result; @@ -103,6 +107,15 @@ namespace skiatest { return result; } + // Fill in bitmap with test data. + void CreateTestBitmap(SkBitmap &bitmap, SkBitmap::Config config, int width, int height, + SkColor color) { + bitmap.setConfig(config, width, height); + REPORTER_ASSERT(fReporter, bitmap.allocPixels()); + bitmap.setIsOpaque(true); + bitmap.eraseColor(color); + } + void RunTest() { // Test self-consistency of checksum algorithms. fWhichAlgorithm = kSkChecksum; @@ -143,6 +156,25 @@ namespace skiatest { GetTestDataChecksum(128) == GetTestDataChecksum(256)); REPORTER_ASSERT(fReporter, GetTestDataChecksum(132) == GetTestDataChecksum(260)); + + // Test SkBitmapChecksummer + SkBitmap bitmap; + // initial test case + CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 333, 555, SK_ColorBLUE); + REPORTER_ASSERT(fReporter, + SkBitmapChecksummer::Compute64(bitmap) == 0x18f9df68b1b02f38ULL); + // same pixel data but different dimensions should yield a different checksum + CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorBLUE); + REPORTER_ASSERT(fReporter, + SkBitmapChecksummer::Compute64(bitmap) == 0x6b0298183f786c8eULL); + // same dimensions but different color should yield a different checksum + CreateTestBitmap(bitmap, SkBitmap::kARGB_8888_Config, 555, 333, SK_ColorGREEN); + REPORTER_ASSERT(fReporter, + SkBitmapChecksummer::Compute64(bitmap) == 0xc6b4b3f6fadaaf37ULL); + // same pixel colors in a different config should yield the same checksum + CreateTestBitmap(bitmap, SkBitmap::kARGB_4444_Config, 555, 333, SK_ColorGREEN); + REPORTER_ASSERT(fReporter, + SkBitmapChecksummer::Compute64(bitmap) == 0xc6b4b3f6fadaaf37ULL); } Reporter* fReporter; -- cgit v1.2.3