Index: src/utils/SkBitmapHasher.cpp |
=================================================================== |
--- src/utils/SkBitmapHasher.cpp (revision 8685) |
+++ src/utils/SkBitmapHasher.cpp (working copy) |
@@ -11,12 +11,12 @@ |
#include "SkBitmapTransformer.h" |
#include "SkCityHash.h" |
#include "SkEndian.h" |
+#include "SkMD5.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; |
@@ -24,7 +24,7 @@ |
} |
/*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 +32,32 @@ |
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 |
+ // EPOGER: if we are using our MD5 or SHA1 implementations, we can add this |
+ // data to the hash algorithm in-place (without the big memcpy). |
+ // Add that optimization! |
if (!transformer.copyBitmapToPixelBuffer(bufPtr, pixelBufferSize)) { |
return false; |
} |
+#ifdef BITMAP_HASH_TYPE_SkHashDigest |
+ SkMD5 hasher; |
+ hasher.update(reinterpret_cast<const uint8_t*>(bufferStart), totalBufferSize); |
+ SkMD5::Digest digest; |
epoger
2013/04/19 17:20:53
In patchset 11, I have reverted all changes to SkM
|
+ hasher.finish(digest); |
+ // EPOGER: instead of creating the extra copy on the stack and running copyFrom, use malloc and then just make the SkHashDigest hold a reference to it? |
+ result->copyFrom(&digest, sizeof(digest)); |
+#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; |