Parent Directory
|
Revision Log
Revision 195 - (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 : | edgomez | 195 | static const uint32_t multipliers[32] = { |
52 : | 0, FIX(2), FIX(4), FIX(6), | ||
53 : | FIX(8), FIX(10), FIX(12), FIX(14), | ||
54 : | FIX(16), FIX(18), FIX(20), FIX(22), | ||
55 : | FIX(24), FIX(26), FIX(28), FIX(30), | ||
56 : | FIX(32), FIX(34), FIX(36), FIX(38), | ||
57 : | FIX(40), FIX(42), FIX(44), FIX(46), | ||
58 : | FIX(48), FIX(50), FIX(52), FIX(54), | ||
59 : | FIX(56), FIX(58), FIX(60), FIX(62) | ||
60 : | }; | ||
61 : | Isibaar | 3 | |
62 : | |||
63 : | |||
64 : | #define DIV_DIV(a, b) ((a)>0) ? ((a)+((b)>>1))/(b) : ((a)-((b)>>1))/(b) | ||
65 : | |||
66 : | // function pointers | ||
67 : | quanth263_intraFuncPtr quant_intra; | ||
68 : | quanth263_intraFuncPtr dequant_intra; | ||
69 : | |||
70 : | quanth263_interFuncPtr quant_inter; | ||
71 : | dequanth263_interFuncPtr dequant_inter; | ||
72 : | |||
73 : | |||
74 : | |||
75 : | /* quantize intra-block | ||
76 : | */ | ||
77 : | |||
78 : | |||
79 : | edgomez | 195 | void |
80 : | quant_intra_c(int16_t * coeff, | ||
81 : | const int16_t * data, | ||
82 : | const uint32_t quant, | ||
83 : | const uint32_t dcscalar) | ||
84 : | Isibaar | 3 | { |
85 : | const uint32_t mult = multipliers[quant]; | ||
86 : | const uint16_t quant_m_2 = quant << 1; | ||
87 : | edgomez | 195 | uint32_t i; |
88 : | Isibaar | 3 | |
89 : | edgomez | 195 | coeff[0] = DIV_DIV(data[0], (int32_t) dcscalar); |
90 : | Isibaar | 3 | |
91 : | for (i = 1; i < 64; i++) { | ||
92 : | int16_t acLevel = data[i]; | ||
93 : | |||
94 : | if (acLevel < 0) { | ||
95 : | acLevel = -acLevel; | ||
96 : | if (acLevel < quant_m_2) { | ||
97 : | coeff[i] = 0; | ||
98 : | continue; | ||
99 : | } | ||
100 : | acLevel = (acLevel * mult) >> SCALEBITS; | ||
101 : | coeff[i] = -acLevel; | ||
102 : | } else { | ||
103 : | if (acLevel < quant_m_2) { | ||
104 : | coeff[i] = 0; | ||
105 : | continue; | ||
106 : | } | ||
107 : | acLevel = (acLevel * mult) >> SCALEBITS; | ||
108 : | coeff[i] = acLevel; | ||
109 : | } | ||
110 : | } | ||
111 : | } | ||
112 : | |||
113 : | |||
114 : | /* quantize inter-block | ||
115 : | */ | ||
116 : | |||
117 : | edgomez | 195 | uint32_t |
118 : | quant_inter_c(int16_t * coeff, | ||
119 : | const int16_t * data, | ||
120 : | const uint32_t quant) | ||
121 : | Isibaar | 3 | { |
122 : | const uint32_t mult = multipliers[quant]; | ||
123 : | const uint16_t quant_m_2 = quant << 1; | ||
124 : | const uint16_t quant_d_2 = quant >> 1; | ||
125 : | int sum = 0; | ||
126 : | uint32_t i; | ||
127 : | |||
128 : | for (i = 0; i < 64; i++) { | ||
129 : | int16_t acLevel = data[i]; | ||
130 : | edgomez | 195 | |
131 : | Isibaar | 3 | if (acLevel < 0) { |
132 : | acLevel = (-acLevel) - quant_d_2; | ||
133 : | if (acLevel < quant_m_2) { | ||
134 : | coeff[i] = 0; | ||
135 : | continue; | ||
136 : | } | ||
137 : | |||
138 : | acLevel = (acLevel * mult) >> SCALEBITS; | ||
139 : | sum += acLevel; // sum += |acLevel| | ||
140 : | coeff[i] = -acLevel; | ||
141 : | } else { | ||
142 : | acLevel -= quant_d_2; | ||
143 : | if (acLevel < quant_m_2) { | ||
144 : | coeff[i] = 0; | ||
145 : | continue; | ||
146 : | } | ||
147 : | acLevel = (acLevel * mult) >> SCALEBITS; | ||
148 : | sum += acLevel; | ||
149 : | coeff[i] = acLevel; | ||
150 : | } | ||
151 : | } | ||
152 : | |||
153 : | return sum; | ||
154 : | } | ||
155 : | |||
156 : | |||
157 : | /* dequantize intra-block & clamp to [-2048,2047] | ||
158 : | */ | ||
159 : | |||
160 : | edgomez | 195 | void |
161 : | dequant_intra_c(int16_t * data, | ||
162 : | const int16_t * coeff, | ||
163 : | const uint32_t quant, | ||
164 : | const uint32_t dcscalar) | ||
165 : | Isibaar | 3 | { |
166 : | const int32_t quant_m_2 = quant << 1; | ||
167 : | const int32_t quant_add = (quant & 1 ? quant : quant - 1); | ||
168 : | edgomez | 195 | uint32_t i; |
169 : | Isibaar | 3 | |
170 : | edgomez | 195 | data[0] = coeff[0] * dcscalar; |
171 : | if (data[0] < -2048) { | ||
172 : | Isibaar | 3 | data[0] = -2048; |
173 : | edgomez | 195 | } else if (data[0] > 2047) { |
174 : | Isibaar | 3 | data[0] = 2047; |
175 : | } | ||
176 : | |||
177 : | |||
178 : | for (i = 1; i < 64; i++) { | ||
179 : | int32_t acLevel = coeff[i]; | ||
180 : | edgomez | 195 | |
181 : | if (acLevel == 0) { | ||
182 : | Isibaar | 3 | data[i] = 0; |
183 : | edgomez | 195 | } else if (acLevel < 0) { |
184 : | Isibaar | 3 | acLevel = quant_m_2 * -acLevel + quant_add; |
185 : | data[i] = (acLevel <= 2048 ? -acLevel : -2048); | ||
186 : | edgomez | 195 | } else // if (acLevel > 0) { |
187 : | { | ||
188 : | Isibaar | 3 | acLevel = quant_m_2 * acLevel + quant_add; |
189 : | data[i] = (acLevel <= 2047 ? acLevel : 2047); | ||
190 : | } | ||
191 : | } | ||
192 : | } | ||
193 : | |||
194 : | |||
195 : | |||
196 : | /* dequantize inter-block & clamp to [-2048,2047] | ||
197 : | */ | ||
198 : | |||
199 : | edgomez | 195 | void |
200 : | dequant_inter_c(int16_t * data, | ||
201 : | const int16_t * coeff, | ||
202 : | const uint32_t quant) | ||
203 : | Isibaar | 3 | { |
204 : | const uint16_t quant_m_2 = quant << 1; | ||
205 : | const uint16_t quant_add = (quant & 1 ? quant : quant - 1); | ||
206 : | uint32_t i; | ||
207 : | |||
208 : | for (i = 0; i < 64; i++) { | ||
209 : | int16_t acLevel = coeff[i]; | ||
210 : | edgomez | 195 | |
211 : | if (acLevel == 0) { | ||
212 : | Isibaar | 3 | data[i] = 0; |
213 : | edgomez | 195 | } else if (acLevel < 0) { |
214 : | Isibaar | 3 | acLevel = acLevel * quant_m_2 - quant_add; |
215 : | data[i] = (acLevel >= -2048 ? acLevel : -2048); | ||
216 : | edgomez | 195 | } else // if (acLevel > 0) |
217 : | { | ||
218 : | Isibaar | 3 | acLevel = acLevel * quant_m_2 + quant_add; |
219 : | data[i] = (acLevel <= 2047 ? acLevel : 2047); | ||
220 : | } | ||
221 : | } | ||
222 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |