summaryrefslogtreecommitdiff
path: root/gst/debugutils/gstcompare.c
diff options
context:
space:
mode:
authorVincent Penquerc'h <vincent.penquerch@collabora.co.uk>2014-04-09 15:18:22 +0100
committerVincent Penquerc'h <vincent.penquerch@collabora.co.uk>2014-04-09 15:21:20 +0100
commit75c09f8d03a1b916df0c4f3b175a0ee7a63f7dd4 (patch)
tree1fa7d8304f156aaca769d5c415836ac840458df7 /gst/debugutils/gstcompare.c
parent93b15049459b979e0cf7face080c179b87bd386f (diff)
downloadgstreamer-plugins-bad-75c09f8d03a1b916df0c4f3b175a0ee7a63f7dd4.tar.gz
compare: special case empty regions with 1 SSIM to avoid dividing by 0
Coverity 1139689, 1139688
Diffstat (limited to 'gst/debugutils/gstcompare.c')
-rw-r--r--gst/debugutils/gstcompare.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/gst/debugutils/gstcompare.c b/gst/debugutils/gstcompare.c
index 8fb44a9c2..5de2f9da3 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);
}