summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Rabaud <vrabaud@google.com>2018-11-07 00:33:14 +0100
committerJames Zern <jzern@google.com>2018-11-07 23:07:24 -0800
commitfa8210e43ca559607bead50d1b931e8c45453ad4 (patch)
tree2ce9523dc6f156f9be8225edfc212bbd01bd7163
parent825389acba39320f7e954e010f1d69ec34b0695e (diff)
downloadlibwebp-fa8210e43ca559607bead50d1b931e8c45453ad4.tar.gz
Fix pair update in stochastic entropy merging.
The old code simply did not make sense. The effect is that the pair would be popped from the queue no matter what; as the queue is small, it does not matter that much on the results. But it will matter for a later CL. Change-Id: If50c9fa9d7f3ac3c48bb7336d81479287d4944c4 (cherry picked from commit 485ff86fbb174b518834503cb39c9c8e20567f38)
-rw-r--r--src/enc/histogram_enc.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/enc/histogram_enc.c b/src/enc/histogram_enc.c
index 28a3e6e6..4e49e0a2 100644
--- a/src/enc/histogram_enc.c
+++ b/src/enc/histogram_enc.c
@@ -756,6 +756,18 @@ static void HistoQueueUpdateHead(HistoQueue* const histo_queue,
}
}
+// Update the cost diff and combo of a pair of histograms. This needs to be
+// called when the the histograms have been merged with a third one.
+static void HistoQueueUpdatePair(const VP8LHistogram* const h1,
+ const VP8LHistogram* const h2,
+ double threshold,
+ HistogramPair* const pair) {
+ const double sum_cost = h1->bit_cost_ + h2->bit_cost_;
+ pair->cost_combo = 0.;
+ GetCombinedHistogramEntropy(h1, h2, sum_cost + threshold, &pair->cost_combo);
+ pair->cost_diff = pair->cost_combo - sum_cost;
+}
+
// Create a pair from indices "idx1" and "idx2" provided its cost
// is inferior to "threshold", a negative entropy.
// It returns the cost of the pair, or 0. if it superior to threshold.
@@ -765,7 +777,6 @@ static double HistoQueuePush(HistoQueue* const histo_queue,
const VP8LHistogram* h1;
const VP8LHistogram* h2;
HistogramPair pair;
- double sum_cost;
assert(threshold <= 0.);
if (idx1 > idx2) {
@@ -777,10 +788,8 @@ static double HistoQueuePush(HistoQueue* const histo_queue,
pair.idx2 = idx2;
h1 = histograms[idx1];
h2 = histograms[idx2];
- sum_cost = h1->bit_cost_ + h2->bit_cost_;
- pair.cost_combo = 0.;
- GetCombinedHistogramEntropy(h1, h2, sum_cost + threshold, &pair.cost_combo);
- pair.cost_diff = pair.cost_combo - sum_cost;
+
+ HistoQueueUpdatePair(h1, h2, threshold, &pair);
// Do not even consider the pair if it does not improve the entropy.
if (pair.cost_diff >= threshold) return 0.;
@@ -973,8 +982,7 @@ static int HistogramCombineStochastic(VP8LHistogramSet* const image_histo,
}
if (do_eval) {
// Re-evaluate the cost of an updated pair.
- GetCombinedHistogramEntropy(histograms[p->idx1], histograms[p->idx2], 0,
- &p->cost_diff);
+ HistoQueueUpdatePair(histograms[p->idx1], histograms[p->idx2], 0., p);
if (p->cost_diff >= 0.) {
HistoQueuePopPair(&histo_queue, p);
continue;