Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: third_party/libwebp/enc/cost.h

Issue 1546003002: libwebp: update to 0.5.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase around clang-cl fix Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2011 Google Inc. All Rights Reserved. 1 // Copyright 2011 Google Inc. All Rights Reserved.
2 // 2 //
3 // Use of this source code is governed by a BSD-style license 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 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 5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may 6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree. 7 // be found in the AUTHORS file in the root of the source tree.
8 // ----------------------------------------------------------------------------- 8 // -----------------------------------------------------------------------------
9 // 9 //
10 // Cost tables for level and modes. 10 // Cost tables for level and modes.
11 // 11 //
12 // Author: Skal (pascal.massimino@gmail.com) 12 // Author: Skal (pascal.massimino@gmail.com)
13 13
14 #ifndef WEBP_ENC_COST_H_ 14 #ifndef WEBP_ENC_COST_H_
15 #define WEBP_ENC_COST_H_ 15 #define WEBP_ENC_COST_H_
16 16
17 #include <assert.h> 17 #include <assert.h>
18 #include <stdlib.h> 18 #include <stdlib.h>
19 #include "./vp8enci.h" 19 #include "./vp8enci.h"
20 20
21 #ifdef __cplusplus 21 #ifdef __cplusplus
22 extern "C" { 22 extern "C" {
23 #endif 23 #endif
24 24
25 // On-the-fly info about the current set of residuals. Handy to avoid 25 // On-the-fly info about the current set of residuals. Handy to avoid
26 // passing zillions of params. 26 // passing zillions of params.
27 typedef struct { 27 typedef struct VP8Residual VP8Residual;
28 struct VP8Residual {
28 int first; 29 int first;
29 int last; 30 int last;
30 const int16_t* coeffs; 31 const int16_t* coeffs;
31 32
32 int coeff_type; 33 int coeff_type;
33 ProbaArray* prob; 34 ProbaArray* prob;
34 StatsArray* stats; 35 StatsArray* stats;
35 CostArray* cost; 36 CostArrayPtr costs;
36 } VP8Residual; 37 };
37 38
38 void VP8InitResidual(int first, int coeff_type, 39 void VP8InitResidual(int first, int coeff_type,
39 VP8Encoder* const enc, VP8Residual* const res); 40 VP8Encoder* const enc, VP8Residual* const res);
40 41
41 typedef void (*VP8SetResidualCoeffsFunc)(const int16_t* const coeffs,
42 VP8Residual* const res);
43 extern VP8SetResidualCoeffsFunc VP8SetResidualCoeffs;
44
45 void VP8SetResidualCoeffsInit(void); // must be called first
46
47 int VP8RecordCoeffs(int ctx, const VP8Residual* const res); 42 int VP8RecordCoeffs(int ctx, const VP8Residual* const res);
48 43
49 // approximate cost per level:
50 extern const uint16_t VP8LevelFixedCosts[MAX_LEVEL + 1];
51 extern const uint16_t VP8EntropyCost[256]; // 8bit fixed-point log(p)
52
53 // Cost of coding one event with probability 'proba'. 44 // Cost of coding one event with probability 'proba'.
54 static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) { 45 static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
55 return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba]; 46 return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
56 } 47 }
57 48
58 // Cost calculation function.
59 typedef int (*VP8GetResidualCostFunc)(int ctx0, const VP8Residual* const res);
60 extern VP8GetResidualCostFunc VP8GetResidualCost;
61
62 void VP8GetResidualCostInit(void); // must be called first
63
64 // Level cost calculations 49 // Level cost calculations
65 extern const uint16_t VP8LevelCodes[MAX_VARIABLE_LEVEL][2]; 50 extern const uint16_t VP8LevelCodes[MAX_VARIABLE_LEVEL][2];
66 void VP8CalculateLevelCosts(VP8Proba* const proba); 51 void VP8CalculateLevelCosts(VP8EncProba* const proba);
67 static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) { 52 static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) {
68 return VP8LevelFixedCosts[level] 53 return VP8LevelFixedCosts[level]
69 + table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level]; 54 + table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level];
70 } 55 }
71 56
72 // Mode costs 57 // Mode costs
73 extern const uint16_t VP8FixedCostsUV[4]; 58 extern const uint16_t VP8FixedCostsUV[4];
74 extern const uint16_t VP8FixedCostsI16[4]; 59 extern const uint16_t VP8FixedCostsI16[4];
75 extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES]; 60 extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES];
76 61
77 //------------------------------------------------------------------------------ 62 //------------------------------------------------------------------------------
78 63
79 #ifdef __cplusplus 64 #ifdef __cplusplus
80 } // extern "C" 65 } // extern "C"
81 #endif 66 #endif
82 67
83 #endif /* WEBP_ENC_COST_H_ */ 68 #endif /* WEBP_ENC_COST_H_ */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698