From 07c2b1679a27c1c1daed5716a57acc2000baa568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesin=CC=81ski?= Date: Wed, 30 Apr 2014 23:16:24 +0100 Subject: [PATCH] Re-enabled export of SSIM map --- dssim.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dssim.c b/dssim.c index eae84ac..882457d 100644 --- a/dssim.c +++ b/dssim.c @@ -375,7 +375,7 @@ int dssim_set_modified(dssim_info *inf, dssim_rgba *row_pointers[], const int im return 0; } -static double dssim_compare_channel(dssim_info_chan *chan, float *ssimmap); +static double dssim_compare_channel(dssim_info_chan *chan, float **ssimmap); /* Algorithm based on Rabah Mehdi's C++ implementation @@ -389,14 +389,14 @@ double dssim_compare(dssim_info *inf, float **ssim_map_out) { double avgssim = 0; for (int ch = 0; ch < CHANS; ch++) { - avgssim += dssim_compare_channel(&inf->chan[ch], NULL); + avgssim += dssim_compare_channel(&inf->chan[ch], ssim_map_out && ch == 0 ? ssim_map_out : NULL); } avgssim /= (double)CHANS; return 1.0 / (avgssim) - 1.0; } -static double dssim_compare_channel(dssim_info_chan *chan, float *ssimmap) +static double dssim_compare_channel(dssim_info_chan *chan, float **ssim_map_out) { const int width = chan->width; const int height = chan->height; @@ -410,6 +410,8 @@ static double dssim_compare_channel(dssim_info_chan *chan, float *ssimmap) const double c1 = 0.01 * 0.01, c2 = 0.03 * 0.03; double avgssim = 0; + float *const ssimmap = ssim_map_out ? chan->mu2 : NULL; + for (int offset = 0; offset < width * height; offset++) { const double mu1_sq = mu1[offset]*mu1[offset]; const double mu2_sq = mu2[offset]*mu2[offset]; @@ -426,7 +428,13 @@ static double dssim_compare_channel(dssim_info_chan *chan, float *ssimmap) } } - free(chan->mu2); chan->mu2 = NULL; + if (ssim_map_out) { + *ssim_map_out = ssimmap; // reuses mu2 memory + } else { + free(chan->mu2); + } + chan->mu2 = NULL; + free(chan->sigma12); chan->sigma12 = NULL; free(chan->sigma2_sq); chan->sigma2_sq = NULL;