]> hackdaworld.org Git - physik/nlsop.git/commitdiff
support: meanvalue/sum of multiple fts
authorhackbard <hackbard>
Tue, 13 Sep 2005 22:29:28 +0000 (22:29 +0000)
committerhackbard <hackbard>
Tue, 13 Sep 2005 22:29:28 +0000 (22:29 +0000)
linescan.c

index 889446c0e7f3c77255381ca7a64310a3b1e17ced..bbabc66095225d4ee5683fff193de7b2d6a6ed10 100644 (file)
 int main(int argc,char **argv) {
 
   t_bmp bmp;
-  int x,y,d;
-  double val;
+  int i,x,y,d;
+  double *val=NULL;
+  char set=1;
+
+  for(i=1;i<argc;i++) {
+
+    bmp_init(&bmp,2);
+    bmp.mode=READ;
+    strcpy(bmp.file,argv[i]);
+    bmp_read_file(&bmp);
+
+    if(set) {
+      val=(double *)malloc(bmp.info.height*sizeof(double));
+      if(val==NULL) {
+        printf("malloc failed!\n");
+        return -23;
+      }
+      memset(val,0,bmp.info.height*sizeof(double));
+      set=0;
+    }
+
+    x=bmp.info.width/2;
+    for(y=0;y<bmp.info.height;y++) {
+      for(d=-DX;d<=DX;d++)
+        val[y]+=(1.0*(bmp.map[x+d].r+bmp.map[x+d].g+bmp.map[x+d].b)/3);
+      x+=bmp.info.width; // jump to [x/2][y+1]
+    }
+
+    bmp_shutdown(&bmp);
 
-  if(argc!=2) {
-    printf("usage: %s <filename>\n",argv[0]);
-    return -1;
   }
 
-  bmp_init(&bmp,2);
-  bmp.mode=READ;
-  strcpy(bmp.file,argv[1]);
-
-  bmp_read_file(&bmp);
-
-  dprintf(2,"width = %d ... delta x = %d.\n",bmp.info.width,DX);
-
-  x=bmp.info.width/2;
   for(y=0;y<bmp.info.height;y++) {
-    val=0.0;
-    for(d=-DX;d<=DX;d++)
-      val+=(1.0*(bmp.map[x+d].r+bmp.map[x+d].g+bmp.map[x+d].b)/3);
-    printf("%f %f\n",1.0*(bmp.info.height/2-y)/(bmp.info.width*3),val);
-    //printf("%f %f\n",1.0*(bmp.info.height/2-y)/(bmp.info.width),val);
-    x+=bmp.info.width;
+    val[y]/=(argc-1);
+    printf("%f %f\n",1.0*(bmp.info.height/2-y)/(bmp.info.width*3),val[y]);
+    //printf("%f %f\n",1.0*(bmp.info.height/2-y)/(bmp.info.width),val[y]);
   }
 
-  bmp_shutdown(&bmp);
+  free(val);
 
   return 1;
 }