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
URL: http://code.google.com/p/libyuv/
Version: 1021
Version: 1022
License: BSD
License File: LICENSE
......
......@@ -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
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
......@@ -10,8 +10,6 @@
#include "./psnr.h" // NOLINT
#include <math.h>
#ifdef _OPENMP
#include <omp.h>
#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,
......
......@@ -13,6 +13,8 @@
#ifndef UTIL_PSNR_H_ // NOLINT
#define UTIL_PSNR_H_
#include <math.h> // 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
......
......@@ -256,10 +256,10 @@ bool UpdateMetrics(uint8* ch_org, uint8* ch_rec,
static_cast<double>(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;
......
......@@ -10,7 +10,6 @@
#include "../util/ssim.h" // NOLINT
#include <math.h>
#include <string.h>
#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
......
......@@ -13,6 +13,8 @@
#ifndef UTIL_SSIM_H_ // NOLINT
#define UTIL_SSIM_H_
#include <math.h> // 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"
......
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