Revision b07a5980 libavcodec/motion_est_template.c

View differences:

libavcodec/motion_est_template.c
67 67
				  int *mx_ptr, int *my_ptr, int dmin,
68 68
				  int xmin, int ymin, int xmax, int ymax,
69 69
                                  int pred_x, int pred_y, Picture *ref_picture, 
70
                                  int n, int size)
70
                                  int n, int size, uint16_t * const mv_penalty)
71 71
{
72
    UINT8 *ptr;
73
    
74 72
    const int xx = 16 * s->mb_x + 8*(n&1);
75 73
    const int yy = 16 * s->mb_y + 8*(n>>1);
76 74
    const int mx = *mx_ptr;
77 75
    const int my = *my_ptr;
76
    const int penalty_factor= s->me.sub_penalty_factor;
78 77
    
79 78
    LOAD_COMMON(xx, yy);
80 79
    
......
120 119
        CHECK_HALF_MV(0, 1, mx  , my  )        
121 120
        CHECK_HALF_MV(1, 1, mx  , my  )
122 121

  
123
        assert(bx < xmin*2 || bx > xmax*2 || by < ymin*2 || by > ymax*2);
122
        assert(bx >= xmin*2 || bx <= xmax*2 || by >= ymin*2 || by <= ymax*2);
124 123

  
125 124
        *mx_ptr = bx;
126 125
        *my_ptr = by;
......
171 170
        int d= dmin;
172 171
        const int index= (my<<ME_MAP_SHIFT) + mx;
173 172
        const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] 
174
                     + (mv_penalty[bx   - pred_x] + mv_penalty[by-2 - pred_y])*penalty_factor;
173
                     + (mv_penalty[bx   - pred_x] + mv_penalty[by-2 - pred_y])*s->me.penalty_factor;
175 174
        const int l= score_map[(index- 1               )&(ME_MAP_SIZE-1)]
176
                     + (mv_penalty[bx-2 - pred_x] + mv_penalty[by   - pred_y])*penalty_factor;
175
                     + (mv_penalty[bx-2 - pred_x] + mv_penalty[by   - pred_y])*s->me.penalty_factor;
177 176
        const int r= score_map[(index+ 1               )&(ME_MAP_SIZE-1)]
178
                     + (mv_penalty[bx+2 - pred_x] + mv_penalty[by   - pred_y])*penalty_factor;
177
                     + (mv_penalty[bx+2 - pred_x] + mv_penalty[by   - pred_y])*s->me.penalty_factor;
179 178
        const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
180
                     + (mv_penalty[bx   - pred_x] + mv_penalty[by+2 - pred_y])*penalty_factor;
181
        
179
                     + (mv_penalty[bx   - pred_x] + mv_penalty[by+2 - pred_y])*s->me.penalty_factor;
180
    
181
#if 0
182
        int key;
183
        int map_generation= s->me.map_generation;
184
        uint32_t *map= s->me.map;
185
        key= ((my-1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
186
        assert(map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
187
        key= ((my+1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
188
        assert(map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
189
        key= ((my)<<ME_MAP_MV_BITS) + (mx+1) + map_generation;
190
        assert(map[(index+1)&(ME_MAP_SIZE-1)] == key);
191
        key= ((my)<<ME_MAP_MV_BITS) + (mx-1) + map_generation;
192
        assert(map[(index-1)&(ME_MAP_SIZE-1)] == key);
193
#endif                
182 194
        if(t<=b){
183 195
            CHECK_HALF_MV(0, 1, mx  ,my-1)
184 196
            if(l<=r){
......
460 472
{\
461 473
    const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
462 474
    const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
475
/*printf("check_mv %d %d\n", x, y);*/\
463 476
    if(map[index]!=key){\
464 477
        CMP(d, x, y, size);\
465 478
        map[index]= key;\
466 479
        score_map[index]= d;\
467 480
        d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
481
/*printf("score:%d\n", d);*/\
468 482
        COPY3_IF_LT(dmin, d, best[0], x, best[1], y)\
469 483
    }\
470 484
}
471 485

  
486
#define CHECK_CLIPED_MV(ax,ay)\
487
{\
488
    const int x= FFMAX(xmin, FFMIN(ax, xmax));\
489
    const int y= FFMAX(ymin, FFMIN(ay, ymax));\
490
    CHECK_MV(x, y)\
491
}
492

  
472 493
#define CHECK_MV_DIR(x,y,new_dir)\
473 494
{\
474 495
    const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
475 496
    const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
497
/*printf("check_mv_dir %d %d %d\n", x, y, new_dir);*/\
476 498
    if(map[index]!=key){\
477 499
        CMP(d, x, y, size);\
478 500
        map[index]= key;\
479 501
        score_map[index]= d;\
480 502
        d += (mv_penalty[((x)<<shift)-pred_x] + mv_penalty[((y)<<shift)-pred_y])*penalty_factor;\
503
/*printf("score:%d\n", d);*/\
481 504
        if(d<dmin){\
482 505
            best[0]=x;\
483 506
            best[1]=y;\
......
508 531
    cmp= s->dsp.me_cmp[size];
509 532
    chroma_cmp= s->dsp.me_cmp[size+1];
510 533

  
534
    { /* ensure that the best point is in the MAP as h/qpel refinement needs it */
535
        const int key= (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
536
        const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);
537
        if(map[index]!=key){ //this will be executed only very rarey
538
            CMP(score_map[index], best[0], best[1], size);
539
            map[index]= key;
540
        }
541
    }
542

  
511 543
    for(;;){
512 544
        int d;
513 545
        const int dir= next_dir;
......
527 559
    }
528 560
}
529 561

  
562
static inline int RENAME(funny_diamond_search)(MpegEncContext * s, int *best, int dmin,
563
                                       Picture *ref_picture,
564
                                       int const pred_x, int const pred_y, int const penalty_factor,
565
                                       int const xmin, int const ymin, int const xmax, int const ymax, int const shift,
566
                                       uint32_t *map, int map_generation, int size, uint16_t * const mv_penalty
567
                                       )
568
{
569
    me_cmp_func cmp, chroma_cmp;
570
    int dia_size;
571
    LOAD_COMMON(s->mb_x*16, s->mb_y*16);
572
    
573
    cmp= s->dsp.me_cmp[size];
574
    chroma_cmp= s->dsp.me_cmp[size+1];
575

  
576
    for(dia_size=1; dia_size<=4; dia_size++){
577
        int dir;
578
        const int x= best[0];
579
        const int y= best[1];
580
        
581
        if(dia_size&(dia_size-1)) continue;
582

  
583
        if(   x + dia_size > xmax
584
           || x - dia_size < xmin
585
           || y + dia_size > ymax
586
           || y - dia_size < ymin)
587
           continue;
588
        
589
        for(dir= 0; dir<dia_size; dir+=2){
590
            int d;
591

  
592
            CHECK_MV(x + dir           , y + dia_size - dir);
593
            CHECK_MV(x + dia_size - dir, y - dir           );
594
            CHECK_MV(x - dir           , y - dia_size + dir);
595
            CHECK_MV(x - dia_size + dir, y + dir           );
596
        }
597

  
598
        if(x!=best[0] || y!=best[1])
599
            dia_size=0;
600
#if 0
601
{
602
int dx, dy, i;
603
static int stats[8*8];
604
dx= ABS(x-best[0]);
605
dy= ABS(y-best[1]);
606
if(dy>dx){
607
    dx^=dy; dy^=dx; dx^=dy;
608
}
609
stats[dy*8 + dx] ++;
610
if(256*256*256*64 % (stats[0]+1)==0){
611
    for(i=0; i<64; i++){
612
        if((i&7)==0) printf("\n");
613
        printf("%8d ", stats[i]);
614
    }
615
    printf("\n");
616
}
617
}
618
#endif
619
    }
620
    return dmin;    
621
}
622

  
623
#define SAB_CHECK_MV(ax,ay)\
624
{\
625
    const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
626
    const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
627
/*printf("sab check %d %d\n", ax, ay);*/\
628
    if(map[index]!=key){\
629
        CMP(d, ax, ay, size);\
630
        map[index]= key;\
631
        score_map[index]= d;\
632
        d += (mv_penalty[((ax)<<shift)-pred_x] + mv_penalty[((ay)<<shift)-pred_y])*penalty_factor;\
633
/*printf("score: %d\n", d);*/\
634
        if(d < minima[minima_count-1].height){\
635
            int j=0;\
636
            \
637
            while(d >= minima[j].height) j++;\
638
\
639
            memmove(&minima [j+1], &minima [j], (minima_count - j - 1)*sizeof(Minima));\
640
\
641
            minima[j].checked= 0;\
642
            minima[j].height= d;\
643
            minima[j].x= ax;\
644
            minima[j].y= ay;\
645
            \
646
            i=-1;\
647
            continue;\
648
        }\
649
    }\
650
}
651

  
652
#define MAX_SAB_SIZE 16
653
static inline int RENAME(sab_diamond_search)(MpegEncContext * s, int *best, int dmin,
654
                                       Picture *ref_picture,
655
                                       int const pred_x, int const pred_y, int const penalty_factor,
656
                                       int const xmin, int const ymin, int const xmax, int const ymax, int const shift,
657
                                       uint32_t *map, int map_generation, int size, uint16_t * const mv_penalty
658
                                       )
659
{
660
    me_cmp_func cmp, chroma_cmp;
661
    Minima minima[MAX_SAB_SIZE];
662
    const int minima_count= ABS(s->avctx->dia_size);
663
    int i, j;
664
    LOAD_COMMON(s->mb_x*16, s->mb_y*16);
665
    
666
    cmp= s->dsp.me_cmp[size];
667
    chroma_cmp= s->dsp.me_cmp[size+1];
668
    
669
    for(j=i=0; i<ME_MAP_SIZE; i++){
670
        uint32_t key= map[i];
671

  
672
        key += (1<<(ME_MAP_MV_BITS-1)) + (1<<(2*ME_MAP_MV_BITS-1));
673
        
674
        if((key&((-1)<<(2*ME_MAP_MV_BITS))) != map_generation) continue;
675
        
676
        assert(j<MAX_SAB_SIZE); //max j = number of predictors
677
        
678
        minima[j].height= score_map[i];
679
        minima[j].x= key & ((1<<ME_MAP_MV_BITS)-1); key>>=ME_MAP_MV_BITS;
680
        minima[j].y= key & ((1<<ME_MAP_MV_BITS)-1);
681
        minima[j].x-= (1<<(ME_MAP_MV_BITS-1));
682
        minima[j].y-= (1<<(ME_MAP_MV_BITS-1));
683
        minima[j].checked=0;
684
        if(minima[j].x || minima[j].y)
685
            minima[j].height+= (mv_penalty[((minima[j].x)<<shift)-pred_x] + mv_penalty[((minima[j].y)<<shift)-pred_y])*penalty_factor;
686
        
687
        j++;
688
    }
689
    
690
    qsort(minima, j, sizeof(Minima), minima_cmp);
691
    
692
    for(; j<minima_count; j++){
693
        minima[j].height=256*256*256*64;
694
        minima[j].checked=0;
695
        minima[j].x= minima[j].y=0;
696
    }
697
    
698
    for(i=0; i<minima_count; i++){
699
        const int x= minima[i].x;
700
        const int y= minima[i].y;
701
        int d;
702
        
703
        if(minima[i].checked) continue;
704
        
705
        if(   x >= xmax || x <= xmin
706
           || y >= ymax || y <= ymin)
707
           continue;
708

  
709
        SAB_CHECK_MV(x-1, y)
710
        SAB_CHECK_MV(x+1, y)
711
        SAB_CHECK_MV(x  , y-1)
712
        SAB_CHECK_MV(x  , y+1)
713
        
714
        minima[i].checked= 1;
715
    }
716
    
717
    best[0]= minima[0].x;
718
    best[1]= minima[0].y;
719
    dmin= minima[0].height;
720
    
721
    if(   best[0] < xmax && best[0] > xmin
722
       && best[1] < ymax && best[1] > ymin){
723
        int d;
724
        //ensure that the refernece samples for hpel refinement are in the map
725
        CHECK_MV(best[0]-1, best[1])
726
        CHECK_MV(best[0]+1, best[1])
727
        CHECK_MV(best[0], best[1]-1)
728
        CHECK_MV(best[0], best[1]+1)
729
    }
730
    return dmin;    
731
}
732

  
530 733
static inline int RENAME(var_diamond_search)(MpegEncContext * s, int *best, int dmin,
531 734
                                       Picture *ref_picture,
532 735
                                       int const pred_x, int const pred_y, int const penalty_factor,
......
535 738
                                       )
536 739
{
537 740
    me_cmp_func cmp, chroma_cmp;
538
    int dia_size=1;
741
    int dia_size;
539 742
    LOAD_COMMON(s->mb_x*16, s->mb_y*16);
540 743
    
541 744
    cmp= s->dsp.me_cmp[size];
......
547 750
        const int y= best[1];
548 751

  
549 752
        start= FFMAX(0, y + dia_size - ymax);
550
        end  = FFMIN(dia_size, xmax - x);
753
        end  = FFMIN(dia_size, xmax - x + 1);
551 754
        for(dir= start; dir<end; dir++){
552 755
            int d;
553 756

  
......
556 759
        }
557 760

  
558 761
        start= FFMAX(0, x + dia_size - xmax);
559
        end  = FFMIN(dia_size, y - ymin);
762
        end  = FFMIN(dia_size, y - ymin + 1);
560 763
        for(dir= start; dir<end; dir++){
561 764
            int d;
562 765

  
......
565 768
        }
566 769

  
567 770
        start= FFMAX(0, -y + dia_size + ymin );
568
        end  = FFMIN(dia_size, x - xmin);
771
        end  = FFMIN(dia_size, x - xmin + 1);
569 772
        for(dir= start; dir<end; dir++){
570 773
            int d;
571 774

  
......
574 777
        }
575 778

  
576 779
        start= FFMAX(0, -x + dia_size + xmin );
577
        end  = FFMIN(dia_size, ymax - y);
780
        end  = FFMIN(dia_size, ymax - y + 1);
578 781
        for(dir= start; dir<end; dir++){
579 782
            int d;
580 783

  
......
584 787

  
585 788
        if(x!=best[0] || y!=best[1])
586 789
            dia_size=0;
790
#if 0
791
{
792
int dx, dy, i;
793
static int stats[8*8];
794
dx= ABS(x-best[0]);
795
dy= ABS(y-best[1]);
796
stats[dy*8 + dx] ++;
797
if(256*256*256*64 % (stats[0]+1)==0){
798
    for(i=0; i<64; i++){
799
        if((i&7)==0) printf("\n");
800
        printf("%6d ", stats[i]);
801
    }
802
    printf("\n");
803
}
804
}
805
#endif
587 806
    }
588 807
    return dmin;    
589 808
}
......
591 810
static int RENAME(epzs_motion_search)(MpegEncContext * s, int block,
592 811
                             int *mx_ptr, int *my_ptr,
593 812
                             int P[10][2], int pred_x, int pred_y,
594
                             int xmin, int ymin, int xmax, int ymax, Picture *ref_picture, uint16_t * const mv_penalty)
813
                             int xmin, int ymin, int xmax, int ymax, Picture *ref_picture, int16_t (*last_mv)[2], 
814
                             int ref_mv_scale, uint16_t * const mv_penalty)
595 815
{
596 816
    int best[2]={0, 0};
597 817
    int d, dmin; 
......
600 820
    int map_generation;
601 821
    const int penalty_factor= s->me.penalty_factor;
602 822
    const int size=0;
823
    const int ref_mv_stride= s->mb_width+2;
824
    const int ref_mv_xy= 1 + s->mb_x + (s->mb_y + 1)*ref_mv_stride;
603 825
    me_cmp_func cmp, chroma_cmp;
604 826
    LOAD_COMMON(s->mb_x*16, s->mb_y*16);
605 827
    
......
615 837
    /* first line */
616 838
    if ((s->mb_y == 0 || s->first_slice_line)) {
617 839
        CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
618
        CHECK_MV(P_LAST[0]>>shift, P_LAST[1]>>shift)
840
        CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, 
841
                        (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
619 842
    }else{
620 843
        if(dmin<256 && ( P_LEFT[0]    |P_LEFT[1]
621 844
                        |P_TOP[0]     |P_TOP[1]
622
                        |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0 && s->avctx->dia_size==0){
845
                        |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){
623 846
            *mx_ptr= 0;
624 847
            *my_ptr= 0;
625 848
            s->me.skip=1;
......
627 850
        }
628 851
        CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
629 852
        if(dmin>256*2){
630
            CHECK_MV(P_LAST[0]    >>shift, P_LAST[1]    >>shift)
853
            CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, 
854
                            (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
631 855
            CHECK_MV(P_LEFT[0]    >>shift, P_LEFT[1]    >>shift)
632 856
            CHECK_MV(P_TOP[0]     >>shift, P_TOP[1]     >>shift)
633 857
            CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
634 858
        }
635 859
    }
636 860
    if(dmin>256*4){
637
        CHECK_MV(P_LAST_RIGHT[0] >>shift, P_LAST_RIGHT[1] >>shift)
638
        CHECK_MV(P_LAST_BOTTOM[0]>>shift, P_LAST_BOTTOM[1]>>shift)
861
        CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16, 
862
                        (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
863
        CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, 
864
                        (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
639 865
    }
640
#if 0 //doest only slow things down
641
    if(dmin>512*3){
642
        int step;
643
        dmin= score_map[0];
644
        best[0]= best[1]=0;
645
        for(step=128; step>0; step>>=1){
646
            const int step2= step;
647
            int y;
648
            for(y=-step2+best[1]; y<=step2+best[1]; y+=step){
649
                int x;
650
                if(y<ymin || y>ymax) continue;
651

  
652
                for(x=-step2+best[0]; x<=step2+best[0]; x+=step){
653
                    if(x<xmin || x>xmax) continue;
654
                    if(x==best[0] && y==best[1]) continue;
655
                    CHECK_MV(x,y)
656
                }
866

  
867
    if(s->avctx->last_predictor_count){
868
        const int count= s->avctx->last_predictor_count;
869
        const int xstart= FFMAX(0, s->mb_x - count);
870
        const int ystart= FFMAX(0, s->mb_y - count);
871
        const int xend= FFMIN(s->mb_width , s->mb_x + count + 1);
872
        const int yend= FFMIN(s->mb_height, s->mb_y + count + 1);
873
        int mb_y;
874

  
875
        for(mb_y=ystart; mb_y<yend; mb_y++){
876
            int mb_x;
877
            for(mb_x=xstart; mb_x<xend; mb_x++){
878
                const int xy= mb_x + 1 + (mb_y + 1)*ref_mv_stride;
879
                int mx= (last_mv[xy][0]*ref_mv_scale + (1<<15))>>16;
880
                int my= (last_mv[xy][1]*ref_mv_scale + (1<<15))>>16;
881

  
882
                if(mx>xmax || mx<xmin || my>ymax || my<ymin) continue;
883
                CHECK_MV(mx,my)
657 884
            }
658 885
        }
659 886
    }
660
#endif
887

  
661 888
//check(best[0],best[1],0, b0)
662
    if(s->avctx->dia_size<2)
889
    if(s->avctx->dia_size==-1)
890
        dmin= RENAME(funny_diamond_search)(s, best, dmin, ref_picture,
891
                                   pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax, 
892
				   shift, map, map_generation, size, mv_penalty);
893
    else if(s->avctx->dia_size<-1)
894
        dmin= RENAME(sab_diamond_search)(s, best, dmin, ref_picture,
895
                                   pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax, 
896
				   shift, map, map_generation, size, mv_penalty);
897
    else if(s->avctx->dia_size<2)
663 898
        dmin= RENAME(small_diamond_search)(s, best, dmin, ref_picture,
664 899
                                   pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax, 
665 900
				   shift, map, map_generation, size, mv_penalty);
......
680 915
static int RENAME(epzs_motion_search4)(MpegEncContext * s, int block,
681 916
                             int *mx_ptr, int *my_ptr,
682 917
                             int P[10][2], int pred_x, int pred_y,
683
                             int xmin, int ymin, int xmax, int ymax, Picture *ref_picture, uint16_t * const mv_penalty)
918
                             int xmin, int ymin, int xmax, int ymax, Picture *ref_picture, int16_t (*last_mv)[2], 
919
                             int ref_mv_scale, uint16_t * const mv_penalty)
684 920
{
685 921
    int best[2]={0, 0};
686 922
    int d, dmin; 
......
689 925
    int map_generation;
690 926
    const int penalty_factor= s->me.penalty_factor;
691 927
    const int size=1;
928
    const int ref_mv_stride= s->mb_width+2;
929
    const int ref_mv_xy= 1 + s->mb_x + (s->mb_y + 1)*ref_mv_stride;
692 930
    me_cmp_func cmp, chroma_cmp;
693 931
    LOAD_COMMON((s->mb_x*2 + (block&1))*8, (s->mb_y*2 + (block>>1))*8);
694 932
    
......
702 940
    /* first line */
703 941
    if ((s->mb_y == 0 || s->first_slice_line) && block<2) {
704 942
	CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
705
        CHECK_MV(P_LAST[0]>>shift, P_LAST[1]>>shift)
943
        CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, 
944
                        (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
706 945
        CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
707 946
    }else{
708 947
        CHECK_MV(P_MV1[0]>>shift, P_MV1[1]>>shift)
......
712 951
            CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
713 952
            CHECK_MV(P_TOP[0]>>shift, P_TOP[1]>>shift)
714 953
            CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
715
            CHECK_MV(P_LAST[0]>>shift, P_LAST[1]>>shift)
954
            CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, 
955
                            (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
716 956
        }
717 957
    }
718 958
    if(dmin>64*4){
719
        CHECK_MV(P_LAST_RIGHT[0]>>shift, P_LAST_RIGHT[1]>>shift)
720
        CHECK_MV(P_LAST_BOTTOM[0]>>shift, P_LAST_BOTTOM[1]>>shift)
959
        CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16, 
960
                        (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
961
        CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, 
962
                        (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
721 963
    }
722 964

  
723
    if(s->avctx->dia_size<2)
965
    if(s->avctx->dia_size==-1)
966
        dmin= RENAME(funny_diamond_search)(s, best, dmin, ref_picture,
967
                                   pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax, 
968
				   shift, map, map_generation, size, mv_penalty);
969
    else if(s->avctx->dia_size<-1)
970
        dmin= RENAME(sab_diamond_search)(s, best, dmin, ref_picture,
971
                                   pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax, 
972
				   shift, map, map_generation, size, mv_penalty);
973
    else if(s->avctx->dia_size<2)
724 974
        dmin= RENAME(small_diamond_search)(s, best, dmin, ref_picture,
725 975
                                   pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax, 
726 976
				   shift, map, map_generation, size, mv_penalty);
......
728 978
        dmin= RENAME(var_diamond_search)(s, best, dmin, ref_picture,
729 979
                                   pred_x, pred_y, penalty_factor, xmin, ymin, xmax, ymax, 
730 980
				   shift, map, map_generation, size, mv_penalty);
981

  
731 982
    *mx_ptr= best[0];
732 983
    *my_ptr= best[1];    
733 984

  

Also available in: Unified diff