[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 368 - (view) (download)
Original Path: trunk/xvidcore/src/utils/mbtransquant.c

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

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