[svn] / branches / dev-api-4 / xvidcore / src / utils / mbtransquant.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/src/utils/mbtransquant.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 677 - (view) (download)
Original Path: trunk/xvidcore/src/utils/mbtransquant.c

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

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4