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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 538 - (view) (download)

1 : Isibaar 3 /******************************************************************************
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 375 * 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 3 * 19.11.2001 introduced coefficient thresholding (Isibaar) *
50 :     * 17.11.2001 initial version *
51 :     * *
52 :     ******************************************************************************/
53 :    
54 : edgomez 78 #include <string.h>
55 :    
56 : Isibaar 3 #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 : h 538 MBFIELDTEST_PTR MBFieldTest;
69 :    
70 : Isibaar 3 #define MIN(X, Y) ((X)<(Y)?(X):(Y))
71 :     #define MAX(X, Y) ((X)>(Y)?(X):(Y))
72 :    
73 : chl 530 #define TOOSMALL_LIMIT 2 /* skip blocks having a coefficient sum below this value */
74 : Isibaar 3
75 :     /* this isnt pretty, but its better than 20 ifdefs */
76 :    
77 : edgomez 195 void
78 :     MBTransQuantIntra(const MBParam * pParam,
79 :     FRAMEINFO * frame,
80 :     MACROBLOCK * pMB,
81 :     const uint32_t x_pos,
82 :     const uint32_t y_pos,
83 :     int16_t data[6 * 64],
84 :     int16_t qcoeff[6 * 64])
85 : Isibaar 3 {
86 : edgomez 78
87 : h 82 uint32_t stride = pParam->edged_width;
88 :     uint32_t stride2 = stride / 2;
89 :     uint32_t next_block = stride * 8;
90 : Isibaar 3 uint32_t i;
91 : suxen_drol 136 uint32_t iQuant = frame->quant;
92 : Isibaar 3 uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
93 : edgomez 195 IMAGE *pCurrent = &frame->image;
94 : Isibaar 3
95 : edgomez 78 pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
96 : h 82 pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
97 :     pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
98 : h 69
99 :     start_timer();
100 : edgomez 195 transfer_8to16copy(&data[0 * 64], pY_Cur, stride);
101 :     transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride);
102 :     transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride);
103 :     transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride);
104 :     transfer_8to16copy(&data[4 * 64], pU_Cur, stride2);
105 :     transfer_8to16copy(&data[5 * 64], pV_Cur, stride2);
106 : h 69 stop_transfer_timer();
107 :    
108 :     start_timer();
109 :     pMB->field_dct = 0;
110 : h 390 if ((frame->global_flags & XVID_INTERLACING) &&
111 :     (x_pos>0) && (x_pos<pParam->mb_width-1) &&
112 :     (y_pos>0) && (y_pos<pParam->mb_height-1)) {
113 : h 69 pMB->field_dct = MBDecideFieldDCT(data);
114 :     }
115 :     stop_interlacing_timer();
116 :    
117 : edgomez 195 for (i = 0; i < 6; i++) {
118 : Isibaar 3 uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
119 :    
120 :     start_timer();
121 : edgomez 195 fdct(&data[i * 64]);
122 : Isibaar 3 stop_dct_timer();
123 :    
124 : edgomez 195 if (pParam->m_quant_type == H263_QUANT) {
125 : Isibaar 3 start_timer();
126 : edgomez 195 quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
127 : Isibaar 3 stop_quant_timer();
128 :    
129 :     start_timer();
130 : edgomez 195 dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
131 : Isibaar 3 stop_iquant_timer();
132 : edgomez 195 } else {
133 : Isibaar 3 start_timer();
134 : edgomez 195 quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
135 : Isibaar 3 stop_quant_timer();
136 :    
137 :     start_timer();
138 : edgomez 195 dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
139 : Isibaar 3 stop_iquant_timer();
140 :     }
141 :    
142 :     start_timer();
143 : edgomez 195 idct(&data[i * 64]);
144 : Isibaar 3 stop_idct_timer();
145 : edgomez 78 }
146 : Isibaar 3
147 : edgomez 195 if (pMB->field_dct) {
148 : h 82 next_block = stride;
149 :     stride *= 2;
150 : h 69 }
151 :    
152 :     start_timer();
153 : edgomez 195 transfer_16to8copy(pY_Cur, &data[0 * 64], stride);
154 :     transfer_16to8copy(pY_Cur + 8, &data[1 * 64], stride);
155 :     transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
156 :     transfer_16to8copy(pY_Cur + next_block + 8, &data[3 * 64], stride);
157 :     transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
158 :     transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
159 : h 69 stop_transfer_timer();
160 : edgomez 78
161 : Isibaar 3 }
162 :    
163 :    
164 : edgomez 195 uint8_t
165 :     MBTransQuantInter(const MBParam * pParam,
166 :     FRAMEINFO * frame,
167 :     MACROBLOCK * pMB,
168 :     const uint32_t x_pos,
169 :     const uint32_t y_pos,
170 :     int16_t data[6 * 64],
171 :     int16_t qcoeff[6 * 64])
172 : Isibaar 3 {
173 : edgomez 78
174 : h 82 uint32_t stride = pParam->edged_width;
175 :     uint32_t stride2 = stride / 2;
176 :     uint32_t next_block = stride * 8;
177 : edgomez 78 uint32_t i;
178 : suxen_drol 136 uint32_t iQuant = frame->quant;
179 : Isibaar 3 uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
180 : edgomez 78 uint8_t cbp = 0;
181 : Isibaar 3 uint32_t sum;
182 : edgomez 195 IMAGE *pCurrent = &frame->image;
183 :    
184 : edgomez 78 pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
185 : h 82 pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
186 :     pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
187 : Isibaar 3
188 : h 69 start_timer();
189 :     pMB->field_dct = 0;
190 : h 390 if ((frame->global_flags & XVID_INTERLACING) &&
191 :     (x_pos>0) && (x_pos<pParam->mb_width-1) &&
192 :     (y_pos>0) && (y_pos<pParam->mb_height-1)) {
193 : h 69 pMB->field_dct = MBDecideFieldDCT(data);
194 :     }
195 :     stop_interlacing_timer();
196 :    
197 : edgomez 195 for (i = 0; i < 6; i++) {
198 : Isibaar 3 /*
199 : edgomez 78 * no need to transfer 8->16-bit
200 :     * (this is performed already in motion compensation)
201 :     */
202 : Isibaar 3 start_timer();
203 : edgomez 195 fdct(&data[i * 64]);
204 : Isibaar 3 stop_dct_timer();
205 :    
206 : edgomez 195 if (pParam->m_quant_type == 0) {
207 : Isibaar 3 start_timer();
208 : edgomez 195 sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant);
209 : Isibaar 3 stop_quant_timer();
210 : edgomez 195 } else {
211 : Isibaar 3 start_timer();
212 : edgomez 195 sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant);
213 : Isibaar 3 stop_quant_timer();
214 :     }
215 :    
216 : Isibaar 375 if ((sum >= TOOSMALL_LIMIT) || (qcoeff[i*64] != 0) ||
217 :     (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) {
218 : Isibaar 3
219 : edgomez 195 if (pParam->m_quant_type == H263_QUANT) {
220 : Isibaar 3 start_timer();
221 : edgomez 195 dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
222 : Isibaar 3 stop_iquant_timer();
223 : edgomez 195 } else {
224 : Isibaar 3 start_timer();
225 : edgomez 195 dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
226 : Isibaar 3 stop_iquant_timer();
227 :     }
228 :    
229 :     cbp |= 1 << (5 - i);
230 :    
231 :     start_timer();
232 : edgomez 195 idct(&data[i * 64]);
233 : Isibaar 3 stop_idct_timer();
234 :     }
235 :     }
236 : h 69
237 : edgomez 195 if (pMB->field_dct) {
238 : h 82 next_block = stride;
239 :     stride *= 2;
240 : h 69 }
241 :    
242 :     start_timer();
243 :     if (cbp & 32)
244 : edgomez 195 transfer_16to8add(pY_Cur, &data[0 * 64], stride);
245 : h 69 if (cbp & 16)
246 : edgomez 195 transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
247 : h 69 if (cbp & 8)
248 : edgomez 195 transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
249 : h 69 if (cbp & 4)
250 : edgomez 195 transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride);
251 : h 69 if (cbp & 2)
252 : edgomez 195 transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
253 : h 69 if (cbp & 1)
254 : edgomez 195 transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
255 : h 69 stop_transfer_timer();
256 :    
257 : edgomez 78 return cbp;
258 :    
259 : Isibaar 3 }
260 : h 69
261 : chl 368 void
262 :     MBTransQuantIntra2(const MBParam * pParam,
263 :     FRAMEINFO * frame,
264 :     MACROBLOCK * pMB,
265 :     const uint32_t x_pos,
266 :     const uint32_t y_pos,
267 :     int16_t data[6 * 64],
268 :     int16_t qcoeff[6 * 64])
269 :     {
270 :     MBTrans(pParam,frame,pMB,x_pos,y_pos,data);
271 :     MBfDCT(pParam,frame,pMB,data);
272 :     MBQuantIntra(pParam,frame,pMB,data,qcoeff);
273 :     MBDeQuantIntra(pParam,frame->quant,data,qcoeff);
274 :     MBiDCT(data,0x3F);
275 :     MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,0x3F);
276 :     }
277 : h 69
278 : chl 368
279 :     uint8_t
280 :     MBTransQuantInter2(const MBParam * pParam,
281 :     FRAMEINFO * frame,
282 :     MACROBLOCK * pMB,
283 :     const uint32_t x_pos,
284 :     const uint32_t y_pos,
285 :     int16_t data[6 * 64],
286 :     int16_t qcoeff[6 * 64])
287 :     {
288 :     uint8_t cbp;
289 :    
290 :     /* there is no MBTrans for Inter block, that's done in motion compensation already */
291 :    
292 :     MBfDCT(pParam,frame,pMB,data);
293 :     cbp = MBQuantInter(pParam,frame->quant,data,qcoeff);
294 :     MBDeQuantInter(pParam,frame->quant,data,qcoeff,cbp);
295 :     MBiDCT(data,cbp);
296 :     MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,cbp);
297 :    
298 :     return cbp;
299 :     }
300 :    
301 :     uint8_t
302 :     MBTransQuantInterBVOP(const MBParam * pParam,
303 :     FRAMEINFO * frame,
304 :     MACROBLOCK * pMB,
305 :     int16_t data[6 * 64],
306 :     int16_t qcoeff[6 * 64])
307 :     {
308 :     uint8_t cbp;
309 :    
310 :     /* there is no MBTrans for Inter block, that's done in motion compensation already */
311 :    
312 :     MBfDCT(pParam,frame,pMB,data);
313 :     cbp = MBQuantInter(pParam,frame->quant,data,qcoeff);
314 :    
315 :     /* we don't have to DeQuant, iDCT and Transfer back data for B-frames */
316 :    
317 :     return cbp;
318 :     }
319 :    
320 :    
321 :     void
322 :     MBfDCT(const MBParam * pParam,
323 :     FRAMEINFO * frame,
324 :     MACROBLOCK * pMB,
325 :     int16_t data[6 * 64])
326 :     {
327 :     int i;
328 :    
329 :     start_timer();
330 :     pMB->field_dct = 0;
331 :     if ((frame->global_flags & XVID_INTERLACING)) {
332 :     pMB->field_dct = MBDecideFieldDCT(data);
333 :     }
334 :     stop_interlacing_timer();
335 :    
336 :     for (i = 0; i < 6; i++) {
337 :     start_timer();
338 :     fdct(&data[i * 64]);
339 :     stop_dct_timer();
340 :     }
341 :     }
342 :    
343 :     void
344 :     MBQuantDeQuantIntra(const MBParam * pParam,
345 :     FRAMEINFO * frame,
346 :     MACROBLOCK * pMB,
347 :     int16_t qcoeff[6 * 64],
348 :     int16_t data[6*64])
349 :     {
350 :     int i;
351 :     int iQuant = frame->quant;
352 :    
353 :     start_timer();
354 :     pMB->field_dct = 0;
355 :     if ((frame->global_flags & XVID_INTERLACING)) {
356 :     pMB->field_dct = MBDecideFieldDCT(data);
357 :     }
358 :     stop_interlacing_timer();
359 :    
360 :     for (i = 0; i < 6; i++) {
361 :     uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
362 :    
363 :     if (pParam->m_quant_type == H263_QUANT) {
364 :     start_timer();
365 :     quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
366 :     stop_quant_timer();
367 :    
368 :     start_timer();
369 :     dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
370 :     stop_iquant_timer();
371 :     } else {
372 :     start_timer();
373 :     quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
374 :     stop_quant_timer();
375 :    
376 :     start_timer();
377 :     dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
378 :     stop_iquant_timer();
379 :     }
380 :     }
381 :     }
382 :    
383 :     void
384 :     MBQuantIntra(const MBParam * pParam,
385 :     FRAMEINFO * frame,
386 :     MACROBLOCK *pMB,
387 :     int16_t qcoeff[6 * 64],
388 :     int16_t data[6*64])
389 :     {
390 :     int i;
391 :     int iQuant = frame->quant;
392 :    
393 :     start_timer();
394 :     pMB->field_dct = 0;
395 :     if ((frame->global_flags & XVID_INTERLACING)) {
396 :     pMB->field_dct = MBDecideFieldDCT(data);
397 :     }
398 :     stop_interlacing_timer();
399 :    
400 :     for (i = 0; i < 6; i++) {
401 :     uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
402 :    
403 :     if (pParam->m_quant_type == H263_QUANT) {
404 :     start_timer();
405 :     quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
406 :     stop_quant_timer();
407 :     } else {
408 :     start_timer();
409 :     quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
410 :     stop_quant_timer();
411 :     }
412 :     }
413 :     }
414 :    
415 :     void
416 :     MBDeQuantIntra(const MBParam * pParam,
417 :     const int iQuant,
418 :     int16_t qcoeff[6 * 64],
419 :     int16_t data[6*64])
420 :     {
421 :     int i;
422 :    
423 :     for (i = 0; i < 6; i++) {
424 :     uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
425 :    
426 :     if (pParam->m_quant_type == H263_QUANT) {
427 :     start_timer();
428 :     dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
429 :     stop_iquant_timer();
430 :     } else {
431 :     start_timer();
432 :     dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
433 :     stop_iquant_timer();
434 :     }
435 :     }
436 :     }
437 :    
438 :     uint8_t
439 :     MBQuantInter(const MBParam * pParam,
440 :     const int iQuant,
441 :     int16_t data[6 * 64],
442 :     int16_t qcoeff[6 * 64])
443 :     {
444 :    
445 :     int i;
446 :     uint8_t cbp = 0;
447 :     int sum;
448 :    
449 :     for (i = 0; i < 6; i++) {
450 :    
451 :     if (pParam->m_quant_type == 0) {
452 :     start_timer();
453 :     sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant);
454 :     stop_quant_timer();
455 :     } else {
456 :     start_timer();
457 :     sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant);
458 :     stop_quant_timer();
459 :     }
460 :    
461 :     if (sum >= TOOSMALL_LIMIT) { // skip block ?
462 :     cbp |= 1 << (5 - i);
463 :     }
464 :     }
465 :     return cbp;
466 :     }
467 :    
468 :     void
469 :     MBDeQuantInter( const MBParam * pParam,
470 :     const int iQuant,
471 :     int16_t data[6 * 64],
472 :     int16_t qcoeff[6 * 64],
473 :     const uint8_t cbp)
474 :     {
475 :     int i;
476 :    
477 :     for (i = 0; i < 6; i++) {
478 :     if (cbp & (1 << (5 - i)))
479 :     {
480 :     if (pParam->m_quant_type == H263_QUANT) {
481 :     start_timer();
482 :     dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
483 :     stop_iquant_timer();
484 :     } else {
485 :     start_timer();
486 :     dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
487 :     stop_iquant_timer();
488 :     }
489 :     }
490 :     }
491 :     }
492 :    
493 :     void
494 :     MBiDCT( int16_t data[6 * 64],
495 :     const uint8_t cbp)
496 :     {
497 :     int i;
498 :    
499 :     for (i = 0; i < 6; i++) {
500 :     if (cbp & (1 << (5 - i)))
501 :     {
502 :     start_timer();
503 :     idct(&data[i * 64]);
504 :     stop_idct_timer();
505 :    
506 :     }
507 :     }
508 :     }
509 :    
510 :    
511 :     void
512 :     MBTrans(const MBParam * pParam,
513 :     FRAMEINFO * frame,
514 :     MACROBLOCK * pMB,
515 :     const uint32_t x_pos,
516 :     const uint32_t y_pos,
517 :     int16_t data[6 * 64])
518 :     {
519 :     uint32_t stride = pParam->edged_width;
520 :     uint32_t stride2 = stride / 2;
521 :     uint32_t next_block = stride * 8;
522 :     uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
523 :     IMAGE *pCurrent = &frame->image;
524 :    
525 :     pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
526 :     pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
527 :     pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
528 :    
529 :     start_timer();
530 :     transfer_8to16copy(&data[0 * 64], pY_Cur, stride);
531 :     transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride);
532 :     transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride);
533 :     transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride);
534 :     transfer_8to16copy(&data[4 * 64], pU_Cur, stride2);
535 :     transfer_8to16copy(&data[5 * 64], pV_Cur, stride2);
536 :     stop_transfer_timer();
537 :     }
538 :    
539 :     void
540 :     MBTransAdd(const MBParam * pParam,
541 :     FRAMEINFO * frame,
542 :     MACROBLOCK * pMB,
543 :     const uint32_t x_pos,
544 :     const uint32_t y_pos,
545 :     int16_t data[6 * 64],
546 :     const uint8_t cbp)
547 :     {
548 :     uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
549 :     uint32_t stride = pParam->edged_width;
550 :     uint32_t stride2 = stride / 2;
551 :     uint32_t next_block = stride * 8;
552 :     IMAGE *pCurrent = &frame->image;
553 :    
554 :     pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
555 :     pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
556 :     pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
557 :    
558 :     if (pMB->field_dct) {
559 :     next_block = stride;
560 :     stride *= 2;
561 :     }
562 :    
563 :     start_timer();
564 :     if (cbp & 32)
565 :     transfer_16to8add(pY_Cur, &data[0 * 64], stride);
566 :     if (cbp & 16)
567 :     transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
568 :     if (cbp & 8)
569 :     transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
570 :     if (cbp & 4)
571 :     transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride);
572 :     if (cbp & 2)
573 :     transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
574 :     if (cbp & 1)
575 :     transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
576 :     stop_transfer_timer();
577 :     }
578 :    
579 :    
580 :    
581 : h 538 /* permute block and return field dct choice */
582 : h 69
583 :    
584 : edgomez 195 uint32_t
585 :     MBDecideFieldDCT(int16_t data[6 * 64])
586 : h 69 {
587 : h 538 uint32_t field = MBFieldTest(data);
588 : h 69
589 : h 538 if (field) {
590 :     MBFrameToField(data);
591 :     }
592 :    
593 :     return field;
594 :     }
595 :    
596 :    
597 :     /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */
598 :    
599 :     uint32_t
600 :     MBFieldTest_c(int16_t data[6 * 64])
601 :     {
602 : edgomez 195 const uint8_t blocks[] =
603 :     { 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 };
604 :     const uint8_t lines[] = { 0, 16, 32, 48, 0, 16, 32, 48 };
605 : edgomez 78
606 : h 69 int frame = 0, field = 0;
607 :     int i, j;
608 :    
609 : edgomez 195 for (i = 0; i < 7; ++i) {
610 :     for (j = 0; j < 8; ++j) {
611 :     frame +=
612 :     ABS(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]);
613 :     frame +=
614 :     ABS(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]);
615 :     frame +=
616 :     ABS(data[2 * 64 + (i + 1) * 8 + j] - data[2 * 64 + i * 8 + j]);
617 :     frame +=
618 :     ABS(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]);
619 : h 69
620 : edgomez 195 field +=
621 :     ABS(data[blocks[i + 1] + lines[i + 1] + j] -
622 :     data[blocks[i] + lines[i] + j]);
623 :     field +=
624 :     ABS(data[blocks[i + 1] + lines[i + 1] + 8 + j] -
625 :     data[blocks[i] + lines[i] + 8 + j]);
626 :     field +=
627 :     ABS(data[blocks[i + 1] + 64 + lines[i + 1] + j] -
628 :     data[blocks[i] + 64 + lines[i] + j]);
629 :     field +=
630 :     ABS(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] -
631 :     data[blocks[i] + 64 + lines[i] + 8 + j]);
632 : h 69 }
633 :     }
634 :    
635 : h 538 return (frame >= field);
636 : h 69 }
637 :    
638 :    
639 :     /* deinterlace Y blocks vertically */
640 :    
641 :     #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp))
642 : edgomez 78 #define LINE(X,Y) &data[X*64 + Y*8]
643 : h 69
644 : edgomez 195 void
645 :     MBFrameToField(int16_t data[6 * 64])
646 : h 69 {
647 :     int16_t tmp[8];
648 :    
649 :     /* left blocks */
650 :    
651 :     // 1=2, 2=4, 4=8, 8=1
652 : edgomez 195 MOVLINE(tmp, LINE(0, 1));
653 :     MOVLINE(LINE(0, 1), LINE(0, 2));
654 :     MOVLINE(LINE(0, 2), LINE(0, 4));
655 :     MOVLINE(LINE(0, 4), LINE(2, 0));
656 :     MOVLINE(LINE(2, 0), tmp);
657 : h 69
658 :     // 3=6, 6=12, 12=9, 9=3
659 : edgomez 195 MOVLINE(tmp, LINE(0, 3));
660 :     MOVLINE(LINE(0, 3), LINE(0, 6));
661 :     MOVLINE(LINE(0, 6), LINE(2, 4));
662 :     MOVLINE(LINE(2, 4), LINE(2, 1));
663 :     MOVLINE(LINE(2, 1), tmp);
664 : h 69
665 :     // 5=10, 10=5
666 : edgomez 195 MOVLINE(tmp, LINE(0, 5));
667 :     MOVLINE(LINE(0, 5), LINE(2, 2));
668 :     MOVLINE(LINE(2, 2), tmp);
669 : h 69
670 :     // 7=14, 14=13, 13=11, 11=7
671 : edgomez 195 MOVLINE(tmp, LINE(0, 7));
672 :     MOVLINE(LINE(0, 7), LINE(2, 6));
673 :     MOVLINE(LINE(2, 6), LINE(2, 5));
674 :     MOVLINE(LINE(2, 5), LINE(2, 3));
675 :     MOVLINE(LINE(2, 3), tmp);
676 : h 69
677 :     /* right blocks */
678 :    
679 :     // 1=2, 2=4, 4=8, 8=1
680 : edgomez 195 MOVLINE(tmp, LINE(1, 1));
681 :     MOVLINE(LINE(1, 1), LINE(1, 2));
682 :     MOVLINE(LINE(1, 2), LINE(1, 4));
683 :     MOVLINE(LINE(1, 4), LINE(3, 0));
684 :     MOVLINE(LINE(3, 0), tmp);
685 : h 69
686 :     // 3=6, 6=12, 12=9, 9=3
687 : edgomez 195 MOVLINE(tmp, LINE(1, 3));
688 :     MOVLINE(LINE(1, 3), LINE(1, 6));
689 :     MOVLINE(LINE(1, 6), LINE(3, 4));
690 :     MOVLINE(LINE(3, 4), LINE(3, 1));
691 :     MOVLINE(LINE(3, 1), tmp);
692 : h 69
693 :     // 5=10, 10=5
694 : edgomez 195 MOVLINE(tmp, LINE(1, 5));
695 :     MOVLINE(LINE(1, 5), LINE(3, 2));
696 :     MOVLINE(LINE(3, 2), tmp);
697 : h 69
698 :     // 7=14, 14=13, 13=11, 11=7
699 : edgomez 195 MOVLINE(tmp, LINE(1, 7));
700 :     MOVLINE(LINE(1, 7), LINE(3, 6));
701 :     MOVLINE(LINE(3, 6), LINE(3, 5));
702 :     MOVLINE(LINE(3, 5), LINE(3, 3));
703 :     MOVLINE(LINE(3, 3), tmp);
704 : h 69 }

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