#include "stdio.h" #include "stdlib.h" #define SWAP(x) ( ((x) << 24) | \ (((x) << 8) & 0x00ff0000) | \ (((x) >> 8) & 0x0000ff00) | \ ((x) >> 24) ) #define FIX(x) (*(unsigned *)&(x) = \ SWAP(*(unsigned *)&(x))) /* Turn the AVS X file into tga Write to stdout, so "normal" usage will be x2tga bla.x > bla.tga Note that this code doesn't buffer the data so the image will appear in the same orientation as the X file, that is, top to bottom, left to right. */ void BM_WriteHexString(FILE *,char *); int main(int argc,char **argv) { int i,j; int a,r,g,b; FILE *fptr; int width,height; /* Assumes 4 byte ints */ if (argc < 2) { fprintf(stderr,"Usage: %s xfilename\n",argv[0]); exit(-1); } /* Attempt to open the file */ if ((fptr = fopen(argv[1],"r")) == NULL) { fprintf(stderr,"Failed to open input file \"%s\"\n",argv[1]); exit(-1); } /* Read the header */ fread(&width,sizeof(int),1,fptr); width = FIX(width); fprintf(stderr,"Width: %d\n",width); fread(&height,sizeof(int),1,fptr); height = FIX(height); fprintf(stderr,"Height: %d\n",height); /* Write the TGA header */ BM_WriteHexString(stdout,"000002"); /* uncompressed RGB */ BM_WriteHexString(stdout,"0000000000"); BM_WriteHexString(stdout,"00000000"); /* X and Y origin */ putc((width & 0x00ff),stdout); /* X width */ putc((width & 0xff00) / 256,stdout); putc((height & 0x00ff),stdout); /* Y width */ putc((height & 0xff00) / 256,stdout); BM_WriteHexString(stdout,"1800"); /* 24 bit bitmap */ /* Read the ARGB for each pixel */ for (j=0;j