[cvs] / xvidcore / src / utils / mbtransquant.c Repository:
ViewVC logotype

Diff of /xvidcore/src/utils/mbtransquant.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.11

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