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;
57 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, &jbuf,
NULL,
NULL);
61 info_ptr = png_create_info_struct(png_ptr);
65 if (setjmp(png_jmpbuf(png_ptr)))
72 png_set_read_fn(png_ptr, input, read_data);
74 png_read_info(png_ptr, info_ptr);
76 png_get_IHDR(png_ptr, info_ptr, &i_width, &i_height, &depth, &color_type,
82 if (i_width != (
unsigned long)
png.
width ||
84 G_fatal_error(
_(
"Input PNG file has incorrect dimensions: expected: "
85 "%dx%d got: %lux%lu"),
87 (
unsigned long)i_height);
90 if (color_type != PNG_COLOR_TYPE_RGB_ALPHA)
94 if (color_type != PNG_COLOR_TYPE_PALETTE)
102 png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
NULL);
104 if (num_trans != 1 || trans[0] != 0)
109 png_set_invert_alpha(png_ptr);
115 png_get_PLTE(png_ptr, info_ptr, &png_pal, &num_palette);
117 if (num_palette > 256)
120 for (i = 0; i < num_palette; i++) {
132 png_read_row(png_ptr, q,
NULL);
151 png_read_end(png_ptr,
NULL);
153 png_destroy_read_struct(&png_ptr, &info_ptr,
NULL);
unsigned int png_get_color(int r, int g, int b, int a)
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
GRASS png display driver - header file.
unsigned char palette[256][4]