From: hackbard Date: Thu, 9 Oct 2003 16:39:54 +0000 (+0000) Subject: add ati tiff to bmp conv tool X-Git-Tag: fpb~10 X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f52b9904f9433013ae0f1a5a059b0f20e66c5552;p=physik%2Fnlsop.git add ati tiff to bmp conv tool --- diff --git a/conv_fg_tif.c b/conv_fg_tif.c new file mode 100644 index 0000000..eb1205a --- /dev/null +++ b/conv_fg_tif.c @@ -0,0 +1,235 @@ +/* + * ati framegrabber tif to bmp converter ;) + * + * achtung: totaler muell code, der hoffentlich seinen zweck erfuellt + * fuer die netten tiff 16bit rgb bilder vom tem(?). + */ + +#include +#include +#include +#include +#include +#include +#include + +typedef struct s_pic_info { + int width; + int height; + int bps; + short bits[3]; /* max 3 values */ + int rps; /* rows per strip */ + int soc; /* strip offset counts */ + int sbc; /* strip byte counts */ + int *so; /* pointer to strip offsets */ + int *sb; /* pointer to the byte counts per strip */ +} t_pic_info; + +static inline void _short2int(short *dst, unsigned char *buf) { + *dst=(buf[1]<<8)|buf[0]; +} + +static inline void _word2int(int *dst, unsigned char *buf) { + *dst=(buf[3]<<24)|(buf[2]<<16)|(buf[1]<<8)|buf[0]; +} +#define short2int(a,b) _short2int(&a,b) +#define word2int(a,b) _word2int(&a,b) + +int parse_table(int fd,int offset,t_pic_info *pi) { + int i; + short de; + unsigned char buf[12]; /* 12 byte directory entry */ + + lseek(fd,offset,SEEK_SET); + read(fd,buf,2); + short2int(de,buf); + + printf("parsing %d tags\n",de); + + for(i=0;iwidth=vo; + printf("width: %d\n",vo); + break; + case 257: + pi->height=vo; + printf("height: %d\n",vo); + break; + case 258: + pi->bps=count; + if(count!=1) { + printf("warning, only converting 16 bit rgb files!"); + obuf=(unsigned char *)malloc(count*2); + lseek(fd,vo,SEEK_SET); + read(fd,obuf,2*count); + for(j=0;jbits[j],obuf+2*j); + free(obuf); + } + else pi->bits[0]=vo; + printf("bits per sample: %d %d %d\n",pi->bits[0],pi->bits[1],pi->bits[2]); + break; + case 259: + if(vo!=1) puts("warning, compressed file - i am going to do bullshit!"); + break; + case 262: + if(vo!=2) puts("warning, no rgb file - i am going to do bullshit!"); + break; + case 273: + pi->soc=count; + printf("%d strip offsets\n",count); + obuf=(unsigned char *)malloc(count*4); + pi->so=(int *)malloc(count*4); + lseek(fd,vo,SEEK_SET); + read(fd,obuf,count*4); + for(j=0;jso[j],obuf+4*j); + free(obuf); + break; + case 278: + pi->rps=vo; + printf("rows per strip: %d\n",vo); + break; + case 279: + pi->sbc=count; + printf("strip bytes: %d\n",count); + obuf=(unsigned char *)malloc(count*4); + pi->sb=(int *)malloc(count*4); + lseek(fd,vo,SEEK_SET); + read(fd,obuf,count*4); + for(j=0;jsb[j],obuf+4*j); + free(obuf); + break; + } + } + + return 1; +} + +int main(int argc,char **argv) { + int tfd,fd,i,tmp=0; + int offset,size; + unsigned char *buf; + unsigned char tbuf[4]; + t_pic_info pi; + /* for bmp */ + int foo,k,l,bmps; + unsigned char bbuf[128]; + short bla; + + puts(""); + puts("ati framegrabber tiff to bmp converter."); + puts(""); + puts("no compressed files!"); + puts("no 'big' or 'special' files! ;)"); + puts(""); + + memset(&pi,0,sizeof(t_pic_info)); + + fd=open(argv[1],O_RDONLY); + tfd=open(argv[2],O_WRONLY|O_CREAT); + + if((fd<0) || (tfd<0)) { + puts("error opening files ..."); + return -1; + } + + lseek(fd,0,SEEK_SET); + size=lseek(fd,0,SEEK_END); + lseek(fd,0,SEEK_SET); + + lseek(fd,4,SEEK_SET); + read(fd,tbuf,4); + word2int(offset,tbuf); + + printf("offset: %04x (%d)\n",offset,offset); + + /* we only need first table! */ + parse_table(fd,offset,&pi); + + printf("\n"); + 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("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); + for(i=0;i>8; + bbuf[10]=0x36; + bbuf[14]=0x28; + bbuf[18]=pi.width&0xff; + bbuf[19]=pi.width>>8; + bbuf[22]=pi.height&0xff; + bbuf[23]=pi.height>>8; + bbuf[26]=1; + bbuf[28]=24; + bbuf[34]=bmps&0xff; + bbuf[35]=bmps>>8; + bbuf[38]=0x12; + bbuf[39]=0x0b; + bbuf[42]=bbuf[38]; + bbuf[43]=bbuf[39]; + + write(tfd,bbuf,54); + for(k=0;k>10)<<3; + bbuf[1]=((bla>>5)&31)<<3; + bbuf[2]=(bla&31)<<3; + write(tfd,bbuf,3); + } + if(foo%4) { + memset(bbuf,0,4-foo%4); + write(tfd,bbuf,4-foo%4); + } + } + + printf("done!\n"); + printf("now go and kill ati!!!1\n"); + + close(fd); + close(tfd); + free(buf); + + return 1; +}