9 static void write_data(png_structp png_ptr, png_bytep
data, png_size_t length)
17 fp = (FILE *) png_get_io_ptr(png_ptr);
21 check = fwrite(data, 1, length, fp);
27 static void output_flush(png_structp png_ptr)
34 fp = (FILE *) png_get_io_ptr(png_ptr);
44 static png_struct *png_ptr;
45 static png_info *info_ptr;
54 png_create_write_struct(PNG_LIBPNG_VER_STRING, &jbuf,
NULL,
NULL);
58 info_ptr = png_create_info_struct(png_ptr);
62 if (setjmp(png_jmpbuf(png_ptr)))
69 png_set_write_fn(png_ptr, output, write_data, output_flush);
71 png_set_IHDR(png_ptr, info_ptr,
74 PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
75 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
78 png_set_invert_alpha(png_ptr);
80 png_color png_pal[256];
83 for (i = 0; i < 256; i++) {
89 png_set_PLTE(png_ptr, info_ptr, png_pal, 256);
92 png_byte
trans = (png_byte) 0;
94 png_set_tRNS(png_ptr, info_ptr, &trans, 1,
NULL);
98 str =
getenv(
"GRASS_PNG_COMPRESSION");
99 if (str && sscanf(str,
"%d", &compress) == 1)
100 png_set_compression_level(png_ptr, compress);
102 png_write_info(png_ptr, info_ptr);
104 line = G_malloc(
width * 4);
110 for (x = 0; x <
width; x++, p++) {
121 for (x = 0; x <
width; x++, p++, q++)
124 png_write_row(png_ptr, line);
129 png_write_end(png_ptr, info_ptr);
131 png_destroy_write_struct(&png_ptr, &info_ptr);
void G_free(void *buf)
Free allocated memory.
void get_pixel(unsigned int pixel, int *r, int *g, int *b, int *a)
unsigned char png_palette[256][4]
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void output(const char *fmt,...)