--- tim2tga.c Thu Mar 18 20:44:06 1999 +++ raw2tga.c Sat May 13 11:48:53 2000 @@ -31,54 +31,45 @@ /* read/write buffer */ unsigned char buffer[2048]; -int load_tim(char *name) +int load_raw(char *name) { FILE *timfile; int rc=1; if ((timfile=fopen(name,"rb"))!=NULL) { char *p; - fread(&buffer,20,1,timfile); - /* All TIM-files I know begin with 0x10. If not, kill this line ! */ - if (buffer[0]==0x10) { - xsize=buffer[16]|(buffer[17]<<8); - ysize=buffer[18]|(buffer[19]<<8); - if ((xsize*2) < sizeof(buffer)) { - printf("size: %u x %u\n",xsize,ysize); - if ((p=scr=malloc(xsize*ysize*3))!=NULL) { - int x,y; - fseek(timfile,20,SEEK_SET); - for (y=0;y> 10) & 31; - g = (pixel >> 5) & 31; - r = (pixel ) & 31; + /* "b" needs "& 31" as well to strip 16th bit used for semi-transparency */ + b = (pixel >> 10) & 31; + g = (pixel >> 5) & 31; + r = (pixel ) & 31; - /* assuming TGA format is BGR */ - *p++ = b << 3; - *p++ = g << 3; - *p++ = r << 3; - } - } - } - } - else { - printf("error allocating memory !\n"); - rc=0; - } - } else { - printf("buffer too small to read a line !\n"); - rc=0; + /* assuming TGA format is BGR */ + *p++ = b << 3; + *p++ = g << 3; + *p++ = r << 3; + } + } + } + } + else { + printf("error allocating memory !\n"); + rc=0; } } else { - printf("unknown format !\n"); - rc=0; + printf("buffer too small to read a line !\n"); + rc=0; } fclose (timfile); } else { @@ -119,13 +110,16 @@ int main(int argc,char *argv[]) { - if (argc==3) { - if (load_tim(argv[1])) { + if (argc==5) { + xsize = atoi(argv[3]); + ysize = atoi(argv[4]); + if (load_raw(argv[1])) { if (save_tga(argv[2])) printf("done.\n"); free(scr); } } else - printf("TIM2TGA \n"); + printf("raw2tga \n"); return 0; } +