cost.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2011 Google Inc. All Rights Reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license
  4. // that can be found in the COPYING file in the root of the source
  5. // tree. An additional intellectual property rights grant can be found
  6. // in the file PATENTS. All contributing project authors may
  7. // be found in the AUTHORS file in the root of the source tree.
  8. // -----------------------------------------------------------------------------
  9. //
  10. // Cost tables for level and modes.
  11. //
  12. // Author: Skal (pascal.massimino@gmail.com)
  13. #ifndef WEBP_ENC_COST_H_
  14. #define WEBP_ENC_COST_H_
  15. #include <assert.h>
  16. #include <stdlib.h>
  17. #include "./vp8enci.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. // On-the-fly info about the current set of residuals. Handy to avoid
  22. // passing zillions of params.
  23. typedef struct {
  24. int first;
  25. int last;
  26. const int16_t* coeffs;
  27. int coeff_type;
  28. ProbaArray* prob;
  29. StatsArray* stats;
  30. CostArray* cost;
  31. } VP8Residual;
  32. void VP8InitResidual(int first, int coeff_type,
  33. VP8Encoder* const enc, VP8Residual* const res);
  34. typedef void (*VP8SetResidualCoeffsFunc)(const int16_t* const coeffs,
  35. VP8Residual* const res);
  36. extern VP8SetResidualCoeffsFunc VP8SetResidualCoeffs;
  37. void VP8SetResidualCoeffsInit(void); // must be called first
  38. int VP8RecordCoeffs(int ctx, const VP8Residual* const res);
  39. // approximate cost per level:
  40. extern const uint16_t VP8LevelFixedCosts[MAX_LEVEL + 1];
  41. extern const uint16_t VP8EntropyCost[256]; // 8bit fixed-point log(p)
  42. // Cost of coding one event with probability 'proba'.
  43. static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
  44. return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
  45. }
  46. // Cost calculation function.
  47. typedef int (*VP8GetResidualCostFunc)(int ctx0, const VP8Residual* const res);
  48. extern VP8GetResidualCostFunc VP8GetResidualCost;
  49. void VP8GetResidualCostInit(void); // must be called first
  50. // Level cost calculations
  51. extern const uint16_t VP8LevelCodes[MAX_VARIABLE_LEVEL][2];
  52. void VP8CalculateLevelCosts(VP8Proba* const proba);
  53. static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) {
  54. return VP8LevelFixedCosts[level]
  55. + table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level];
  56. }
  57. // Mode costs
  58. extern const uint16_t VP8FixedCostsUV[4];
  59. extern const uint16_t VP8FixedCostsI16[4];
  60. extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES];
  61. //------------------------------------------------------------------------------
  62. #ifdef __cplusplus
  63. } // extern "C"
  64. #endif
  65. #endif /* WEBP_ENC_COST_H_ */