Chromium Code Reviews| 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,29 @@ |
| 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; |
|
epoger
2013/04/18 17:45:48
Here's what I like so much about the SkHashDigest
|
| + hasher.update(reinterpret_cast<const uint8_t*>(bufferStart), totalBufferSize); |
| + hasher.finish(*result); |
| +#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; |