Commit 44e049b3 authored by fbarchard@google.com's avatar fbarchard@google.com

move Calc functions for psnr into header to avoid duplicate links.

BUG=339
TESTED=gyp build
R=harryjin@google.com

Review URL: https://webrtc-codereview.appspot.com/16769004

git-svn-id: http://libyuv.googlecode.com/svn/trunk@1022 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent f939fb76
Name: libyuv Name: libyuv
URL: http://code.google.com/p/libyuv/ URL: http://code.google.com/p/libyuv/
Version: 1021 Version: 1022
License: BSD License: BSD
License File: LICENSE License File: LICENSE
......
...@@ -11,6 +11,6 @@ ...@@ -11,6 +11,6 @@
#ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT #ifndef INCLUDE_LIBYUV_VERSION_H_ // NOLINT
#define INCLUDE_LIBYUV_VERSION_H_ #define INCLUDE_LIBYUV_VERSION_H_
#define LIBYUV_VERSION 1021 #define LIBYUV_VERSION 1022
#endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT #endif // INCLUDE_LIBYUV_VERSION_H_ NOLINT
psnr: psnr.cc ssim.cc psnr_main.cc psnr: psnr.cc ssim.cc psnr_main.cc
ifeq ($(CXX),icl) ifeq ($(CXX),icl)
$(CXX) /arch:SSE2 /Ox /openmp psnr.cc ssim.cc psnr_main.cc $(CXX) /arch:SSE2 /Ox /openmp psnr.cc ssim.cc psnr_main.cc
else else
$(CXX) -msse2 -O3 -fopenmp -static -o psnr psnr.cc ssim.cc psnr_main.cc -Wl,--strip-all $(CXX) -msse2 -O3 -fopenmp -static -o psnr psnr.cc ssim.cc psnr_main.cc -Wl,--strip-all
endif endif
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
#include "./psnr.h" // NOLINT #include "./psnr.h" // NOLINT
#include <math.h>
#ifdef _OPENMP #ifdef _OPENMP
#include <omp.h> #include <omp.h>
#endif #endif
...@@ -34,14 +32,6 @@ typedef unsigned long long uint64; // NOLINT ...@@ -34,14 +32,6 @@ typedef unsigned long long uint64; // NOLINT
#endif // __LP64__ #endif // __LP64__
#endif // _MSC_VER #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__) #if !defined(LIBYUV_DISABLE_NEON) && defined(__ARM_NEON__)
#define HAS_SUMSQUAREERROR_NEON #define HAS_SUMSQUAREERROR_NEON
static uint32 SumSquareError_NEON(const uint8* src_a, static uint32 SumSquareError_NEON(const uint8* src_a,
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#ifndef UTIL_PSNR_H_ // NOLINT #ifndef UTIL_PSNR_H_ // NOLINT
#define UTIL_PSNR_H_ #define UTIL_PSNR_H_
#include <math.h> // For log10()
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
...@@ -24,14 +26,20 @@ typedef unsigned char uint8; ...@@ -24,14 +26,20 @@ typedef unsigned char uint8;
static const double kMaxPSNR = 128.0; 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). // 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). // Computer Sum of Squared Error (SSE).
// Pass this to ComputePSNR for final result. // Pass this to ComputePSNR for final result.
double ComputeSumSquareError(const uint8* org, const uint8* rec, int size); double ComputeSumSquareError(const uint8* org, const uint8* rec, int size);
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif
......
...@@ -256,10 +256,10 @@ bool UpdateMetrics(uint8* ch_org, uint8* ch_rec, ...@@ -256,10 +256,10 @@ bool UpdateMetrics(uint8* ch_org, uint8* ch_rec,
static_cast<double>(total_size)); static_cast<double>(total_size));
} else { } else {
distorted_frame->y = CalcSSIM(ch_org, ch_rec, image_width, image_height); distorted_frame->y = CalcSSIM(ch_org, ch_rec, image_width, image_height);
distorted_frame->u = CalcSSIM(u_org, u_rec, image_width / 2, distorted_frame->u = CalcSSIM(u_org, u_rec, (image_width + 1) / 2,
image_height / 2); (image_height + 1) / 2);
distorted_frame->v = CalcSSIM(v_org, v_rec, image_width / 2, distorted_frame->v = CalcSSIM(v_org, v_rec, (image_width + 1) / 2,
image_height / 2); (image_height + 1) / 2);
distorted_frame->all = distorted_frame->all =
(distorted_frame->y + distorted_frame->u + distorted_frame->v) (distorted_frame->y + distorted_frame->u + distorted_frame->v)
/ total_size; / total_size;
...@@ -417,11 +417,12 @@ int main(int argc, const char* argv[]) { ...@@ -417,11 +417,12 @@ int main(int argc, const char* argv[]) {
// Try parsing file as a jpeg. // Try parsing file as a jpeg.
uint8* const ch_jpeg = new uint8[bytes_org]; uint8* const ch_jpeg = new uint8[bytes_org];
memcpy(ch_jpeg, ch_org, bytes_org); memcpy(ch_jpeg, ch_org, bytes_org);
memset(ch_org, 0, total_size);
if (0 != libyuv::MJPGToI420(ch_jpeg, bytes_org, if (0 != libyuv::MJPGToI420(ch_jpeg, bytes_org,
ch_org, image_width, ch_org, image_width,
ch_org + y_size, image_width / 2, ch_org + y_size, (image_width + 1) / 2,
ch_org + y_size + uv_size, image_width / 2, ch_org + y_size + uv_size, (image_width + 1) / 2,
image_width, image_height, image_width, image_height,
image_width, image_height)) { image_width, image_height)) {
delete[] ch_jpeg; delete[] ch_jpeg;
...@@ -441,11 +442,12 @@ int main(int argc, const char* argv[]) { ...@@ -441,11 +442,12 @@ int main(int argc, const char* argv[]) {
// Try parsing file as a jpeg. // Try parsing file as a jpeg.
uint8* const ch_jpeg = new uint8[bytes_rec]; uint8* const ch_jpeg = new uint8[bytes_rec];
memcpy(ch_jpeg, ch_rec, bytes_rec); memcpy(ch_jpeg, ch_rec, bytes_rec);
memset(ch_rec, 0, total_size);
if (0 != libyuv::MJPGToI420(ch_jpeg, bytes_rec, if (0 != libyuv::MJPGToI420(ch_jpeg, bytes_rec,
ch_rec, image_width, ch_rec, image_width,
ch_rec + y_size, image_width / 2, ch_rec + y_size, (image_width + 1) / 2,
ch_rec + y_size + uv_size, image_width / 2, ch_rec + y_size + uv_size, (image_width + 1) / 2,
image_width, image_height, image_width, image_height,
image_width, image_height)) { image_width, image_height)) {
delete[] ch_jpeg; delete[] ch_jpeg;
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "../util/ssim.h" // NOLINT #include "../util/ssim.h" // NOLINT
#include <math.h>
#include <string.h> #include <string.h>
#ifdef __cplusplus #ifdef __cplusplus
...@@ -327,10 +326,6 @@ double CalcSSIM(const uint8 *org, const uint8 *rec, ...@@ -327,10 +326,6 @@ double CalcSSIM(const uint8 *org, const uint8 *rec,
return SSIM; return SSIM;
} }
double CalcLSSIM(double ssim) {
return -10.0 * log10(1.0 - ssim);
}
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
#endif #endif
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#ifndef UTIL_SSIM_H_ // NOLINT #ifndef UTIL_SSIM_H_ // NOLINT
#define UTIL_SSIM_H_ #define UTIL_SSIM_H_
#include <math.h> // For log10()
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
...@@ -25,8 +27,9 @@ typedef unsigned char uint8; ...@@ -25,8 +27,9 @@ typedef unsigned char uint8;
double CalcSSIM(const uint8* org, const uint8* rec, double CalcSSIM(const uint8* org, const uint8* rec,
const int image_width, const int image_height); const int image_width, const int image_height);
// does -10.0 * log10(1.0 - ssim) static double CalcLSSIM(double ssim) {
double CalcLSSIM(double ssim); return -10.0 * log10(1.0 - ssim);
}
#ifdef __cplusplus #ifdef __cplusplus
} // extern "C" } // extern "C"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment