12 static png_struct *png_ptr;
13 static png_info *info_ptr;
18 png_uint_32 i_width, i_height;
19 int depth, color_type;
22 png_create_read_struct(PNG_LIBPNG_VER_STRING, &jbuf,
NULL,
NULL);
26 info_ptr = png_create_info_struct(png_ptr);
30 if (setjmp(png_jmpbuf(png_ptr)))
37 png_init_io(png_ptr, input);
39 png_read_info(png_ptr, info_ptr);
41 png_get_IHDR(png_ptr, info_ptr, &i_width, &i_height,
49 (
"PNG: input file has incorrect dimensions: expected: %dx%d got: %lux%lu",
50 width,
height, (
unsigned long) i_width, (
unsigned long) i_height);
53 if (color_type != PNG_COLOR_TYPE_RGB_ALPHA)
57 if (color_type != PNG_COLOR_TYPE_PALETTE)
65 png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans,
NULL);
67 if (num_trans != 1 || trans[0] != 0)
72 png_set_invert_alpha(png_ptr);
78 png_get_PLTE(png_ptr, info_ptr, &png_pal, &num_palette);
80 if (num_palette > 256)
83 for (i = 0; i < num_palette; i++) {
90 line = G_malloc(
width * 4);
95 png_read_row(png_ptr, q,
NULL);
98 for (x = 0; x <
width; x++, p++) {
108 for (x = 0; x <
width; x++, p++, q++)
114 png_read_end(png_ptr,
NULL);
116 png_destroy_read_struct(&png_ptr, &info_ptr,
NULL);