15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright 2011 Google Inc. All Rights Reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// Use of this source code is governed by a BSD-style license
4eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// that can be found in the COPYING file in the root of the source
5eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// tree. An additional intellectual property rights grant can be found
6eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// in the file PATENTS. All contributing project authors may
7eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch// be found in the AUTHORS file in the root of the source tree.
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// -----------------------------------------------------------------------------
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Cost tables for level and modes.
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Author: Skal (pascal.massimino@gmail.com)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef WEBP_ENC_COST_H_
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define WEBP_ENC_COST_H_
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "./vp8enci.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(__cplusplus) || defined(c_plusplus)
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern "C" {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
23c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// approximate cost per level:
24c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)extern const uint16_t VP8LevelFixedCosts[MAX_LEVEL + 1];
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern const uint16_t VP8EntropyCost[256];        // 8bit fixed-point log(p)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Cost of coding one event with probability 'proba'.
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Level cost calculations
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern const uint16_t VP8LevelCodes[MAX_VARIABLE_LEVEL][2];
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void VP8CalculateLevelCosts(VP8Proba* const proba);
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) {
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return VP8LevelFixedCosts[level]
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)       + table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level];
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Mode costs
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern const uint16_t VP8FixedCostsUV[4];
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern const uint16_t VP8FixedCostsI16[4];
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES];
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//------------------------------------------------------------------------------
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(__cplusplus) || defined(c_plusplus)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}    // extern "C"
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  /* WEBP_ENC_COST_H_ */
52