/* expand_mask.c -- read a world 2' imgfile bitmask and reverse all the bits. Looks like I got the slmask backwards, initially. WHFS 24 Apr 97 */ #include #include #define MASKSIZE 8553600 #define OUTSIZE 68428800 unsigned char maskset[8] = { 128, 64, 32, 16, 8, 4, 2, 1}; unsigned char a[MASKSIZE]; unsigned char b[OUTSIZE]; main(argc, argv) int argc; char **argv; { FILE *fp; int i; if (argc != 3 || (fp = fopen(argv[1], "r")) == NULL) { fprintf(stderr,"usage: expand_mask \n"); if (argc > 1) fprintf(stderr,"expand_mask: ERROR. Cannot open r %s\n", argv[1]); exit(-1); } if ((fread(a, 1, MASKSIZE, fp)) != MASKSIZE) { fprintf(stderr,"expand_mask: ERROR during read of %s\n", argv[1]); exit(-1); } fclose(fp); for (i = 0; i < OUTSIZE; i++) { b[i] = 0; if((a[i/8] & maskset[i%8]) > 0) b[i] = 1; } if ( (fp = fopen(argv[2], "w")) == NULL) { fprintf(stderr,"expand_mask: ERROR. Cannot open w %s\n", argv[2]); exit(-1); } if ((fwrite(b, 1, OUTSIZE, fp)) != OUTSIZE) { fprintf(stderr,"expand_mask: ERROR during write of %s\n", argv[2]); exit(-1); } fclose(fp); exit(0); }