/* * TFT2TGA Copyright 2004 John Maushammer * * translates 280x240 image suitable for an LCD display into a .TGA format. * Both files are uncompressed. Quick & dirty - could be improved. * * http://www.maushammer.com/systems/dakotadigital/lcd.html */ #include main(int argc, char * argv[]) { FILE *fin, *fout; char filein[200], fileout[200]; int x,y,phase; unsigned char inbyte; unsigned char red, green, blue; unsigned char header[20]= {0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x01, 0xdc, 0x00, 0x18, 0x20, 0x00, 0x00}; unsigned char trailer[26]= {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x52, 0x55, 0x45, 0x56, 0x49, 0x53, 0x49, 0x4f, 0x4e, 0x2d, 0x58, 0x46, 0x49, 0x4c, 0x45, 0x2e, 0x00}; if(argc!=2) { printf("Usage: tft2tga filebasename\n\n"); exit(1); } sprintf(filein, "%s.TFT", argv[1]); sprintf(fileout, "%s.TGA", argv[1]); if(NULL==(fin=fopen(filein, "rb"))) { printf("unable to open input file '%s' for reading\n\n", filein); exit(1); } if(NULL==(fout=fopen(fileout, "wb"))) { printf("unable to open output file '%s' for writing\n\n", fileout); fclose(fin); exit(1); } /* write tga header */ for(x=0; x<20; x++) { fputc(header[x], fout); } /* File format is 280x220). Even lines RGB, odd lines GBR */ for(y=0; y<220; y++) { red = 0; green = 0; blue = 0; for(x=0; x<280; x++) { inbyte = fgetc(fin) * 4; /* 6 bit -> 8 bit scaling conversion */ phase=(x + (y & 1)) % 3; #if 0 /* draw with lcd artifacts: */ switch(phase) { case 0: fputc(inbyte, fout); fputc(0, fout); fputc(0, fout); break; /* Red */ case 1: fputc(0, fout); fputc(inbyte, fout); fputc(0, fout); break; /* Blue */ case 2: fputc(0, fout); fputc(0, fout); fputc(inbyte, fout); break; /* Green */ } #else /* attempt better picture (could still be improved, this alg. will bleed) */ switch(phase) { case 0: red = inbyte; break; case 1: blue = inbyte; break; case 2: green = inbyte; break; } fputc(red, fout); fputc(blue, fout); fputc(green, fout); #endif } } /* write tga trailer */ for(x=0; x<24; x++) { fputc(trailer[x], fout); } fclose(fin); fclose(fout); }