diff --git a/README.chromium b/README.chromium index 0a150d4d2..9430208f3 100644 --- a/README.chromium +++ b/README.chromium @@ -1,6 +1,6 @@ Name: libyuv URL: http://code.google.com/p/libyuv/ -Version: 1021 +Version: 1022 License: BSD License File: LICENSE diff --git a/include/libyuv/version.h b/include/libyuv/version.h index 4053fd09e..efe28797d 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 1021 +#define LIBYUV_VERSION 1022 #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT diff --git a/util/Makefile b/util/Makefile index be6de3591..6044d2adf 100644 --- a/util/Makefile +++ b/util/Makefile @@ -1,6 +1,6 @@ -psnr: psnr.cc ssim.cc psnr_main.cc -ifeq ($(CXX),icl) - $(CXX) /arch:SSE2 /Ox /openmp psnr.cc ssim.cc psnr_main.cc -else - $(CXX) -msse2 -O3 -fopenmp -static -o psnr psnr.cc ssim.cc psnr_main.cc -Wl,--strip-all -endif +psnr: psnr.cc ssim.cc psnr_main.cc +ifeq ($(CXX),icl) + $(CXX) /arch:SSE2 /Ox /openmp psnr.cc ssim.cc psnr_main.cc +else + $(CXX) -msse2 -O3 -fopenmp -static -o psnr psnr.cc ssim.cc psnr_main.cc -Wl,--strip-all +endif diff --git a/util/psnr.cc b/util/psnr.cc index e8fd16a3e..77a2f9fd5 100644 --- a/util/psnr.cc +++ b/util/psnr.cc @@ -10,8 +10,6 @@ #include "./psnr.h" // NOLINT -#include - #ifdef _OPENMP #include #endif @@ -34,14 +32,6 @@ typedef unsigned long long uint64; // NOLINT #endif // __LP64__ #endif // _MSC_VER -// PSNR formula: psnr = 10 * log10 (Peak Signal^2 * size / sse) -double ComputePSNR(double sse, double size) { - const double kMINSSE = 255.0 * 255.0 * size / pow(10., kMaxPSNR / 10.); - if (sse <= kMINSSE) - sse = kMINSSE; // Produces max PSNR of 128 - return 10.0 * log10(65025.0 * size / sse); -} - #if !defined(LIBYUV_DISABLE_NEON) && defined(__ARM_NEON__) #define HAS_SUMSQUAREERROR_NEON static uint32 SumSquareError_NEON(const uint8* src_a, diff --git a/util/psnr.h b/util/psnr.h index 370337a75..8254266c4 100644 --- a/util/psnr.h +++ b/util/psnr.h @@ -13,6 +13,8 @@ #ifndef UTIL_PSNR_H_ // NOLINT #define UTIL_PSNR_H_ +#include // For log10() + #ifdef __cplusplus extern "C" { #endif @@ -24,14 +26,20 @@ typedef unsigned char uint8; static const double kMaxPSNR = 128.0; -// PSNR formula: psnr = 10 * log10 (Peak Signal^2 * size / sse). +// 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); +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); +} // Computer Sum of Squared Error (SSE). // Pass this to ComputePSNR for final result. double ComputeSumSquareError(const uint8* org, const uint8* rec, int size); + #ifdef __cplusplus } // extern "C" #endif diff --git a/util/psnr_main.cc b/util/psnr_main.cc index ae8ee0116..c29610bfb 100644 --- a/util/psnr_main.cc +++ b/util/psnr_main.cc @@ -256,10 +256,10 @@ bool UpdateMetrics(uint8* ch_org, uint8* ch_rec, static_cast(total_size)); } else { distorted_frame->y = CalcSSIM(ch_org, ch_rec, image_width, image_height); - distorted_frame->u = CalcSSIM(u_org, u_rec, image_width / 2, - image_height / 2); - distorted_frame->v = CalcSSIM(v_org, v_rec, image_width / 2, - image_height / 2); + distorted_frame->u = CalcSSIM(u_org, u_rec, (image_width + 1) / 2, + (image_height + 1) / 2); + distorted_frame->v = CalcSSIM(v_org, v_rec, (image_width + 1) / 2, + (image_height + 1) / 2); distorted_frame->all = (distorted_frame->y + distorted_frame->u + distorted_frame->v) / total_size; @@ -417,11 +417,12 @@ int main(int argc, const char* argv[]) { // Try parsing file as a jpeg. uint8* const ch_jpeg = new uint8[bytes_org]; memcpy(ch_jpeg, ch_org, bytes_org); + memset(ch_org, 0, total_size); if (0 != libyuv::MJPGToI420(ch_jpeg, bytes_org, ch_org, image_width, - ch_org + y_size, image_width / 2, - ch_org + y_size + uv_size, image_width / 2, + ch_org + y_size, (image_width + 1) / 2, + ch_org + y_size + uv_size, (image_width + 1) / 2, image_width, image_height, image_width, image_height)) { delete[] ch_jpeg; @@ -441,11 +442,12 @@ int main(int argc, const char* argv[]) { // Try parsing file as a jpeg. uint8* const ch_jpeg = new uint8[bytes_rec]; memcpy(ch_jpeg, ch_rec, bytes_rec); + memset(ch_rec, 0, total_size); if (0 != libyuv::MJPGToI420(ch_jpeg, bytes_rec, ch_rec, image_width, - ch_rec + y_size, image_width / 2, - ch_rec + y_size + uv_size, image_width / 2, + ch_rec + y_size, (image_width + 1) / 2, + ch_rec + y_size + uv_size, (image_width + 1) / 2, image_width, image_height, image_width, image_height)) { delete[] ch_jpeg; diff --git a/util/ssim.cc b/util/ssim.cc index d07889a8a..9da30df18 100644 --- a/util/ssim.cc +++ b/util/ssim.cc @@ -10,7 +10,6 @@ #include "../util/ssim.h" // NOLINT -#include #include #ifdef __cplusplus @@ -327,10 +326,6 @@ 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 40120b4f4..52a89327c 100644 --- a/util/ssim.h +++ b/util/ssim.h @@ -13,6 +13,8 @@ #ifndef UTIL_SSIM_H_ // NOLINT #define UTIL_SSIM_H_ +#include // For log10() + #ifdef __cplusplus extern "C" { #endif @@ -25,8 +27,9 @@ typedef unsigned char uint8; double CalcSSIM(const uint8* org, const uint8* rec, const int image_width, const int image_height); -// does -10.0 * log10(1.0 - ssim) -double CalcLSSIM(double ssim); +static double CalcLSSIM(double ssim) { + return -10.0 * log10(1.0 - ssim); +} #ifdef __cplusplus } // extern "C"