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

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