[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 995 - (view) (download)

1 : edgomez 965 /*****************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - MB Transfert/Quantization functions -
5 :     *
6 :     * Copyright(C) 2001-2003 Peter Ross <pross@xvid.org>
7 :     * 2001-2003 Michael Militzer <isibaar@xvid.org>
8 :     * 2003 Edouard Gomez <ed.gomez@free.fr>
9 :     *
10 :     * This program is free software ; you can redistribute it and/or modify
11 :     * it under the terms of the GNU General Public License as published by
12 :     * the Free Software Foundation ; either version 2 of the License, or
13 :     * (at your option) any later version.
14 :     *
15 :     * This program is distributed in the hope that it will be useful,
16 :     * but WITHOUT ANY WARRANTY ; without even the implied warranty of
17 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 :     * GNU General Public License for more details.
19 :     *
20 :     * You should have received a copy of the GNU General Public License
21 :     * along with this program ; if not, write to the Free Software
22 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 :     *
24 : chl 995 * $Id: mbtransquant.c,v 1.21.2.9 2003-04-27 19:47:48 chl Exp $
25 : edgomez 965 *
26 :     ****************************************************************************/
27 : Isibaar 3
28 : edgomez 78 #include <string.h>
29 : edgomez 982 #include <stdlib.h>
30 : edgomez 78
31 : Isibaar 3 #include "../portab.h"
32 :     #include "mbfunctions.h"
33 :    
34 :     #include "../global.h"
35 :     #include "mem_transfer.h"
36 :     #include "timer.h"
37 : chl 995 #include "../bitstream/mbcoding.h"
38 : Isibaar 3 #include "../dct/fdct.h"
39 :     #include "../dct/idct.h"
40 :     #include "../quant/quant_mpeg4.h"
41 :     #include "../quant/quant_h263.h"
42 :     #include "../encoder.h"
43 :    
44 : edgomez 851 #include "../image/reduced.h"
45 : Isibaar 3
46 : edgomez 851 MBFIELDTEST_PTR MBFieldTest;
47 : Isibaar 3
48 : edgomez 965 /*
49 :     * Skip blocks having a coefficient sum below this value. This value will be
50 :     * corrected according to the MB quantizer to avoid artifacts for quant==1
51 :     */
52 :     #define PVOP_TOOSMALL_LIMIT 1
53 :     #define BVOP_TOOSMALL_LIMIT 3
54 : Isibaar 3
55 : edgomez 965 /*****************************************************************************
56 :     * Local functions
57 :     ****************************************************************************/
58 :    
59 :     /* permute block and return field dct choice */
60 :     static __inline uint32_t
61 :     MBDecideFieldDCT(int16_t data[6 * 64])
62 : Isibaar 3 {
63 : edgomez 965 uint32_t field = MBFieldTest(data);
64 : edgomez 78
65 : edgomez 965 if (field)
66 :     MBFrameToField(data);
67 : Isibaar 3
68 : edgomez 965 return field;
69 :     }
70 : h 69
71 : edgomez 965 /* Performs Forward DCT on all blocks */
72 :     static __inline void
73 : syskin 984 MBfDCT(const MBParam * const pParam,
74 :     const FRAMEINFO * const frame,
75 :     MACROBLOCK * const pMB,
76 : edgomez 965 uint32_t x_pos,
77 :     uint32_t y_pos,
78 :     int16_t data[6 * 64])
79 : syskin 984 {
80 : edgomez 965 /* Handles interlacing */
81 : h 69 start_timer();
82 :     pMB->field_dct = 0;
83 : edgomez 949 if ((frame->vol_flags & XVID_VOL_INTERLACING) &&
84 : h 390 (x_pos>0) && (x_pos<pParam->mb_width-1) &&
85 :     (y_pos>0) && (y_pos<pParam->mb_height-1)) {
86 : h 69 pMB->field_dct = MBDecideFieldDCT(data);
87 :     }
88 :     stop_interlacing_timer();
89 :    
90 : edgomez 965 /* Perform DCT */
91 :     start_timer();
92 :     fdct(&data[0 * 64]);
93 :     fdct(&data[1 * 64]);
94 :     fdct(&data[2 * 64]);
95 :     fdct(&data[3 * 64]);
96 :     fdct(&data[4 * 64]);
97 :     fdct(&data[5 * 64]);
98 :     stop_dct_timer();
99 :     }
100 :    
101 :     /* Performs Inverse DCT on all blocks */
102 :     static __inline void
103 :     MBiDCT(int16_t data[6 * 64],
104 :     const uint8_t cbp)
105 :     {
106 :     start_timer();
107 :     if(cbp & (1 << (5 - 0))) idct(&data[0 * 64]);
108 :     if(cbp & (1 << (5 - 1))) idct(&data[1 * 64]);
109 :     if(cbp & (1 << (5 - 2))) idct(&data[2 * 64]);
110 :     if(cbp & (1 << (5 - 3))) idct(&data[3 * 64]);
111 :     if(cbp & (1 << (5 - 4))) idct(&data[4 * 64]);
112 :     if(cbp & (1 << (5 - 5))) idct(&data[5 * 64]);
113 :     stop_idct_timer();
114 :     }
115 :    
116 :     /* Quantize all blocks -- Intra mode */
117 :     static __inline void
118 :     MBQuantIntra(const MBParam * pParam,
119 : chl 995 const FRAMEINFO * const frame,
120 : edgomez 965 const MACROBLOCK * pMB,
121 : syskin 984 int16_t qcoeff[6 * 64],
122 : edgomez 965 int16_t data[6*64])
123 :     {
124 :     int i;
125 :    
126 : edgomez 195 for (i = 0; i < 6; i++) {
127 : edgomez 965 uint32_t iDcScaler = get_dc_scaler(pMB->quant, i < 4);
128 :    
129 :     /* Quantize the block */
130 :     start_timer();
131 : chl 995 if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) {
132 : edgomez 965 quant_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler);
133 : chl 995 } else {
134 : edgomez 965 quant4_intra(&data[i * 64], &qcoeff[i * 64], pMB->quant, iDcScaler);
135 : chl 995 }
136 : edgomez 965 stop_quant_timer();
137 :     }
138 :     }
139 :    
140 :     /* DeQuantize all blocks -- Intra mode */
141 :     static __inline void
142 :     MBDeQuantIntra(const MBParam * pParam,
143 :     const int iQuant,
144 :     int16_t qcoeff[6 * 64],
145 :     int16_t data[6*64])
146 :     {
147 :     int i;
148 :    
149 :     for (i = 0; i < 6; i++) {
150 : Isibaar 3 uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
151 :    
152 :     start_timer();
153 : edgomez 965 if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))
154 :     dequant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
155 :     else
156 :     dequant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
157 :     stop_iquant_timer();
158 :     }
159 :     }
160 : Isibaar 3
161 : edgomez 965 /* Quantize all blocks -- Inter mode */
162 :     static __inline uint8_t
163 :     MBQuantInter(const MBParam * pParam,
164 : chl 995 const FRAMEINFO * const frame,
165 : edgomez 965 const MACROBLOCK * pMB,
166 :     int16_t data[6 * 64],
167 :     int16_t qcoeff[6 * 64],
168 :     int bvop,
169 :     int limit)
170 :     {
171 :    
172 :     int i;
173 :     uint8_t cbp = 0;
174 :     int sum;
175 :     int code_block;
176 :    
177 :     for (i = 0; i < 6; i++) {
178 : syskin 984
179 : edgomez 965 /* Quantize the block */
180 :     start_timer();
181 : chl 995 if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT)) {
182 :     sum = quant_inter(&qcoeff[i*64], &data[i*64], pMB->quant);
183 :     if ( (sum) && (frame->vop_flags & XVID_VOP_TRELLISQUANT) ) {
184 :     sum = dct_quantize_trellis_inter_h263_c (&qcoeff[i*64], &data[i*64], pMB->quant)+1;
185 :     limit = 1;
186 :     }
187 :     } else {
188 : edgomez 965 sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], pMB->quant);
189 : chl 995 // if ( (sum) && (frame->vop_flags & XVID_VOP_TRELLISQUANT) )
190 :     // sum = dct_quantize_trellis_inter_mpeg_c (&qcoeff[i*64], &data[i*64], pMB->quant)+1;
191 :     }
192 : edgomez 965 stop_quant_timer();
193 :    
194 :     /*
195 :     * We code the block if the sum is higher than the limit and if the first
196 :     * two AC coefficients in zig zag order are not zero.
197 :     */
198 :     code_block = 0;
199 :     if ((sum >= limit) || (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) {
200 :     code_block = 1;
201 : edgomez 195 } else {
202 : Isibaar 3
203 : edgomez 965 if (bvop && (pMB->mode == MODE_DIRECT || pMB->mode == MODE_DIRECT_NO4V)) {
204 :     /* dark blocks prevention for direct mode */
205 :     if ((qcoeff[i*64] < -1) || (qcoeff[i*64] > 0))
206 :     code_block = 1;
207 : edgomez 851 } else {
208 : edgomez 965 /* not direct mode */
209 :     if (qcoeff[i*64] != 0)
210 :     code_block = 1;
211 : edgomez 851 }
212 : Isibaar 3 }
213 :    
214 : edgomez 965 /* Set the corresponding cbp bit */
215 :     cbp |= code_block << (5 - i);
216 :     }
217 : edgomez 851
218 : edgomez 965 return(cbp);
219 :     }
220 : Isibaar 3
221 : edgomez 965 /* DeQuantize all blocks -- Inter mode */
222 : syskin 984 static __inline void
223 : edgomez 965 MBDeQuantInter(const MBParam * pParam,
224 :     const int iQuant,
225 :     int16_t data[6 * 64],
226 :     int16_t qcoeff[6 * 64],
227 :     const uint8_t cbp)
228 :     {
229 :     int i;
230 :    
231 :     for (i = 0; i < 6; i++) {
232 : syskin 984 if (cbp & (1 << (5 - i))) {
233 : edgomez 965 start_timer();
234 :     if (!(pParam->vol_flags & XVID_VOL_MPEGQUANT))
235 :     dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
236 :     else
237 :     dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
238 :     stop_iquant_timer();
239 : edgomez 851 }
240 : h 69 }
241 : Isibaar 3 }
242 :    
243 : edgomez 965 typedef void (transfer_operation_8to16_t) (int16_t *Dst, const uint8_t *Src, int BpS);
244 :     typedef void (transfer_operation_16to8_t) (uint8_t *Dst, const int16_t *Src, int BpS);
245 : Isibaar 3
246 : edgomez 78
247 : edgomez 965 static __inline void
248 : syskin 984 MBTrans8to16(const MBParam * const pParam,
249 :     const FRAMEINFO * const frame,
250 :     const MACROBLOCK * const pMB,
251 : edgomez 965 const uint32_t x_pos,
252 :     const uint32_t y_pos,
253 :     int16_t data[6 * 64])
254 :     {
255 : h 82 uint32_t stride = pParam->edged_width;
256 :     uint32_t stride2 = stride / 2;
257 : edgomez 965 uint32_t next_block = stride * 8;
258 : syskin 984 int32_t cst;
259 : Isibaar 3 uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
260 : syskin 984 const IMAGE * const pCurrent = &frame->image;
261 : edgomez 965 transfer_operation_8to16_t *transfer_op = NULL;
262 : edgomez 195
263 : edgomez 965 if ((frame->vop_flags & XVID_VOP_REDUCED)) {
264 :    
265 :     /* Image pointers */
266 :     pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5);
267 : edgomez 851 pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
268 :     pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
269 : edgomez 965
270 :     /* Block size */
271 :     cst = 16;
272 :    
273 :     /* Operation function */
274 :     transfer_op = (transfer_operation_8to16_t*)filter_18x18_to_8x8;
275 :     } else {
276 :    
277 :     /* Image pointers */
278 :     pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
279 : edgomez 851 pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
280 :     pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
281 : edgomez 965
282 :     /* Block size */
283 :     cst = 8;
284 :    
285 :     /* Operation function */
286 :     transfer_op = (transfer_operation_8to16_t*)transfer_8to16copy;
287 : edgomez 851 }
288 : Isibaar 3
289 : edgomez 965 /* Do the transfer */
290 : h 69 start_timer();
291 : edgomez 965 transfer_op(&data[0 * 64], pY_Cur, stride);
292 :     transfer_op(&data[1 * 64], pY_Cur + cst, stride);
293 :     transfer_op(&data[2 * 64], pY_Cur + next_block, stride);
294 :     transfer_op(&data[3 * 64], pY_Cur + next_block + cst, stride);
295 :     transfer_op(&data[4 * 64], pU_Cur, stride2);
296 :     transfer_op(&data[5 * 64], pV_Cur, stride2);
297 :     stop_transfer_timer();
298 : syskin 984 }
299 : edgomez 965
300 :     static __inline void
301 : syskin 984 MBTrans16to8(const MBParam * const pParam,
302 :     const FRAMEINFO * const frame,
303 :     const MACROBLOCK * const pMB,
304 : edgomez 965 const uint32_t x_pos,
305 :     const uint32_t y_pos,
306 :     int16_t data[6 * 64],
307 :     const uint32_t add,
308 :     const uint8_t cbp)
309 :     {
310 :     uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
311 :     uint32_t stride = pParam->edged_width;
312 :     uint32_t stride2 = stride / 2;
313 :     uint32_t next_block = stride * 8;
314 : syskin 984 uint32_t cst;
315 :     const IMAGE * const pCurrent = &frame->image;
316 : edgomez 965 transfer_operation_16to8_t *transfer_op = NULL;
317 :    
318 :     if (pMB->field_dct) {
319 :     next_block = stride;
320 :     stride *= 2;
321 : h 69 }
322 :    
323 : edgomez 965 if ((frame->vop_flags & XVID_VOP_REDUCED)) {
324 : edgomez 851
325 : edgomez 965 /* Image pointers */
326 :     pY_Cur = pCurrent->y + (y_pos << 5) * stride + (x_pos << 5);
327 :     pU_Cur = pCurrent->u + (y_pos << 4) * stride2 + (x_pos << 4);
328 :     pV_Cur = pCurrent->v + (y_pos << 4) * stride2 + (x_pos << 4);
329 : Isibaar 3
330 : edgomez 965 /* Block size */
331 :     cst = 16;
332 : Isibaar 3
333 : edgomez 965 /* Operation function */
334 :     if(add)
335 :     transfer_op = (transfer_operation_16to8_t*)add_upsampled_8x8_16to8;
336 :     else
337 :     transfer_op = (transfer_operation_16to8_t*)copy_upsampled_8x8_16to8;
338 :     } else {
339 : Isibaar 3
340 : edgomez 965 /* Image pointers */
341 :     pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
342 :     pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
343 :     pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
344 : Isibaar 3
345 : edgomez 965 /* Block size */
346 :     cst = 8;
347 : Isibaar 3
348 : edgomez 965 /* Operation function */
349 :     if(add)
350 :     transfer_op = (transfer_operation_16to8_t*)transfer_16to8add;
351 :     else
352 :     transfer_op = (transfer_operation_16to8_t*)transfer_16to8copy;
353 : Isibaar 3 }
354 : h 69
355 : edgomez 965 /* Do the operation */
356 : h 69 start_timer();
357 : edgomez 965 if (cbp&32) transfer_op(pY_Cur, &data[0 * 64], stride);
358 :     if (cbp&16) transfer_op(pY_Cur + cst, &data[1 * 64], stride);
359 :     if (cbp& 8) transfer_op(pY_Cur + next_block, &data[2 * 64], stride);
360 :     if (cbp& 4) transfer_op(pY_Cur + next_block + cst, &data[3 * 64], stride);
361 :     if (cbp& 2) transfer_op(pU_Cur, &data[4 * 64], stride2);
362 :     if (cbp& 1) transfer_op(pV_Cur, &data[5 * 64], stride2);
363 : h 69 stop_transfer_timer();
364 : Isibaar 3 }
365 : h 69
366 : edgomez 965 /*****************************************************************************
367 :     * Module functions
368 :     ****************************************************************************/
369 :    
370 : syskin 984 void
371 :     MBTransQuantIntra(const MBParam * const pParam,
372 :     const FRAMEINFO * const frame,
373 :     MACROBLOCK * const pMB,
374 : chl 368 const uint32_t x_pos,
375 :     const uint32_t y_pos,
376 :     int16_t data[6 * 64],
377 :     int16_t qcoeff[6 * 64])
378 :     {
379 : h 69
380 : edgomez 965 /* Transfer data */
381 :     MBTrans8to16(pParam, frame, pMB, x_pos, y_pos, data);
382 : chl 368
383 : edgomez 965 /* Perform DCT (and field decision) */
384 :     MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);
385 : chl 368
386 : edgomez 965 /* Quantize the block */
387 : chl 995 MBQuantIntra(pParam, frame, pMB, data, qcoeff);
388 : edgomez 965
389 :     /* DeQuantize the block */
390 :     MBDeQuantIntra(pParam, pMB->quant, data, qcoeff);
391 :    
392 :     /* Perform inverse DCT*/
393 :     MBiDCT(data, 0x3F);
394 :    
395 :     /* Transfer back the data -- Don't add data */
396 :     MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 0, 0x3F);
397 : chl 368 }
398 :    
399 : edgomez 965
400 : chl 368 uint8_t
401 : syskin 984 MBTransQuantInter(const MBParam * const pParam,
402 :     const FRAMEINFO * const frame,
403 :     MACROBLOCK * const pMB,
404 : edgomez 914 const uint32_t x_pos,
405 :     const uint32_t y_pos,
406 : chl 368 int16_t data[6 * 64],
407 :     int16_t qcoeff[6 * 64])
408 :     {
409 :     uint8_t cbp;
410 : edgomez 965 uint32_t limit;
411 : chl 368
412 : edgomez 914 /*
413 : edgomez 965 * There is no MBTrans8to16 for Inter block, that's done in motion compensation
414 :     * already
415 : edgomez 914 */
416 : chl 368
417 : edgomez 965 /* Perform DCT (and field decision) */
418 :     MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);
419 : edgomez 914
420 : edgomez 965 /* Set the limit threshold */
421 :     limit = PVOP_TOOSMALL_LIMIT + ((pMB->quant == 1)? 1 : 0);
422 : chl 368
423 : edgomez 965 /* Quantize the block */
424 : chl 995 cbp = MBQuantInter(pParam, frame, pMB, data, qcoeff, 0, limit);
425 : chl 368
426 : edgomez 965 /* DeQuantize the block */
427 :     MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp);
428 : chl 368
429 : edgomez 965 /* Perform inverse DCT*/
430 :     MBiDCT(data, cbp);
431 : chl 368
432 : edgomez 965 /* Transfer back the data -- Add the data */
433 :     MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp);
434 : syskin 984
435 : edgomez 965 return(cbp);
436 : chl 368 }
437 :    
438 : edgomez 965 uint8_t
439 :     MBTransQuantInterBVOP(const MBParam * pParam,
440 : chl 368 FRAMEINFO * frame,
441 :     MACROBLOCK * pMB,
442 :     const uint32_t x_pos,
443 :     const uint32_t y_pos,
444 :     int16_t data[6 * 64],
445 : edgomez 965 int16_t qcoeff[6 * 64])
446 : chl 368 {
447 : edgomez 965 uint8_t cbp;
448 :     uint32_t limit;
449 : syskin 984
450 : edgomez 965 /*
451 :     * There is no MBTrans8to16 for Inter block, that's done in motion compensation
452 :     * already
453 :     */
454 : chl 368
455 : edgomez 965 /* Perform DCT (and field decision) */
456 :     MBfDCT(pParam, frame, pMB, x_pos, y_pos, data);
457 : chl 368
458 : edgomez 965 /* Set the limit threshold */
459 :     limit = BVOP_TOOSMALL_LIMIT;
460 : chl 368
461 : edgomez 965 /* Quantize the block */
462 : chl 995 cbp = MBQuantInter(pParam, frame, pMB, data, qcoeff, 1, limit);
463 : chl 368
464 : edgomez 965 /*
465 :     * History comment:
466 :     * We don't have to DeQuant, iDCT and Transfer back data for B-frames.
467 :     *
468 :     * BUT some plugins require the original frame to be passed so we have
469 :     * to take care of that here
470 :     */
471 :     if((pParam->plugin_flags & XVID_REQORIGINAL)) {
472 : chl 368
473 : edgomez 965 /* DeQuantize the block */
474 :     MBDeQuantInter(pParam, pMB->quant, data, qcoeff, cbp);
475 : chl 368
476 : edgomez 965 /* Perform inverse DCT*/
477 :     MBiDCT(data, cbp);
478 : h 69
479 : edgomez 965 /* Transfer back the data -- Add the data */
480 :     MBTrans16to8(pParam, frame, pMB, x_pos, y_pos, data, 1, cbp);
481 : edgomez 851 }
482 :    
483 : edgomez 965 return(cbp);
484 : edgomez 851 }
485 :    
486 :     /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */
487 :     uint32_t
488 :     MBFieldTest_c(int16_t data[6 * 64])
489 :     {
490 : edgomez 195 const uint8_t blocks[] =
491 :     { 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 };
492 :     const uint8_t lines[] = { 0, 16, 32, 48, 0, 16, 32, 48 };
493 : edgomez 78
494 : h 69 int frame = 0, field = 0;
495 :     int i, j;
496 :    
497 : edgomez 195 for (i = 0; i < 7; ++i) {
498 :     for (j = 0; j < 8; ++j) {
499 :     frame +=
500 : edgomez 982 abs(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]);
501 : edgomez 195 frame +=
502 : edgomez 982 abs(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]);
503 : edgomez 195 frame +=
504 : edgomez 982 abs(data[2 * 64 + (i + 1) * 8 + j] - data[2 * 64 + i * 8 + j]);
505 : edgomez 195 frame +=
506 : edgomez 982 abs(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]);
507 : h 69
508 : edgomez 195 field +=
509 : edgomez 982 abs(data[blocks[i + 1] + lines[i + 1] + j] -
510 : edgomez 195 data[blocks[i] + lines[i] + j]);
511 :     field +=
512 : edgomez 982 abs(data[blocks[i + 1] + lines[i + 1] + 8 + j] -
513 : edgomez 195 data[blocks[i] + lines[i] + 8 + j]);
514 :     field +=
515 : edgomez 982 abs(data[blocks[i + 1] + 64 + lines[i + 1] + j] -
516 : edgomez 195 data[blocks[i] + 64 + lines[i] + j]);
517 :     field +=
518 : edgomez 982 abs(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] -
519 : edgomez 195 data[blocks[i] + 64 + lines[i] + 8 + j]);
520 : h 69 }
521 :     }
522 :    
523 : edgomez 851 return (frame >= (field + 350));
524 : h 69 }
525 :    
526 :    
527 :     /* deinterlace Y blocks vertically */
528 :    
529 :     #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp))
530 : syskin 984 #define LINE(X,Y) &data[X*64 + Y*8]
531 : h 69
532 : edgomez 195 void
533 :     MBFrameToField(int16_t data[6 * 64])
534 : h 69 {
535 :     int16_t tmp[8];
536 :    
537 :     /* left blocks */
538 :    
539 : edgomez 851 // 1=2, 2=4, 4=8, 8=1
540 : edgomez 195 MOVLINE(tmp, LINE(0, 1));
541 :     MOVLINE(LINE(0, 1), LINE(0, 2));
542 :     MOVLINE(LINE(0, 2), LINE(0, 4));
543 :     MOVLINE(LINE(0, 4), LINE(2, 0));
544 :     MOVLINE(LINE(2, 0), tmp);
545 : h 69
546 : edgomez 851 // 3=6, 6=12, 12=9, 9=3
547 : edgomez 195 MOVLINE(tmp, LINE(0, 3));
548 :     MOVLINE(LINE(0, 3), LINE(0, 6));
549 :     MOVLINE(LINE(0, 6), LINE(2, 4));
550 :     MOVLINE(LINE(2, 4), LINE(2, 1));
551 :     MOVLINE(LINE(2, 1), tmp);
552 : h 69
553 : edgomez 851 // 5=10, 10=5
554 : edgomez 195 MOVLINE(tmp, LINE(0, 5));
555 :     MOVLINE(LINE(0, 5), LINE(2, 2));
556 :     MOVLINE(LINE(2, 2), tmp);
557 : h 69
558 : edgomez 851 // 7=14, 14=13, 13=11, 11=7
559 : edgomez 195 MOVLINE(tmp, LINE(0, 7));
560 :     MOVLINE(LINE(0, 7), LINE(2, 6));
561 :     MOVLINE(LINE(2, 6), LINE(2, 5));
562 :     MOVLINE(LINE(2, 5), LINE(2, 3));
563 :     MOVLINE(LINE(2, 3), tmp);
564 : h 69
565 :     /* right blocks */
566 :    
567 : edgomez 851 // 1=2, 2=4, 4=8, 8=1
568 : edgomez 195 MOVLINE(tmp, LINE(1, 1));
569 :     MOVLINE(LINE(1, 1), LINE(1, 2));
570 :     MOVLINE(LINE(1, 2), LINE(1, 4));
571 :     MOVLINE(LINE(1, 4), LINE(3, 0));
572 :     MOVLINE(LINE(3, 0), tmp);
573 : h 69
574 : edgomez 851 // 3=6, 6=12, 12=9, 9=3
575 : edgomez 195 MOVLINE(tmp, LINE(1, 3));
576 :     MOVLINE(LINE(1, 3), LINE(1, 6));
577 :     MOVLINE(LINE(1, 6), LINE(3, 4));
578 :     MOVLINE(LINE(3, 4), LINE(3, 1));
579 :     MOVLINE(LINE(3, 1), tmp);
580 : h 69
581 : edgomez 851 // 5=10, 10=5
582 : edgomez 195 MOVLINE(tmp, LINE(1, 5));
583 :     MOVLINE(LINE(1, 5), LINE(3, 2));
584 :     MOVLINE(LINE(3, 2), tmp);
585 : h 69
586 : edgomez 851 // 7=14, 14=13, 13=11, 11=7
587 : edgomez 195 MOVLINE(tmp, LINE(1, 7));
588 :     MOVLINE(LINE(1, 7), LINE(3, 6));
589 :     MOVLINE(LINE(3, 6), LINE(3, 5));
590 :     MOVLINE(LINE(3, 5), LINE(3, 3));
591 :     MOVLINE(LINE(3, 3), tmp);
592 : h 69 }

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