9 static void read_data(png_structp png_ptr, png_bytep
data, png_size_t length)
17 fp = (FILE *) png_get_io_ptr(png_ptr);
25 check = fread(data, 1, length, fp);
34 static png_struct *png_ptr;
35 static png_info *info_ptr;
40 png_uint_32 i_width, i_height;
41 int depth, color_type;
44 png_create_read_struct(PNG_LIBPNG_VER_STRING, &jbuf,
NULL,
NULL);
48 info_ptr = png_create_info_struct(png_ptr);
52 if (setjmp(png_jmpbuf(png_ptr)))
59 png_set_read_fn(png_ptr, input, read_data);
61 png_read_info(png_ptr, info_ptr);
63 png_get_IHDR(png_ptr, info_ptr, &i_width, &i_height,
71 (
"PNG: input file has incorrect dimensions: expected: %dx%d got: %lux%lu",
72 width,
height, (
unsigned long) i_width, (
unsigned long) i_height);
75 if (color_type != PNG_COLOR_TYPE_RGB_ALPHA)
79 if (color_type != PNG_COLOR_TYPE_PALETTE)
87 png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
NULL);
89 if (num_trans != 1 || trans[0] != 0)
94 png_set_invert_alpha(png_ptr);
100 png_get_PLTE(png_ptr, info_ptr, &png_pal, &num_palette);
102 if (num_palette > 256)
105 for (i = 0; i < num_palette; i++) {
112 line = G_malloc(
width * 4);
117 png_read_row(png_ptr, q,
NULL);
120 for (x = 0; x <
width; x++, p++) {
130 for (x = 0; x <
width; x++, p++, q++)
136 png_read_end(png_ptr,
NULL);
138 png_destroy_read_struct(&png_ptr, &info_ptr,
NULL);
void G_free(void *buf)
Free allocated memory.
unsigned char png_palette[256][4]
unsigned int get_color(int r, int g, int b, int a)
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.