2013-04-12 02:23:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SkBitmapHasher.h"
|
2014-01-06 12:43:53 +00:00
|
|
|
|
|
|
|
#include "SkBitmap.h"
|
2013-04-12 02:23:55 +00:00
|
|
|
#include "SkColor.h"
|
2014-01-06 12:43:53 +00:00
|
|
|
#include "Test.h"
|
2013-04-12 02:23:55 +00:00
|
|
|
|
|
|
|
// Word size that is large enough to hold results of any checksum type.
|
|
|
|
typedef uint64_t checksum_result;
|
|
|
|
|
2014-01-06 12:43:53 +00:00
|
|
|
// Fill in bitmap with test data.
|
2014-03-05 13:43:15 +00:00
|
|
|
static void CreateTestBitmap(SkBitmap* bitmap, int width, int height,
|
2014-01-06 12:43:53 +00:00
|
|
|
SkColor color, skiatest::Reporter* reporter) {
|
2014-03-05 13:43:15 +00:00
|
|
|
SkImageInfo info = SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType);
|
|
|
|
REPORTER_ASSERT(reporter, bitmap->allocPixels(info));
|
|
|
|
bitmap->eraseColor(color);
|
2014-01-06 12:43:53 +00:00
|
|
|
}
|
2013-04-12 02:23:55 +00:00
|
|
|
|
2014-01-06 12:43:53 +00:00
|
|
|
DEF_TEST(BitmapHasher, reporter) {
|
|
|
|
// Test SkBitmapHasher
|
|
|
|
SkBitmap bitmap;
|
|
|
|
uint64_t digest;
|
|
|
|
// initial test case
|
2014-03-05 13:43:15 +00:00
|
|
|
CreateTestBitmap(&bitmap, 333, 555, SK_ColorBLUE, reporter);
|
2014-01-06 12:43:53 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
|
|
|
|
REPORTER_ASSERT(reporter, digest == 0xfb2903562766ef87ULL);
|
|
|
|
// same pixel data but different dimensions should yield a different checksum
|
2014-03-05 13:43:15 +00:00
|
|
|
CreateTestBitmap(&bitmap, 555, 333, SK_ColorBLUE, reporter);
|
2014-01-06 12:43:53 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
|
|
|
|
REPORTER_ASSERT(reporter, digest == 0xfe04023fb97d0f61ULL);
|
|
|
|
// same dimensions but different color should yield a different checksum
|
2014-03-05 13:43:15 +00:00
|
|
|
CreateTestBitmap(&bitmap, 555, 333, SK_ColorGREEN, reporter);
|
2014-01-06 12:43:53 +00:00
|
|
|
REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
|
|
|
|
REPORTER_ASSERT(reporter, digest == 0x2423c51cad6d1edcULL);
|
2013-04-12 02:23:55 +00:00
|
|
|
}
|