Parent Directory
|
Revision Log
Revision 3 - (view) (download)
1 : | Isibaar | 3 | /************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | * quantization/dequantization | ||
5 : | * | ||
6 : | * This program is an implementation of a part of one or more MPEG-4 | ||
7 : | * Video tools as specified in ISO/IEC 14496-2 standard. Those intending | ||
8 : | * to use this software module in hardware or software products are | ||
9 : | * advised that its use may infringe existing patents or copyrights, and | ||
10 : | * any such use would be at such party's own risk. The original | ||
11 : | * developer of this software module and his/her company, and subsequent | ||
12 : | * editors and their companies, will have no liability for use of this | ||
13 : | * software or modifications or derivatives thereof. | ||
14 : | * | ||
15 : | * This program is free software; you can redistribute it and/or modify | ||
16 : | * it under the terms of the GNU General Public License as published by | ||
17 : | * the Free Software Foundation; either version 2 of the License, or | ||
18 : | * (at your option) any later version. | ||
19 : | * | ||
20 : | * This program is distributed in the hope that it will be useful, | ||
21 : | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
22 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
23 : | * GNU General Public License for more details. | ||
24 : | * | ||
25 : | * You should have received a copy of the GNU General Public License | ||
26 : | * along with this program; if not, write to the Free Software | ||
27 : | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
28 : | * | ||
29 : | *************************************************************************/ | ||
30 : | |||
31 : | /************************************************************************** | ||
32 : | * | ||
33 : | * History: | ||
34 : | * | ||
35 : | * 26.12.2001 dequant_inter bug fix | ||
36 : | * 22.12.2001 clamp dequant output to [-2048,2047] | ||
37 : | * 19.11.2001 quant_inter now returns sum of abs. coefficient values | ||
38 : | * 02.11.2001 added const to function args <pross@cs.rmit.edu.au> | ||
39 : | * 28.10.2001 total rewrite <pross@cs.rmit.edu.au> | ||
40 : | * | ||
41 : | *************************************************************************/ | ||
42 : | |||
43 : | #include "quant_h263.h" | ||
44 : | |||
45 : | /* mutliply+shift division table | ||
46 : | */ | ||
47 : | |||
48 : | #define SCALEBITS 16 | ||
49 : | #define FIX(X) ((1L << SCALEBITS) / (X) + 1) | ||
50 : | |||
51 : | static const uint32_t multipliers[32] = | ||
52 : | { | ||
53 : | 0, FIX(2), FIX(4), FIX(6), | ||
54 : | FIX(8), FIX(10), FIX(12), FIX(14), | ||
55 : | FIX(16), FIX(18), FIX(20), FIX(22), | ||
56 : | FIX(24), FIX(26), FIX(28), FIX(30), | ||
57 : | FIX(32), FIX(34), FIX(36), FIX(38), | ||
58 : | FIX(40), FIX(42), FIX(44), FIX(46), | ||
59 : | FIX(48), FIX(50), FIX(52), FIX(54), | ||
60 : | FIX(56), FIX(58), FIX(60), FIX(62) | ||
61 : | }; | ||
62 : | |||
63 : | |||
64 : | |||
65 : | #define DIV_DIV(a, b) ((a)>0) ? ((a)+((b)>>1))/(b) : ((a)-((b)>>1))/(b) | ||
66 : | |||
67 : | // function pointers | ||
68 : | quanth263_intraFuncPtr quant_intra; | ||
69 : | quanth263_intraFuncPtr dequant_intra; | ||
70 : | |||
71 : | quanth263_interFuncPtr quant_inter; | ||
72 : | dequanth263_interFuncPtr dequant_inter; | ||
73 : | |||
74 : | |||
75 : | |||
76 : | /* quantize intra-block | ||
77 : | */ | ||
78 : | |||
79 : | |||
80 : | void quant_intra_c(int16_t * coeff, const int16_t * data, const uint32_t quant, const uint32_t dcscalar) | ||
81 : | { | ||
82 : | const uint32_t mult = multipliers[quant]; | ||
83 : | const uint16_t quant_m_2 = quant << 1; | ||
84 : | uint32_t i; | ||
85 : | |||
86 : | coeff[0] = DIV_DIV(data[0], (int32_t)dcscalar); | ||
87 : | |||
88 : | for (i = 1; i < 64; i++) { | ||
89 : | int16_t acLevel = data[i]; | ||
90 : | |||
91 : | if (acLevel < 0) { | ||
92 : | acLevel = -acLevel; | ||
93 : | if (acLevel < quant_m_2) { | ||
94 : | coeff[i] = 0; | ||
95 : | continue; | ||
96 : | } | ||
97 : | acLevel = (acLevel * mult) >> SCALEBITS; | ||
98 : | coeff[i] = -acLevel; | ||
99 : | } else { | ||
100 : | if (acLevel < quant_m_2) { | ||
101 : | coeff[i] = 0; | ||
102 : | continue; | ||
103 : | } | ||
104 : | acLevel = (acLevel * mult) >> SCALEBITS; | ||
105 : | coeff[i] = acLevel; | ||
106 : | } | ||
107 : | } | ||
108 : | } | ||
109 : | |||
110 : | |||
111 : | /* quantize inter-block | ||
112 : | */ | ||
113 : | |||
114 : | uint32_t quant_inter_c(int16_t *coeff, const int16_t *data, const uint32_t quant) | ||
115 : | { | ||
116 : | const uint32_t mult = multipliers[quant]; | ||
117 : | const uint16_t quant_m_2 = quant << 1; | ||
118 : | const uint16_t quant_d_2 = quant >> 1; | ||
119 : | int sum = 0; | ||
120 : | uint32_t i; | ||
121 : | |||
122 : | for (i = 0; i < 64; i++) { | ||
123 : | int16_t acLevel = data[i]; | ||
124 : | |||
125 : | if (acLevel < 0) { | ||
126 : | acLevel = (-acLevel) - quant_d_2; | ||
127 : | if (acLevel < quant_m_2) { | ||
128 : | coeff[i] = 0; | ||
129 : | continue; | ||
130 : | } | ||
131 : | |||
132 : | acLevel = (acLevel * mult) >> SCALEBITS; | ||
133 : | sum += acLevel; // sum += |acLevel| | ||
134 : | coeff[i] = -acLevel; | ||
135 : | } else { | ||
136 : | acLevel -= quant_d_2; | ||
137 : | if (acLevel < quant_m_2) { | ||
138 : | coeff[i] = 0; | ||
139 : | continue; | ||
140 : | } | ||
141 : | acLevel = (acLevel * mult) >> SCALEBITS; | ||
142 : | sum += acLevel; | ||
143 : | coeff[i] = acLevel; | ||
144 : | } | ||
145 : | } | ||
146 : | |||
147 : | return sum; | ||
148 : | } | ||
149 : | |||
150 : | |||
151 : | /* dequantize intra-block & clamp to [-2048,2047] | ||
152 : | */ | ||
153 : | |||
154 : | void dequant_intra_c(int16_t *data, const int16_t *coeff, const uint32_t quant, const uint32_t dcscalar) | ||
155 : | { | ||
156 : | const int32_t quant_m_2 = quant << 1; | ||
157 : | const int32_t quant_add = (quant & 1 ? quant : quant - 1); | ||
158 : | uint32_t i; | ||
159 : | |||
160 : | data[0] = coeff[0] * dcscalar; | ||
161 : | if (data[0] < -2048) | ||
162 : | { | ||
163 : | data[0] = -2048; | ||
164 : | } | ||
165 : | else if (data[0] > 2047) | ||
166 : | { | ||
167 : | data[0] = 2047; | ||
168 : | } | ||
169 : | |||
170 : | |||
171 : | for (i = 1; i < 64; i++) { | ||
172 : | int32_t acLevel = coeff[i]; | ||
173 : | if (acLevel == 0) | ||
174 : | { | ||
175 : | data[i] = 0; | ||
176 : | } | ||
177 : | else if (acLevel < 0) | ||
178 : | { | ||
179 : | acLevel = quant_m_2 * -acLevel + quant_add; | ||
180 : | data[i] = (acLevel <= 2048 ? -acLevel : -2048); | ||
181 : | } | ||
182 : | else // if (acLevel > 0) { | ||
183 : | { | ||
184 : | acLevel = quant_m_2 * acLevel + quant_add; | ||
185 : | data[i] = (acLevel <= 2047 ? acLevel : 2047); | ||
186 : | } | ||
187 : | } | ||
188 : | } | ||
189 : | |||
190 : | |||
191 : | |||
192 : | /* dequantize inter-block & clamp to [-2048,2047] | ||
193 : | */ | ||
194 : | |||
195 : | void dequant_inter_c(int16_t *data, const int16_t *coeff, const uint32_t quant) | ||
196 : | { | ||
197 : | const uint16_t quant_m_2 = quant << 1; | ||
198 : | const uint16_t quant_add = (quant & 1 ? quant : quant - 1); | ||
199 : | uint32_t i; | ||
200 : | |||
201 : | for (i = 0; i < 64; i++) { | ||
202 : | int16_t acLevel = coeff[i]; | ||
203 : | |||
204 : | if (acLevel == 0) | ||
205 : | { | ||
206 : | data[i] = 0; | ||
207 : | } | ||
208 : | else if (acLevel < 0) | ||
209 : | { | ||
210 : | acLevel = acLevel * quant_m_2 - quant_add; | ||
211 : | data[i] = (acLevel >= -2048 ? acLevel : -2048); | ||
212 : | } | ||
213 : | else // if (acLevel > 0) | ||
214 : | { | ||
215 : | acLevel = acLevel * quant_m_2 + quant_add; | ||
216 : | data[i] = (acLevel <= 2047 ? acLevel : 2047); | ||
217 : | } | ||
218 : | } | ||
219 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |