1 // Copyright 2011 Google Inc. All Rights Reserved.
3 // This code is licensed under the same terms as WebM:
4 // Software License Agreement: http://www.webmproject.org/license/software/
5 // Additional IP Rights Grant: http://www.webmproject.org/license/additional/
6 // -----------------------------------------------------------------------------
8 // Cost tables for level and modes.
10 // Author: Skal (pascal.massimino@gmail.com)
12 #ifndef WEBP_ENC_COST_H_
13 #define WEBP_ENC_COST_H_
15 #include "./vp8enci.h"
17 #if defined(__cplusplus) || defined(c_plusplus)
21 // approximate cost per level:
22 extern const uint16_t VP8LevelFixedCosts[MAX_LEVEL + 1];
23 extern const uint16_t VP8EntropyCost[256]; // 8bit fixed-point log(p)
25 // Cost of coding one event with probability 'proba'.
26 static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
27 return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
30 // Level cost calculations
31 extern const uint16_t VP8LevelCodes[MAX_VARIABLE_LEVEL][2];
32 void VP8CalculateLevelCosts(VP8Proba* const proba);
33 static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) {
34 return VP8LevelFixedCosts[level]
35 + table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level];
39 extern const uint16_t VP8FixedCostsUV[4];
40 extern const uint16_t VP8FixedCostsI16[4];
41 extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES];
43 //------------------------------------------------------------------------------
45 #if defined(__cplusplus) || defined(c_plusplus)
49 #endif /* WEBP_ENC_COST_H_ */