comparison motion_est_template.c @ 4249:17e04bdf8d69 libavcodec

UMH support (dia_size=-1 activates it)
author michael
date Fri, 01 Dec 2006 09:48:33 +0000
parents 4be0e20c0eeb
children 507ba4483ffc
comparison
equal deleted inserted replaced
4248:4be0e20c0eeb 4249:17e04bdf8d69
656 #endif 656 #endif
657 } 657 }
658 return dmin; 658 return dmin;
659 } 659 }
660 660
661 static int umh_search(MpegEncContext * s, int *best, int dmin,
662 int src_index, int ref_index, int const penalty_factor,
663 int size, int h, int flags)
664 {
665 MotionEstContext * const c= &s->me;
666 me_cmp_func cmpf, chroma_cmpf;
667 LOAD_COMMON
668 LOAD_COMMON2
669 int map_generation= c->map_generation;
670 int x,y,x2,y2, i, j, d;
671 static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},
672 { 4,-2}, { 4,-1}, { 4, 0}, { 4, 1}, { 4, 2},
673 {-2, 3}, { 0, 4}, { 2, 3},
674 {-2, 3}, { 0, 4}, { 2, 3},};
675 static const int hex2[6][2]={{-2, 0}, { 2,0}, {-1,-2}, {1,-2}, {-1,2},{1,2}};
676
677 cmpf= s->dsp.me_cmp[size];
678 chroma_cmpf= s->dsp.me_cmp[size+1];
679
680 x= best[0];
681 y= best[1];
682 for(x2=FFMAX(x-15, xmin); x2<=FFMIN(x+15,xmax); x2+=2){
683 CHECK_MV(x2, y);
684 }
685 for(y2=FFMAX(y- 7, ymin); y2<=FFMIN(y+ 7,ymax); y2+=2){
686 CHECK_MV(x, y2);
687 }
688
689 x= best[0];
690 y= best[1];
691 for(y2=FFMAX(y-2, ymin); y2<=FFMIN(y+2,ymax); y2++){
692 for(x2=FFMAX(x-2, xmin); x2<=FFMIN(x+2,xmax); x2++){
693 CHECK_MV(x2, y2);
694 }
695 }
696
697 //FIXME prevent the CLIP stuff
698
699 for(j=1; j<=4; j++){
700 for(i=0; i<16; i++){
701 CHECK_CLIPED_MV(x+hex[i][0]*j, y+hex[i][1]*j);
702 }
703 }
704
705 do{
706 x= best[0];
707 y= best[1];
708 for(i=0; i<6; i++){
709 CHECK_CLIPED_MV(x+hex2[i][0], y+hex2[i][1]);
710 }
711 }while(best[0] != x || best[1] != y);
712
713 do{
714 x= best[0];
715 y= best[1];
716 CHECK_CLIPED_MV(x+1, y);
717 CHECK_CLIPED_MV(x, y+1);
718 CHECK_CLIPED_MV(x-1, y);
719 CHECK_CLIPED_MV(x, y-1);
720 }while(best[0] != x || best[1] != y);
721
722 return dmin;
723 }
724
661 #define SAB_CHECK_MV(ax,ay)\ 725 #define SAB_CHECK_MV(ax,ay)\
662 {\ 726 {\
663 const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\ 727 const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
664 const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\ 728 const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
665 /*printf("sab check %d %d\n", ax, ay);*/\ 729 /*printf("sab check %d %d\n", ax, ay);*/\
848 static always_inline int diamond_search(MpegEncContext * s, int *best, int dmin, 912 static always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,
849 int src_index, int ref_index, int const penalty_factor, 913 int src_index, int ref_index, int const penalty_factor,
850 int size, int h, int flags){ 914 int size, int h, int flags){
851 MotionEstContext * const c= &s->me; 915 MotionEstContext * const c= &s->me;
852 if(c->dia_size==-1) 916 if(c->dia_size==-1)
853 return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags); 917 return umh_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
854 else if(c->dia_size<-1) 918 else if(c->dia_size<-1)
855 return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags); 919 return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
856 else if(c->dia_size<2) 920 else if(c->dia_size<2)
857 return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags); 921 return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
858 else 922 else