#include #include #include #include #ifdef THINK_C #include #endif #ifdef MYGETOPT char getopt( int argc, char *argv[], char *format ); #endif #include "cplx.h" #define FACTOR ((double)(IH*IW)) #define Boolean char #define Output if (G_prefs.Verbose) printf #define IH pictIn->image_H #define IW pictIn->image_W #define IN pictIn->n_comp #define MIN(a,b) ((a)>(b)?(b):(a)) /*#define ctod(a) ((double)(a)/255.0)*/ #define ctod(a) ((double)(a)) typedef struct { char *AppName; int direct; int Verbose; char *outname; } pref; pref G_prefs; void fftpict(char *orgname,char *dstname); void fatalError(char *str); void usage(void); void fatalError(char *str) { fprintf(stderr, "%s: Fatal Error: %s. bye...\n",G_prefs.AppName,str); exit(-2); } void usage(void) { fprintf(stderr,"Uso: %s [-o output] [-i] file [file...]\n", G_prefs.AppName); exit(1); } main( int argc, char *argv[] ) { int i,opcion; char scname[256]; int theError=0; int OutputOpt=0; extern char *optarg; extern int optind,opterr; G_prefs.AppName=argv[0]; G_prefs.direct=1; G_prefs.Verbose=0; G_prefs.outname=NULL; #ifdef THINK_C argc = ccommand(&argv); #endif while ( (opcion=getopt(argc,argv,"hivo:")) != EOF ) { switch(opcion) { case 'h': usage(); break; case 'i': G_prefs.direct=0; break; case 'v': G_prefs.Verbose=1; break; case 'o': G_prefs.outname=optarg; break; defatult: usage(); } } if (strcmp("ifftp", argv[0])) G_prefs.direct=1; if (optind==argc) usage(); for (i=optind; i\t%s\n", G_prefs.AppName,argv[i], G_prefs.outname==NULL?"stdout":G_prefs.outname); fflush(stdout); } fftpict(argv[i], G_prefs.outname); } } void fftpict(char *orgname,char *dstname) { Pict pictIn; Pict pictOut; int ReadMode = P_READ; int WriteMode = P_WRITE; int mode,f,i,j, ic; int gx, gy; U_char *r_ptr,*g_ptr,*b_ptr,*a_ptr,*po; complex *cimg[3], **pcimg[3]; pictIn = pict_open(orgname,ReadMode,0,0,0,NULL); pictIn->pixels = (U_char *)malloc((size_t)IW*(size_t)pictIn->n_comp+1); if (pictIn->pixels==NULL) fatalError("Se acabo la memoria"); for(i=0; i<3; i++) { if(( cimg[i] = (complex *) calloc( (size_t)(IW*IH), sizeof( complex))) ==NULL) fatalError("Se acabo la memoria"); if(( pcimg[i] = (complex **) calloc( (size_t)(IH), sizeof( complex*))) ==NULL) fatalError("Se acabo la memoria"); for(j=0;jpixels; r_ptr = a_ptr+IW; g_ptr = r_ptr+IW; b_ptr = g_ptr+IW; pict_get_line(pictIn,pictIn->pixels); switch(pictIn->clr_mode) { case M_MONO: case M_RGB8: for (j=0; jmap[*a_ptr][0]); Re(cimg[1][ic]) = ctod(pictIn->map[*a_ptr][1]); Re(cimg[2][ic]) = ctod(pictIn->map[*a_ptr++][2]); } break; case M_RGB24: for (j=0; jpixels = (U_char*)malloc(pictOut->image_W*pictOut->n_comp))==NULL) exit(1); for(j=0;jpixels; for(i=0;ipixels); } pict_close(pictOut); pict_free(pictIn); }