Index: third_party/libwebp/enc/token.c |
diff --git a/third_party/libwebp/enc/token.c b/third_party/libwebp/enc/token.c |
index 6a63371f71e90e81d1cc4dc8060aa8efd3eee6ba..e696642f168a60b198a5b0e6ce2451cf8fbbf3a9 100644 |
--- a/third_party/libwebp/enc/token.c |
+++ b/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 |