2 * io-png.c: GdkPixBuf image loader for PNG files.
5 * Miguel de Icaza (miguel@gnu.org)
10 #include "gdk-pixbuf.h"
11 #include "gdk-pixbuf-io.h"
14 /* Shared library entry point */
19 png_infop info_ptr, end_info;
20 int width, height, depth, color_type, interlace_type;
21 int have_alpha, number_passes;
24 g_return_val_if_fail (filename != NULL, NULL);
26 png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
30 info_ptr = png_create_info_struct (png);
32 png_destroy_read_struct (&png, NULL, NULL);
36 end_info = png_create_info_struct (png);
38 png_destroy_read_struct (&png, &info_ptr, NULL);
42 if (setjmp (png->jmpbuf)){
43 png_destroy_read_struct (&png, &info_ptr, &end_info);
47 png_init_io (pngptr, f);
49 png_read_info (png, info_ptr);
50 png_get_IHDR (png, info_ptr, &width, &height, &depth, &color_type, &interlace_type, NULL, NULL);
52 if (color_type == color_type == PNG_COLOR_TYPE_PALETTE)
56 * Strip 16 bit information to 8 bit
58 png_set_strip_16 (png);
61 * Extract multiple pixels with bit depths 1, 2 and 4 from a single
62 * byte into separate bytes
64 png_set_packing (png);
67 * Makes the PNG file to be rendered into RGB or RGBA
68 * modes (no matter of the bit depth nor the image
74 * Simplify loading by always having 4 bytes
76 png_set_filler (png, 0xff, PNG_FILLER_AFTER);
78 if (color_type & PNG_COLOR_MASK_ALPHA)
83 data = art_alloc (width * height * (3 + have_alpha));
85 png_destroy_read_struct (&png, &info_ptr, &end_info);
89 number_passes = png_set_interlace_handling (png);