2 * ati framegrabber tif to bmp converter ;)
4 * achtung: totaler muell code, der hoffentlich seinen zweck erfuellt
5 * fuer die netten tiff 16bit rgb bilder vom tem(?).
16 typedef struct s_pic_info {
20 short bits[3]; /* max 3 values */
21 int rps; /* rows per strip */
22 int soc; /* strip offset counts */
23 int sbc; /* strip byte counts */
24 int *so; /* pointer to strip offsets */
25 int *sb; /* pointer to the byte counts per strip */
28 static inline void _short2int(short *dst, unsigned char *buf) {
29 *dst=(buf[1]<<8)|buf[0];
32 static inline void _word2int(int *dst, unsigned char *buf) {
33 *dst=(buf[3]<<24)|(buf[2]<<16)|(buf[1]<<8)|buf[0];
35 #define short2int(a,b) _short2int(&a,b)
36 #define word2int(a,b) _word2int(&a,b)
38 int parse_table(int fd,int offset,t_pic_info *pi) {
41 unsigned char buf[12]; /* 12 byte directory entry */
43 lseek(fd,offset,SEEK_SET);
47 printf("parsing %d tags\n",de);
57 lseek(fd,offset+2+i*12,SEEK_SET);
60 short2int(type,buf+2);
61 word2int(count,buf+4);
67 printf("width: %d\n",vo);
71 printf("height: %d\n",vo);
76 printf("warning, only converting 16 bit rgb files!");
77 obuf=(unsigned char *)malloc(count*2);
78 lseek(fd,vo,SEEK_SET);
79 read(fd,obuf,2*count);
80 for(j=0;j<count;j++) short2int(pi->bits[j],obuf+2*j);
84 printf("bits per sample: %d %d %d\n",pi->bits[0],pi->bits[1],pi->bits[2]);
87 if(vo!=1) puts("warning, compressed file - i am going to do bullshit!");
90 if(vo!=2) puts("warning, no rgb file - i am going to do bullshit!");
94 printf("%d strip offsets\n",count);
95 obuf=(unsigned char *)malloc(count*4);
96 pi->so=(int *)malloc(count*4);
97 lseek(fd,vo,SEEK_SET);
98 read(fd,obuf,count*4);
99 for(j=0;j<count;j++) word2int(pi->so[j],obuf+4*j);
104 printf("rows per strip: %d\n",vo);
108 printf("strip bytes: %d\n",count);
109 obuf=(unsigned char *)malloc(count*4);
110 pi->sb=(int *)malloc(count*4);
111 lseek(fd,vo,SEEK_SET);
112 read(fd,obuf,count*4);
113 for(j=0;j<count;j++) word2int(pi->sb[j],obuf+4*j);
122 int main(int argc,char **argv) {
126 unsigned char tbuf[4];
130 unsigned char bbuf[128];
135 puts("ati framegrabber tiff to bmp converter.");
137 puts("no compressed files!");
138 puts("no 'big' or 'special' files! ;)");
141 memset(&pi,0,sizeof(t_pic_info));
143 fd=open(argv[1],O_RDONLY);
144 tfd=open(argv[2],O_WRONLY|O_CREAT);
146 if((fd<0) || (tfd<0)) {
147 puts("error opening files ...");
151 lseek(fd,0,SEEK_SET);
152 size=lseek(fd,0,SEEK_END);
153 lseek(fd,0,SEEK_SET);
155 lseek(fd,4,SEEK_SET);
157 word2int(offset,tbuf);
159 printf("offset: %04x (%d)\n",offset,offset);
161 /* we only need first table! */
162 parse_table(fd,offset,&pi);
165 printf("let's see what we have:\n");
167 printf("we have %d strips, the offsets are:\n",pi.soc);
168 printf("1st: %04x, 2nd: %04x, ... last: %04x\n",
169 pi.so[0],pi.so[1],pi.so[pi.soc-1]);
170 printf("their lenght in bytes is:\n");
171 printf("1st: %d ... last: %d\n",pi.sb[0],pi.sb[pi.sbc-1]);
173 printf("checking ...\n");
174 printf("we have %d pixels, each has %d bytes => %d bytes\n",
175 pi.width*pi.height,pi.bps*pi.bits[0]/8,
176 pi.width*pi.height*pi.bps*pi.bits[0]/8);
177 for(i=0;i<pi.sbc;i++) tmp+=pi.sb[i];
178 printf("the tiff provides %d bytes! ok? :)\n",tmp);
181 printf("writing bmp file %s...",argv[2]);
184 bmps=(foo+(4-foo%4))*pi.height;
186 memset(bbuf,0,sizeof(bbuf));
187 bbuf[0]='B'; bbuf[1]='M';
188 bbuf[2]=(bmps+0x36)&0xff;
189 bbuf[3]=(bmps+0x36)>>8;
192 bbuf[18]=pi.width&0xff;
193 bbuf[19]=pi.width>>8;
194 bbuf[22]=pi.height&0xff;
195 bbuf[23]=pi.height>>8;
207 buf=(unsigned char *)malloc(pi.width*pi.height*pi.bits[0]/8);
209 for(k=0;k<pi.sbc;k++) {
210 lseek(fd,pi.so[k],SEEK_SET);
211 read(fd,buf+m,pi.sb[k]);
215 for(k=0;k<pi.height;k++) {
216 for(l=0;l<pi.width;l++) {
217 short2int(bla,buf+2*(pi.width*(pi.height-k-1)+l));
218 bbuf[0]=((bla>>10)&31)<<3; /* blau */
219 bbuf[1]=((bla>>5)&31)<<3; /* gelb */
220 bbuf[2]=(bla&31)<<3; /* rot */
224 memset(bbuf,0,4-foo%4);
225 write(tfd,bbuf,4-foo%4);
230 printf("now go and kill ati!!!1\n");