1 /* ft.c - fourier transformation on nlsop save files */
4 * author: frank.zirkelbach@physik.uni-augsburg.de
12 puts("ft -i <infile> -o <outfile> -itype <intype> -otype <outtype> -d <dimensions> -g <geometry> -debug <debug file>");
14 puts("i/o type may be bmp or nlsop");
15 puts("dimensions: 2 or 3");
16 puts("geometry in 2d: <resolution> <start> , eg: 64 32 0 80 (64x32 big area starting from (0|80)");
17 puts("geometry in 3d: <resolution> <start> , eg: 64 64 32 0 0 80 (the same in 3 dimensions ^)");
19 puts("you must set -dimensions before specifying -geometry");
20 puts("default: dimension = 2 , resolution = whole image");
24 int get_size_of_infile(int fd,int *res,unigned char set) {
28 unsigned char buf[BMP_HEADER_LEN];
30 puts("reading bmp header ...");
31 read(fd,buf,BMP_HEADER_LEN);
32 res[0]=buf[18]|(buf[19]<<8);
33 res[1]=buf[22]|(buf[23]<<8);
35 return ((int)buf[10]);
41 puts("reading nlsop header ...");
42 d3l=(d3_lattice *)malloc(sizeof(d3_lattice));
43 read(fd,d3l,sizeof(d3_lattice));
48 } else res[1]=d3l->max_z;
50 return (sizeof(d3_lattice)+sizeof(info));
55 int get_infile_data(int fd,int offset,int *RES,int *res,int *x,unsigned char *orig,unsigned char set) {
60 lseek(fd,offset,SEEK_SET);
65 lseek(fd,x[1]*w_len,SEEK_CUR);
66 buf=(unsigned char)malloc(w_len);
67 for(j=0;j<res[1];j++) {
69 for(i=x[0];i<res[0];i++) if(buf[3*i]!=0) orig+j*res[0]+i-x[0]=0xff;
73 else if(set&SET_IN_NLSOP) {
74 puts("NOT SUPPORTED RIGT NOW!");
81 int main(int argc,char **argv) {
83 char infile[FILE_LEN]="",outfile[FILE_LEN]="",debugfile[FILE_LEN]="";
84 char itype[TYPE_LEN]="",otype[TYPE_LEN]="";
88 int i,j,k,size,offset;
90 unsigned char *orig,*image;
91 int RES[3]; /* resolution of the original image */
96 if(!strncmp(argv[i],"-i",2)) strncpy(infile,argv[++i],FILE_LEN);
97 else if(!strncmp(argv[i],"-o",2)) strncpy(outfile,argv[++i],FILE_LEN);
98 else if(!strncmp(argv[i],"-itype",6)) strncpy(itype,argv[++i],TYPE_LEN);
99 else if(!strncmp(argv[i],"-otype",6)) strncpy(otype,argv[++i],TYPE_LEN);
100 else if(!strncmp(argv[i],"-d",2)) {
101 strncpy(debugfile,argv[++i],FILE_LEN);
104 else if(!strncmp(argv[i],"-d",2)) {
107 if(dim==3) set|=SET_3D;
109 else if(!strncmp(argv[i],"-g",2)) {
111 res[0]=atoi(argv[++i]); res[1]=atoi(argv[++i]);
112 if(dim==3) res[2]=atoi(argv[++i]);
113 x[0]=atoi(argv[++i]); x[1]=atoi(argv[++i]);
114 if(dim==3) x[2]=atoi(argv[++i]);
121 if((ifd=open(infile,O_RDONLY))<0) {
122 perror("unable to open file readonly");
126 if((ofd=open(ofile,O_WRONLY))<0) {
127 perror("unable to open file writeonly");
132 if((dfd=open(debugfile,O_WRONLY))<0) {
133 perror("unable to open degugfile writeonly");
138 if(!strncmp(itype,"bmp",3)) {
141 puts("there is no 3 dimensional bmp file!");
145 else if(!strncmp(itype,"nlsop",5)) set|=SET_IN_NLSOP;
148 if(!strncmp(otype,"bmp",3)) {
151 puts("cant write 3 dimensional bmp file!");
155 else if(!strncmp(otype,"nlsop",5)) set|=SET_OUT_NLSOP;
158 offset=get_size_of_infile(ifd,RES,set);
166 /* allocate buffer for original and transformed image */
168 if(dim==3) size*=res[2];
169 orig=(unsigned char *)malloc(size);
170 image=(unsigned char *)malloc(size);
172 get_infile_data(ifd,offset,RES,res,x,orig,set);
174 /* to be continued ... */