mirror of
https://github.com/webmproject/libwebp.git
synced 2024-11-20 12:28:26 +01:00
add VP8EstimateTokenSize()
estimates final size of coded tokens given a set of probabilities Change-Id: Ia5a459422557d98b78b3cd8e1a88cb30835825b6
This commit is contained in:
parent
10fddf53bb
commit
b7d4e04255
@ -20,6 +20,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "./cost.h"
|
||||||
#include "./vp8enci.h"
|
#include "./vp8enci.h"
|
||||||
|
|
||||||
#if defined(__cplusplus) || defined(c_plusplus)
|
#if defined(__cplusplus) || defined(c_plusplus)
|
||||||
@ -238,6 +239,29 @@ int VP8EmitTokens(VP8TBuffer* const b, VP8BitWriter* const bw,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Size estimation
|
||||||
|
size_t VP8EstimateTokenSize(VP8TBuffer* const b, const uint8_t* const probas) {
|
||||||
|
size_t size = 0;
|
||||||
|
const VP8Tokens* p = b->pages_;
|
||||||
|
if (b->error_) return 0;
|
||||||
|
while (p != NULL) {
|
||||||
|
const VP8Tokens* const next = p->next_;
|
||||||
|
const int N = (next == NULL) ? b->left_ : 0;
|
||||||
|
int n = MAX_NUM_TOKEN;
|
||||||
|
while (n-- > N) {
|
||||||
|
const uint16_t token = p->tokens_[n];
|
||||||
|
const int bit = token & (1 << 15);
|
||||||
|
if (token & FIXED_PROBA_BIT) {
|
||||||
|
size += VP8BitCost(bit, token & 0xffu);
|
||||||
|
} else {
|
||||||
|
size += VP8BitCost(bit, probas[token & 0x3fffu]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p = next;
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
#else // DISABLE_TOKEN_BUFFER
|
#else // DISABLE_TOKEN_BUFFER
|
||||||
|
@ -379,6 +379,9 @@ int VP8RecordCoeffTokens(int ctx, int coeff_type, int first, int last,
|
|||||||
const int16_t* const coeffs,
|
const int16_t* const coeffs,
|
||||||
VP8TBuffer* const tokens);
|
VP8TBuffer* const tokens);
|
||||||
|
|
||||||
|
// Estimate the final coded size given a set of 'probas'.
|
||||||
|
size_t VP8EstimateTokenSize(VP8TBuffer* const b, const uint8_t* const probas);
|
||||||
|
|
||||||
// unused for now
|
// unused for now
|
||||||
void VP8TokenToStats(const VP8TBuffer* const b, proba_t* const stats);
|
void VP8TokenToStats(const VP8TBuffer* const b, proba_t* const stats);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user