[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.7, Wed Jun 12 20:38:41 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    *  29.03.2002 interlacing speedup - used transfer strides instead of    *  29.03.2002 interlacing speedup - used transfer strides instead of             *
46    *             manual field-to-frame conversion    *             manual field-to-frame conversion                                                           *
47    *  26.03.2002 interlacing support - moved transfers outside loops    *  26.03.2002 interlacing support - moved transfers outside loops                        *
48    *  22.12.2001 get_dc_scaler() moved to common.h    *  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 65  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    
# Line 105  Line 107 
107    
108          start_timer();          start_timer();
109          pMB->field_dct = 0;          pMB->field_dct = 0;
110          if ((frame->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();
# Line 183  Line 187 
187    
188          start_timer();          start_timer();
189          pMB->field_dct = 0;          pMB->field_dct = 0;
190          if ((frame->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();
# Line 207  Line 213 
213                          stop_quant_timer();                          stop_quant_timer();
214                  }                  }
215    
216                  if (sum >= TOOSMALL_LIMIT) {    // skip block ?                  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) {                          if (pParam->m_quant_type == H263_QUANT) {
220                                  start_timer();                                  start_timer();
# Line 251  Line 258 
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  /* if sum(diff between field lines) < sum(diff between frame lines), use field dct */  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    
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();
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);
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();
503                            idct(&data[i * 64]);
504                            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();
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            if (pMB->field_dct) {
559                    next_block = stride;
560                    stride *= 2;
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();
577    }
578    
579    
580    
581    /* permute block and return field dct choice */
582    
583    
584  uint32_t  uint32_t
585  MBDecideFieldDCT(int16_t data[6 * 64])  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 */
598    
599    uint32_t
600    MBFieldTest_c(int16_t data[6 * 64])
601    {
602          const uint8_t blocks[] =          const uint8_t blocks[] =
603                  { 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 };
# Line 292  Line 632 
632                  }                  }
633          }          }
634    
635          if (frame > field) {          return (frame >= (field + 350));
                 MBFrameToField(data);  
         }  
   
         return (frame > field);  
636  }  }
637    
638    

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

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