/src/libvpx/vp8/common/quant_common.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 | | * |
4 | | * Use of this source code is governed by a BSD-style license |
5 | | * that can be found in the LICENSE file in the root of the source |
6 | | * tree. An additional intellectual property rights grant can be found |
7 | | * in the file PATENTS. All contributing project authors may |
8 | | * be found in the AUTHORS file in the root of the source tree. |
9 | | */ |
10 | | |
11 | | #include "quant_common.h" |
12 | | |
13 | | static const int dc_qlookup[QINDEX_RANGE] = { |
14 | | 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, |
15 | | 17, 18, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, |
16 | | 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, |
17 | | 41, 42, 43, 44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54, |
18 | | 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, |
19 | | 70, 71, 72, 73, 74, 75, 76, 76, 77, 78, 79, 80, 81, 82, 83, |
20 | | 84, 85, 86, 87, 88, 89, 91, 93, 95, 96, 98, 100, 101, 102, 104, |
21 | | 106, 108, 110, 112, 114, 116, 118, 122, 124, 126, 128, 130, 132, 134, 136, |
22 | | 138, 140, 143, 145, 148, 151, 154, 157, |
23 | | }; |
24 | | |
25 | | static const int ac_qlookup[QINDEX_RANGE] = { |
26 | | 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, |
27 | | 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, |
28 | | 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, |
29 | | 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 62, 64, 66, 68, |
30 | | 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, |
31 | | 100, 102, 104, 106, 108, 110, 112, 114, 116, 119, 122, 125, 128, 131, 134, |
32 | | 137, 140, 143, 146, 149, 152, 155, 158, 161, 164, 167, 170, 173, 177, 181, |
33 | | 185, 189, 193, 197, 201, 205, 209, 213, 217, 221, 225, 229, 234, 239, 245, |
34 | | 249, 254, 259, 264, 269, 274, 279, 284, |
35 | | }; |
36 | | |
37 | 2.20M | int vp8_dc_quant(int QIndex, int Delta) { |
38 | 2.20M | int retval; |
39 | | |
40 | 2.20M | QIndex = QIndex + Delta; |
41 | | |
42 | 2.20M | if (QIndex > 127) { |
43 | 0 | QIndex = 127; |
44 | 2.20M | } else if (QIndex < 0) { |
45 | 0 | QIndex = 0; |
46 | 0 | } |
47 | | |
48 | 2.20M | retval = dc_qlookup[QIndex]; |
49 | 2.20M | return retval; |
50 | 2.20M | } |
51 | | |
52 | 1.56M | int vp8_dc2quant(int QIndex, int Delta) { |
53 | 1.56M | int retval; |
54 | | |
55 | 1.56M | QIndex = QIndex + Delta; |
56 | | |
57 | 1.56M | if (QIndex > 127) { |
58 | 0 | QIndex = 127; |
59 | 1.56M | } else if (QIndex < 0) { |
60 | 0 | QIndex = 0; |
61 | 0 | } |
62 | | |
63 | 1.56M | retval = dc_qlookup[QIndex] * 2; |
64 | 1.56M | return retval; |
65 | 1.56M | } |
66 | 1.56M | int vp8_dc_uv_quant(int QIndex, int Delta) { |
67 | 1.56M | int retval; |
68 | | |
69 | 1.56M | QIndex = QIndex + Delta; |
70 | | |
71 | 1.56M | if (QIndex > 127) { |
72 | 0 | QIndex = 127; |
73 | 1.56M | } else if (QIndex < 0) { |
74 | 0 | QIndex = 0; |
75 | 0 | } |
76 | | |
77 | 1.56M | retval = dc_qlookup[QIndex]; |
78 | | |
79 | 1.56M | if (retval > 132) retval = 132; |
80 | | |
81 | 1.56M | return retval; |
82 | 1.56M | } |
83 | | |
84 | 1.56M | int vp8_ac_yquant(int QIndex) { |
85 | 1.56M | int retval; |
86 | | |
87 | 1.56M | if (QIndex > 127) { |
88 | 0 | QIndex = 127; |
89 | 1.56M | } else if (QIndex < 0) { |
90 | 0 | QIndex = 0; |
91 | 0 | } |
92 | | |
93 | 1.56M | retval = ac_qlookup[QIndex]; |
94 | 1.56M | return retval; |
95 | 1.56M | } |
96 | | |
97 | 1.56M | int vp8_ac2quant(int QIndex, int Delta) { |
98 | 1.56M | int retval; |
99 | | |
100 | 1.56M | QIndex = QIndex + Delta; |
101 | | |
102 | 1.56M | if (QIndex > 127) { |
103 | 0 | QIndex = 127; |
104 | 1.56M | } else if (QIndex < 0) { |
105 | 0 | QIndex = 0; |
106 | 0 | } |
107 | | |
108 | | /* For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16. |
109 | | * The smallest precision for that is '(x*6349) >> 12' but 16 is a good |
110 | | * word size. */ |
111 | 1.56M | retval = (ac_qlookup[QIndex] * 101581) >> 16; |
112 | | |
113 | 1.56M | if (retval < 8) retval = 8; |
114 | | |
115 | 1.56M | return retval; |
116 | 1.56M | } |
117 | 1.56M | int vp8_ac_uv_quant(int QIndex, int Delta) { |
118 | 1.56M | int retval; |
119 | | |
120 | 1.56M | QIndex = QIndex + Delta; |
121 | | |
122 | 1.56M | if (QIndex > 127) { |
123 | 0 | QIndex = 127; |
124 | 1.56M | } else if (QIndex < 0) { |
125 | 0 | QIndex = 0; |
126 | 0 | } |
127 | | |
128 | 1.56M | retval = ac_qlookup[QIndex]; |
129 | 1.56M | return retval; |
130 | 1.56M | } |