static void gif_setup(FILE *s) { int i; int rtn; BYTE cmap[3][256]; if (num_colors > 256) fatal("number of colors must be <= 256 with GIF output"); dither_setup(num_colors); dith = (u16or32 *) malloc((unsigned) sizeof(u16or32) * wdth); assert(dith != NULL); for (i=0; i<dither_ncolors; i++) { cmap[0][i] = dither_colormap[i*3+0]; cmap[1][i] = dither_colormap[i*3+1]; cmap[2][i] = dither_colormap[i*3+2]; } rtn = gifout_open_file(s, wdth, hght, dither_ncolors, cmap, 0); assert(rtn == GIFLIB_SUCCESS); rtn = gifout_open_image(0, 0, wdth, hght); assert(rtn == GIFLIB_SUCCESS); }
static void bmp_setup() { int i; struct BITMAPFILEHEADER bmf; struct BITMAPINFOHEADER bmi; dither_setup(num_colors); dith = (u16or32 *) malloc((unsigned) sizeof(u16or32) * wdth); assert(dith != NULL); assert(sizeof(struct BITMAPFILEHEADER) == 14); assert(sizeof(struct BITMAPINFOHEADER) == 40); bmf.bfType[0] = 'B'; bmf.bfType[1] = 'M'; bmf.bfSize = sizeof(struct BITMAPFILEHEADER) + sizeof(struct BITMAPINFOHEADER) + num_colors * sizeof(struct RGBQUAD) + hght * 4 * ((wdth + 3) / 4); bmf.bfReserved1 = 0; bmf.bfReserved2 = 0; bmf.bfOffBits = sizeof(struct BITMAPFILEHEADER) + sizeof(struct BITMAPINFOHEADER) + num_colors * sizeof(struct RGBQUAD); fwrite(&bmf, 1, sizeof(bmf), stdout); bmi.biSize = sizeof(bmi); bmi.biWidth = wdth; bmi.biHeight = -hght; bmi.biPlanes = 1; bmi.biBitCount = 8; bmi.biCompression = BI_RGB; bmi.biSizeImage = hght * 4 * ((wdth + 3) / 4); bmi.biXPelsPerMeter = 0; bmi.biYPelsPerMeter = 0; bmi.biClrUsed = num_colors; bmi.biClrImportant = num_colors; fwrite(&bmi, 1, sizeof(bmi), stdout); for (i=0; i<dither_ncolors; i++) { struct RGBQUAD rgb; rgb.rgbBlue = dither_colormap[i*3+2]; rgb.rgbGreen = dither_colormap[i*3+1]; rgb.rgbRed = dither_colormap[i*3+0]; rgb.rgbReserved = 0; fwrite(&rgb, 1, sizeof(rgb), stdout); } }
static void png_setup () { int i; img = gdImageCreate (wdth, hght); dither_setup (num_colors); dith = (u16or32 *) malloc ((unsigned) sizeof (u16or32) * wdth); assert (dith != NULL); for (i = 0; i < dither_ncolors; i++) { colors[i] = gdImageColorAllocate (img, dither_colormap[i * 3 + 0], dither_colormap[i * 3 + 1], dither_colormap[i * 3 + 2]); } y = 0; }