From 7f23678da0bf546c9b8e11cca6bf28647691fc3c Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Mon, 23 Jan 2012 09:17:35 -0800 Subject: [PATCH] fix for LevelCost + little speed-up the p0 proba was incorrectly accumulated. Merging its contribution into the LevelCost[] was creating more problems than anything (esp. with trellis) so let's just not. Change-Id: I4c07bfee471085df901228d97b20a4d9606ba44e --- src/enc/cost.c | 2 +- src/enc/frame.c | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/enc/cost.c b/src/enc/cost.c index 1eead3fa..14b357ba 100644 --- a/src/enc/cost.c +++ b/src/enc/cost.c @@ -359,7 +359,7 @@ void VP8CalculateLevelCosts(VP8Proba* const proba) { for(ctx = 0; ctx < NUM_CTX; ++ctx) { const uint8_t* const p = proba->coeffs_[ctype][band][ctx]; uint16_t* const table = proba->level_cost_[ctype][band][ctx]; - const int cost_base = VP8BitCost(0, p[0]) + VP8BitCost(1, p[1]); + const int cost_base = VP8BitCost(1, p[1]); int v; table[0] = VP8BitCost(0, p[1]); for (v = 1; v <= MAX_VARIABLE_LEVEL; ++v) { diff --git a/src/enc/frame.c b/src/enc/frame.c index 8a958f2e..f9fbdf2d 100644 --- a/src/enc/frame.c +++ b/src/enc/frame.c @@ -274,12 +274,15 @@ static int GetResidualCost(int ctx, const VP8Residual* const res) { const int b = VP8EncBands[n + 1]; ++n; if (v == 0) { - cost += VP8LevelCost(t, 0); + // short-case for VP8LevelCost(t, 0) (note: VP8LevelFixedCosts[0] == 0): + cost += t[0]; t = res->cost[b][0]; continue; } + cost += VP8BitCost(1, p0); if (2u >= (unsigned int)(v + 1)) { // v = -1 or 1 - cost += VP8LevelCost(t, 1); + // short-case for "VP8LevelCost(t, 1)" (256 is VP8LevelFixedCosts[1]): + cost += 256 + t[1]; p0 = res->prob[b][1][0]; t = res->cost[b][1]; } else {