new runs
[physik/nlsop.git] / conv_fg_tif.c
index eb1205a..26fcdd7 100644 (file)
@@ -129,6 +129,7 @@ int main(int argc,char **argv) {
  int foo,k,l,bmps;
  unsigned char bbuf[128];
  short bla;
+ int m;
 
  puts("");
  puts("ati framegrabber tiff to bmp converter.");
@@ -164,22 +165,18 @@ int main(int argc,char **argv) {
  printf("let's see what we have:\n");
  puts("");
  printf("we have %d strips, the offsets are:\n",pi.soc);
- printf("1st: %04x, 2nd: %04x, ... last: %04x\n",pi.so[0],pi.so[1],pi.so[pi.soc-1]);
+ printf("1st: %04x, 2nd: %04x, ... last: %04x\n",
+       pi.so[0],pi.so[1],pi.so[pi.soc-1]);
  printf("their lenght in bytes is:\n");
  printf("1st: %d ... last: %d\n",pi.sb[0],pi.sb[pi.sbc-1]);
 
  printf("checking ...\n");
- printf("we have %d pixels, each has %d bytes => %d bytes\n",pi.width*pi.height,pi.bps*pi.bits[0]/8,pi.width*pi.height*pi.bps*pi.bits[0]/8);
+ printf("we have %d pixels, each has %d bytes => %d bytes\n",
+       pi.width*pi.height,pi.bps*pi.bits[0]/8,
+       pi.width*pi.height*pi.bps*pi.bits[0]/8);
  for(i=0;i<pi.sbc;i++) tmp+=pi.sb[i];
  printf("the tiff provides %d bytes! ok? :)\n",tmp);
 
- buf=(unsigned char *)malloc(size);
-
- if(buf==NULL) {
-  puts("error allocating memory ...");
-  return -1;
- }
-
  puts("");
  printf("writing bmp file %s...",argv[2]);
 
@@ -206,21 +203,26 @@ int main(int argc,char **argv) {
  bbuf[43]=bbuf[39];
  
  write(tfd,bbuf,54);
+
+ buf=(unsigned char *)malloc(pi.width*pi.height*pi.bits[0]/8);
+ m=0;
+ for(k=0;k<pi.sbc;k++) {
+  lseek(fd,pi.so[k],SEEK_SET);
+  read(fd,buf+m,pi.sb[k]);
+  m+=pi.sb[k];
+ }
+
  for(k=0;k<pi.height;k++) {
   for(l=0;l<pi.width;l++) {
-   /* read rgb value (16bit) */
-   lseek(fd,pi.so[k/pi.rps]+2*l+2*(k%pi.rps)*pi.width,SEEK_SET);
-   read(fd,tbuf,pi.bits[0]/8);
-   short2int(bla,tbuf);
-   // bla=(tbuf[0]<<8)|tbuf[1];
-   bbuf[0]=(bla>>10)<<3;
-   bbuf[1]=((bla>>5)&31)<<3;
-   bbuf[2]=(bla&31)<<3;
+   short2int(bla,buf+2*(pi.width*(pi.height-k-1)+l));
+   bbuf[0]=((bla>>10)&31)<<3; /* blau */
+   bbuf[1]=((bla>>5)&31)<<3; /* gelb */
+   bbuf[2]=(bla&31)<<3; /* rot */
    write(tfd,bbuf,3);
   }
   if(foo%4) {
    memset(bbuf,0,4-foo%4);
-   write(tfd,bbuf,4-foo%4);
+   write(tfd,bbuf,4-foo%4);  
   }
  }