Index: src/utils/SkBitmapHasher.cpp |
=================================================================== |
--- src/utils/SkBitmapHasher.cpp (revision 8685) |
+++ src/utils/SkBitmapHasher.cpp (working copy) |
@@ -13,18 +13,29 @@ |
#include "SkEndian.h" |
/** |
- * Write an integer value into a bytebuffer in little-endian order. |
+ * Write an int32_t value into a bytebuffer in little-endian order. |
*/ |
-static void write_int_to_buffer(int val, char* buf) { |
- val = SkEndian_SwapLE32(val); |
+static void write_int32_to_buffer(int32_t val, char* buf) { |
for (int byte=0; byte<4; byte++) { |
*buf++ = (char)(val & 0xff); |
val = val >> 8; |
} |
} |
+#ifdef BITMAP_HASH_TYPE_SkHashDigest |
+/** |
+ * Write an int64_t value into a bytebuffer in little-endian order. |
+ */ |
+static void write_int64_to_buffer(int64_t val, char* buf) { |
+ for (int byte=0; byte<8; byte++) { |
+ *buf++ = (char)(val & 0xff); |
+ val = val >> 8; |
+ } |
+} |
+#endif |
+ |
/*static*/ bool SkBitmapHasher::ComputeDigestInternal( |
- const SkBitmap& bitmap, const SkBitmapTransformer& transformer, SkHashDigest *result) { |
+ const SkBitmap& bitmap, const SkBitmapTransformer& transformer, BITMAP_HASH_TYPE *result) { |
size_t pixelBufferSize = transformer.bytesNeededTotal(); |
size_t totalBufferSize = pixelBufferSize + 8; // leave room for x/y dimensions |
@@ -32,20 +43,27 @@ |
char *bufferStart = static_cast<char *>(bufferManager.get()); |
char *bufPtr = bufferStart; |
// start with the x/y dimensions |
- write_int_to_buffer(bitmap.width(), bufPtr); |
+ write_int32_to_buffer(bitmap.width(), bufPtr); |
bufPtr += 4; |
- write_int_to_buffer(bitmap.height(), bufPtr); |
+ write_int32_to_buffer(bitmap.height(), bufPtr); |
bufPtr += 4; |
// add all the pixel data |
if (!transformer.copyBitmapToPixelBuffer(bufPtr, pixelBufferSize)) { |
return false; |
} |
+#ifdef BITMAP_HASH_TYPE_SkHashDigest |
+ uint64_t cityhash = SkCityHash::Compute64(bufferStart, totalBufferSize); |
+ char tempResult[8]; |
+ write_int64_to_buffer(cityhash, tempResult); |
+ result->copyFrom(tempResult, 8); |
+#else |
*result = SkCityHash::Compute64(bufferStart, totalBufferSize); |
+#endif |
return true; |
} |
-/*static*/ bool SkBitmapHasher::ComputeDigest(const SkBitmap& bitmap, SkHashDigest *result) { |
+/*static*/ bool SkBitmapHasher::ComputeDigest(const SkBitmap& bitmap, BITMAP_HASH_TYPE *result) { |
const SkBitmapTransformer::PixelFormat kPixelFormat = |
SkBitmapTransformer::kARGB_8888_Premul_PixelFormat; |