Parent Directory | Revision Log
Revision 1.10 - (view) (download)
1 : | Isibaar | 1.1 | /****************************************************************************** |
2 : | * * | ||
3 : | * This file is part of XviD, a free MPEG-4 video encoder/decoder * | ||
4 : | * * | ||
5 : | * XviD is an implementation of a part of one or more MPEG-4 Video tools * | ||
6 : | * as specified in ISO/IEC 14496-2 standard. Those intending to use this * | ||
7 : | * software module in hardware or software products are advised that its * | ||
8 : | * use may infringe existing patents or copyrights, and any such use * | ||
9 : | * would be at such party's own risk. The original developer of this * | ||
10 : | * software module and his/her company, and subsequent editors and their * | ||
11 : | * companies, will have no liability for use of this software or * | ||
12 : | * modifications or derivatives thereof. * | ||
13 : | * * | ||
14 : | * XviD is free software; you can redistribute it and/or modify it * | ||
15 : | * under the terms of the GNU General Public License as published by * | ||
16 : | * the Free Software Foundation; either version 2 of the License, or * | ||
17 : | * (at your option) any later version. * | ||
18 : | * * | ||
19 : | * XviD is distributed in the hope that it will be useful, but * | ||
20 : | * WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
21 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
22 : | * GNU General Public License for more details. * | ||
23 : | * * | ||
24 : | * You should have received a copy of the GNU General Public License * | ||
25 : | * along with this program; if not, write to the Free Software * | ||
26 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | ||
27 : | * * | ||
28 : | ******************************************************************************/ | ||
29 : | |||
30 : | /****************************************************************************** | ||
31 : | * * | ||
32 : | * mbtransquant.c * | ||
33 : | * * | ||
34 : | * Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au> * | ||
35 : | * Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org> * | ||
36 : | * * | ||
37 : | * For more information visit the XviD homepage: http://www.xvid.org * | ||
38 : | * * | ||
39 : | ******************************************************************************/ | ||
40 : | |||
41 : | /****************************************************************************** | ||
42 : | * * | ||
43 : | * Revision history: * | ||
44 : | * * | ||
45 : | Isibaar | 1.9 | * 29.03.2002 interlacing speedup - used transfer strides instead of * |
46 : | * manual field-to-frame conversion * | ||
47 : | * 26.03.2002 interlacing support - moved transfers outside loops * | ||
48 : | * 22.12.2001 get_dc_scaler() moved to common.h * | ||
49 : | Isibaar | 1.1 | * 19.11.2001 introduced coefficient thresholding (Isibaar) * |
50 : | * 17.11.2001 initial version * | ||
51 : | * * | ||
52 : | ******************************************************************************/ | ||
53 : | |||
54 : | edgomez | 1.3 | #include <string.h> |
55 : | |||
56 : | Isibaar | 1.1 | #include "../portab.h" |
57 : | #include "mbfunctions.h" | ||
58 : | |||
59 : | #include "../global.h" | ||
60 : | #include "mem_transfer.h" | ||
61 : | #include "timer.h" | ||
62 : | #include "../dct/fdct.h" | ||
63 : | #include "../dct/idct.h" | ||
64 : | #include "../quant/quant_mpeg4.h" | ||
65 : | #include "../quant/quant_h263.h" | ||
66 : | #include "../encoder.h" | ||
67 : | |||
68 : | #define MIN(X, Y) ((X)<(Y)?(X):(Y)) | ||
69 : | #define MAX(X, Y) ((X)>(Y)?(X):(Y)) | ||
70 : | |||
71 : | Isibaar | 1.9 | #define TOOSMALL_LIMIT 3 /* skip blocks having a coefficient sum below this value */ |
72 : | Isibaar | 1.1 | |
73 : | /* this isnt pretty, but its better than 20 ifdefs */ | ||
74 : | |||
75 : | edgomez | 1.7 | void |
76 : | MBTransQuantIntra(const MBParam * pParam, | ||
77 : | FRAMEINFO * frame, | ||
78 : | MACROBLOCK * pMB, | ||
79 : | const uint32_t x_pos, | ||
80 : | const uint32_t y_pos, | ||
81 : | int16_t data[6 * 64], | ||
82 : | int16_t qcoeff[6 * 64]) | ||
83 : | Isibaar | 1.1 | { |
84 : | edgomez | 1.3 | |
85 : | h | 1.4 | uint32_t stride = pParam->edged_width; |
86 : | uint32_t stride2 = stride / 2; | ||
87 : | uint32_t next_block = stride * 8; | ||
88 : | Isibaar | 1.1 | uint32_t i; |
89 : | suxen_drol | 1.6 | uint32_t iQuant = frame->quant; |
90 : | Isibaar | 1.1 | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
91 : | edgomez | 1.7 | IMAGE *pCurrent = &frame->image; |
92 : | Isibaar | 1.1 | |
93 : | edgomez | 1.3 | pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
94 : | h | 1.4 | pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
95 : | pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
96 : | h | 1.2 | |
97 : | start_timer(); | ||
98 : | edgomez | 1.7 | transfer_8to16copy(&data[0 * 64], pY_Cur, stride); |
99 : | transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride); | ||
100 : | transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride); | ||
101 : | transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride); | ||
102 : | transfer_8to16copy(&data[4 * 64], pU_Cur, stride2); | ||
103 : | transfer_8to16copy(&data[5 * 64], pV_Cur, stride2); | ||
104 : | h | 1.2 | stop_transfer_timer(); |
105 : | |||
106 : | start_timer(); | ||
107 : | pMB->field_dct = 0; | ||
108 : | edgomez | 1.7 | if ((frame->global_flags & XVID_INTERLACING)) { |
109 : | h | 1.2 | pMB->field_dct = MBDecideFieldDCT(data); |
110 : | } | ||
111 : | stop_interlacing_timer(); | ||
112 : | |||
113 : | edgomez | 1.7 | for (i = 0; i < 6; i++) { |
114 : | Isibaar | 1.1 | uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); |
115 : | |||
116 : | start_timer(); | ||
117 : | edgomez | 1.7 | fdct(&data[i * 64]); |
118 : | Isibaar | 1.1 | stop_dct_timer(); |
119 : | |||
120 : | edgomez | 1.7 | if (pParam->m_quant_type == H263_QUANT) { |
121 : | Isibaar | 1.1 | start_timer(); |
122 : | edgomez | 1.7 | quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
123 : | Isibaar | 1.1 | stop_quant_timer(); |
124 : | |||
125 : | start_timer(); | ||
126 : | edgomez | 1.7 | dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); |
127 : | Isibaar | 1.1 | stop_iquant_timer(); |
128 : | edgomez | 1.7 | } else { |
129 : | Isibaar | 1.1 | start_timer(); |
130 : | edgomez | 1.7 | quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); |
131 : | Isibaar | 1.1 | stop_quant_timer(); |
132 : | |||
133 : | start_timer(); | ||
134 : | edgomez | 1.7 | dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); |
135 : | Isibaar | 1.1 | stop_iquant_timer(); |
136 : | } | ||
137 : | |||
138 : | start_timer(); | ||
139 : | edgomez | 1.7 | idct(&data[i * 64]); |
140 : | Isibaar | 1.1 | stop_idct_timer(); |
141 : | edgomez | 1.3 | } |
142 : | h | 1.2 | |
143 : | edgomez | 1.7 | if (pMB->field_dct) { |
144 : | h | 1.4 | next_block = stride; |
145 : | stride *= 2; | ||
146 : | h | 1.2 | } |
147 : | Isibaar | 1.1 | |
148 : | h | 1.2 | start_timer(); |
149 : | edgomez | 1.7 | transfer_16to8copy(pY_Cur, &data[0 * 64], stride); |
150 : | transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride); | ||
151 : | transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride); | ||
152 : | transfer_16to8copy(pY_Cur + next_block + 8, &data[3 * 64], stride); | ||
153 : | transfer_16to8copy(pU_Cur, &data[4 * 64], stride2); | ||
154 : | transfer_16to8copy(pV_Cur, &data[5 * 64], stride2); | ||
155 : | h | 1.2 | stop_transfer_timer(); |
156 : | edgomez | 1.3 | |
157 : | Isibaar | 1.1 | } |
158 : | |||
159 : | |||
160 : | edgomez | 1.7 | uint8_t |
161 : | MBTransQuantInter(const MBParam * pParam, | ||
162 : | FRAMEINFO * frame, | ||
163 : | MACROBLOCK * pMB, | ||
164 : | const uint32_t x_pos, | ||
165 : | const uint32_t y_pos, | ||
166 : | int16_t data[6 * 64], | ||
167 : | int16_t qcoeff[6 * 64]) | ||
168 : | Isibaar | 1.1 | { |
169 : | edgomez | 1.3 | |
170 : | h | 1.4 | uint32_t stride = pParam->edged_width; |
171 : | uint32_t stride2 = stride / 2; | ||
172 : | uint32_t next_block = stride * 8; | ||
173 : | edgomez | 1.3 | uint32_t i; |
174 : | suxen_drol | 1.6 | uint32_t iQuant = frame->quant; |
175 : | Isibaar | 1.1 | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; |
176 : | edgomez | 1.3 | uint8_t cbp = 0; |
177 : | Isibaar | 1.1 | uint32_t sum; |
178 : | edgomez | 1.7 | IMAGE *pCurrent = &frame->image; |
179 : | |||
180 : | edgomez | 1.3 | pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); |
181 : | h | 1.4 | pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); |
182 : | pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
183 : | Isibaar | 1.1 | |
184 : | h | 1.2 | start_timer(); |
185 : | pMB->field_dct = 0; | ||
186 : | edgomez | 1.7 | if ((frame->global_flags & XVID_INTERLACING)) { |
187 : | h | 1.2 | pMB->field_dct = MBDecideFieldDCT(data); |
188 : | } | ||
189 : | stop_interlacing_timer(); | ||
190 : | |||
191 : | edgomez | 1.7 | for (i = 0; i < 6; i++) { |
192 : | Isibaar | 1.1 | /* |
193 : | edgomez | 1.3 | * no need to transfer 8->16-bit |
194 : | * (this is performed already in motion compensation) | ||
195 : | */ | ||
196 : | Isibaar | 1.1 | start_timer(); |
197 : | edgomez | 1.7 | fdct(&data[i * 64]); |
198 : | Isibaar | 1.1 | stop_dct_timer(); |
199 : | |||
200 : | edgomez | 1.7 | if (pParam->m_quant_type == 0) { |
201 : | Isibaar | 1.1 | start_timer(); |
202 : | edgomez | 1.7 | sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant); |
203 : | Isibaar | 1.1 | stop_quant_timer(); |
204 : | edgomez | 1.7 | } else { |
205 : | Isibaar | 1.1 | start_timer(); |
206 : | edgomez | 1.7 | sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant); |
207 : | Isibaar | 1.1 | stop_quant_timer(); |
208 : | } | ||
209 : | |||
210 : | Isibaar | 1.9 | if ((sum >= TOOSMALL_LIMIT) || (qcoeff[i*64] != 0) || |
211 : | (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) { | ||
212 : | Isibaar | 1.1 | |
213 : | edgomez | 1.7 | if (pParam->m_quant_type == H263_QUANT) { |
214 : | Isibaar | 1.1 | start_timer(); |
215 : | edgomez | 1.7 | dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant); |
216 : | Isibaar | 1.1 | stop_iquant_timer(); |
217 : | edgomez | 1.7 | } else { |
218 : | Isibaar | 1.1 | start_timer(); |
219 : | edgomez | 1.7 | dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant); |
220 : | Isibaar | 1.1 | stop_iquant_timer(); |
221 : | } | ||
222 : | |||
223 : | cbp |= 1 << (5 - i); | ||
224 : | |||
225 : | start_timer(); | ||
226 : | edgomez | 1.7 | idct(&data[i * 64]); |
227 : | Isibaar | 1.1 | stop_idct_timer(); |
228 : | h | 1.2 | } |
229 : | } | ||
230 : | |||
231 : | edgomez | 1.7 | if (pMB->field_dct) { |
232 : | h | 1.4 | next_block = stride; |
233 : | stride *= 2; | ||
234 : | h | 1.2 | } |
235 : | |||
236 : | start_timer(); | ||
237 : | if (cbp & 32) | ||
238 : | edgomez | 1.7 | transfer_16to8add(pY_Cur, &data[0 * 64], stride); |
239 : | h | 1.2 | if (cbp & 16) |
240 : | edgomez | 1.7 | transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride); |
241 : | h | 1.2 | if (cbp & 8) |
242 : | edgomez | 1.7 | transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride); |
243 : | h | 1.2 | if (cbp & 4) |
244 : | edgomez | 1.7 | transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride); |
245 : | h | 1.2 | if (cbp & 2) |
246 : | edgomez | 1.7 | transfer_16to8add(pU_Cur, &data[4 * 64], stride2); |
247 : | h | 1.2 | if (cbp & 1) |
248 : | edgomez | 1.7 | transfer_16to8add(pV_Cur, &data[5 * 64], stride2); |
249 : | h | 1.2 | stop_transfer_timer(); |
250 : | |||
251 : | edgomez | 1.3 | return cbp; |
252 : | |||
253 : | h | 1.2 | } |
254 : | |||
255 : | chl | 1.8 | void |
256 : | MBTransQuantIntra2(const MBParam * pParam, | ||
257 : | FRAMEINFO * frame, | ||
258 : | MACROBLOCK * pMB, | ||
259 : | const uint32_t x_pos, | ||
260 : | const uint32_t y_pos, | ||
261 : | int16_t data[6 * 64], | ||
262 : | int16_t qcoeff[6 * 64]) | ||
263 : | { | ||
264 : | MBTrans(pParam,frame,pMB,x_pos,y_pos,data); | ||
265 : | MBfDCT(pParam,frame,pMB,data); | ||
266 : | MBQuantIntra(pParam,frame,pMB,data,qcoeff); | ||
267 : | MBDeQuantIntra(pParam,frame->quant,data,qcoeff); | ||
268 : | MBiDCT(data,0x3F); | ||
269 : | MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,0x3F); | ||
270 : | } | ||
271 : | |||
272 : | |||
273 : | uint8_t | ||
274 : | MBTransQuantInter2(const MBParam * pParam, | ||
275 : | FRAMEINFO * frame, | ||
276 : | MACROBLOCK * pMB, | ||
277 : | const uint32_t x_pos, | ||
278 : | const uint32_t y_pos, | ||
279 : | int16_t data[6 * 64], | ||
280 : | int16_t qcoeff[6 * 64]) | ||
281 : | { | ||
282 : | uint8_t cbp; | ||
283 : | |||
284 : | /* there is no MBTrans for Inter block, that's done in motion compensation already */ | ||
285 : | |||
286 : | MBfDCT(pParam,frame,pMB,data); | ||
287 : | cbp = MBQuantInter(pParam,frame->quant,data,qcoeff); | ||
288 : | MBDeQuantInter(pParam,frame->quant,data,qcoeff,cbp); | ||
289 : | MBiDCT(data,cbp); | ||
290 : | MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,cbp); | ||
291 : | |||
292 : | return cbp; | ||
293 : | } | ||
294 : | |||
295 : | uint8_t | ||
296 : | MBTransQuantInterBVOP(const MBParam * pParam, | ||
297 : | FRAMEINFO * frame, | ||
298 : | MACROBLOCK * pMB, | ||
299 : | int16_t data[6 * 64], | ||
300 : | int16_t qcoeff[6 * 64]) | ||
301 : | { | ||
302 : | uint8_t cbp; | ||
303 : | |||
304 : | /* there is no MBTrans for Inter block, that's done in motion compensation already */ | ||
305 : | |||
306 : | MBfDCT(pParam,frame,pMB,data); | ||
307 : | cbp = MBQuantInter(pParam,frame->quant,data,qcoeff); | ||
308 : | |||
309 : | /* we don't have to DeQuant, iDCT and Transfer back data for B-frames */ | ||
310 : | |||
311 : | return cbp; | ||
312 : | } | ||
313 : | |||
314 : | |||
315 : | void | ||
316 : | MBfDCT(const MBParam * pParam, | ||
317 : | FRAMEINFO * frame, | ||
318 : | MACROBLOCK * pMB, | ||
319 : | int16_t data[6 * 64]) | ||
320 : | { | ||
321 : | int i; | ||
322 : | |||
323 : | start_timer(); | ||
324 : | pMB->field_dct = 0; | ||
325 : | if ((frame->global_flags & XVID_INTERLACING)) { | ||
326 : | pMB->field_dct = MBDecideFieldDCT(data); | ||
327 : | } | ||
328 : | stop_interlacing_timer(); | ||
329 : | |||
330 : | for (i = 0; i < 6; i++) { | ||
331 : | start_timer(); | ||
332 : | fdct(&data[i * 64]); | ||
333 : | stop_dct_timer(); | ||
334 : | } | ||
335 : | } | ||
336 : | |||
337 : | void | ||
338 : | MBQuantDeQuantIntra(const MBParam * pParam, | ||
339 : | FRAMEINFO * frame, | ||
340 : | MACROBLOCK * pMB, | ||
341 : | int16_t qcoeff[6 * 64], | ||
342 : | int16_t data[6*64]) | ||
343 : | { | ||
344 : | int i; | ||
345 : | int iQuant = frame->quant; | ||
346 : | |||
347 : | start_timer(); | ||
348 : | pMB->field_dct = 0; | ||
349 : | if ((frame->global_flags & XVID_INTERLACING)) { | ||
350 : | pMB->field_dct = MBDecideFieldDCT(data); | ||
351 : | } | ||
352 : | stop_interlacing_timer(); | ||
353 : | |||
354 : | for (i = 0; i < 6; i++) { | ||
355 : | uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); | ||
356 : | |||
357 : | if (pParam->m_quant_type == H263_QUANT) { | ||
358 : | start_timer(); | ||
359 : | quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); | ||
360 : | stop_quant_timer(); | ||
361 : | |||
362 : | start_timer(); | ||
363 : | dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); | ||
364 : | stop_iquant_timer(); | ||
365 : | } else { | ||
366 : | start_timer(); | ||
367 : | quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); | ||
368 : | stop_quant_timer(); | ||
369 : | |||
370 : | start_timer(); | ||
371 : | dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); | ||
372 : | stop_iquant_timer(); | ||
373 : | } | ||
374 : | } | ||
375 : | } | ||
376 : | |||
377 : | void | ||
378 : | MBQuantIntra(const MBParam * pParam, | ||
379 : | FRAMEINFO * frame, | ||
380 : | MACROBLOCK *pMB, | ||
381 : | int16_t qcoeff[6 * 64], | ||
382 : | int16_t data[6*64]) | ||
383 : | { | ||
384 : | int i; | ||
385 : | int iQuant = frame->quant; | ||
386 : | |||
387 : | start_timer(); | ||
388 : | pMB->field_dct = 0; | ||
389 : | if ((frame->global_flags & XVID_INTERLACING)) { | ||
390 : | pMB->field_dct = MBDecideFieldDCT(data); | ||
391 : | } | ||
392 : | stop_interlacing_timer(); | ||
393 : | |||
394 : | for (i = 0; i < 6; i++) { | ||
395 : | uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); | ||
396 : | |||
397 : | if (pParam->m_quant_type == H263_QUANT) { | ||
398 : | start_timer(); | ||
399 : | quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); | ||
400 : | stop_quant_timer(); | ||
401 : | } else { | ||
402 : | start_timer(); | ||
403 : | quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler); | ||
404 : | stop_quant_timer(); | ||
405 : | } | ||
406 : | } | ||
407 : | } | ||
408 : | |||
409 : | void | ||
410 : | MBDeQuantIntra(const MBParam * pParam, | ||
411 : | const int iQuant, | ||
412 : | int16_t qcoeff[6 * 64], | ||
413 : | int16_t data[6*64]) | ||
414 : | { | ||
415 : | int i; | ||
416 : | |||
417 : | for (i = 0; i < 6; i++) { | ||
418 : | uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4); | ||
419 : | |||
420 : | if (pParam->m_quant_type == H263_QUANT) { | ||
421 : | start_timer(); | ||
422 : | dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); | ||
423 : | stop_iquant_timer(); | ||
424 : | } else { | ||
425 : | start_timer(); | ||
426 : | dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler); | ||
427 : | stop_iquant_timer(); | ||
428 : | } | ||
429 : | } | ||
430 : | } | ||
431 : | |||
432 : | uint8_t | ||
433 : | MBQuantInter(const MBParam * pParam, | ||
434 : | const int iQuant, | ||
435 : | int16_t data[6 * 64], | ||
436 : | int16_t qcoeff[6 * 64]) | ||
437 : | { | ||
438 : | |||
439 : | int i; | ||
440 : | uint8_t cbp = 0; | ||
441 : | int sum; | ||
442 : | |||
443 : | for (i = 0; i < 6; i++) { | ||
444 : | |||
445 : | if (pParam->m_quant_type == 0) { | ||
446 : | start_timer(); | ||
447 : | sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant); | ||
448 : | stop_quant_timer(); | ||
449 : | } else { | ||
450 : | start_timer(); | ||
451 : | sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant); | ||
452 : | stop_quant_timer(); | ||
453 : | } | ||
454 : | |||
455 : | if (sum >= TOOSMALL_LIMIT) { // skip block ? | ||
456 : | cbp |= 1 << (5 - i); | ||
457 : | } | ||
458 : | } | ||
459 : | return cbp; | ||
460 : | } | ||
461 : | |||
462 : | void | ||
463 : | MBDeQuantInter( const MBParam * pParam, | ||
464 : | const int iQuant, | ||
465 : | int16_t data[6 * 64], | ||
466 : | int16_t qcoeff[6 * 64], | ||
467 : | const uint8_t cbp) | ||
468 : | { | ||
469 : | int i; | ||
470 : | |||
471 : | for (i = 0; i < 6; i++) { | ||
472 : | if (cbp & (1 << (5 - i))) | ||
473 : | { | ||
474 : | if (pParam->m_quant_type == H263_QUANT) { | ||
475 : | start_timer(); | ||
476 : | dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant); | ||
477 : | stop_iquant_timer(); | ||
478 : | } else { | ||
479 : | start_timer(); | ||
480 : | dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant); | ||
481 : | stop_iquant_timer(); | ||
482 : | } | ||
483 : | } | ||
484 : | } | ||
485 : | } | ||
486 : | |||
487 : | void | ||
488 : | MBiDCT( int16_t data[6 * 64], | ||
489 : | const uint8_t cbp) | ||
490 : | { | ||
491 : | int i; | ||
492 : | |||
493 : | for (i = 0; i < 6; i++) { | ||
494 : | if (cbp & (1 << (5 - i))) | ||
495 : | { | ||
496 : | start_timer(); | ||
497 : | idct(&data[i * 64]); | ||
498 : | stop_idct_timer(); | ||
499 : | |||
500 : | } | ||
501 : | } | ||
502 : | } | ||
503 : | |||
504 : | |||
505 : | void | ||
506 : | MBTrans(const MBParam * pParam, | ||
507 : | FRAMEINFO * frame, | ||
508 : | MACROBLOCK * pMB, | ||
509 : | const uint32_t x_pos, | ||
510 : | const uint32_t y_pos, | ||
511 : | int16_t data[6 * 64]) | ||
512 : | { | ||
513 : | uint32_t stride = pParam->edged_width; | ||
514 : | uint32_t stride2 = stride / 2; | ||
515 : | uint32_t next_block = stride * 8; | ||
516 : | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; | ||
517 : | IMAGE *pCurrent = &frame->image; | ||
518 : | |||
519 : | pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); | ||
520 : | pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); | ||
521 : | pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
522 : | |||
523 : | start_timer(); | ||
524 : | transfer_8to16copy(&data[0 * 64], pY_Cur, stride); | ||
525 : | transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride); | ||
526 : | transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride); | ||
527 : | transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride); | ||
528 : | transfer_8to16copy(&data[4 * 64], pU_Cur, stride2); | ||
529 : | transfer_8to16copy(&data[5 * 64], pV_Cur, stride2); | ||
530 : | stop_transfer_timer(); | ||
531 : | } | ||
532 : | |||
533 : | void | ||
534 : | MBTransAdd(const MBParam * pParam, | ||
535 : | FRAMEINFO * frame, | ||
536 : | MACROBLOCK * pMB, | ||
537 : | const uint32_t x_pos, | ||
538 : | const uint32_t y_pos, | ||
539 : | int16_t data[6 * 64], | ||
540 : | const uint8_t cbp) | ||
541 : | { | ||
542 : | uint8_t *pY_Cur, *pU_Cur, *pV_Cur; | ||
543 : | uint32_t stride = pParam->edged_width; | ||
544 : | uint32_t stride2 = stride / 2; | ||
545 : | uint32_t next_block = stride * 8; | ||
546 : | IMAGE *pCurrent = &frame->image; | ||
547 : | |||
548 : | pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4); | ||
549 : | pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3); | ||
550 : | pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3); | ||
551 : | |||
552 : | if (pMB->field_dct) { | ||
553 : | next_block = stride; | ||
554 : | stride *= 2; | ||
555 : | } | ||
556 : | |||
557 : | start_timer(); | ||
558 : | if (cbp & 32) | ||
559 : | transfer_16to8add(pY_Cur, &data[0 * 64], stride); | ||
560 : | if (cbp & 16) | ||
561 : | transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride); | ||
562 : | if (cbp & 8) | ||
563 : | transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride); | ||
564 : | if (cbp & 4) | ||
565 : | transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride); | ||
566 : | if (cbp & 2) | ||
567 : | transfer_16to8add(pU_Cur, &data[4 * 64], stride2); | ||
568 : | if (cbp & 1) | ||
569 : | transfer_16to8add(pV_Cur, &data[5 * 64], stride2); | ||
570 : | stop_transfer_timer(); | ||
571 : | } | ||
572 : | |||
573 : | |||
574 : | h | 1.2 | |
575 : | /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */ | ||
576 : | |||
577 : | Isibaar | 1.1 | |
578 : | edgomez | 1.7 | uint32_t |
579 : | MBDecideFieldDCT(int16_t data[6 * 64]) | ||
580 : | h | 1.2 | { |
581 : | edgomez | 1.3 | |
582 : | edgomez | 1.7 | const uint8_t blocks[] = |
583 : | { 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 }; | ||
584 : | const uint8_t lines[] = { 0, 16, 32, 48, 0, 16, 32, 48 }; | ||
585 : | h | 1.2 | |
586 : | int frame = 0, field = 0; | ||
587 : | int i, j; | ||
588 : | |||
589 : | edgomez | 1.7 | for (i = 0; i < 7; ++i) { |
590 : | for (j = 0; j < 8; ++j) { | ||
591 : | frame += | ||
592 : | ABS(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]); | ||
593 : | frame += | ||
594 : | ABS(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]); | ||
595 : | frame += | ||
596 : | ABS(data[2 * 64 + (i + 1) * 8 + j] - data[2 * 64 + i * 8 + j]); | ||
597 : | frame += | ||
598 : | ABS(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]); | ||
599 : | |||
600 : | field += | ||
601 : | ABS(data[blocks[i + 1] + lines[i + 1] + j] - | ||
602 : | data[blocks[i] + lines[i] + j]); | ||
603 : | field += | ||
604 : | ABS(data[blocks[i + 1] + lines[i + 1] + 8 + j] - | ||
605 : | data[blocks[i] + lines[i] + 8 + j]); | ||
606 : | field += | ||
607 : | ABS(data[blocks[i + 1] + 64 + lines[i + 1] + j] - | ||
608 : | data[blocks[i] + 64 + lines[i] + j]); | ||
609 : | field += | ||
610 : | ABS(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] - | ||
611 : | data[blocks[i] + 64 + lines[i] + 8 + j]); | ||
612 : | Isibaar | 1.1 | } |
613 : | } | ||
614 : | h | 1.2 | |
615 : | edgomez | 1.7 | if (frame > field) { |
616 : | h | 1.2 | MBFrameToField(data); |
617 : | } | ||
618 : | |||
619 : | return (frame > field); | ||
620 : | } | ||
621 : | |||
622 : | |||
623 : | /* deinterlace Y blocks vertically */ | ||
624 : | |||
625 : | #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp)) | ||
626 : | edgomez | 1.3 | #define LINE(X,Y) &data[X*64 + Y*8] |
627 : | h | 1.2 | |
628 : | edgomez | 1.7 | void |
629 : | MBFrameToField(int16_t data[6 * 64]) | ||
630 : | h | 1.2 | { |
631 : | int16_t tmp[8]; | ||
632 : | |||
633 : | /* left blocks */ | ||
634 : | |||
635 : | // 1=2, 2=4, 4=8, 8=1 | ||
636 : | edgomez | 1.7 | MOVLINE(tmp, LINE(0, 1)); |
637 : | MOVLINE(LINE(0, 1), LINE(0, 2)); | ||
638 : | MOVLINE(LINE(0, 2), LINE(0, 4)); | ||
639 : | MOVLINE(LINE(0, 4), LINE(2, 0)); | ||
640 : | MOVLINE(LINE(2, 0), tmp); | ||
641 : | h | 1.2 | |
642 : | // 3=6, 6=12, 12=9, 9=3 | ||
643 : | edgomez | 1.7 | MOVLINE(tmp, LINE(0, 3)); |
644 : | MOVLINE(LINE(0, 3), LINE(0, 6)); | ||
645 : | MOVLINE(LINE(0, 6), LINE(2, 4)); | ||
646 : | MOVLINE(LINE(2, 4), LINE(2, 1)); | ||
647 : | MOVLINE(LINE(2, 1), tmp); | ||
648 : | h | 1.2 | |
649 : | // 5=10, 10=5 | ||
650 : | edgomez | 1.7 | MOVLINE(tmp, LINE(0, 5)); |
651 : | MOVLINE(LINE(0, 5), LINE(2, 2)); | ||
652 : | MOVLINE(LINE(2, 2), tmp); | ||
653 : | h | 1.2 | |
654 : | // 7=14, 14=13, 13=11, 11=7 | ||
655 : | edgomez | 1.7 | MOVLINE(tmp, LINE(0, 7)); |
656 : | MOVLINE(LINE(0, 7), LINE(2, 6)); | ||
657 : | MOVLINE(LINE(2, 6), LINE(2, 5)); | ||
658 : | MOVLINE(LINE(2, 5), LINE(2, 3)); | ||
659 : | MOVLINE(LINE(2, 3), tmp); | ||
660 : | h | 1.2 | |
661 : | /* right blocks */ | ||
662 : | |||
663 : | // 1=2, 2=4, 4=8, 8=1 | ||
664 : | edgomez | 1.7 | MOVLINE(tmp, LINE(1, 1)); |
665 : | MOVLINE(LINE(1, 1), LINE(1, 2)); | ||
666 : | MOVLINE(LINE(1, 2), LINE(1, 4)); | ||
667 : | MOVLINE(LINE(1, 4), LINE(3, 0)); | ||
668 : | MOVLINE(LINE(3, 0), tmp); | ||
669 : | h | 1.2 | |
670 : | // 3=6, 6=12, 12=9, 9=3 | ||
671 : | edgomez | 1.7 | MOVLINE(tmp, LINE(1, 3)); |
672 : | MOVLINE(LINE(1, 3), LINE(1, 6)); | ||
673 : | MOVLINE(LINE(1, 6), LINE(3, 4)); | ||
674 : | MOVLINE(LINE(3, 4), LINE(3, 1)); | ||
675 : | MOVLINE(LINE(3, 1), tmp); | ||
676 : | h | 1.2 | |
677 : | // 5=10, 10=5 | ||
678 : | edgomez | 1.7 | MOVLINE(tmp, LINE(1, 5)); |
679 : | MOVLINE(LINE(1, 5), LINE(3, 2)); | ||
680 : | MOVLINE(LINE(3, 2), tmp); | ||
681 : | h | 1.2 | |
682 : | // 7=14, 14=13, 13=11, 11=7 | ||
683 : | edgomez | 1.7 | MOVLINE(tmp, LINE(1, 7)); |
684 : | MOVLINE(LINE(1, 7), LINE(3, 6)); | ||
685 : | MOVLINE(LINE(3, 6), LINE(3, 5)); | ||
686 : | MOVLINE(LINE(3, 5), LINE(3, 3)); | ||
687 : | MOVLINE(LINE(3, 3), tmp); | ||
688 : | Isibaar | 1.1 | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |