avoid using tmp histogram in PreparePair()

we don't need to store the resulting histogram, so no need to
call HistogramAddEval().
Allows some signature simplifications...

Change-Id: I3fff6c45f4a7c6179499c6078ff159df4ca0ac53
This commit is contained in:
Pascal Massimino 2016-06-12 14:28:56 -07:00
parent 7685123a7f
commit 1df5e26001

View File

@ -631,8 +631,11 @@ static void UpdateQueueFront(HistoQueue* const histo_queue) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
static void PreparePair(VP8LHistogram** histograms, int idx1, int idx2, static void PreparePair(VP8LHistogram** histograms, int idx1, int idx2,
HistogramPair* const pair, HistogramPair* const pair) {
VP8LHistogram* const histos) { VP8LHistogram* h1;
VP8LHistogram* h2;
double sum_cost;
if (idx1 > idx2) { if (idx1 > idx2) {
const int tmp = idx2; const int tmp = idx2;
idx2 = idx1; idx2 = idx1;
@ -640,15 +643,17 @@ static void PreparePair(VP8LHistogram** histograms, int idx1, int idx2,
} }
pair->idx1 = idx1; pair->idx1 = idx1;
pair->idx2 = idx2; pair->idx2 = idx2;
pair->cost_diff = h1 = histograms[idx1];
HistogramAddEval(histograms[idx1], histograms[idx2], histos, 0); h2 = histograms[idx2];
pair->cost_combo = histos->bit_cost_; sum_cost = h1->bit_cost_ + h2->bit_cost_;
pair->cost_combo = 0.;
GetCombinedHistogramEntropy(h1, h2, sum_cost, &pair->cost_combo);
pair->cost_diff = pair->cost_combo - sum_cost;
} }
// Combines histograms by continuously choosing the one with the highest cost // Combines histograms by continuously choosing the one with the highest cost
// reduction. // reduction.
static int HistogramCombineGreedy(VP8LHistogramSet* const image_histo, static int HistogramCombineGreedy(VP8LHistogramSet* const image_histo) {
VP8LHistogram* const histos) {
int ok = 0; int ok = 0;
int image_histo_size = image_histo->size; int image_histo_size = image_histo->size;
int i, j; int i, j;
@ -667,8 +672,7 @@ static int HistogramCombineGreedy(VP8LHistogramSet* const image_histo,
clusters[i] = i; clusters[i] = i;
for (j = i + 1; j < image_histo_size; ++j) { for (j = i + 1; j < image_histo_size; ++j) {
// Initialize positions array. // Initialize positions array.
PreparePair(histograms, i, j, &histo_queue.queue[histo_queue.size], PreparePair(histograms, i, j, &histo_queue.queue[histo_queue.size]);
histos);
UpdateQueueFront(&histo_queue); UpdateQueueFront(&histo_queue);
} }
} }
@ -710,7 +714,7 @@ static int HistogramCombineGreedy(VP8LHistogramSet* const image_histo,
for (i = 0; i < image_histo_size; ++i) { for (i = 0; i < image_histo_size; ++i) {
if (clusters[i] != idx1) { if (clusters[i] != idx1) {
PreparePair(histograms, idx1, clusters[i], PreparePair(histograms, idx1, clusters[i],
&histo_queue.queue[histo_queue.size], histos); &histo_queue.queue[histo_queue.size]);
UpdateQueueFront(&histo_queue); UpdateQueueFront(&histo_queue);
} }
} }
@ -731,8 +735,7 @@ static int HistogramCombineGreedy(VP8LHistogramSet* const image_histo,
return ok; return ok;
} }
static VP8LHistogram* HistogramCombineStochastic( static void HistogramCombineStochastic(VP8LHistogramSet* const image_histo,
VP8LHistogramSet* const image_histo,
VP8LHistogram* tmp_histo, VP8LHistogram* tmp_histo,
VP8LHistogram* best_combo, VP8LHistogram* best_combo,
int quality, int min_cluster_size) { int quality, int min_cluster_size) {
@ -795,7 +798,6 @@ static VP8LHistogram* HistogramCombineStochastic(
} }
} }
image_histo->size = image_histo_size; image_histo->size = image_histo_size;
return best_combo;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -914,11 +916,10 @@ int VP8LGetHistoImageSymbols(int xsize, int ysize,
const float x = quality / 100.f; const float x = quality / 100.f;
// cubic ramp between 1 and MAX_HISTO_GREEDY: // cubic ramp between 1 and MAX_HISTO_GREEDY:
const int threshold_size = (int)(1 + (x * x * x) * (MAX_HISTO_GREEDY - 1)); const int threshold_size = (int)(1 + (x * x * x) * (MAX_HISTO_GREEDY - 1));
cur_combo = HistogramCombineStochastic(image_histo, HistogramCombineStochastic(image_histo, tmp_histos->histograms[0],
tmp_histos->histograms[0],
cur_combo, quality, threshold_size); cur_combo, quality, threshold_size);
if ((image_histo->size <= threshold_size) && if ((image_histo->size <= threshold_size) &&
!HistogramCombineGreedy(image_histo, cur_combo)) { !HistogramCombineGreedy(image_histo)) {
goto Error; goto Error;
} }
} }