hash funtion for comparing images

BUG=none
TEST=none
Review URL: https://webrtc-codereview.appspot.com/380006

git-svn-id: http://libyuv.googlecode.com/svn/trunk@166 16f28f9a-4ce2-e073-06de-1de4eb20be90
This commit is contained in:
fbarchard@google.com 2012-02-06 22:05:16 +00:00
parent 8ae294e440
commit 3e34b8e89d
2 changed files with 51 additions and 34 deletions

View File

@ -18,39 +18,43 @@ namespace libyuv {
extern "C" { extern "C" {
#endif #endif
// Compute a hash for specified memory. Seed of 5381 recommended.
uint32 HashDjb2(const uint8* src, uint64 count, uint32 seed);
// Sum Square Error - used to compute Mean Square Error or PSNR
uint64 ComputeSumSquareError(const uint8* src_a,
const uint8* src_b, int count);
uint64 ComputeSumSquareErrorPlane(const uint8* src_a, int stride_a,
const uint8* src_b, int stride_b,
int width, int height);
static const int kMaxPsnr = 128; static const int kMaxPsnr = 128;
double SumSquareErrorToPsnr(uint64 sse, uint64 count); double SumSquareErrorToPsnr(uint64 sse, uint64 count);
uint64 ComputeSumSquareError(const uint8 *src_a, double CalcFramePsnr(const uint8* src_a, int stride_a,
const uint8 *src_b, int count); const uint8* src_b, int stride_b,
uint64 ComputeSumSquareErrorPlane(const uint8 *src_a, int stride_a,
const uint8 *src_b, int stride_b,
int width, int height);
double CalcFramePsnr(const uint8 *src_a, int stride_a,
const uint8 *src_b, int stride_b,
int width, int height); int width, int height);
double CalcFrameSsim(const uint8 *src_a, int stride_a, double I420Psnr(const uint8* src_y_a, int stride_y_a,
const uint8 *src_b, int stride_b, const uint8* src_u_a, int stride_u_a,
int width, int height); const uint8* src_v_a, int stride_v_a,
const uint8* src_y_b, int stride_y_b,
double I420Psnr(const uint8 *src_y_a, int stride_y_a, const uint8* src_u_b, int stride_u_b,
const uint8 *src_u_a, int stride_u_a, const uint8* src_v_b, int stride_v_b,
const uint8 *src_v_a, int stride_v_a,
const uint8 *src_y_b, int stride_y_b,
const uint8 *src_u_b, int stride_u_b,
const uint8 *src_v_b, int stride_v_b,
int width, int height); int width, int height);
double I420Ssim(const uint8 *src_y_a, int stride_y_a, double CalcFrameSsim(const uint8* src_a, int stride_a,
const uint8 *src_u_a, int stride_u_a, const uint8* src_b, int stride_b,
const uint8 *src_v_a, int stride_v_a, int width, int height);
const uint8 *src_y_b, int stride_y_b,
const uint8 *src_u_b, int stride_u_b, double I420Ssim(const uint8* src_y_a, int stride_y_a,
const uint8 *src_v_b, int stride_v_b, const uint8* src_u_a, int stride_u_a,
const uint8* src_v_a, int stride_v_a,
const uint8* src_y_b, int stride_y_b,
const uint8* src_u_b, int stride_u_b,
const uint8* src_v_b, int stride_v_b,
int width, int height); int width, int height);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -22,6 +22,17 @@ namespace libyuv {
extern "C" { extern "C" {
#endif #endif
// hash seed of 5381 recommended.
uint32 HashDjb2(const uint8* src, size_t len, uint32 seed) {
uint32 hash = seed;
if (len > 0) {
do {
hash = hash * 33 + *src++;
} while (--len);
}
return hash;
}
#if defined(__ARM_NEON__) && !defined(YUV_DISABLE_ASM) #if defined(__ARM_NEON__) && !defined(YUV_DISABLE_ASM)
#define HAS_SUMSQUAREERROR_NEON #define HAS_SUMSQUAREERROR_NEON
@ -181,21 +192,23 @@ uint64 ComputeSumSquareError(const uint8* src_a,
} }
const int kBlockSize = 32768; const int kBlockSize = 32768;
uint64 sse = 0; uint64 sse = 0;
while (count >= kBlockSize) { #ifdef _OPENMP
sse += SumSquareError(src_a, src_b, kBlockSize); #pragma omp parallel for reduction(+: sse)
src_a += kBlockSize; #endif
src_b += kBlockSize; for (int i = 0; i < (count - (kBlockSize - 1)); i += kBlockSize) {
count -= kBlockSize; sse += SumSquareError(src_a + i, src_b + i, kBlockSize);
} }
int remainder = count & ~15; src_a += count & ~(kBlockSize - 1);
src_b += count & ~(kBlockSize - 1);
int remainder = count & (kBlockSize - 1) & ~15;
if (remainder) { if (remainder) {
sse += SumSquareError(src_a, src_b, remainder); sse += SumSquareError(src_a, src_b, remainder);
src_a += remainder; src_a += remainder;
src_b += remainder; src_b += remainder;
count -= remainder;
} }
if (count) { remainder = count & 15;
sse += SumSquareError_C(src_a, src_b, count); if (remainder) {
sse += SumSquareError_C(src_a, src_b, remainder);
} }
return sse; return sse;
} }