--- /dev/null
+/* ft.c - fourier transformation on nlsop save files */
+
+/*
+ * author: frank.zirkelbach@physik.uni-augsburg.de
+ *
+ */
+
+#include "ft.h"
+
+int usage(void) {
+ puts("usage:");
+ puts("ft -i <infile> -o <outfile> -itype <intype> -otype <outtype> -d <dimensions> -g <geometry> -debug <debug file>");
+ puts("");
+ puts("i/o type may be bmp or nlsop");
+ puts("dimensions: 2 or 3");
+ puts("geometry in 2d: <resolution> <start> , eg: 64 32 0 80 (64x32 big area starting from (0|80)");
+ puts("geometry in 3d: <resolution> <start> , eg: 64 64 32 0 0 80 (the same in 3 dimensions ^)");
+ puts("");
+ puts("you must set -dimensions before specifying -geometry");
+ puts("default: dimension = 2 , resolution = whole image");
+ return 1;
+}
+
+int get_size_of_infile(int fd,int *res,unigned char set) {
+
+ if(set&SET_IN_BMP) {
+
+ unsigned char buf[BMP_HEADER_LEN];
+
+ puts("reading bmp header ...");
+ read(fd,buf,BMP_HEADER_LEN);
+ res[0]=buf[18]|(buf[19]<<8);
+ res[1]=buf[22]|(buf[23]<<8);
+
+ return ((int)buf[10]);
+ }
+ else {
+
+ d3_lattice *d3l;
+
+ puts("reading nlsop header ...");
+ d3l=(d3_lattice *)malloc(sizeof(d3_lattice));
+ read(fd,d3l,sizeof(d3_lattice));
+ res[0]=d3l->max_x;
+ if(set&SET_3D) {
+ res[1]=d3l->max_y;
+ res[2]=d3l->max_z;
+ } else res[1]=d3l->max_z;
+
+ return (sizeof(d3_lattice)+sizeof(info));
+ }
+
+}
+
+int get_infile_data(int fd,int offset,int *RES,int *res,int *x,unsigned char *orig,unsigned char set) {
+
+ int i,j,k,w_len;
+ unsigned char *buf;
+
+ lseek(fd,offset,SEEK_SET);
+
+ if(set&SET_IN_BMP) {
+ w_len=3*RES[1];
+ w_len+=(4-w_len%4);
+ lseek(fd,x[1]*w_len,SEEK_CUR);
+ buf=(unsigned char)malloc(w_len);
+ for(j=0;j<res[1];j++) {
+ read(fd,buf,w_len);
+ for(i=x[0];i<res[0];i++) if(buf[3*i]!=0) orig+j*res[0]+i-x[0]=0xff;
+ }
+ free(buf);
+ }
+ else if(set&SET_IN_NLSOP) {
+ puts("NOT SUPPORTED RIGT NOW!");
+ return -1;
+ }
+
+ return 1;
+}
+
+int main(int argc,char **argv) {
+
+ char infile[FILE_LEN]="",outfile[FILE_LEN]="",debugfile[FILE_LEN]="";
+ char itype[TYPE_LEN]="",otype[TYPE_LEN]="";
+ int ifd,ofd,dfd;
+ int dim=2;
+ int x[3],res[3];
+ int i,j,k,size,offset;
+ unsigned char set=0;
+ unsigned char *orig,*image;
+ int RES[3]; /* resolution of the original image */
+
+
+ /* parse argv */
+ for(i=1;i<argc;i++) {
+ if(!strncmp(argv[i],"-i",2)) strncpy(infile,argv[++i],FILE_LEN);
+ else if(!strncmp(argv[i],"-o",2)) strncpy(outfile,argv[++i],FILE_LEN);
+ else if(!strncmp(argv[i],"-itype",6)) strncpy(itype,argv[++i],TYPE_LEN);
+ else if(!strncmp(argv[i],"-otype",6)) strncpy(otype,argv[++i],TYPE_LEN);
+ else if(!strncmp(argv[i],"-d",2)) {
+ strncpy(debugfile,argv[++i],FILE_LEN);
+ set|=SET_DEBUG;
+ }
+ else if(!strncmp(argv[i],"-d",2)) {
+ dim=atoi(argv[++i]);
+ set|=SET_DIM;
+ if(dim==3) set|=SET_3D;
+ }
+ else if(!strncmp(argv[i],"-g",2)) {
+ set|=SET_GEO;
+ res[0]=atoi(argv[++i]); res[1]=atoi(argv[++i]);
+ if(dim==3) res[2]=atoi(argv[++i]);
+ x[0]=atoi(argv[++i]); x[1]=atoi(argv[++i]);
+ if(dim==3) x[2]=atoi(argv[++i]);
+ }
+ usage();
+ return -1;
+ }
+ }
+
+ if((ifd=open(infile,O_RDONLY))<0) {
+ perror("unable to open file readonly");
+ return -1;
+ }
+
+ if((ofd=open(ofile,O_WRONLY))<0) {
+ perror("unable to open file writeonly");
+ return -1;
+ }
+
+ if(set&SET_DEBUG) {
+ if((dfd=open(debugfile,O_WRONLY))<0) {
+ perror("unable to open degugfile writeonly");
+ return -1;
+ }
+ }
+
+ if(!strncmp(itype,"bmp",3)) {
+ set|=SET_IN_BMP;
+ if(dim==3) {
+ puts("there is no 3 dimensional bmp file!");
+ return -1;
+ }
+ }
+ else if(!strncmp(itype,"nlsop",5)) set|=SET_IN_NLSOP;
+ else usage();
+
+ if(!strncmp(otype,"bmp",3)) {
+ set|=SET_OUT_BMP;
+ if(dim==3) {
+ puts("cant write 3 dimensional bmp file!");
+ return -1;
+ }
+ }
+ else if(!strncmp(otype,"nlsop",5)) set|=SET_OUT_NLSOP;
+ else usage();
+
+ offset=get_size_of_infile(ifd,RES,set);
+ if(!set&SET_GEO) {
+ for(i=0;i<3;i++) {
+ x[i]=0;
+ res[i]=RES[i];
+ }
+ }
+
+ /* allocate buffer for original and transformed image */
+ size=res[0]*res[1];
+ if(dim==3) size*=res[2];
+ orig=(unsigned char *)malloc(size);
+ image=(unsigned char *)malloc(size);
+
+ get_infile_data(ifd,offset,RES,res,x,orig,set);
+
+ /* to be continued ... */
+
+
+ return 1;
+}