23 static void read_data(png_structp png_ptr, png_bytep data, png_size_t length)
31 fp = (FILE *) png_get_io_ptr(png_ptr);
39 check = fread(data, 1, length, fp);
48 static png_struct *png_ptr;
49 static png_info *info_ptr;
54 png_uint_32 i_width, i_height;
55 int depth, color_type;
58 png_create_read_struct(PNG_LIBPNG_VER_STRING, &jbuf,
NULL,
NULL);
62 info_ptr = png_create_info_struct(png_ptr);
66 if (setjmp(png_jmpbuf(png_ptr)))
73 png_set_read_fn(png_ptr, input, read_data);
75 png_read_info(png_ptr, info_ptr);
77 png_get_IHDR(png_ptr, info_ptr, &i_width, &i_height,
85 (
_(
"Input PNG file has incorrect dimensions: expected: %dx%d got: %lux%lu"),
89 if (color_type != PNG_COLOR_TYPE_RGB_ALPHA)
93 if (color_type != PNG_COLOR_TYPE_PALETTE)
101 png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
NULL);
103 if (num_trans != 1 || trans[0] != 0)
108 png_set_invert_alpha(png_ptr);
114 png_get_PLTE(png_ptr, info_ptr, &png_pal, &num_palette);
116 if (num_palette > 256)
119 for (i = 0; i < num_palette; i++) {
131 png_read_row(png_ptr, q,
NULL);
134 for (x = 0; x <
png.
width; x++, p++) {
144 for (x = 0; x <
png.
width; x++, p++, q++)
150 png_read_end(png_ptr,
NULL);
152 png_destroy_read_struct(&png_ptr, &info_ptr,
NULL);
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
GRASS png display driver - header file.
unsigned char palette[256][4]
void G_free(void *)
Free allocated memory.
unsigned int png_get_color(int r, int g, int b, int a)