[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.3, Thu Mar 28 20:57:25 2002 UTC revision 1.11.2.3, Thu Sep 26 04:51:01 2002 UTC
# Line 42  Line 42 
42    *                                                                            *    *                                                                            *
43    *  Revision history:                                                         *    *  Revision history:                                                         *
44    *                                                                            *    *                                                                            *
45    *  26.03.2002 interlacing support - moved transfers outside loops    *  29.03.2002 interlacing speedup - used transfer strides instead of             *
46    *  22.12.2001 get_dc_scaler() moved to common.h    *             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    *                                                                            *    *                                                                            *
# Line 63  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  2       /* skip blocks having a coefficient sum below this value */
74    
75  /* this isnt pretty, but its better than 20 ifdefs */  /* this isnt pretty, but its better than 20 ifdefs */
76    
77  void MBTransQuantIntra(const MBParam *pParam,  void
78    MBTransQuantIntra(const MBParam * pParam,
79                                      FRAMEINFO * frame,
80                         MACROBLOCK * pMB,                         MACROBLOCK * pMB,
81                         const uint32_t x_pos,                         const uint32_t x_pos,
82                         const uint32_t y_pos,                         const uint32_t y_pos,
83                         int16_t data[6*64],                         int16_t data[6*64],
84                         int16_t qcoeff[6*64],                                    int16_t qcoeff[6 * 64])
                        IMAGE * const pCurrent)  
   
85  {  {
86    
87          const uint32_t stride = pParam->edged_width;          uint32_t stride = pParam->edged_width;
88            uint32_t stride2 = stride / 2;
89            uint32_t next_block = stride * 8;
90          uint32_t i;          uint32_t i;
91          uint32_t iQuant = pParam->quant;          uint32_t iQuant = frame->quant;
92          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
93            IMAGE *pCurrent = &frame->image;
94    
95          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
96          pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3);          pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
97          pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3);          pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
98    
99          start_timer();          start_timer();
100          transfer_8to16copy(&data[0*64], pY_Cur, stride);          transfer_8to16copy(&data[0*64], pY_Cur, stride);
101          transfer_8to16copy(&data[1*64], pY_Cur + 8, stride);          transfer_8to16copy(&data[1*64], pY_Cur + 8, stride);
102          transfer_8to16copy(&data[2*64], pY_Cur + 8 * stride, stride);          transfer_8to16copy(&data[2 * 64], pY_Cur + next_block, stride);
103          transfer_8to16copy(&data[3*64], pY_Cur + 8 * stride + 8, stride);          transfer_8to16copy(&data[3 * 64], pY_Cur + next_block + 8, stride);
104          transfer_8to16copy(&data[4*64], pU_Cur, stride / 2);          transfer_8to16copy(&data[4 * 64], pU_Cur, stride2);
105          transfer_8to16copy(&data[5*64], pV_Cur, stride / 2);          transfer_8to16copy(&data[5 * 64], pV_Cur, stride2);
106          stop_transfer_timer();          stop_transfer_timer();
107    
108          start_timer();          start_timer();
109          pMB->field_dct = 0;          pMB->field_dct = 0;
110          if (pParam->global_flags & XVID_INTERLACING)          if ((frame->global_flags & XVID_INTERLACING) &&
111          {                  (x_pos>0) && (x_pos<pParam->mb_width-1) &&
112                    (y_pos>0) && (y_pos<pParam->mb_height-1)) {
113                  pMB->field_dct = MBDecideFieldDCT(data);                  pMB->field_dct = MBDecideFieldDCT(data);
114          }          }
115          stop_interlacing_timer();          stop_interlacing_timer();
116    
117          for(i = 0; i < 6; i++)          for (i = 0; i < 6; i++) {
         {  
118                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);                  uint32_t iDcScaler = get_dc_scaler(iQuant, i < 4);
119    
120                  start_timer();                  start_timer();
121                  fdct(&data[i*64]);                  fdct(&data[i*64]);
122                  stop_dct_timer();                  stop_dct_timer();
123    
124                  if (pParam->quant_type == H263_QUANT)                  if (pParam->m_quant_type == H263_QUANT) {
                 {  
125                          start_timer();                          start_timer();
126                          quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler);                          quant_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler);
127                          stop_quant_timer();                          stop_quant_timer();
# Line 123  Line 129 
129                          start_timer();                          start_timer();
130                          dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler);                          dequant_intra(&data[i*64], &qcoeff[i*64], iQuant, iDcScaler);
131                          stop_iquant_timer();                          stop_iquant_timer();
132                  }                  } else {
                 else  
                 {  
133                          start_timer();                          start_timer();
134                          quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler);                          quant4_intra(&qcoeff[i*64], &data[i*64], iQuant, iDcScaler);
135                          stop_quant_timer();                          stop_quant_timer();
# Line 140  Line 144 
144                  stop_idct_timer();                  stop_idct_timer();
145          }          }
146    
147          start_timer();          if (pMB->field_dct) {
148          if (pMB->field_dct)                  next_block = stride;
149          {                  stride *= 2;
                 MBFieldToFrame(data);  
150          }          }
         stop_interlacing_timer();  
151    
152          start_timer();          start_timer();
153          transfer_16to8copy(pY_Cur,                  &data[0*64], stride);          transfer_16to8copy(pY_Cur,                  &data[0*64], stride);
154          transfer_16to8copy(pY_Cur + 8,              &data[1*64], stride);          transfer_16to8copy(pY_Cur + 8,              &data[1*64], stride);
155          transfer_16to8copy(pY_Cur + 8 * stride,     &data[2*64], stride);          transfer_16to8copy(pY_Cur + next_block, &data[2 * 64], stride);
156          transfer_16to8copy(pY_Cur + 8 + 8 * stride, &data[3*64], stride);          transfer_16to8copy(pY_Cur + next_block + 8, &data[3 * 64], stride);
157          transfer_16to8copy(pU_Cur,                  &data[4*64], stride / 2);          transfer_16to8copy(pU_Cur, &data[4 * 64], stride2);
158          transfer_16to8copy(pV_Cur,                  &data[5*64], stride / 2);          transfer_16to8copy(pV_Cur, &data[5 * 64], stride2);
159          stop_transfer_timer();          stop_transfer_timer();
160    
161  }  }
162    
163    
164  uint8_t MBTransQuantInter(const MBParam *pParam,  uint8_t
165    MBTransQuantInter(const MBParam * pParam,
166                                      FRAMEINFO * frame,
167                            MACROBLOCK * pMB,                            MACROBLOCK * pMB,
168                            const uint32_t x_pos, const uint32_t y_pos,                                    const uint32_t x_pos,
169                                      const uint32_t y_pos,
170                            int16_t data[6*64],                            int16_t data[6*64],
171                            int16_t qcoeff[6*64],                                    int16_t qcoeff[6 * 64])
                           IMAGE * const pCurrent)  
   
172  {  {
173    
174          const uint32_t stride = pParam->edged_width;          uint32_t stride = pParam->edged_width;
175            uint32_t stride2 = stride / 2;
176            uint32_t next_block = stride * 8;
177          uint32_t i;          uint32_t i;
178          uint32_t iQuant = pParam->quant;          uint32_t iQuant = frame->quant;
179          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;          uint8_t *pY_Cur, *pU_Cur, *pV_Cur;
180          uint8_t cbp = 0;          uint8_t cbp = 0;
181          uint32_t sum;          uint32_t sum;
182            IMAGE *pCurrent = &frame->image;
183    
184          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);          pY_Cur = pCurrent->y + (y_pos << 4) * stride + (x_pos << 4);
185          pU_Cur = pCurrent->u + (y_pos << 3) * (stride >> 1) + (x_pos << 3);          pU_Cur = pCurrent->u + (y_pos << 3) * stride2 + (x_pos << 3);
186          pV_Cur = pCurrent->v + (y_pos << 3) * (stride >> 1) + (x_pos << 3);          pV_Cur = pCurrent->v + (y_pos << 3) * stride2 + (x_pos << 3);
187    
188          start_timer();          start_timer();
189          pMB->field_dct = 0;          pMB->field_dct = 0;
190          if (pParam->global_flags & XVID_INTERLACING)          if ((frame->global_flags & XVID_INTERLACING) &&
191          {                  (x_pos>0) && (x_pos<pParam->mb_width-1) &&
192                    (y_pos>0) && (y_pos<pParam->mb_height-1)) {
193                  pMB->field_dct = MBDecideFieldDCT(data);                  pMB->field_dct = MBDecideFieldDCT(data);
194          }          }
195          stop_interlacing_timer();          stop_interlacing_timer();
196    
197          for(i = 0; i < 6; i++)          for (i = 0; i < 6; i++) {
         {  
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)
# Line 197  Line 203 
203                  fdct(&data[i*64]);                  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*64], &data[i*64], 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) || (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    
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();
330            pMB->field_dct = 0;
331            if ((frame->global_flags & XVID_INTERLACING)) {
332                    pMB->field_dct = MBDecideFieldDCT(data);
333            }
334            stop_interlacing_timer();
335    
336            for (i = 0; i < 6; i++) {
337                    start_timer();
338                    fdct(&data[i * 64]);
339                    stop_dct_timer();
340            }
341    }
342    
343    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();
354            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();
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                  }                  }
382                  else  
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();
409                            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();
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();                          start_timer();
457                          sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant);                          sum = quant4_inter(&qcoeff[i*64], &data[i*64], iQuant);
458                          stop_quant_timer();                          stop_quant_timer();
459                  }                  }
460    
461                  if(sum >= TOOSMALL_LIMIT) { // skip block ?                  if(sum >= TOOSMALL_LIMIT) { // skip block ?
462                            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                          if (pParam->quant_type == H263_QUANT)          for (i = 0; i < 6; i++) {
478                    if (cbp & (1 << (5 - i)))
479                          {                          {
480                            if (pParam->m_quant_type == H263_QUANT) {
481                                  start_timer();                                  start_timer();
482                                  dequant_inter(&data[i*64], &qcoeff[i*64], iQuant);                                  dequant_inter(&data[i*64], &qcoeff[i*64], iQuant);
483                                  stop_iquant_timer();                                  stop_iquant_timer();
484                          }                          } else {
                         else  
                         {  
485                                  start_timer();                                  start_timer();
486                                  dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant);                                  dequant4_inter(&data[i*64], &qcoeff[i*64], iQuant);
487                                  stop_iquant_timer();                                  stop_iquant_timer();
488                          }                          }
489                    }
490            }
491    }
492    
493                          cbp |= 1 << (5 - i);  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*64]);                          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          if (pMB->field_dct)          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                  MBFieldToFrame(data);          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            if (pMB->field_dct) {
559                    next_block = stride;
560                    stride *= 2;
561          }          }
         stop_interlacing_timer();  
562    
563          start_timer();          start_timer();
564          if (cbp & 32)          if (cbp & 32)
# Line 246  Line 566 
566          if (cbp & 16)          if (cbp & 16)
567                  transfer_16to8add(pY_Cur + 8,              &data[1*64], stride);                  transfer_16to8add(pY_Cur + 8,              &data[1*64], stride);
568          if (cbp & 8)          if (cbp & 8)
569                  transfer_16to8add(pY_Cur + 8 * stride,     &data[2*64], stride);                  transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride);
570          if (cbp & 4)          if (cbp & 4)
571                  transfer_16to8add(pY_Cur + 8 + 8 * stride, &data[3*64], stride);                  transfer_16to8add(pY_Cur + next_block + 8, &data[3 * 64], stride);
572          if (cbp & 2)          if (cbp & 2)
573                  transfer_16to8add(pU_Cur,                  &data[4*64], stride / 2);                  transfer_16to8add(pU_Cur, &data[4 * 64], stride2);
574          if (cbp & 1)          if (cbp & 1)
575                  transfer_16to8add(pV_Cur,                  &data[5*64], stride / 2);                  transfer_16to8add(pV_Cur, &data[5 * 64], stride2);
576          stop_transfer_timer();          stop_transfer_timer();
577    }
578    
         return cbp;  
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    
596    
597  /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */  /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */
598    
599  #define ABS(X) (X)<0 ? -(X) : (X)  uint32_t
600    MBFieldTest_c(int16_t data[6 * 64])
 uint32_t MBDecideFieldDCT(int16_t data[6*64])  
601  {  {
602            const uint8_t blocks[] =
603          const uint8_t blocks[] = {0*64, 0*64, 0*64, 0*64, 2*64, 2*64, 2*64, 2*64};                  { 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};          const uint8_t lines[]  = {0, 16, 32, 48, 0, 16, 32, 48};
605    
606          int frame = 0, field = 0;          int frame = 0, field = 0;
607          int i, j;          int i, j;
608    
609          for (i=0 ; i<7 ; ++i)          for (i = 0; i < 7; ++i) {
610          {                  for (j = 0; j < 8; ++j) {
611                  for (j=0 ; j<8 ; ++j)                          frame +=
612                  {                                  ABS(data[0 * 64 + (i + 1) * 8 + j] - data[0 * 64 + i * 8 + j]);
613                          frame += ABS(data[0*64 + (i+1)*8 + j] - data[0*64 + i*8 + j]);                          frame +=
614                          frame += ABS(data[1*64 + (i+1)*8 + j] - data[1*64 + i*8 + j]);                                  ABS(data[1 * 64 + (i + 1) * 8 + j] - data[1 * 64 + i * 8 + j]);
615                          frame += ABS(data[2*64 + (i+1)*8 + j] - data[2*64 + i*8 + j]);                          frame +=
616                          frame += ABS(data[3*64 + (i+1)*8 + j] - data[3*64 + i*8 + j]);                                  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 += ABS(data[blocks[i+1] + lines[i+1] + j] -\                          field +=
621                                    ABS(data[blocks[i + 1] + lines[i + 1] + j] -
622                                       data[blocks[i  ] + lines[i  ] + j]);                                       data[blocks[i  ] + lines[i  ] + j]);
623                          field += ABS(data[blocks[i+1] + lines[i+1] + 8 + j] -\                          field +=
624                                    ABS(data[blocks[i + 1] + lines[i + 1] + 8 + j] -
625                                       data[blocks[i  ] + lines[i  ] + 8 + j]);                                       data[blocks[i  ] + lines[i  ] + 8 + j]);
626                          field += ABS(data[blocks[i+1] + 64 + lines[i+1] + j] -\                          field +=
627                                    ABS(data[blocks[i + 1] + 64 + lines[i + 1] + j] -
628                                       data[blocks[i  ] + 64 + lines[i  ] + j]);                                       data[blocks[i  ] + 64 + lines[i  ] + j]);
629                          field += ABS(data[blocks[i+1] + 64 + lines[i+1] + 8 + j] -\                          field +=
630                                    ABS(data[blocks[i + 1] + 64 + lines[i + 1] + 8 + j] -
631                                       data[blocks[i  ] + 64 + lines[i  ] + 8 + j]);                                       data[blocks[i  ] + 64 + lines[i  ] + 8 + j]);
632                  }                  }
633          }          }
634    
635          if (frame > field)          return (frame >= (field + 350));
         {  
                 MBFrameToField(data);  
         }  
   
         return (frame > field);  
636  }  }
637    
638    
# Line 307  Line 641 
641  #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp))  #define MOVLINE(X,Y) memcpy(X, Y, sizeof(tmp))
642  #define LINE(X,Y)    &data[X*64 + Y*8]  #define LINE(X,Y)    &data[X*64 + Y*8]
643    
644  void MBFrameToField(int16_t data[6*64])  void
645    MBFrameToField(int16_t data[6 * 64])
646  {  {
647          int16_t tmp[8];          int16_t tmp[8];
648    
# Line 367  Line 702 
702          MOVLINE(LINE(3,5),      LINE(3,3));          MOVLINE(LINE(3,5),      LINE(3,3));
703          MOVLINE(LINE(3,3),      tmp);          MOVLINE(LINE(3,3),      tmp);
704  }  }
   
   
 /* interlace Y blocks vertically */  
   
 void MBFieldToFrame(int16_t data[6*64])  
 {  
         uint16_t tmp[8];  
   
         /* left blocks */  
   
         // 1=8, 8=4, 4=2, 2=1  
         MOVLINE(tmp,            LINE(0,1));  
         MOVLINE(LINE(0,1),      LINE(2,0));  
         MOVLINE(LINE(2,0),      LINE(0,4));  
         MOVLINE(LINE(0,4),      LINE(0,2));  
         MOVLINE(LINE(0,2),      tmp);  
   
         // 3=9, 9=12, 12=6, 6=3  
         MOVLINE(tmp,            LINE(0,3));  
         MOVLINE(LINE(0,3),      LINE(2,1));  
         MOVLINE(LINE(2,1),      LINE(2,4));  
         MOVLINE(LINE(2,4),      LINE(0,6));  
         MOVLINE(LINE(0,6),      tmp);  
   
         // 5=10, 10=5  
         MOVLINE(tmp,            LINE(0,5));  
         MOVLINE(LINE(0,5),      LINE(2,2));  
         MOVLINE(LINE(2,2),      tmp);  
   
         // 7=11, 11=13, 13=14, 14=7  
         MOVLINE(tmp,            LINE(0,7));  
         MOVLINE(LINE(0,7),      LINE(2,3));  
         MOVLINE(LINE(2,3),      LINE(2,5));  
         MOVLINE(LINE(2,5),      LINE(2,6));  
         MOVLINE(LINE(2,6),      tmp);  
   
         /* right blocks */  
   
         // 1=8, 8=4, 4=2, 2=1  
         MOVLINE(tmp,            LINE(1,1));  
         MOVLINE(LINE(1,1),      LINE(3,0));  
         MOVLINE(LINE(3,0),      LINE(1,4));  
         MOVLINE(LINE(1,4),      LINE(1,2));  
         MOVLINE(LINE(1,2),      tmp);  
   
         // 3=9, 9=12, 12=6, 6=3  
         MOVLINE(tmp,            LINE(1,3));  
         MOVLINE(LINE(1,3),      LINE(3,1));  
         MOVLINE(LINE(3,1),      LINE(3,4));  
         MOVLINE(LINE(3,4),      LINE(1,6));  
         MOVLINE(LINE(1,6),      tmp);  
   
         // 5=10, 10=5  
         MOVLINE(tmp,            LINE(1,5));  
         MOVLINE(LINE(1,5),      LINE(3,2));  
         MOVLINE(LINE(3,2),      tmp);  
   
         // 7=11, 11=13, 13=14, 14=7  
         MOVLINE(tmp,            LINE(1,7));  
         MOVLINE(LINE(1,7),      LINE(3,3));  
         MOVLINE(LINE(3,3),      LINE(3,5));  
         MOVLINE(LINE(3,5),      LINE(3,6));  
         MOVLINE(LINE(3,6),      tmp);  
 }  

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.11.2.3

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