Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1336)

Unified Diff: src/utils/SkBitmapHasher.cpp

Issue 14265010: Make SkSHA1 and SkM5 use common SkDigestHash result type (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: revert_all_md5_and_sha1_changes Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/utils/SkBitmapHasher.h ('k') | src/utils/SkHashDigest.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « src/utils/SkBitmapHasher.h ('k') | src/utils/SkHashDigest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698