Set a max dB value for PSNR_HVS and FAST_SSIM

Now set at 100.0 instead of infinite

Change-Id: I41bae0c4bd95a26f9819584e7311b7945df1271a
diff --git a/vpx/internal/vpx_psnr.h b/vpx/internal/vpx_psnr.h
index 07d81bb..0e90085 100644
--- a/vpx/internal/vpx_psnr.h
+++ b/vpx/internal/vpx_psnr.h
@@ -11,6 +11,8 @@
 #ifndef VPX_INTERNAL_VPX_PSNR_H_
 #define VPX_INTERNAL_VPX_PSNR_H_
 
+#define MAX_PSNR 100.0
+
 #ifdef __cplusplus
 extern "C" {
 #endif
diff --git a/vpx/src/vpx_psnr.c b/vpx/src/vpx_psnr.c
index 05843ac..27a6180 100644
--- a/vpx/src/vpx_psnr.c
+++ b/vpx/src/vpx_psnr.c
@@ -12,7 +12,6 @@
 
 #include "vpx/internal/vpx_psnr.h"
 
-#define MAX_PSNR 100.0
 
 double vpx_sse_to_psnr(double samples, double peak, double sse) {
   if (sse > 0.0) {
diff --git a/vpx_dsp/fastssim.c b/vpx_dsp/fastssim.c
index 1405a30..569f18b 100644
--- a/vpx_dsp/fastssim.c
+++ b/vpx_dsp/fastssim.c
@@ -10,6 +10,7 @@
  *  This code was originally written by: Nathan E. Egge, at the Daala
  *  project.
  */
+#include <assert.h>
 #include <math.h>
 #include <stdlib.h>
 #include <string.h>
@@ -17,6 +18,7 @@
 #include "./vpx_dsp_rtcd.h"
 #include "vpx_dsp/ssim.h"
 #include "vpx_ports/system_state.h"
+
 /* TODO(jbb): High bit depth version of this code needed */
 typedef struct fs_level fs_level;
 typedef struct fs_ctx fs_ctx;
@@ -442,6 +444,9 @@
 }
 
 static double convert_ssim_db(double _ssim, double _weight) {
+  assert(_weight >= _ssim);
+  if ((_weight - _ssim) < 1e-10)
+    return MAX_SSIM_DB;
   return 10 * (log10(_weight) - log10(_weight - _ssim));
 }
 
diff --git a/vpx_dsp/psnrhvs.c b/vpx_dsp/psnrhvs.c
index b10f9f3..083cc80 100644
--- a/vpx_dsp/psnrhvs.c
+++ b/vpx_dsp/psnrhvs.c
@@ -10,6 +10,7 @@
  *  This code was originally written by: Gregory Maxwell, at the Daala
  *  project.
  */
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
@@ -18,6 +19,7 @@
 #include "./vpx_dsp_rtcd.h"
 #include "vpx_dsp/ssim.h"
 #include "vpx_ports/system_state.h"
+#include "vpx/internal/vpx_psnr.h"
 
 #if !defined(M_PI)
 # define M_PI (3.141592653589793238462643)
@@ -90,6 +92,9 @@
      0.478717061273, 0.393021669543, 0.330555063063, 0.285345396658}};
 
 static double convert_score_db(double _score, double _weight) {
+  assert(_score * _weight >= 0.0);
+  if (_weight * _score < 255 * 255 * 1e-10)
+    return MAX_PSNR;
   return 10 * (log10(255 * 255) - log10(_weight * _score));
 }
 
diff --git a/vpx_dsp/ssim.h b/vpx_dsp/ssim.h
index 132f7f9..1d90f9b 100644
--- a/vpx_dsp/ssim.h
+++ b/vpx_dsp/ssim.h
@@ -11,6 +11,8 @@
 #ifndef VPX_DSP_SSIM_H_
 #define VPX_DSP_SSIM_H_
 
+#define MAX_SSIM_DB 100.0;
+
 #ifdef __cplusplus
 extern "C" {
 #endif