[cvs] / xvidcore / src / prediction / mbprediction.h Repository:
ViewVC logotype

Diff of /xvidcore/src/prediction/mbprediction.h

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

revision 1.9, Wed Jun 12 20:38:40 2002 UTC revision 1.13, Wed Jul 10 19:17:49 2002 UTC
# Line 30  Line 30 
30   *   *
31   *************************************************************************/   *************************************************************************/
32    
33     /******************************************************************************
34      *                                                                            *
35      *  Revision history:                                                         *
36      *                                                                            *
37      *  29.06.2002 get_pmvdata() bounding                                         *
38      *                                                                            *
39      ******************************************************************************/
40    
41    
42  #ifndef _MBPREDICTION_H_  #ifndef _MBPREDICTION_H_
43  #define _MBPREDICTION_H_  #define _MBPREDICTION_H_
44    
# Line 70  Line 79 
79                                    int16_t qcoeff[64],                                    int16_t qcoeff[64],
80                                    uint32_t current_quant,                                    uint32_t current_quant,
81                                    int32_t iDcScaler,                                    int32_t iDcScaler,
82                                    int16_t predictors[8]);                                    int16_t predictors[8],
83                                    const int bound);
84    
85    
86    #ifdef OLD_GETPMV
87  /* get_pmvdata returns the median predictor and nothing else */  /* get_pmvdata returns the median predictor and nothing else */
88    
89  static __inline VECTOR  static __inline VECTOR
# Line 336  Line 348 
348                  psad[3] = MV_MAX_ERROR;                  psad[3] = MV_MAX_ERROR;
349          } else {          } else {
350                  pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3];                  pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3];
351                  psad[3] = pMBs[xin2 + yin2 * x_dim].sad8[vec3];                  psad[3] = pMBs[xin3 + yin3 * x_dim].sad8[vec3];
352          }          }
353    
354          if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {          if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {
# Line 358  Line 370 
370          return 0;          return 0;
371  }  }
372    
373    #endif
374    
375            /*
376             * MODE_INTER, vm18 page 48
377             * MODE_INTER4V vm18 page 51
378             *
379             *   (x,y-1)      (x+1,y-1)
380             *   [   |   ]    [   |   ]
381             *   [ 2 | 3 ]    [ 2 |   ]
382             *
383             *   (x-1,y)       (x,y)        (x+1,y)
384             *   [   | 1 ]    [ 0 | 1 ]    [ 0 |   ]
385             *   [   | 3 ]    [ 2 | 3 ]    [   |   ]
386             */
387    
388    static __inline VECTOR
389    get_pmv2(const MACROBLOCK * const mbs,
390             const int mb_width,
391             const int bound,
392             const int x,
393             const int y,
394             const int block)
395    {
396            static const VECTOR zeroMV = { 0, 0 };
397    
398        int lx, ly, lz;         /* left */
399        int tx, ty, tz;         /* top */
400        int rx, ry, rz;         /* top-right */
401        int lpos, tpos, rpos;
402        int num_cand, last_cand;
403    
404            VECTOR pmv[4];  /* left neighbour, top neighbour, top-right neighbour */
405    
406            switch (block) {
407            case 0:
408                    lx = x - 1;     ly = y;         lz = 1;
409                    tx = x;         ty = y - 1;     tz = 2;
410                    rx = x + 1;     ry = y - 1;     rz = 2;
411                    break;
412            case 1:
413                    lx = x;         ly = y;         lz = 0;
414                    tx = x;         ty = y - 1;     tz = 3;
415                    rx = x + 1;     ry = y - 1;     rz = 2;
416                    break;
417            case 2:
418                    lx = x - 1;     ly = y;         lz = 3;
419                    tx = x;         ty = y;         tz = 0;
420                    rx = x;         ry = y;         rz = 1;
421                    break;
422            default:
423                    lx = x;         ly = y;         lz = 2;
424                    tx = x;         ty = y;         tz = 0;
425                    rx = x;         ry = y;         rz = 1;
426            }
427    
428        lpos = lx + ly * mb_width;
429        rpos = rx + ry * mb_width;
430        tpos = tx + ty * mb_width;
431        num_cand = 0;
432    
433        if (lpos >= bound && lx >= 0) {
434            num_cand++;
435            last_cand = 1;
436            pmv[1] = mbs[lpos].mvs[lz];
437        } else {
438            pmv[1] = zeroMV;
439        }
440    
441        if (tpos >= bound) {
442            num_cand++;
443            last_cand = 2;
444            pmv[2] = mbs[tpos].mvs[tz];
445        } else {
446            pmv[2] = zeroMV;
447        }
448    
449        if (rpos >= bound && rx < mb_width) {
450            num_cand++;
451            last_cand = 3;
452            pmv[3] = mbs[rpos].mvs[rz];
453        } else {
454            pmv[3] = zeroMV;
455        }
456    
457        /* if only one valid candidate predictor, the invalid candiates are set to the canidate */
458            if (num_cand != 1) {
459                    /* set median */
460    
461                    pmv[0].x =
462                            MIN(MAX(pmv[1].x, pmv[2].x),
463                                    MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
464                    pmv[0].y =
465                            MIN(MAX(pmv[1].y, pmv[2].y),
466                                    MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
467                    return pmv[0];
468             }
469    
470             return pmv[last_cand];  /* no point calculating median mv */
471    }
472    
473    
474    
475            /*
476             * pmv are filled with:
477             *  [0]: Median (or whatever is correct in a special case)
478             *  [1]: left neighbour
479             *  [2]: top neighbour
480             *  [3]: topright neighbour
481             * psad are filled with:
482             *  [0]: minimum of [1] to [3]
483             *  [1]: left neighbour's SAD (NB:[1] to [3] are actually not needed)
484             *  [2]: top neighbour's SAD
485             *  [3]: topright neighbour's SAD
486             */
487    
488    static __inline int
489    get_pmvdata2(const MACROBLOCK * const mbs,
490             const int mb_width,
491             const int bound,
492             const int x,
493             const int y,
494             const int block,
495                     VECTOR * const pmv,
496                     int32_t * const psad)
497    {
498            static const VECTOR zeroMV = { 0, 0 };
499    
500        int lx, ly, lz;         /* left */
501        int tx, ty, tz;         /* top */
502        int rx, ry, rz;         /* top-right */
503        int lpos, tpos, rpos;
504        int num_cand, last_cand;
505    
506            switch (block) {
507            case 0:
508                    lx = x - 1;     ly = y;         lz = 1;
509                    tx = x;         ty = y - 1;     tz = 2;
510                    rx = x + 1;     ry = y - 1;     rz = 2;
511                    break;
512            case 1:
513                    lx = x;         ly = y;         lz = 0;
514                    tx = x;         ty = y - 1;     tz = 3;
515                    rx = x + 1;     ry = y - 1;     rz = 2;
516                    break;
517            case 2:
518                    lx = x - 1;     ly = y;         lz = 3;
519                    tx = x;         ty = y;         tz = 0;
520                    rx = x;         ry = y;         rz = 1;
521                    break;
522            default:
523                    lx = x;         ly = y;         lz = 2;
524                    tx = x;         ty = y;         tz = 0;
525                    rx = x;         ry = y;         rz = 1;
526            }
527    
528        lpos = lx + ly * mb_width;
529        rpos = rx + ry * mb_width;
530        tpos = tx + ty * mb_width;
531        num_cand = 0;
532    
533        if (lpos >= bound && lx >= 0) {
534            num_cand++;
535            last_cand = 1;
536            pmv[1] = mbs[lpos].mvs[lz];
537                    psad[1] = mbs[lpos].sad8[lz];
538        } else {
539            pmv[1] = zeroMV;
540                    psad[1] = MV_MAX_ERROR;
541        }
542    
543        if (tpos >= bound) {
544            num_cand++;
545            last_cand = 2;
546            pmv[2]= mbs[tpos].mvs[tz];
547            psad[2] = mbs[tpos].sad8[tz];
548        } else {
549            pmv[2] = zeroMV;
550                    psad[2] = MV_MAX_ERROR;
551        }
552    
553        if (rpos >= bound && rx < mb_width) {
554            num_cand++;
555            last_cand = 3;
556            pmv[3] = mbs[rpos].mvs[rz];
557            psad[3] = mbs[rpos].sad8[rz];
558        } else {
559            pmv[3] = zeroMV;
560                    psad[3] = MV_MAX_ERROR;
561        }
562    
563            /* original pmvdata() compatibility hack */
564            if (x == 0 && y == 0 && block == 0)
565            {
566                    pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;
567                    psad[0] = 0;
568                    psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;
569                    return 0;
570            }
571    
572        /* if only one valid candidate preictor, the invalid candiates are set to the canidate */
573            if (num_cand == 1) {
574                    pmv[0] = pmv[last_cand];
575                    psad[0] = psad[last_cand];
576            // return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */
577    
578                    /* original pmvdata() compatibility hack */
579                    return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV);
580            }
581    
582            if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {
583                    pmv[0] = pmv[1];
584                    psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
585                    return 1;
586                    /* compatibility patch */
587                    //return y==0 && block <= 1 ? 0 : 1;
588            }
589    
590            /* set median, minimum */
591    
592            pmv[0].x =
593                    MIN(MAX(pmv[1].x, pmv[2].x),
594                            MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
595            pmv[0].y =
596                    MIN(MAX(pmv[1].y, pmv[2].y),
597                            MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
598    
599            psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
600    
601            return 0;
602    }
603    
604    /* copies of get_pmv and get_pmvdata for prediction from integer search */
605    
606    static __inline VECTOR
607    get_ipmv(const MACROBLOCK * const mbs,
608             const int mb_width,
609             const int bound,
610             const int x,
611             const int y,
612             const int block)
613    {
614            static const VECTOR zeroMV = { 0, 0 };
615    
616            int lx, ly, lz;         /* left */
617            int tx, ty, tz;         /* top */
618            int rx, ry, rz;         /* top-right */
619            int lpos, tpos, rpos;
620            int num_cand, last_cand;
621    
622            VECTOR pmv[4];  /* left neighbour, top neighbour, top-right neighbour */
623    
624            switch (block) {
625            case 0:
626                    lx = x - 1;     ly = y;         lz = 1;
627                    tx = x;         ty = y - 1;     tz = 2;
628                    rx = x + 1;     ry = y - 1;     rz = 2;
629                    break;
630            case 1:
631                    lx = x;         ly = y;         lz = 0;
632                    tx = x;         ty = y - 1;     tz = 3;
633                    rx = x + 1;     ry = y - 1;     rz = 2;
634                    break;
635            case 2:
636                    lx = x - 1;     ly = y;         lz = 3;
637                    tx = x;         ty = y;         tz = 0;
638                    rx = x;         ry = y;         rz = 1;
639                    break;
640            default:
641                    lx = x;         ly = y;         lz = 2;
642                    tx = x;         ty = y;         tz = 0;
643                    rx = x;         ry = y;         rz = 1;
644            }
645    
646        lpos = lx + ly * mb_width;
647        rpos = rx + ry * mb_width;
648        tpos = tx + ty * mb_width;
649        num_cand = 0;
650    
651        if (lpos >= bound && lx >= 0) {
652            num_cand++;
653            last_cand = 1;
654            pmv[1] = mbs[lpos].i_mvs[lz];
655        } else {
656            pmv[1] = zeroMV;
657        }
658    
659        if (tpos >= bound) {
660            num_cand++;
661            last_cand = 2;
662            pmv[2] = mbs[tpos].i_mvs[tz];
663        } else {
664            pmv[2] = zeroMV;
665        }
666    
667        if (rpos >= bound && rx < mb_width) {
668            num_cand++;
669            last_cand = 3;
670            pmv[3] = mbs[rpos].i_mvs[rz];
671        } else {
672            pmv[3] = zeroMV;
673        }
674    
675        /* if only one valid candidate predictor, the invalid candiates are set to the canidate */
676            if (num_cand != 1) {
677                    /* set median */
678    
679                    pmv[0].x =
680                            MIN(MAX(pmv[1].x, pmv[2].x),
681                                    MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
682                    pmv[0].y =
683                            MIN(MAX(pmv[1].y, pmv[2].y),
684                                    MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
685                    return pmv[0];
686             }
687    
688             return pmv[last_cand];  /* no point calculating median mv */
689    }
690    
691    static __inline int
692    get_ipmvdata(const MACROBLOCK * const mbs,
693             const int mb_width,
694             const int bound,
695             const int x,
696             const int y,
697             const int block,
698                     VECTOR * const pmv,
699                     int32_t * const psad)
700    {
701            static const VECTOR zeroMV = { 0, 0 };
702    
703        int lx, ly, lz;         /* left */
704        int tx, ty, tz;         /* top */
705        int rx, ry, rz;         /* top-right */
706        int lpos, tpos, rpos;
707        int num_cand, last_cand;
708    
709            switch (block) {
710            case 0:
711                    lx = x - 1;     ly = y;         lz = 1;
712                    tx = x;         ty = y - 1;     tz = 2;
713                    rx = x + 1;     ry = y - 1;     rz = 2;
714                    break;
715            case 1:
716                    lx = x;         ly = y;         lz = 0;
717                    tx = x;         ty = y - 1;     tz = 3;
718                    rx = x + 1;     ry = y - 1;     rz = 2;
719                    break;
720            case 2:
721                    lx = x - 1;     ly = y;         lz = 3;
722                    tx = x;         ty = y;         tz = 0;
723                    rx = x;         ry = y;         rz = 1;
724                    break;
725            default:
726                    lx = x;         ly = y;         lz = 2;
727                    tx = x;         ty = y;         tz = 0;
728                    rx = x;         ry = y;         rz = 1;
729            }
730    
731        lpos = lx + ly * mb_width;
732        rpos = rx + ry * mb_width;
733        tpos = tx + ty * mb_width;
734        num_cand = 0;
735    
736        if (lpos >= bound && lx >= 0) {
737            num_cand++;
738            last_cand = 1;
739            pmv[1] = mbs[lpos].i_mvs[lz];
740                    psad[1] = mbs[lpos].i_sad8[lz];
741        } else {
742            pmv[1] = zeroMV;
743                    psad[1] = MV_MAX_ERROR;
744        }
745    
746        if (tpos >= bound) {
747            num_cand++;
748            last_cand = 2;
749            pmv[2]= mbs[tpos].i_mvs[tz];
750            psad[2] = mbs[tpos].i_sad8[tz];
751        } else {
752            pmv[2] = zeroMV;
753                    psad[2] = MV_MAX_ERROR;
754        }
755    
756        if (rpos >= bound && rx < mb_width) {
757            num_cand++;
758            last_cand = 3;
759            pmv[3] = mbs[rpos].i_mvs[rz];
760            psad[3] = mbs[rpos].i_sad8[rz];
761        } else {
762            pmv[3] = zeroMV;
763                    psad[3] = MV_MAX_ERROR;
764        }
765    
766            /* original pmvdata() compatibility hack */
767            if (x == 0 && y == 0 && block == 0)
768            {
769                    pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;
770                    psad[0] = 0;
771                    psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;
772                    return 0;
773            }
774    
775        /* if only one valid candidate preictor, the invalid candiates are set to the canidate */
776            if (num_cand == 1) {
777                    pmv[0] = pmv[last_cand];
778                    psad[0] = psad[last_cand];
779            // return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */
780    
781                    /* original pmvdata() compatibility hack */
782                    return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV);
783            }
784    
785            if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {
786                    pmv[0] = pmv[1];
787                    psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
788                    return 1;
789                    /* compatibility patch */
790                    //return y==0 && block <= 1 ? 0 : 1;
791            }
792    
793            /* set median, minimum */
794    
795            pmv[0].x =
796                    MIN(MAX(pmv[1].x, pmv[2].x),
797                            MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
798            pmv[0].y =
799                    MIN(MAX(pmv[1].y, pmv[2].y),
800                            MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
801    
802            psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
803    
804            return 0;
805    }
806    
807    
808  #endif                                                  /* _MBPREDICTION_H_ */  #endif                                                  /* _MBPREDICTION_H_ */

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.13

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