[svn] / branches / dev-api-3 / xvidcore / src / prediction / mbprediction.h Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/prediction/mbprediction.h

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

revision 254, Wed Jul 3 12:32:50 2002 UTC revision 286, Wed Jul 10 19:17:49 2002 UTC
# Line 26  Line 26 
26   *  along with this program; if not, write to the xvid_free Software   *  along with this program; if not, write to the xvid_free Software
27   *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28   *   *
29   *  $Id: mbprediction.h,v 1.12 2002-07-03 12:32:50 suxen_drol Exp $   *  $Id: mbprediction.h,v 1.13 2002-07-10 19:17:49 chl Exp $
30   *   *
31   *************************************************************************/   *************************************************************************/
32    
# Line 83  Line 83 
83                                  const int bound);                                  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 369  Line 370 
370          return 0;          return 0;
371  }  }
372    
373    #endif
374    
375          /*          /*
376           * MODE_INTER, vm18 page 48           * MODE_INTER, vm18 page 48
# Line 452  Line 454 
454          pmv[3] = zeroMV;          pmv[3] = zeroMV;
455      }      }
456    
457      /* if only one valid candidate preictor, the invalid candiates are set to the canidate */      /* if only one valid candidate predictor, the invalid candiates are set to the canidate */
458          if (num_cand != 1) {          if (num_cand != 1) {
459                  /* set median */                  /* set median */
460    
# Line 482  Line 484 
484           *  [2]: top neighbour's SAD           *  [2]: top neighbour's SAD
485           *  [3]: topright neighbour's SAD           *  [3]: topright neighbour's SAD
486           */           */
487    
488  static __inline int  static __inline int
489  get_pmvdata2(const MACROBLOCK * const mbs,  get_pmvdata2(const MACROBLOCK * const mbs,
490           const int mb_width,           const int mb_width,
# Line 598  Line 601 
601          return 0;          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.254  
changed lines
  Added in v.286

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