[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.11, Sun Jun 30 10:46:29 2002 UTC revision 1.12, Wed Jul 3 12:32:50 2002 UTC
# Line 207  Line 207 
207  }  }
208    
209    
   
 int  
 get_pmvdata2(const MACROBLOCK * const pMBs,  
                         const uint32_t x,  
                         const uint32_t y,  
                         const uint32_t x_dim,  
                         const uint32_t block,  
                         VECTOR * const pmv,  
                         int32_t * const psad,  
                         const int bound);  
   
   
210  /* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD  /* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD
211     instead of only Median MV */     instead of only Median MV */
212    
# Line 359  Line 347 
347                  psad[3] = MV_MAX_ERROR;                  psad[3] = MV_MAX_ERROR;
348          } else {          } else {
349                  pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3];                  pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3];
350                  psad[3] = pMBs[xin2 + yin2 * x_dim].sad8[vec3];                  psad[3] = pMBs[xin3 + yin3 * x_dim].sad8[vec3];
351          }          }
352    
353          if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {          if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {
# Line 382  Line 370 
370  }  }
371    
372    
373            /*
374             * MODE_INTER, vm18 page 48
375             * MODE_INTER4V vm18 page 51
376             *
377             *   (x,y-1)      (x+1,y-1)
378             *   [   |   ]    [   |   ]
379             *   [ 2 | 3 ]    [ 2 |   ]
380             *
381             *   (x-1,y)       (x,y)        (x+1,y)
382             *   [   | 1 ]    [ 0 | 1 ]    [ 0 |   ]
383             *   [   | 3 ]    [ 2 | 3 ]    [   |   ]
384             */
385    
386    static __inline VECTOR
387    get_pmv2(const MACROBLOCK * const mbs,
388             const int mb_width,
389             const int bound,
390             const int x,
391             const int y,
392             const int block)
393    {
394            static const VECTOR zeroMV = { 0, 0 };
395    
396        int lx, ly, lz;         /* left */
397        int tx, ty, tz;         /* top */
398        int rx, ry, rz;         /* top-right */
399        int lpos, tpos, rpos;
400        int num_cand, last_cand;
401    
402            VECTOR pmv[4];  /* left neighbour, top neighbour, top-right neighbour */
403    
404            switch (block) {
405            case 0:
406                    lx = x - 1;     ly = y;         lz = 1;
407                    tx = x;         ty = y - 1;     tz = 2;
408                    rx = x + 1;     ry = y - 1;     rz = 2;
409                    break;
410            case 1:
411                    lx = x;         ly = y;         lz = 0;
412                    tx = x;         ty = y - 1;     tz = 3;
413                    rx = x + 1;     ry = y - 1;     rz = 2;
414                    break;
415            case 2:
416                    lx = x - 1;     ly = y;         lz = 3;
417                    tx = x;         ty = y;         tz = 0;
418                    rx = x;         ry = y;         rz = 1;
419                    break;
420            default:
421                    lx = x;         ly = y;         lz = 2;
422                    tx = x;         ty = y;         tz = 0;
423                    rx = x;         ry = y;         rz = 1;
424            }
425    
426        lpos = lx + ly * mb_width;
427        rpos = rx + ry * mb_width;
428        tpos = tx + ty * mb_width;
429        num_cand = 0;
430    
431        if (lpos >= bound && lx >= 0) {
432            num_cand++;
433            last_cand = 1;
434            pmv[1] = mbs[lpos].mvs[lz];
435        } else {
436            pmv[1] = zeroMV;
437        }
438    
439        if (tpos >= bound) {
440            num_cand++;
441            last_cand = 2;
442            pmv[2] = mbs[tpos].mvs[tz];
443        } else {
444            pmv[2] = zeroMV;
445        }
446    
447        if (rpos >= bound && rx < mb_width) {
448            num_cand++;
449            last_cand = 3;
450            pmv[3] = mbs[rpos].mvs[rz];
451        } else {
452            pmv[3] = zeroMV;
453        }
454    
455        /* if only one valid candidate preictor, the invalid candiates are set to the canidate */
456            if (num_cand != 1) {
457                    /* set median */
458    
459                    pmv[0].x =
460                            MIN(MAX(pmv[1].x, pmv[2].x),
461                                    MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
462                    pmv[0].y =
463                            MIN(MAX(pmv[1].y, pmv[2].y),
464                                    MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
465                    return pmv[0];
466             }
467    
468             return pmv[last_cand];  /* no point calculating median mv */
469    }
470    
471    
472    
473            /*
474             * pmv are filled with:
475             *  [0]: Median (or whatever is correct in a special case)
476             *  [1]: left neighbour
477             *  [2]: top neighbour
478             *  [3]: topright neighbour
479             * psad are filled with:
480             *  [0]: minimum of [1] to [3]
481             *  [1]: left neighbour's SAD (NB:[1] to [3] are actually not needed)
482             *  [2]: top neighbour's SAD
483             *  [3]: topright neighbour's SAD
484             */
485    static __inline int
486    get_pmvdata2(const MACROBLOCK * const mbs,
487             const int mb_width,
488             const int bound,
489             const int x,
490             const int y,
491             const int block,
492                     VECTOR * const pmv,
493                     int32_t * const psad)
494    {
495            static const VECTOR zeroMV = { 0, 0 };
496    
497        int lx, ly, lz;         /* left */
498        int tx, ty, tz;         /* top */
499        int rx, ry, rz;         /* top-right */
500        int lpos, tpos, rpos;
501        int num_cand, last_cand;
502    
503            switch (block) {
504            case 0:
505                    lx = x - 1;     ly = y;         lz = 1;
506                    tx = x;         ty = y - 1;     tz = 2;
507                    rx = x + 1;     ry = y - 1;     rz = 2;
508                    break;
509            case 1:
510                    lx = x;         ly = y;         lz = 0;
511                    tx = x;         ty = y - 1;     tz = 3;
512                    rx = x + 1;     ry = y - 1;     rz = 2;
513                    break;
514            case 2:
515                    lx = x - 1;     ly = y;         lz = 3;
516                    tx = x;         ty = y;         tz = 0;
517                    rx = x;         ry = y;         rz = 1;
518                    break;
519            default:
520                    lx = x;         ly = y;         lz = 2;
521                    tx = x;         ty = y;         tz = 0;
522                    rx = x;         ry = y;         rz = 1;
523            }
524    
525        lpos = lx + ly * mb_width;
526        rpos = rx + ry * mb_width;
527        tpos = tx + ty * mb_width;
528        num_cand = 0;
529    
530        if (lpos >= bound && lx >= 0) {
531            num_cand++;
532            last_cand = 1;
533            pmv[1] = mbs[lpos].mvs[lz];
534                    psad[1] = mbs[lpos].sad8[lz];
535        } else {
536            pmv[1] = zeroMV;
537                    psad[1] = MV_MAX_ERROR;
538        }
539    
540        if (tpos >= bound) {
541            num_cand++;
542            last_cand = 2;
543            pmv[2]= mbs[tpos].mvs[tz];
544            psad[2] = mbs[tpos].sad8[tz];
545        } else {
546            pmv[2] = zeroMV;
547                    psad[2] = MV_MAX_ERROR;
548        }
549    
550        if (rpos >= bound && rx < mb_width) {
551            num_cand++;
552            last_cand = 3;
553            pmv[3] = mbs[rpos].mvs[rz];
554            psad[3] = mbs[rpos].sad8[rz];
555        } else {
556            pmv[3] = zeroMV;
557                    psad[3] = MV_MAX_ERROR;
558        }
559    
560            /* original pmvdata() compatibility hack */
561            if (x == 0 && y == 0 && block == 0)
562            {
563                    pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;
564                    psad[0] = 0;
565                    psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;
566                    return 0;
567            }
568    
569        /* if only one valid candidate preictor, the invalid candiates are set to the canidate */
570            if (num_cand == 1) {
571                    pmv[0] = pmv[last_cand];
572                    psad[0] = psad[last_cand];
573            // return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */
574    
575                    /* original pmvdata() compatibility hack */
576                    return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV);
577            }
578    
579            if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {
580                    pmv[0] = pmv[1];
581                    psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
582                    return 1;
583                    /* compatibility patch */
584                    //return y==0 && block <= 1 ? 0 : 1;
585            }
586    
587            /* set median, minimum */
588    
589            pmv[0].x =
590                    MIN(MAX(pmv[1].x, pmv[2].x),
591                            MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
592            pmv[0].y =
593                    MIN(MAX(pmv[1].y, pmv[2].y),
594                            MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
595    
596            psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
597    
598            return 0;
599    }
600    
601    
602  #endif                                                  /* _MBPREDICTION_H_ */  #endif                                                  /* _MBPREDICTION_H_ */

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

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