aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils
diff options
context:
space:
mode:
authorGravatar epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-12 02:23:55 +0000
committerGravatar epoger@google.com <epoger@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-04-12 02:23:55 +0000
commit908f5836626d792c5e33ad93f44c6a418a0cc8f5 (patch)
tree2387bc49caeabbd315b34d9973327a5fa310335e /src/utils
parentbcbf5aa77ddce07c95efc51c567ce737da7f267d (diff)
rename SkBitmapChecksummer as SkBitmapHasher, and prepare for it to possibly use
some algorithm other than CityHash Review URL: https://codereview.chromium.org/14170010 git-svn-id: http://skia.googlecode.com/svn/trunk@8639 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/SkBitmapChecksummer.h37
-rw-r--r--src/utils/SkBitmapHasher.cpp (renamed from src/utils/SkBitmapChecksummer.cpp)19
-rw-r--r--src/utils/SkBitmapHasher.h42
3 files changed, 52 insertions, 46 deletions
diff --git a/src/utils/SkBitmapChecksummer.h b/src/utils/SkBitmapChecksummer.h
deleted file mode 100644
index 63ac726c2e..0000000000
--- a/src/utils/SkBitmapChecksummer.h
+++ /dev/null
@@ -1,37 +0,0 @@
-
-/*
- * Copyright 2012 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkBitmapChecksummer_DEFINED
-#define SkBitmapChecksummer_DEFINED
-
-#include "SkBitmap.h"
-#include "SkBitmapTransformer.h"
-
-/**
- * Static class that can generate checksums from SkBitmaps.
- */
-class SkBitmapChecksummer {
-public:
- /**
- * Returns a 64-bit checksum of the pixels in this bitmap.
- *
- * If this is unable to compute the checksum for some reason,
- * it returns 0.
- *
- * Note: depending on the bitmap config, we may need to create an
- * intermediate SkBitmap and copy the pixels over to it... so in some
- * cases, performance and memory usage can suffer.
- */
- static uint64_t Compute64(const SkBitmap& bitmap);
-
-private:
- static uint64_t Compute64Internal(const SkBitmap& bitmap,
- const SkBitmapTransformer& transformer);
-};
-
-#endif
diff --git a/src/utils/SkBitmapChecksummer.cpp b/src/utils/SkBitmapHasher.cpp
index 883210c360..6df3ab9f27 100644
--- a/src/utils/SkBitmapChecksummer.cpp
+++ b/src/utils/SkBitmapHasher.cpp
@@ -7,7 +7,7 @@
*/
#include "SkBitmap.h"
-#include "SkBitmapChecksummer.h"
+#include "SkBitmapHasher.h"
#include "SkBitmapTransformer.h"
#include "SkCityHash.h"
#include "SkEndian.h"
@@ -23,8 +23,8 @@ static void write_int_to_buffer(int val, char* buf) {
}
}
-/*static*/ uint64_t SkBitmapChecksummer::Compute64Internal(
- const SkBitmap& bitmap, const SkBitmapTransformer& transformer) {
+/*static*/ bool SkBitmapHasher::ComputeDigestInternal(
+ const SkBitmap& bitmap, const SkBitmapTransformer& transformer, SkHashDigest *result) {
size_t pixelBufferSize = transformer.bytesNeededTotal();
size_t totalBufferSize = pixelBufferSize + 8; // leave room for x/y dimensions
@@ -39,12 +39,13 @@ static void write_int_to_buffer(int val, char* buf) {
// add all the pixel data
if (!transformer.copyBitmapToPixelBuffer(bufPtr, pixelBufferSize)) {
- return 0;
+ return false;
}
- return SkCityHash::Compute64(bufferStart, totalBufferSize);
+ *result = SkCityHash::Compute64(bufferStart, totalBufferSize);
+ return true;
}
-/*static*/ uint64_t SkBitmapChecksummer::Compute64(const SkBitmap& bitmap) {
+/*static*/ bool SkBitmapHasher::ComputeDigest(const SkBitmap& bitmap, SkHashDigest *result) {
const SkBitmapTransformer::PixelFormat kPixelFormat =
SkBitmapTransformer::kARGB_8888_Premul_PixelFormat;
@@ -52,7 +53,7 @@ static void write_int_to_buffer(int val, char* buf) {
const SkBitmapTransformer transformer =
SkBitmapTransformer(bitmap, kPixelFormat);
if (transformer.isValid(false)) {
- return Compute64Internal(bitmap, transformer);
+ return ComputeDigestInternal(bitmap, transformer, result);
}
// Hmm, that didn't work. Maybe if we create a new
@@ -62,8 +63,8 @@ static void write_int_to_buffer(int val, char* buf) {
const SkBitmapTransformer copyTransformer =
SkBitmapTransformer(copyBitmap, kPixelFormat);
if (copyTransformer.isValid(true)) {
- return Compute64Internal(copyBitmap, copyTransformer);
+ return ComputeDigestInternal(copyBitmap, copyTransformer, result);
} else {
- return 0;
+ return false;
}
}
diff --git a/src/utils/SkBitmapHasher.h b/src/utils/SkBitmapHasher.h
new file mode 100644
index 0000000000..dc8685bddb
--- /dev/null
+++ b/src/utils/SkBitmapHasher.h
@@ -0,0 +1,42 @@
+
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkBitmapHasher_DEFINED
+#define SkBitmapHasher_DEFINED
+
+#include "SkBitmap.h"
+#include "SkBitmapTransformer.h"
+
+// TODO(epoger): Soon, SkHashDigest will become a real class of its own,
+// and callers won't be able to assume it converts to/from a uint64_t.
+typedef uint64_t SkHashDigest;
+
+/**
+ * Static class that can generate an SkHashDigest from an SkBitmap.
+ */
+class SkBitmapHasher {
+public:
+ /**
+ * Fills in "result" with a hash of the pixels in this bitmap.
+ *
+ * If this is unable to compute the hash for some reason,
+ * it returns false.
+ *
+ * Note: depending on the bitmap config, we may need to create an
+ * intermediate SkBitmap and copy the pixels over to it... so in some
+ * cases, performance and memory usage can suffer.
+ */
+ static bool ComputeDigest(const SkBitmap& bitmap, SkHashDigest *result);
+
+private:
+ static bool ComputeDigestInternal(const SkBitmap& bitmap,
+ const SkBitmapTransformer& transformer,
+ SkHashDigest *result);
+};
+
+#endif