/* (c) SPDsoft & GTIC 20 julio 1993*/ #include #include #include #include "pict.h" #ifdef THINK_C #include #endif #ifdef MYGETOPT char getopt( int argc, char *argv[], char *format ); #endif #define iw (pictIn->image_W) #define ih (pictIn->image_H) #define MAX_FILTER_W 16 void usage(char *name); void fatalError(char *name,char *str); void usage(char *name) { fprintf(stderr, "usage: %s [-o output] -f 'filter string' [-d div] files...\n",name); exit(-1); } void fatalError(char *name,char *str) { fprintf(stderr, "%s: Fatal Error: %s. bye...\n",name,str); exit(-2); } int GetFilter( char *str, float filter[], float div ) { char *tmpstr; int filter_w = 0; for( tmpstr=strtok(str," "); tmpstr!=NULL ; tmpstr = strtok(NULL," ")) filter[filter_w++]=atof(tmpstr)/div; return(filter_w); } main(int argc,char *argv[]) { char *fname="fltout.pict"; unsigned int first=0, last=0, NumOfSFrames; int FilterOpt=0; int OutputOpt=0; char Verbose=0; Pict pictIn,pictOut; int np,nl,nm,nf,i,j,opcion; int theError=0; int data_w; int filter_w; unsigned char *filterp[MAX_FILTER_W]; float num[MAX_FILTER_W]; float div=1.0; float res; extern char *optarg; extern int optind,opterr; #ifdef THINK_C argc = ccommand(&argv); #endif while ( (opcion=getopt(argc,argv,"o:f:d:vh")) != EOF ) { switch(opcion) { case 'o': theError += ( *optarg==0x00 ); OutputOpt=optind-1; break; case 'f': theError += ( *optarg==0x00 ); FilterOpt=optind-1; break; case 'd': theError += ( *optarg==0x00 ); div = atof(optarg); break; case 'v': printf("%s:v. 20 julio 1993\n",argv[0]); Verbose=1; break; defatult: usage(argv[0]); } } if ((theError!=0)||(FilterOpt==0)||(div <= 0.0 )) usage(argv[0]); if ( 0==(filter_w=GetFilter( argv[FilterOpt],num,div))) fatalError(argv[0],"Bad filter string"); if ( 0==(filter_w%2)) fatalError(argv[0],"Filter width must be odd"); first=optind; last=argc-1; NumOfSFrames=last-first+1; if ( NumOfSFrames==0 ) usage(argv[0]); if (( NumOfSFrames>1 )&&(OutputOpt!=0)) fatalError(argv[0],"-o requires just one pict"); if(Verbose) { printf("%s:filter_w\t%d\n",argv[0],filter_w); for( i=0 ; in_comp==1) fatalError(argv[0],"Not True Color!"); data_w=iw *pictIn->n_comp; if ((pictIn->pixels = (U_char*)malloc(data_w*filter_w))==NULL) fatalError(argv[0],"Buy more memory!"); pictOut = pict_open(OutputOpt!=0?argv[OutputOpt]:fname,P_WRITE, ih,iw,pictIn->clr_mode,pictIn->map); if ((pictOut->pixels = (U_char*)malloc(data_w))==NULL) fatalError(argv[0],"Buy more memory!"); /******************************************************************/ /* This is the real work */ for(np=filter_w/2;nppixels+data_w*np; pict_get_line(pictIn,filterp[np]); } for(j=0,nm=0;jpixels+data_w*((np+nm)%filter_w); for(np=0;np= ih-1 ) filterp[np]=filterp[filter_w-1]; } if(filterp[filter_w-1]!=filterp[filter_w-2]) pict_get_line(pictIn,filterp[filter_w-1]); for(i=0;i255.0) res=255.0; *(pictOut->pixels+i)=(unsigned char)res; }/* columns */ pict_put_line(pictOut,pictOut->pixels); }/* lines */ /* End of real work */ /******************************************************************/ pict_close(pictIn); pict_close(pictOut); } }