From f4059d0c7d5627c6baef0472c6978e4358e64ebf Mon Sep 17 00:00:00 2001 From: Vikas Arora Date: Tue, 26 Aug 2014 15:44:04 -0700 Subject: [PATCH] Code cleanup for HistogramRemap. Avoid call to HistogramAddThresh when there's only one Histogram image. Change-Id: I43b09e8e2d218c95969567034224777dcce37ab9 --- src/enc/histogram.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/enc/histogram.c b/src/enc/histogram.c index 7c6abb4d..79879b32 100644 --- a/src/enc/histogram.c +++ b/src/enc/histogram.c @@ -640,12 +640,15 @@ static void HistogramRemap(const VP8LHistogramSet* const orig_histo, int i; VP8LHistogram** const orig_histograms = orig_histo->histograms; VP8LHistogram** const histograms = image_histo->histograms; - for (i = 0; i < orig_histo->size; ++i) { + const int orig_histo_size = orig_histo->size; + const int image_histo_size = image_histo->size; + if (image_histo_size > 1) { + for (i = 0; i < orig_histo_size; ++i) { int best_out = 0; double best_bits = HistogramAddThresh(histograms[0], orig_histograms[i], MAX_COST); int k; - for (k = 1; k < image_histo->size; ++k) { + for (k = 1; k < image_histo_size; ++k) { const double cur_bits = HistogramAddThresh(histograms[k], orig_histograms[i], best_bits); if (cur_bits < best_bits) { @@ -655,13 +658,19 @@ static void HistogramRemap(const VP8LHistogramSet* const orig_histo, } symbols[i] = best_out; } + } else { + assert(image_histo_size == 1); + for (i = 0; i < orig_histo_size; ++i) { + symbols[i] = 0; + } + } // Recompute each out based on raw and symbols. - for (i = 0; i < image_histo->size; ++i) { + for (i = 0; i < image_histo_size; ++i) { HistogramClear(histograms[i]); } - for (i = 0; i < orig_histo->size; ++i) { + for (i = 0; i < orig_histo_size; ++i) { const int idx = symbols[i]; VP8LHistogramAdd(orig_histograms[i], histograms[idx], histograms[idx]); }