#include #include #include void write_pnm(image_ptr ptr, char *filename, int rows, int cols, int magic_number); main(int argc, char *argv[]) { int row, byte; int length, i; FILE *fp; unsigned char data; char type; image_ptr buffer; unsigned int index; if(argc != 3) { printf("usage: mac2pbm \n"); exit(1); } if(!(fp = fopen(argv[1], "rb"))) { printf("Can't open %s",argv[1]); exit(1); } buffer = (image_ptr) IP_MALLOC(51840); /* storage for a 576x720 image */ if(buffer == (image_ptr) NULL) { printf("Can't malloc enough memory for conversion \n"); exit(1); } fseek(fp, 512, 0); /* skip file header */ row = 0; index = 0; while(row<720) { byte = 1; while(byte < 73) { type = fgetc(fp); if(type & 0x80) /* check if MSB is set */ { /* Run-Length encoded data */ data = fgetc(fp); length = -1*type+1; /* compute number of repeating bytes */ for(i=0; i