// ppmdim.c : make frame of picture dim #include #include #include #include #include #include "ppmif.c" // dim target color int tag[3]={0,0,0}; int t0,t1,t2; int bwidth=10; int ctag=-1; int dimmode=0; // 0: linear 1: parabola 2:sin /* the algorithm */ inline int tagadd(imgbyte *p) { t0+=p[0]; t1+=p[1]; t2+=p[2]; } void CalculateTargetColor(imgbyte *data, int w,int h,int sx,int sy,int ex,int ey) { int i,x,y; int dw,dh; imgbyte *p; int ts; if(ex-sx+1bwidth) return 256; switch(dimmode) { case 1: // parabola if(t<0.5) return (int)(t*t*2*256); if(t<0.5) return (int)(1-2*(t-1)*(t-1)*256); case 2: //sin return (int)(256*(1-cos(t*3.141592))/2); default: // linear return (int)(256*t); } } inline int ColChange(imgbyte *p,int d1,int d2) { p[0]=(d1*p[0]+d2*t0)>>8; p[1]=(d1*p[1]+d2*t1)>>8; p[2]=(d1*p[2]+d2*t2)>>8; } void DimFrame(imgbyte *data,int w,int h,int sx,int sy,int ex,int ey) { int x,y; int i,l; imgbyte *p; int d1,d2; int dw,dh; RegulatePos(w,h,&sx,&sy,&ex,&ey); if(ex-sx+10) CalculateTargetColor(data,w,h,sx,sy,ex,ey); for(i=0;i