From b7d674e305f53c83145405a9721a9e822afde004 Mon Sep 17 00:00:00 2001 From: "fbarchard@google.com" Date: Thu, 26 Jun 2014 21:55:38 +0000 Subject: [PATCH] jpeg psnr avoid duplicates with libyuv by checking HAVE_JPEG BUG=339 TESTED=local psnr test R=harryjin@google.com Review URL: https://webrtc-codereview.appspot.com/15949004 git-svn-id: http://libyuv.googlecode.com/svn/trunk@1023 16f28f9a-4ce2-e073-06de-1de4eb20be90 --- README.chromium | 2 +- include/libyuv/version.h | 2 +- util/psnr.cc | 13 +++++++++++++ util/psnr.h | 16 +++++++--------- util/psnr_main.cc | 7 +++++++ util/ssim.cc | 4 ++++ util/ssim.h | 4 +--- 7 files changed, 34 insertions(+), 14 deletions(-) diff --git a/README.chromium b/README.chromium index 9430208f3..581aa455b 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 1022 +Version: 1023 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index efe28797d..67b5fb3db 100644 --- a/include/libyuv/version.h +++ b/include/libyuv/version.h @@ -11,6 +11,6 @@ #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #define INCLUDE_LIBYUV_VERSION_H_ -#define LIBYUV_VERSION 1022 +#define LIBYUV_VERSION 1023 #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT diff --git a/util/psnr.cc b/util/psnr.cc index 77a2f9fd5..f3cc0cf8d 100644 --- a/util/psnr.cc +++ b/util/psnr.cc @@ -32,6 +32,9 @@ typedef unsigned long long uint64; // NOLINT #endif // __LP64__ #endif // _MSC_VER +// libyuv provides this function when linking library for jpeg support. +#if !defined(HAVE_JPEG) + #if !defined(LIBYUV_DISABLE_NEON) && defined(__ARM_NEON__) #define HAS_SUMSQUAREERROR_NEON static uint32 SumSquareError_NEON(const uint8* src_a, @@ -231,6 +234,16 @@ double ComputeSumSquareError(const uint8* src_a, } return static_cast(sse); } +#endif + +// PSNR formula: psnr = 10 * log10 (Peak Signal^2 * size / sse) +// Returns 128.0 (kMaxPSNR) if sse is 0 (perfect match). +double ComputePSNR(double sse, double size) { + const double kMINSSE = 255.0 * 255.0 * size / pow(10.0, kMaxPSNR / 10.0); + if (sse <= kMINSSE) + sse = kMINSSE; // Produces max PSNR of 128 + return 10.0 * log10(255.0 * 255.0 * size / sse); +} #ifdef __cplusplus } // extern "C" diff --git a/util/psnr.h b/util/psnr.h index 8254266c4..0816b9760 100644 --- a/util/psnr.h +++ b/util/psnr.h @@ -26,19 +26,17 @@ typedef unsigned char uint8; static const double kMaxPSNR = 128.0; -// PSNR formula: psnr = 10 * log10 (Peak Signal^2 * size / sse) -// Returns 128.0 (kMaxPSNR) if sse is 0 (perfect match). -static double ComputePSNR(double sse, double size) { - const double kMINSSE = 255.0 * 255.0 * size / pow(10.0, kMaxPSNR / 10.0); - if (sse <= kMINSSE) - sse = kMINSSE; // Produces max PSNR of 128 - return 10.0 * log10(255.0 * 255.0 * size / sse); -} - +// libyuv provides this function when linking library for jpeg support. +// TODO(fbarchard): make psnr lib compatible subset of libyuv. +#if !defined(HAVE_JPEG) // Computer Sum of Squared Error (SSE). // Pass this to ComputePSNR for final result. double ComputeSumSquareError(const uint8* org, const uint8* rec, int size); +#endif +// PSNR formula: psnr = 10 * log10 (Peak Signal^2 * size / sse) +// Returns 128.0 (kMaxPSNR) if sse is 0 (perfect match). +double ComputePSNR(double sse, double size); #ifdef __cplusplus } // extern "C" diff --git a/util/psnr_main.cc b/util/psnr_main.cc index c29610bfb..c458e151c 100644 --- a/util/psnr_main.cc +++ b/util/psnr_main.cc @@ -33,6 +33,7 @@ #include "./psnr.h" #include "./ssim.h" #ifdef HAVE_JPEG +#include "libyuv/compare.h" #include "libyuv/convert.h" #endif @@ -241,9 +242,15 @@ bool UpdateMetrics(uint8* ch_org, uint8* ch_rec, const uint8* const v_org = ch_org + y_size + (uv_size - uv_offset); const uint8* const v_rec = ch_rec + y_size + uv_size; if (do_psnr) { +#ifdef HAVE_JPEG + double y_err = (double)libyuv::ComputeSumSquareError(ch_org, ch_rec, y_size); + double u_err = (double)libyuv::ComputeSumSquareError(u_org, u_rec, uv_size); + double v_err = (double)libyuv::ComputeSumSquareError(v_org, v_rec, uv_size); +#else double y_err = ComputeSumSquareError(ch_org, ch_rec, y_size); double u_err = ComputeSumSquareError(u_org, u_rec, uv_size); double v_err = ComputeSumSquareError(v_org, v_rec, uv_size); +#endif const double total_err = y_err + u_err + v_err; cur_distortion_psnr->global_y += y_err; cur_distortion_psnr->global_u += u_err; diff --git a/util/ssim.cc b/util/ssim.cc index 9da30df18..5a6399b78 100644 --- a/util/ssim.cc +++ b/util/ssim.cc @@ -326,6 +326,10 @@ double CalcSSIM(const uint8 *org, const uint8 *rec, return SSIM; } +double CalcLSSIM(double ssim) { + return -10.0 * log10(1.0 - ssim); +} + #ifdef __cplusplus } // extern "C" #endif diff --git a/util/ssim.h b/util/ssim.h index 52a89327c..430eb71c3 100644 --- a/util/ssim.h +++ b/util/ssim.h @@ -27,9 +27,7 @@ typedef unsigned char uint8; double CalcSSIM(const uint8* org, const uint8* rec, const int image_width, const int image_height); -static double CalcLSSIM(double ssim) { - return -10.0 * log10(1.0 - ssim); -} +double CalcLSSIM(double ssim); #ifdef __cplusplus } // extern "C"