From 75c09f8d03a1b916df0c4f3b175a0ee7a63f7dd4 Mon Sep 17 00:00:00 2001 From: Vincent Penquerc'h Date: Wed, 9 Apr 2014 15:18:22 +0100 Subject: [PATCH] compare: special case empty regions with 1 SSIM to avoid dividing by 0 Coverity 1139689, 1139688 --- gst/debugutils/gstcompare.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gst/debugutils/gstcompare.c b/gst/debugutils/gstcompare.c index 8fb44a9c2b..5de2f9da36 100644 --- a/gst/debugutils/gstcompare.c +++ b/gst/debugutils/gstcompare.c @@ -363,6 +363,10 @@ gst_compare_ssim_window (GstCompare * comp, guint8 * data1, guint8 * data2, const gdouble c1 = (k1 * L) * (k1 * L); const gdouble c2 = (k2 * L) * (k2 * L); + /* For empty images, return maximum similarity */ + if (height <= 0 || width <= 0) + return 1.0; + /* plain and simple; no fancy optimizations */ for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { @@ -414,6 +418,10 @@ gst_compare_ssim_component (GstCompare * comp, guint8 * data1, guint8 * data2, } } + /* For empty images, return maximum similarity */ + if (count == 0) + return 1.0; + return (ssim_sum / count); }