[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.2.5, Tue Nov 12 16:05:27 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 60  Line 65 
65  #include "../quant/quant_h263.h"  #include "../quant/quant_h263.h"
66  #include "../encoder.h"  #include "../encoder.h"
67    
68    MBFIELDTEST_PTR MBFieldTest;
69    
70  #define MIN(X, Y) ((X)<(Y)?(X):(Y))  #define MIN(X, Y) ((X)<(Y)?(X):(Y))
71  #define MAX(X, Y) ((X)>(Y)?(X):(Y))  #define MAX(X, Y) ((X)>(Y)?(X):(Y))
72    
73  #define TOOSMALL_LIMIT 1 /* skip blocks having a coefficient sum below this value */  #define TOOSMALL_LIMIT 1 /* skip blocks having a coefficient sum below this value */
74    
75  /* this isnt pretty, but its better than 20 ifdefs */  void
76    MBTransQuantIntra(const MBParam * pParam,
77  void MBTransQuantIntra(const MBParam *pParam,                                    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                    uint32_t increase_limit = (iQuant == 1) ? 1 : 0;
197    
198                  /*                  /*
199                  no need to transfer 8->16-bit                   *  no need to transfer 8->16-bit
200                  (this is performed already in motion compensation)                   * (this is performed already in motion compensation)
201                  */                  */
202                  start_timer();                  start_timer();
203                  fdct(data[i]);                  fdct(&data[i * 64]);
204                  stop_dct_timer();                  stop_dct_timer();
205    
206                  if (pParam->quant_type == 0)                  if (pParam->m_quant_type == 0) {
                 {  
207                          start_timer();                          start_timer();
208                          sum = quant_inter(qcoeff[i], data[i], iQuant);                          sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant);
209                          stop_quant_timer();                          stop_quant_timer();
210                    } else {
211                            start_timer();
212                            sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant);
213                            stop_quant_timer();
214                    }
215    
216                    if ((sum >= TOOSMALL_LIMIT + increase_limit) || (qcoeff[i*64] != 0) ||
217                            (qcoeff[i*64+1] != 0) || (qcoeff[i*64+8] != 0)) {
218    
219                            if (pParam->m_quant_type == H263_QUANT) {
220                                    start_timer();
221                                    dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
222                                    stop_iquant_timer();
223                            } else {
224                                    start_timer();
225                                    dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
226                                    stop_iquant_timer();
227                            }
228    
229                            cbp |= 1 << (5 - i);
230    
231                            start_timer();
232                            idct(&data[i * 64]);
233                            stop_idct_timer();
234                    }
235            }
236    
237            if (pMB->field_dct) {
238                    next_block = stride;
239                    stride *= 2;
240            }
241    
242            start_timer();
243            if (cbp & 32)
244                    transfer_16to8add(pY_Cur, &data[0 * 64], stride);
245            if (cbp & 16)
246                    transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
247            if (cbp & 8)
248                    transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
249            if (cbp & 4)
250                    transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride);
251            if (cbp & 2)
252                    transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
253            if (cbp & 1)
254                    transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
255            stop_transfer_timer();
256    
257            return cbp;
258    
259    }
260    
261    void
262    MBTransQuantIntra2(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            MBTrans(pParam,frame,pMB,x_pos,y_pos,data);
271            MBfDCT(pParam,frame,pMB,data);
272            MBQuantIntra(pParam,frame,pMB,data,qcoeff);
273            MBDeQuantIntra(pParam,frame->quant,data,qcoeff);
274            MBiDCT(data,0x3F);
275            MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,0x3F);
276    }
277    
278    
279    uint8_t
280    MBTransQuantInter2(const MBParam * pParam,
281                                      FRAMEINFO * frame,
282                                      MACROBLOCK * pMB,
283                                      const uint32_t x_pos,
284                                      const uint32_t y_pos,
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            MBDeQuantInter(pParam,frame->quant,data,qcoeff,cbp);
295            MBiDCT(data,cbp);
296            MBTransAdd(pParam,frame,pMB,x_pos,y_pos,data,cbp);
297    
298            return cbp;
299    }
300    
301    uint8_t
302    MBTransQuantInterBVOP(const MBParam * pParam,
303                                      FRAMEINFO * frame,
304                                      MACROBLOCK * pMB,
305                                      int16_t data[6 * 64],
306                                      int16_t qcoeff[6 * 64])
307    {
308            uint8_t cbp;
309    
310    /* there is no MBTrans for Inter block, that's done in motion compensation already */
311    
312            MBfDCT(pParam,frame,pMB,data);
313            cbp = MBQuantInter(pParam,frame->quant,data,qcoeff);
314    
315    /* we don't have to DeQuant, iDCT and Transfer back data for B-frames */
316    
317            return cbp;
318                  }                  }
319                  else  
320    
321    void
322    MBfDCT(const MBParam * pParam,
323                                      FRAMEINFO * frame,
324                                      MACROBLOCK * pMB,
325                                      int16_t data[6 * 64])
326                  {                  {
327            int i;
328    
329                          start_timer();                          start_timer();
330                          sum = quant4_inter(qcoeff[i], data[i], iQuant);          pMB->field_dct = 0;
331                          stop_quant_timer();          if ((frame->global_flags & XVID_INTERLACING)) {
332                    pMB->field_dct = MBDecideFieldDCT(data);
333                  }                  }
334            stop_interlacing_timer();
335    
336                  if(sum >= TOOSMALL_LIMIT) { // skip block ?          for (i = 0; i < 6; i++) {
337                    start_timer();
338                    fdct(&data[i * 64]);
339                    stop_dct_timer();
340            }
341    }
342    
343                          if (pParam->quant_type == H263_QUANT)  void
344    MBQuantDeQuantIntra(const MBParam * pParam,
345                                            FRAMEINFO * frame,
346                                            MACROBLOCK * pMB,
347                                            int16_t qcoeff[6 * 64],
348                                            int16_t data[6*64])
349                          {                          {
350            int i;
351            int iQuant = frame->quant;
352    
353                                  start_timer();                                  start_timer();
354                                  dequant_inter(data[i], qcoeff[i], iQuant);          pMB->field_dct = 0;
355            if ((frame->global_flags & XVID_INTERLACING)) {
356                    pMB->field_dct = MBDecideFieldDCT(data);
357            }
358            stop_interlacing_timer();
359    
360            for (i = 0; i < 6; i++) {
361                    uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
362    
363                    if (pParam->m_quant_type == H263_QUANT) {
364                            start_timer();
365                            quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
366                            stop_quant_timer();
367    
368                            start_timer();
369                            dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
370                                  stop_iquant_timer();                                  stop_iquant_timer();
371                    } else {
372                            start_timer();
373                            quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
374                            stop_quant_timer();
375    
376                            start_timer();
377                            dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
378                            stop_iquant_timer();
379                    }
380                          }                          }
381                          else  }
382    
383    void
384    MBQuantIntra(const MBParam * pParam,
385                             FRAMEINFO * frame,
386                             MACROBLOCK *pMB,
387                         int16_t qcoeff[6 * 64],
388                             int16_t data[6*64])
389                          {                          {
390            int i;
391            int iQuant = frame->quant;
392    
393            start_timer();
394            pMB->field_dct = 0;
395            if ((frame->global_flags & XVID_INTERLACING)) {
396                    pMB->field_dct = MBDecideFieldDCT(data);
397            }
398            stop_interlacing_timer();
399    
400            for (i = 0; i < 6; i++) {
401                    uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
402    
403                    if (pParam->m_quant_type == H263_QUANT) {
404                            start_timer();
405                            quant_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
406                            stop_quant_timer();
407                    } else {
408                                  start_timer();                                  start_timer();
409                                  dequant4_inter(data[i], qcoeff[i], iQuant);                          quant4_intra(&qcoeff[i * 64], &data[i * 64], iQuant, iDcScaler);
410                            stop_quant_timer();
411                    }
412            }
413    }
414    
415    void
416    MBDeQuantIntra(const MBParam * pParam,
417                               const int iQuant,
418                                      int16_t qcoeff[6 * 64],
419                                      int16_t data[6*64])
420    {
421            int i;
422    
423            for (i = 0; i < 6; i++) {
424                    uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
425    
426                    if (pParam->m_quant_type == H263_QUANT) {
427                            start_timer();
428                            dequant_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
429                            stop_iquant_timer();
430                    } else {
431                            start_timer();
432                            dequant4_intra(&data[i * 64], &qcoeff[i * 64], iQuant, iDcScaler);
433                                  stop_iquant_timer();                                  stop_iquant_timer();
434                          }                          }
435            }
436    }
437    
438    uint8_t
439    MBQuantInter(const MBParam * pParam,
440                             const int iQuant,
441                                      int16_t data[6 * 64],
442                                      int16_t qcoeff[6 * 64])
443    {
444    
445            int i;
446            uint8_t cbp = 0;
447            int sum;
448    
449            for (i = 0; i < 6; i++) {
450    
451                    if (pParam->m_quant_type == 0) {
452                            start_timer();
453                            sum = quant_inter(&qcoeff[i * 64], &data[i * 64], iQuant);
454                            stop_quant_timer();
455                    } else {
456                            start_timer();
457                            sum = quant4_inter(&qcoeff[i * 64], &data[i * 64], iQuant);
458                            stop_quant_timer();
459                    }
460    
461                    if (sum >= TOOSMALL_LIMIT) {    // skip block ?
462                          cbp |= 1 << (5 - i);                          cbp |= 1 << (5 - i);
463                    }
464            }
465            return cbp;
466    }
467    
468    void
469    MBDeQuantInter( const MBParam * pParam,
470                                    const int iQuant,
471                                      int16_t data[6 * 64],
472                                      int16_t qcoeff[6 * 64],
473                                      const uint8_t cbp)
474    {
475            int i;
476    
477            for (i = 0; i < 6; i++) {
478                    if (cbp & (1 << (5 - i)))
479                    {
480                            if (pParam->m_quant_type == H263_QUANT) {
481                                    start_timer();
482                                    dequant_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
483                                    stop_iquant_timer();
484                            } else {
485                                    start_timer();
486                                    dequant4_inter(&data[i * 64], &qcoeff[i * 64], iQuant);
487                                    stop_iquant_timer();
488                            }
489                    }
490            }
491    }
492    
493    void
494    MBiDCT( int16_t data[6 * 64],
495                    const uint8_t cbp)
496    {
497            int i;
498    
499            for (i = 0; i < 6; i++) {
500                    if (cbp & (1 << (5 - i)))
501                    {
502                          start_timer();                          start_timer();
503                          idct(data[i]);                          idct(&data[i * 64]);
504                          stop_idct_timer();                          stop_idct_timer();
505    
506                    }
507            }
508    }
509    
510    
511    void
512    MBTrans(const MBParam * pParam,
513                                      FRAMEINFO * frame,
514                                      MACROBLOCK * pMB,
515                                      const uint32_t x_pos,
516                                      const uint32_t y_pos,
517                                      int16_t data[6 * 64])
518    {
519            uint32_t stride = pParam->edged_width;
520            uint32_t stride2 = stride / 2;
521            uint32_t next_block = stride * 8;
522            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
523            IMAGE *pCurrent = &frame->image;
524    
525            pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
526            pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
527            pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
528    
529                          start_timer();                          start_timer();
530            transfer_8to16copy(&data[0 * 64], pY_Cur, stride);
531            transfer_8to16copy(&data[1 * 64], pY_Cur + 8, stride);
532            transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride);
533            transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride);
534            transfer_8to16copy(&data[4 * 64], pU_Cur, stride2);
535            transfer_8to16copy(&data[5 * 64], pV_Cur, stride2);
536            stop_transfer_timer();
537    }
538    
539    void
540    MBTransAdd(const MBParam * pParam,
541                                      FRAMEINFO * frame,
542                                      MACROBLOCK * pMB,
543                                      const uint32_t x_pos,
544                                      const uint32_t y_pos,
545                                      int16_t data[6 * 64],
546                                      const uint8_t cbp)
547    {
548            uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
549            uint32_t stride = pParam->edged_width;
550            uint32_t stride2 = stride / 2;
551            uint32_t next_block = stride * 8;
552            IMAGE *pCurrent = &frame->image;
553    
554            pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
555            pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
556            pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
557    
558                          switch(i) {          if (pMB->field_dct) {
559                          case 0:                  next_block = stride;
560                                  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;  
561                          }                          }
562    
563            start_timer();
564            if (cbp & 32)
565                    transfer_16to8add(pY_Cur, &data[0 * 64], stride);
566            if (cbp & 16)
567                    transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride);
568            if (cbp & 8)
569                    transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
570            if (cbp & 4)
571                    transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride);
572            if (cbp & 2)
573                    transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
574            if (cbp & 1)
575                    transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
576                          stop_transfer_timer();                          stop_transfer_timer();
577                  }                  }
578    
579    
580    
581    /* permute block and return field dct choice */
582    
583    
584    uint32_t
585    MBDecideFieldDCT(int16_t data[6 * 64])
586    {
587            uint32_t field = MBFieldTest(data);
588    
589            if (field) {
590                    MBFrameToField(data);
591            }
592    
593            return field;
594          }          }
595      return cbp;  
596    
597    /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */
598    
599    uint32_t
600    MBFieldTest_c(int16_t data[6 * 64])
601    {
602            const uint8_t blocks[] =
603                    { 0 * 64, 0 * 64, 0 * 64, 0 * 64, 2 * 64, 2 * 64, 2 * 64, 2 * 64 };
604            const uint8_t lines[] = { 0, 16, 32, 48, 0, 16, 32, 48 };
605    
606            int frame = 0, field = 0;
607            int i, j;
608    
609            for (i = 0; i < 7; ++i) {
610                    for (j = 0; j < 8; ++j) {
611                            frame +=
612                                    ABS(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]);
613                            frame +=
614                                    ABS(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]);
615                            frame +=
616                                    ABS(data[2 * 64 + (i + 1) * 8 + j] - data[2 * 64 + i * 8 + j]);
617                            frame +=
618                                    ABS(data[3 * 64 + (i + 1) * 8 + j] - data[3 * 64 + i * 8 + j]);
619    
620                            field +=
621                                    ABS(data[blocks[i + 1] + lines[i + 1] + j] -
622                                            data[blocks[i] + lines[i] + j]);
623                            field +=
624                                    ABS(data[blocks[i + 1] + lines[i + 1] + 8 + j] -
625                                            data[blocks[i] + lines[i] + 8 + j]);
626                            field +=
627                                    ABS(data[blocks[i + 1] + 64 + lines[i + 1] + j] -
628                                            data[blocks[i] + 64 + lines[i] + j]);
629                            field +=
630                                    ABS(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] -
631                                            data[blocks[i] + 64 + lines[i] + 8 + j]);
632                    }
633            }
634    
635            return (frame >= (field + 350));
636    }
637    
638    
639    /* deinterlace Y blocks vertically */
640    
641    #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp))
642    #define LINE(X,Y)    &data[X*64 + Y*8]
643    
644    void
645    MBFrameToField(int16_t data[6 * 64])
646    {
647            int16_t tmp[8];
648    
649            /* left blocks */
650    
651            // 1=2, 2=4, 4=8, 8=1
652            MOVLINE(tmp, LINE(0, 1));
653            MOVLINE(LINE(0, 1), LINE(0, 2));
654            MOVLINE(LINE(0, 2), LINE(0, 4));
655            MOVLINE(LINE(0, 4), LINE(2, 0));
656            MOVLINE(LINE(2, 0), tmp);
657    
658            // 3=6, 6=12, 12=9, 9=3
659            MOVLINE(tmp, LINE(0, 3));
660            MOVLINE(LINE(0, 3), LINE(0, 6));
661            MOVLINE(LINE(0, 6), LINE(2, 4));
662            MOVLINE(LINE(2, 4), LINE(2, 1));
663            MOVLINE(LINE(2, 1), tmp);
664    
665            // 5=10, 10=5
666            MOVLINE(tmp, LINE(0, 5));
667            MOVLINE(LINE(0, 5), LINE(2, 2));
668            MOVLINE(LINE(2, 2), tmp);
669    
670            // 7=14, 14=13, 13=11, 11=7
671            MOVLINE(tmp, LINE(0, 7));
672            MOVLINE(LINE(0, 7), LINE(2, 6));
673            MOVLINE(LINE(2, 6), LINE(2, 5));
674            MOVLINE(LINE(2, 5), LINE(2, 3));
675            MOVLINE(LINE(2, 3), tmp);
676    
677            /* right blocks */
678    
679            // 1=2, 2=4, 4=8, 8=1
680            MOVLINE(tmp, LINE(1, 1));
681            MOVLINE(LINE(1, 1), LINE(1, 2));
682            MOVLINE(LINE(1, 2), LINE(1, 4));
683            MOVLINE(LINE(1, 4), LINE(3, 0));
684            MOVLINE(LINE(3, 0), tmp);
685    
686            // 3=6, 6=12, 12=9, 9=3
687            MOVLINE(tmp, LINE(1, 3));
688            MOVLINE(LINE(1, 3), LINE(1, 6));
689            MOVLINE(LINE(1, 6), LINE(3, 4));
690            MOVLINE(LINE(3, 4), LINE(3, 1));
691            MOVLINE(LINE(3, 1), tmp);
692    
693            // 5=10, 10=5
694            MOVLINE(tmp, LINE(1, 5));
695            MOVLINE(LINE(1, 5), LINE(3, 2));
696            MOVLINE(LINE(3, 2), tmp);
697    
698            // 7=14, 14=13, 13=11, 11=7
699            MOVLINE(tmp, LINE(1, 7));
700            MOVLINE(LINE(1, 7), LINE(3, 6));
701            MOVLINE(LINE(3, 6), LINE(3, 5));
702            MOVLINE(LINE(3, 5), LINE(3, 3));
703            MOVLINE(LINE(3, 3), tmp);
704  }  }

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

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