summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/libwebp/enc/token.c
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/libwebp/enc/token.c')
-rw-r--r--chromium/third_party/libwebp/enc/token.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/chromium/third_party/libwebp/enc/token.c b/chromium/third_party/libwebp/enc/token.c
index 6a63371f71e..e696642f168 100644
--- a/chromium/third_party/libwebp/enc/token.c
+++ b/chromium/third_party/libwebp/enc/token.c
@@ -20,12 +20,9 @@
#include <stdlib.h>
#include <string.h>
+#include "./cost.h"
#include "./vp8enci.h"
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
#if !defined(DISABLE_TOKEN_BUFFER)
// we use pages to reduce the number of memcpy()
@@ -238,6 +235,29 @@ int VP8EmitTokens(VP8TBuffer* const b, VP8BitWriter* const bw,
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
@@ -251,6 +271,3 @@ void VP8TBufferClear(VP8TBuffer* const b) {
#endif // !DISABLE_TOKEN_BUFFER
-#if defined(__cplusplus) || defined(c_plusplus)
-} // extern "C"
-#endif