/* tga2lbl.c tl1.bat = cl /AL tga2lbl.c getfile converts a '.tga' file to a '.lbl' ,'.pal', and '.dat' file */ #include #include #include "nomouse.h" #define MAX_COL 32768 int Mouse=0; struct hdr { int id_size; /* byte 0 */ int color_map; /* byte 1 (1 if PAL else 0) */ unsigned char image_type; /* byte 2 */ /* 0 -- no image data */ /* 1 -- Uncomp,color map */ /* 2 -- Uncomp,true color */ /* 3 -- Uncomp, B&W */ /* 9 -- Comprs,color map */ /* 10 -- Comprs,true color */ /* 11 -- Comprs, B&W */ int map_length; /* bytes 6 and 5 */ int bits_per_color; /* byte 7 */ int col; /* bytes 13 & 12 */ int row; /* bytes 15 & 14 */ int pixel_depth; /* byte 16 */ int first_pixel; /* byte 17 */ /* 0 -- Bottom Left */ /* 16 -- Bottom Right */ /* 32 -- Top Left */ /* 48 -- Top Right */ }; unsigned char Pal[256][3],Buffer[MAX_COL]; unsigned char Vga[16][3]= { { 0, 0, 0}, { 46, 46, 46}, { 128,128,128}, { 255,255,255}, { 105, 90, 75}, { 130,111, 93}, { 96, 28, 14}, { 255, 0, 0}, { 255,128, 0}, { 160,160, 0}, { 0,200, 0}, { 0,120, 0}, { 0, 72, 0}, { 0, 0,200}, { 0, 20, 60}, { 255, 0,255} }; int trans_header(unsigned char *dat,struct hdr *h); int print_hdr(struct hdr h); int make_pal(char *name,FILE *fptga,struct hdr h); int make_lbl(char *name,struct hdr h); int make_dat(char *name,FILE *fptga,struct hdr h); main() { int i,j,k; char name[100],string[100]; FILE *fptga,*fplbl,*fpdat; unsigned char header[18]; struct hdr h; if(get_file_name("*.tga",name,0)>=0) { printf("input = '%s'\n",name); fptga=fopen(name,"rb"); if(!fptga) { printf("Could not open '%s'\n",name); exit(0); } for(k=0;kMAX_COL) { printf("Image to wide\n\n"); exit(0); } printf(" of %d",h.row); for(i=0;i256) { printf("color map too long\n\n"); exit(0); } for(i=0;iid_size=dat[0]; h->color_map=dat[1]; h->image_type=dat[2]; h->map_length=(int)dat[6]*256+(int)dat[5]; h->bits_per_color=dat[7]; h->col=(int)dat[13]*256+(int)dat[12]; h->row=(int)dat[15]*256+(int)dat[14]; h->pixel_depth=dat[16]; h->first_pixel=dat[17]; }