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

Side by Side Diff: src/utils/SkBitmapHasher.cpp

Issue 1704783002: Delete dead code. SkBitmapHasher has not been used since gm. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/utils/SkBitmapHasher.h ('k') | tests/BitmapHasherTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkBitmap.h"
9 #include "SkBitmapHasher.h"
10 #include "SkEndian.h"
11 #include "SkImageEncoder.h"
12
13 #include "SkMD5.h"
14
15 /**
16 * Write an int32 value to a stream in little-endian order.
17 */
18 static void write_int32_to_buffer(uint32_t val, SkWStream* out) {
19 val = SkEndian_SwapLE32(val);
20 for (size_t byte = 0; byte < 4; ++byte) {
21 out->write8((uint8_t)(val & 0xff));
22 val = val >> 8;
23 }
24 }
25
26 /**
27 * Return the first 8 bytes of a bytearray, encoded as a little-endian uint64.
28 */
29 static inline uint64_t first_8_bytes_as_uint64(const uint8_t *bytearray) {
30 return SkEndian_SwapLE64(*(reinterpret_cast<const uint64_t *>(bytearray)));
31 }
32
33 /*static*/ bool SkBitmapHasher::ComputeDigestInternal(const SkBitmap& bitmap, ui nt64_t *result) {
34 SkMD5 out;
35
36 // start with the x/y dimensions
37 write_int32_to_buffer(SkToU32(bitmap.width()), &out);
38 write_int32_to_buffer(SkToU32(bitmap.height()), &out);
39
40 // add all the pixel data
41 SkAutoTDelete<SkImageEncoder> enc(CreateARGBImageEncoder());
42 if (!enc->encodeStream(&out, bitmap, SkImageEncoder::kDefaultQuality)) {
43 return false;
44 }
45
46 SkMD5::Digest digest;
47 out.finish(digest);
48 *result = first_8_bytes_as_uint64(digest.data);
49 return true;
50 }
51
52 /*static*/ bool SkBitmapHasher::ComputeDigest(const SkBitmap& bitmap, uint64_t * result) {
53 if (ComputeDigestInternal(bitmap, result)) {
54 return true;
55 }
56
57 // Hmm, that didn't work. Maybe if we create a new
58 // version of the bitmap it will work better?
59 SkBitmap copyBitmap;
60 if (!bitmap.copyTo(&copyBitmap, kN32_SkColorType)) {
61 return false;
62 }
63 return ComputeDigestInternal(copyBitmap, result);
64 }
OLDNEW
« no previous file with comments | « src/utils/SkBitmapHasher.h ('k') | tests/BitmapHasherTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698