Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/libwebp/src/enc/cost_enc.h
9913 views
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 ([email protected])
13
14
#ifndef WEBP_ENC_COST_ENC_H_
15
#define WEBP_ENC_COST_ENC_H_
16
17
#include <assert.h>
18
#include <stdlib.h>
19
#include "src/enc/vp8i_enc.h"
20
21
#ifdef __cplusplus
22
extern "C" {
23
#endif
24
25
// On-the-fly info about the current set of residuals. Handy to avoid
26
// passing zillions of params.
27
typedef struct VP8Residual VP8Residual;
28
struct VP8Residual {
29
int first;
30
int last;
31
const int16_t* coeffs;
32
33
int coeff_type;
34
ProbaArray* prob;
35
StatsArray* stats;
36
CostArrayPtr costs;
37
};
38
39
void VP8InitResidual(int first, int coeff_type,
40
VP8Encoder* const enc, VP8Residual* const res);
41
42
int VP8RecordCoeffs(int ctx, const VP8Residual* const res);
43
44
// Record proba context used.
45
static WEBP_INLINE int VP8RecordStats(int bit, proba_t* const stats) {
46
proba_t p = *stats;
47
// An overflow is inbound. Note we handle this at 0xfffe0000u instead of
48
// 0xffff0000u to make sure p + 1u does not overflow.
49
if (p >= 0xfffe0000u) {
50
p = ((p + 1u) >> 1) & 0x7fff7fffu; // -> divide the stats by 2.
51
}
52
// record bit count (lower 16 bits) and increment total count (upper 16 bits).
53
p += 0x00010000u + bit;
54
*stats = p;
55
return bit;
56
}
57
58
// Cost of coding one event with probability 'proba'.
59
static WEBP_INLINE int VP8BitCost(int bit, uint8_t proba) {
60
return !bit ? VP8EntropyCost[proba] : VP8EntropyCost[255 - proba];
61
}
62
63
// Level cost calculations
64
void VP8CalculateLevelCosts(VP8EncProba* const proba);
65
static WEBP_INLINE int VP8LevelCost(const uint16_t* const table, int level) {
66
return VP8LevelFixedCosts[level]
67
+ table[(level > MAX_VARIABLE_LEVEL) ? MAX_VARIABLE_LEVEL : level];
68
}
69
70
// Mode costs
71
extern const uint16_t VP8FixedCostsUV[4];
72
extern const uint16_t VP8FixedCostsI16[4];
73
extern const uint16_t VP8FixedCostsI4[NUM_BMODES][NUM_BMODES][NUM_BMODES];
74
75
//------------------------------------------------------------------------------
76
77
#ifdef __cplusplus
78
} // extern "C"
79
#endif
80
81
#endif // WEBP_ENC_COST_ENC_H_
82
83