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

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