/* * 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, b; unsigned char red, green, blue; unsigned char header[20]= {0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*width:*/ 0x08, 0x00, /* height 3072: */ 0x00, 0x0c, 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<18; x++) { fputc(header[x], fout); } /* File format is 280x220). Even lines RGB, odd lines GBR */ for(y=0; y<0xC00; y++) { inbyte = fgetc(fin); if((y & 0xf) == 0) { printf("\n== CHAR %02x ==\n", y / 16); } for(b=0x80; b; b = b >> 1) { printf((inbyte & b) ? "#" : "."); fputc((inbyte & b) ? 0 : 0xff, fout); /* inverse, just 'cus it looks better */ fputc((inbyte & b) ? 0 : 0xff, fout); /* in mac preview */ fputc((inbyte & b) ? 0 : 0xff, fout); } printf("\n"); } /* write tga trailer */ for(x=0; x<24; x++) { fputc(trailer[x], fout); } fclose(fout); /* now translate the text... */ for(; y<0x2000; y++) { fgetc(fin); } for(; y<0x28A0; y++) { if((y & 0x0f) == 0) { printf("\n%04x: ", y); } inbyte = fgetc(fin) - 0x26 + 'A'; printf("%c", isprint(inbyte) ? inbyte : '.'); } fclose(fin); }