/* gdImageCreateFromWBMPCtx ** ------------------------ ** Create a gdImage from a WBMP file input from an gdIOCtx */ BGD_DECLARE(gdImagePtr) gdImageCreateFromWBMPCtx (gdIOCtx * infile) { /* FILE *wbmp_file; */ Wbmp *wbmp; gdImagePtr im = NULL; int black, white; int col, row, pos; if (readwbmp (&gd_getin, infile, &wbmp)) return (NULL); if (!(im = gdImageCreate (wbmp->width, wbmp->height))) { freewbmp (wbmp); return (NULL); } /* create the background color */ white = gdImageColorAllocate (im, 255, 255, 255); /* create foreground color */ black = gdImageColorAllocate (im, 0, 0, 0); /* fill in image (in a wbmp 1 = white/ 0 = black) */ pos = 0; for (row = 0; row < wbmp->height; row++) { for (col = 0; col < wbmp->width; col++) { if (wbmp->bitmap[pos++] == WBMP_WHITE) { gdImageSetPixel (im, col, row, white); } else { gdImageSetPixel (im, col, row, black); } } } freewbmp (wbmp); return (im); }
/* Main function * ------------- */ int main(int argc, char *argv[]) { FILE *wbmp_file; Wbmp *wbmp; wbmp_file = fopen(argv[1], "rb"); if(wbmp_file) { readwbmp(&getin, wbmp_file, &wbmp); #ifdef __VIEW #ifdef __DEBUG printf("\nVIEWING IMAGE\n"); #endif printwbmp(wbmp); #endif #ifdef __WRITE #ifdef __DEBUG printf("\nDUMPING WBMP to STDOUT\n"); #endif writewbmp(wbmp, &putout, stdout); #endif freewbmp(wbmp); fclose(wbmp_file); } }