Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / libyuv / util / psnr.cc
index e8fd16a..f3cc0cf 100644 (file)
@@ -10,8 +10,6 @@
 
 #include "./psnr.h"  // NOLINT
 
-#include <math.h>
-
 #ifdef _OPENMP
 #include <omp.h>
 #endif
@@ -34,13 +32,8 @@ 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);
-}
+// 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
@@ -241,6 +234,16 @@ double ComputeSumSquareError(const uint8* src_a,
   }
   return static_cast<double>(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"