Do token recording and counting in a single loop

Change-Id: I8afd3c486b210bd67888de03e91dde7f78276f89
This commit is contained in:
hui su
2016-07-19 16:28:26 -07:00
parent 9ac74f922e
commit 0c0fb83211
5 changed files with 62 additions and 62 deletions

View File

@ -41,6 +41,18 @@ void VP8InitResidual(int first, int coeff_type,
int VP8RecordCoeffs(int ctx, const VP8Residual* const res);
// Record proba context used.
static WEBP_INLINE int VP8RecordStats(int bit, proba_t* const stats) {
proba_t p = *stats;
if (p >= 0xffff0000u) { // an overflow is inbound.
p = ((p + 1u) >> 1) & 0x7fff7fffu; // -> divide the stats by 2.
}
// record bit count (lower 16 bits) and increment total count (upper 16 bits).
p += 0x00010000u + bit;
*stats = p;
return bit;
}
// Cost of coding one event with probability 'proba'.
static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];