/*------------------------------------------------------------*/ void eps_finish_output (void) { int byte_count = output_width * components; int row, pos, slot; GLenum format; unsigned char *buffer; char *pix; format = (components == 1) ? GL_LUMINANCE : GL_RGB; image_render(); buffer = malloc (byte_count * sizeof (unsigned char)); for (row = 0; row < output_height; row++) { glReadPixels (0, row, output_width, 1, format, GL_UNSIGNED_BYTE, buffer); pos = 0; pix = (char *) buffer; for (slot = 0; slot < byte_count; slot++) { fprintf (outfile, "%02hx", *pix++); if (++pos >= 32) { fprintf (outfile, "\n"); pos = 0; } } if (pos) fprintf (outfile, "\n"); } free (buffer); PRINT ("%%EndData\n"); PRINT ("grestore\n"); PRINT ("end\n"); image_close(); }
void image_show(image_t *image) { image_render(image); image->layer->show = TRUE; register_update_for_layer(image->layer); }
/*------------------------------------------------------------*/ void gifi_finish_output (void) { int row, col, value, r, g, b, error, right, leftbelow, below; unsigned char *buffer, *buf; int *rcurr, *gcurr, *bcurr, *rnext, *gnext, *bnext, *swap; image_render(); buffer = malloc (output_width * 3 * sizeof (unsigned char)); rcurr = malloc ((output_width + 1) * sizeof (int)); gcurr = malloc ((output_width + 1) * sizeof (int)); bcurr = malloc ((output_width + 1) * sizeof (int)); rnext = calloc (output_width + 1, sizeof (int)); gnext = calloc (output_width + 1, sizeof (int)); bnext = calloc (output_width + 1, sizeof (int)); for (row = 0; row < output_height; row++) { swap = rnext; rnext = rcurr; rcurr = swap; swap = gnext; gnext = gcurr; gcurr = swap; swap = bnext; bnext = bcurr; bcurr = swap; for (col = 0; col < output_width; col++) { rnext[col] = 0; gnext[col] = 0; bnext[col] = 0; } glReadPixels (0, output_height - row - 1, output_width, 1, GL_RGB, GL_UNSIGNED_BYTE, buffer); buf = buffer; for (col = 0; col < output_width; col++) { rcurr[col] += *buf++; gcurr[col] += *buf++; bcurr[col] += *buf++; } for (col = 0; col < output_width; col++) { /* error diffusion */ value = rcurr[col]; for (r = 0; 51 * (r + 1) - 26 < value; r++); error = value - r * 51; right = (7 * error) / 16; leftbelow = (3 * error) / 16; below = (5 * error) / 16; rcurr[col+1] += right; if (col > 0) rnext[col-1] += leftbelow; rnext[col] += below; rnext[col+1] = error - right - leftbelow - below; value = gcurr[col]; for (g = 0; 51 * (g + 1) - 26 < value; g++); error = value - g * 51; right = (7 * error) / 16; leftbelow = (3 * error) / 16; below = (5 * error) / 16; gcurr[col+1] += right; if (col > 0) gnext[col-1] += leftbelow; gnext[col] += below; gnext[col+1] = error - right - leftbelow - below; value = bcurr[col]; for (b = 0; 51 * (b + 1) - 26 < value; b++); error = value - b * 51; right = (7 * error) / 16; leftbelow = (3 * error) / 16; below = (5 * error) / 16; bcurr[col+1] += right; if (col > 0) bnext[col-1] += leftbelow; bnext[col] += below; bnext[col+1] = error - right - leftbelow - below; gdImageSetPixel (image, col, row, ((r * 6) + g) * 6 + b); } } free (rnext); free (gnext); free (bnext); free (rcurr); free (gcurr); free (bcurr); free (buffer); gdImageGif (image, outfile); gdImageDestroy (image); image_close(); }