1// Copyright 2011 Google Inc. 2// 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// ----------------------------------------------------------------------------- 7// 8// Cost tables for level and modes. 9// 10// Author: Skal (pascal.massimino@gmail.com) 11 12#ifndef WEBP_ENC_COST_H_ 13#define WEBP_ENC_COST_H_ 14 15#include "vp8enci.h" 16 17#if defined(__cplusplus) || defined(c_plusplus) 18extern "C" { 19#endif 20 21extern const uint16_t VP8LevelFixedCosts[2048]; // approximate cost per level 22extern const uint16_t VP8EntropyCost[256]; // 8bit fixed-point log(p) 23 24// Cost of coding one event with probability 'proba'. 25static inline int VP8BitCost(int bit, uint8_t proba) { 26 return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba]; 27} 28 29// Cost of coding 'nb' 1's and 'total-nb' 0's using 'proba' probability. 30static inline uint64_t VP8BranchCost(uint64_t nb, uint64_t total, uint8_t proba) { 31 return nb * VP8BitCost(1, proba) + (total - nb) * VP8BitCost(0, proba); 32} 33 34// Level cost calculations 35void VP8CalculateLevelCosts(VP8Proba* const proba); 36static inline int VP8LevelCost(const uint16_t* const table, int level) { 37 return VP8LevelFixedCosts[level] 38 + table[level > MAX_VARIABLE_LEVEL ? MAX_VARIABLE_LEVEL : level]; 39} 40 41// Mode costs 42extern const uint16_t VP8FixedCostsUV[4]; 43extern const uint16_t VP8FixedCostsI16[4]; 44extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES]; 45 46//----------------------------------------------------------------------------- 47 48#if defined(__cplusplus) || defined(c_plusplus) 49} // extern "C" 50#endif 51 52#endif // WEBP_ENC_COST_H_ 53