예제 #1
0
/* gdImageWBMPCtx
 *  --------------
 *  Write the image as a wbmp file
 *  Parameters are:
 *  image:  gd image structure;
 *  fg:     the index of the foreground color. any other value will be
 *          considered as background and will not be written
 *  out:    the stream where to write
 */
BGD_DECLARE(void) gdImageWBMPCtx(gdImagePtr image, int fg, gdIOCtx *out)
{
	int x, y, pos;
	Wbmp *wbmp;

	/* create the WBMP */
	if((wbmp = createwbmp(gdImageSX(image), gdImageSY(image), WBMP_WHITE)) == NULL) {
		fprintf(stderr, "Could not create WBMP\n");
		return;
	}

	/* fill up the WBMP structure */
	pos = 0;
	for(y = 0; y < gdImageSY(image); y++) {
		for(x = 0; x < gdImageSX(image); x++) {
			if(gdImageGetPixel(image, x, y) == fg) {
				wbmp->bitmap[pos] = WBMP_BLACK;
			}
			pos++;
		}
	}

	/* write the WBMP to a gd file descriptor */
	if(writewbmp(wbmp, &gd_putout, out)) {
		fprintf(stderr, "Could not save WBMP\n");
	}

	/* des submitted this bugfix: gdFree the memory. */
	freewbmp(wbmp);
}
예제 #2
0
/* 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);
	}
}