#include "prj.h" #include int mv_around(short frame,short row,short column,int old_mad,unsigned short flag[31][31],unsigned short step,short *vector_x,short *vector_y,unsigned short *finished) { register short mx,my; long status; int curr_mad,value; short min_y,max_y,min_x,max_x; int old_mx,old_my,vx,vy; curr_mad=old_mad; old_my=*vector_y; old_mx=*vector_x; vy=old_my;vx=old_mx; status=tot_count; for(my=old_my-step;my<=old_my+step;my+=step) for(mx=old_mx-step;mx<=old_mx+step;mx+=step){ if(mx<1-N2 || my<1-N2 || mx>N2-1 || my>N2-1) continue; if(my<0 && row==0) continue; if(my>0 && row==ROW-N2) continue; if(mx<0 && column==0) continue; if(mx>0 && column==COLUMN-N2) continue; if(flag[my+15][mx+15]==1) continue; value=mad2(frame,row,column,my,mx,curr_mad,256); tot_count++; if(valuemx*mx+my*my){ vy=my; vx=mx; } flag[my+15][mx+15]=1; } *vector_y=vy; *vector_x=vx; if(status==tot_count) *finished= 1; else *finished=0; return curr_mad; } int mv_step4(short frame,short row,short column) { short vector_x,vector_y; int curr_mad; unsigned short flag[31][31],finished; int i,j; for(j=0;j<31;j++) for(i=0;i<31;i++) flag[j][i]=0; finished=0; curr_mad=99999; vector_x=0; vector_y=0; while(!finished){ curr_mad=mv_around(frame,row,column,curr_mad,flag,2,&vector_x,&vector_y,&finished); } curr_mad=mv_around(frame,row,column,curr_mad,flag,1,&vector_x,&vector_y,&finished); mv_y[frame][row/N2][column/N2]=vector_y; mv_x[frame][row/N2][column/N2]=vector_x; return curr_mad; } int mv_8(short frame,short row,short column,int old_mad,unsigned short step,short *vector_x,short *vector_y) { register short mx,my; long status; int curr_mad,value; short min_y,max_y,min_x,max_x; int old_mx,old_my,vx,vy; curr_mad=old_mad; old_my=*vector_y; old_mx=*vector_x; vy=old_my;vx=old_mx; status=tot_count; for(my=old_my-step;my<=old_my+step;my+=step) for(mx=old_mx-step;mx<=old_mx+step;mx+=step){ if(mx<1-N2 || my<1-N2 || mx>N2-1 || my>N2-1) continue; if(my<0 && row==0) continue; if(my>0 && row==ROW-N2) continue; if(mx<0 && column==0) continue; if(mx>0 && column==COLUMN-N2) continue; if(my==old_my && mx==old_mx) continue; value=mad2(frame,row,column,my,mx,curr_mad,256); tot_count++; if(valuemx*mx+my*my){ vy=my; vx=mx; } } *vector_y=vy; *vector_x=vx; return curr_mad; } int mv_step3(short frame,short row,short column) { short vector_x,vector_y; int curr_mad; curr_mad=mad2(frame,row,column,0,0,99999,256); tot_count++; vector_x=0; vector_y=0; curr_mad=mv_8(frame,row,column,curr_mad,8,&vector_x,&vector_y); curr_mad=mv_8(frame,row,column,curr_mad,4,&vector_x,&vector_y); curr_mad=mv_8(frame,row,column,curr_mad,2,&vector_x,&vector_y); curr_mad=mv_8(frame,row,column,curr_mad,1,&vector_x,&vector_y); mv_y[frame][row/N2][column/N2]=vector_y; mv_x[frame][row/N2][column/N2]=vector_x; return curr_mad; } int mv_adapt(short frame,short row,short column) { short vector_x,vector_y; int curr_mad; vector_x=mv_x[frame-1][row/N2][column/N2]; vector_y=mv_y[frame-1][row/N2][column/N2]; curr_mad=mad2(frame,row,column,vector_x,vector_y,99999,256); tot_count++; curr_mad=mv_8(frame,row,column,curr_mad,2,&vector_x,&vector_y); curr_mad=mv_8(frame,row,column,curr_mad,1,&vector_x,&vector_y); mv_y[frame][row/N2][column/N2]=vector_y; mv_x[frame][row/N2][column/N2]=vector_x; return curr_mad; }