Delete dead code. SkBitmapHasher has not been used since gm.
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1704783002 Review URL: https://codereview.chromium.org/1704783002
This commit is contained in:
parent
2a42f48b58
commit
f60a8908d2
@ -11,7 +11,6 @@
|
||||
|
||||
#include "gm.h"
|
||||
#include "SkBitmap.h"
|
||||
#include "SkBitmapHasher.h"
|
||||
#include "SkData.h"
|
||||
#include "SkJSONCPP.h"
|
||||
#include "SkOSFile.h"
|
||||
|
@ -35,8 +35,6 @@
|
||||
|
||||
'<(skia_src_path)/utils/SkBase64.cpp',
|
||||
'<(skia_src_path)/utils/SkBase64.h',
|
||||
'<(skia_src_path)/utils/SkBitmapHasher.cpp',
|
||||
'<(skia_src_path)/utils/SkBitmapHasher.h',
|
||||
'<(skia_src_path)/utils/SkBitmapSourceDeserializer.cpp',
|
||||
'<(skia_src_path)/utils/SkBitmapSourceDeserializer.h',
|
||||
'<(skia_src_path)/utils/SkBitSet.cpp',
|
||||
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkBitmapHasher.h"
|
||||
#include "SkEndian.h"
|
||||
#include "SkImageEncoder.h"
|
||||
|
||||
#include "SkMD5.h"
|
||||
|
||||
/**
|
||||
* Write an int32 value to a stream in little-endian order.
|
||||
*/
|
||||
static void write_int32_to_buffer(uint32_t val, SkWStream* out) {
|
||||
val = SkEndian_SwapLE32(val);
|
||||
for (size_t byte = 0; byte < 4; ++byte) {
|
||||
out->write8((uint8_t)(val & 0xff));
|
||||
val = val >> 8;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first 8 bytes of a bytearray, encoded as a little-endian uint64.
|
||||
*/
|
||||
static inline uint64_t first_8_bytes_as_uint64(const uint8_t *bytearray) {
|
||||
return SkEndian_SwapLE64(*(reinterpret_cast<const uint64_t *>(bytearray)));
|
||||
}
|
||||
|
||||
/*static*/ bool SkBitmapHasher::ComputeDigestInternal(const SkBitmap& bitmap, uint64_t *result) {
|
||||
SkMD5 out;
|
||||
|
||||
// start with the x/y dimensions
|
||||
write_int32_to_buffer(SkToU32(bitmap.width()), &out);
|
||||
write_int32_to_buffer(SkToU32(bitmap.height()), &out);
|
||||
|
||||
// add all the pixel data
|
||||
SkAutoTDelete<SkImageEncoder> enc(CreateARGBImageEncoder());
|
||||
if (!enc->encodeStream(&out, bitmap, SkImageEncoder::kDefaultQuality)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SkMD5::Digest digest;
|
||||
out.finish(digest);
|
||||
*result = first_8_bytes_as_uint64(digest.data);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*static*/ bool SkBitmapHasher::ComputeDigest(const SkBitmap& bitmap, uint64_t *result) {
|
||||
if (ComputeDigestInternal(bitmap, result)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Hmm, that didn't work. Maybe if we create a new
|
||||
// version of the bitmap it will work better?
|
||||
SkBitmap copyBitmap;
|
||||
if (!bitmap.copyTo(©Bitmap, kN32_SkColorType)) {
|
||||
return false;
|
||||
}
|
||||
return ComputeDigestInternal(copyBitmap, result);
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
|
||||
/*
|
||||
* Copyright 2012 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkBitmapHasher_DEFINED
|
||||
#define SkBitmapHasher_DEFINED
|
||||
|
||||
#include "SkBitmap.h"
|
||||
|
||||
/**
|
||||
* Static class that generates a uint64 hash digest from an SkBitmap.
|
||||
*/
|
||||
class SkBitmapHasher {
|
||||
public:
|
||||
/**
|
||||
* Fills in "result" with a hash of the pixels in this bitmap.
|
||||
*
|
||||
* If this is unable to compute the hash for some reason,
|
||||
* it returns false.
|
||||
*
|
||||
* Note: depending on the bitmap colortype, we may need to create an
|
||||
* intermediate SkBitmap and copy the pixels over to it... so in some
|
||||
* cases, performance and memory usage can suffer.
|
||||
*/
|
||||
static bool ComputeDigest(const SkBitmap& bitmap, uint64_t *result);
|
||||
|
||||
private:
|
||||
static bool ComputeDigestInternal(const SkBitmap& bitmap, uint64_t *result);
|
||||
};
|
||||
|
||||
#endif
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkBitmapHasher.h"
|
||||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkColor.h"
|
||||
#include "Test.h"
|
||||
|
||||
// Word size that is large enough to hold results of any checksum type.
|
||||
typedef uint64_t checksum_result;
|
||||
|
||||
// Fill in bitmap with test data.
|
||||
static void CreateTestBitmap(SkBitmap* bitmap, int width, int height,
|
||||
SkColor color, skiatest::Reporter* reporter) {
|
||||
bitmap->allocN32Pixels(width, height, kOpaque_SkAlphaType);
|
||||
bitmap->eraseColor(color);
|
||||
}
|
||||
|
||||
DEF_TEST(BitmapHasher, reporter) {
|
||||
// Test SkBitmapHasher
|
||||
SkBitmap bitmap;
|
||||
uint64_t digest;
|
||||
// initial test case
|
||||
CreateTestBitmap(&bitmap, 333, 555, SK_ColorBLUE, reporter);
|
||||
REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
|
||||
REPORTER_ASSERT(reporter, digest == 0xfb2903562766ef87ULL);
|
||||
// same pixel data but different dimensions should yield a different checksum
|
||||
CreateTestBitmap(&bitmap, 555, 333, SK_ColorBLUE, reporter);
|
||||
REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
|
||||
REPORTER_ASSERT(reporter, digest == 0xfe04023fb97d0f61ULL);
|
||||
// same dimensions but different color should yield a different checksum
|
||||
CreateTestBitmap(&bitmap, 555, 333, SK_ColorGREEN, reporter);
|
||||
REPORTER_ASSERT(reporter, SkBitmapHasher::ComputeDigest(bitmap, &digest));
|
||||
REPORTER_ASSERT(reporter, digest == 0x2423c51cad6d1edcULL);
|
||||
}
|
Loading…
Reference in New Issue
Block a user