[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, Wed Sep 4 06:24:37 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 68  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    
# Line 105  Line 105 
105    
106          start_timer();          start_timer();
107          pMB->field_dct = 0;          pMB->field_dct = 0;
108          if ((frame->global_flags & XVID_INTERLACING)) {          if ((frame->global_flags & XVID_INTERLACING) &&
109                    (x_pos>0) && (x_pos<pParam->mb_width-1) &&
110                    (y_pos>0) && (y_pos<pParam->mb_height-1)) {
111                  pMB->field_dct = MBDecideFieldDCT(data);                  pMB->field_dct = MBDecideFieldDCT(data);
112          }          }
113          stop_interlacing_timer();          stop_interlacing_timer();
# Line 183  Line 185 
185    
186          start_timer();          start_timer();
187          pMB->field_dct = 0;          pMB->field_dct = 0;
188          if ((frame->global_flags & XVID_INTERLACING)) {          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);                  pMB->field_dct = MBDecideFieldDCT(data);
192          }          }
193          stop_interlacing_timer();          stop_interlacing_timer();
# Line 207  Line 211 
211                          stop_quant_timer();                          stop_quant_timer();
212                  }                  }
213    
214                  if (sum >= TOOSMALL_LIMIT) {    // skip block ?                  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) {                          if (pParam->m_quant_type == H263_QUANT) {
218                                  start_timer();                                  start_timer();
# Line 251  Line 256 
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    
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();
328            pMB->field_dct = 0;
329            if ((frame->global_flags & XVID_INTERLACING)) {
330                    pMB->field_dct = MBDecideFieldDCT(data);
331            }
332            stop_interlacing_timer();
333    
334            for (i = 0; i < 6; i++) {
335                    start_timer();
336                    fdct(&data[i * 64]);
337                    stop_dct_timer();
338            }
339    }
340    
341    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();
363                            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();
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    
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();
407                            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();
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);
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();
480                                    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();
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();
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            if (pMB->field_dct) {
557                    next_block = stride;
558                    stride *= 2;
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();
575    }
576    
577    
578    
579  /* 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 */
580    

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

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