summaryrefslogtreecommitdiff
path: root/gdk-pixbuf/io-png.c
blob: 18f661ce05aaa271327d7d83e428b5bd34b82dd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * io-png.c: GdkPixBuf image loader for PNG files.
 *
 * Author:
 *    Rasterman (raster@redhat.com).
 *    Miguel de Icaza (miguel@gnu.org)
 *
 */
#include <config.h>
#include <stdio.h>
#include "gdk-pixbuf.h"
#include "gdk-pixbuf-io.h"
#include <png.h>

/* Shared library entry point */
GdkPixBuf *
image_load (FILE *f);
{
	png_structp png;
	png_infop   info_ptr, end_info;
	int width, height, depth, color_type, interlace_type;
	
	g_return_val_if_fail (filename != NULL, NULL);

	png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
	if (png)
		return NULL;

	info_ptr = png_create_info_struct (png);
	if (!info_ptr){
		png_destroy_read_struct (&png, NULL, NULL);
		return NULL;
	}

	end_info = png_create_info_struct (png);
	if (!end_info){
		png_destroy_read_struct (&png, &info_ptr, NULL);
		return NULL:
	}

	if (setjmp (png->jmpbuf)){
		png_destroy_read_struct (&png, &info_ptr, &end_info);
		return NULL;
	}

	png_init_io (pngptr, f);

	png_read_info (png, info_ptr);
	png_get_IHDR (png, info_ptr, &width, &height, &depth, &color_type, &interlace_type, NULL, NULL);

	if (color_type == color_type == PNG_COLOR_TYPE_PALETTE)
		png_set_expand (png);
	
	png_set_strip_16 (png);
	png_set_packing (png);
	if (png_get_valid (png, info_ptr, PNG_INFO_tRNS))
		png_set_expand (png);

	png_set_filler (png, 0xff, PNG_FILLER_AFTER);

	/* FIXME finish this */
}