// CSE 373 // University of Washington // Routines for manipulating bitmap files // Homework 5 // May 2000 #include #include "bmp.h" //#include //using namespace std; void out(FILE *f, unsigned char *pch) { fputc(*pch, f); } void out2(FILE *f, unsigned char *pch) { out(f, pch++); out(f, pch); } void out3(FILE *f, unsigned char *pch) { out(f, pch++); out2(f, pch); } void out4(FILE *f, unsigned char *pch) { out2(f, pch); pch+=2; out2(f, pch); } // read in bitmap data and echo header info to output file f // reads from standard input // f should be an already-opened output file, e.g. "out.bmp" // pixels should be a 256x256 array to work with the sample files void readbmp(FILE *f, RGBQUAD palette[palsize], unsigned char pixels[rows][cols]) { BITMAPFILEHEADER bmfh; BITMAPINFO bmi; int i; unsigned char *pch; // read in BITMAPFILEHEADER structure from file pch = (unsigned char *)&bmfh; scanf("%2c", pch); out2(f, pch); pch+=2; // just read 2 chars pch+=2; // skip 2 bytes of padding; may need to comment out this line for (i=0; i<12; i++) { scanf("%c", pch); out(f, pch++); } // read in BITMAPINFO structure pch = (unsigned char *)&bmi; for (i=0; i