From 30176619c69d425eab962c4fe5fe3d26ea646b66 Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 5 Mar 2014 23:21:43 +0100 Subject: [PATCH] 4-5% faster trellis by removing some unneeded calculations. (We didn't need the exact value of the max_error properly. We can work with relative values instead of absolute) Output is bitwise the same as before. Change-Id: I67aeaaea5f81bfd9ca8e1158387a5083a2b6c649 --- src/enc/quant.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/enc/quant.c b/src/enc/quant.c index 2b0964ad..3bdab80f 100644 --- a/src/enc/quant.c +++ b/src/enc/quant.c @@ -553,22 +553,22 @@ static int TrellisQuantizeBlock(const VP8EncIterator* const it, Node nodes[17][NUM_NODES]; int best_path[3] = {-1, -1, -1}; // store best-last/best-level/best-previous score_t best_score; - int last = first - 1; - int n, m, p; + int n, m, p, last; { score_t cost; - score_t max_error; const int thresh = mtx->q_[1] * mtx->q_[1] / 4; const int last_proba = probas[VP8EncBands[first]][ctx0][0]; - // compute maximal distortion. - max_error = 0; - for (n = first; n < 16; ++n) { + // compute the position of the last interesting coefficient + last = first - 1; + for (n = 15; n >= first; --n) { const int j = kZigzag[n]; const int err = in[j] * in[j]; - max_error += kWeightTrellis[j] * err; - if (err > thresh) last = n; + if (err > thresh) { + last = n; + break; + } } // we don't need to go inspect up to n = 16 coeffs. We can just go up // to last + 1 (inclusive) without losing much. @@ -576,13 +576,13 @@ static int TrellisQuantizeBlock(const VP8EncIterator* const it, // compute 'skip' score. This is the max score one can do. cost = VP8BitCost(0, last_proba); - best_score = RDScoreTrellis(lambda, cost, max_error); + best_score = RDScoreTrellis(lambda, cost, 0); // initialize source node. n = first - 1; for (m = -MIN_DELTA; m <= MAX_DELTA; ++m) { const score_t rate = (ctx0 == 0) ? VP8BitCost(1, last_proba) : 0; - NODE(n, m).score = RDScoreTrellis(lambda, rate, max_error); + NODE(n, m).score = RDScoreTrellis(lambda, rate, 0); NODE(n, m).costs = costs[VP8EncBands[first]][ctx0]; } } @@ -615,6 +615,7 @@ static int TrellisQuantizeBlock(const VP8EncIterator* const it, cur->sign = sign; cur->level = level; cur->costs = costs[band][ctx]; + cur->prev = 0; // default, in case // Compute extra rate cost if last coeff's position is < 15 last_pos_cost = (n < 15) ? VP8BitCost(0, probas[band][ctx][0]) : 0;