/* Pro2BMP.c - converts Amiga 3-D Professional RGB files to 24-bit Microsoft Windows 3.0 format - djh */ #include #include #define PROIDLEN 9 #define STD_METHOD 1 #define RGBSIZE 3 /* Aztec pads sizeof(rgb) to 4! */ typedef struct { /*char identifier[9];*/ short width,height,vxoff,vyoff, vwidth,vheight; long dflags,method; } ProRGBHeader; typedef struct { unsigned char r,g,b; } rgb; #define BM 0x4D42 typedef struct { unsigned char b,g,r; } w_rgb; typedef struct { /*short bfType; avoid SPARC alignment problems - deal separately! */ long bfSize; short bfReserved1,bfReserved2; long bfOffBits; } BITMAPFILEHEADER; typedef struct { long biSize,biWidth,biHeight; short biPlanes,biBitCount; long biCompression,biSizeImage, biXPelsPerMeter,biYPelsPerMeter, biClrUsed,biClrImportant; } BITMAPINFOHEADER; SafeRead(fp,buf,len) FILE *fp; char *buf; int len; { if (fread(buf,1,len,fp)!=len) { puts("\nError while reading file.\n"); return(TRUE); } return(FALSE); } SafeWrite(fp,buf,len) FILE *fp; char *buf; int len; { if (fwrite(buf,1,len,fp)!=len) { puts("\nError while writing file.\n"); return(TRUE); } return(FALSE); } Swap4(arg) int arg; { return ( ((arg&0xFF000000) >> 24) | ((arg&0x00FF0000) >> 8) | ((arg&0x0000FF00) << 8) | ((arg&0x000000FF) << 24)); } Swap2(arg) int arg; { return ( ((arg&0xFF00) >> 8) | ((arg&0x00FF) << 8)); } unsigned char main(argc,argv) int argc; char *argv[]; { static char pro_id[PROIDLEN+1]; ProRGBHeader pro_hdr; static BITMAPFILEHEADER bm; static BITMAPINFOHEADER bi; UBYTE *buf=NULL,*tmp; rgb *switch_p,color; w_rgb *switch_b; int i,j,linesize,bufsize; unsigned short word; FILE *fp=NULL; puts("Pro2BMP: 3-D Professional to Windows converter - djh\n"); if (argc<3) { puts("Usage: Pro2BMP "); goto cleanup; } if (!(fp=fopen(argv[1],"r"))) { printf("Error: couldn't open ProRGB file %s for reading.\n",argv[1]); goto cleanup; } if (SafeRead(fp,pro_id,PROIDLEN)) goto cleanup; if (SafeRead(fp,&pro_hdr,sizeof(pro_hdr))) goto cleanup; if (pro_hdr.method!=STD_METHOD) { printf("\nError: storage method %d not recognized!\n",pro_hdr.method); goto cleanup; } printf("Converting [Width=%d,Height=%d]... ",pro_hdr.width,pro_hdr.height); linesize=pro_hdr.width*RGBSIZE; bufsize=linesize*pro_hdr.height; tmp=buf=AllocMem(bufsize,MEMF_CHIP|MEMF_CLEAR); for (i=0;ir=color.r; switch_b->g=color.g; switch_b->b=color.b; switch_b++; } if (SafeWrite(fp,tmp,linesize)) goto cleanup; } puts("Done."); cleanup: if (buf) FreeMem(buf,bufsize); if (fp) fclose(fp); }