b3fd6d28ad3fe21edc692246351107a339c9b1b3
1 /*****************************************************************************
2 * RRDtool 1.2.10 Copyright by Tobi Oetiker, 1997-2005
3 *****************************************************************************
4 * pngsize.c determine the size of a PNG image
5 *****************************************************************************/
7 #include <png.h>
8 #include "rrd_tool.h"
10 int
11 PngSize(FILE *fd, long *width, long *height)
12 {
13 png_structp png_read_ptr =
14 png_create_read_struct(PNG_LIBPNG_VER_STRING,
15 (png_voidp)NULL,
16 /* we would need to point to error handlers
17 here to do it properly */
18 (png_error_ptr)NULL, (png_error_ptr)NULL);
20 png_infop info_ptr = png_create_info_struct(png_read_ptr);
22 (*width)=0;
23 (*height)=0;
25 /* this is to make compile on aix work since they seem to define jmpbuf
26 to be _jmpbuf which breaks compilation */
28 #ifdef jmpbuf
29 #undef jmpbuf
30 #endif
32 if (setjmp(png_read_ptr->jmpbuf)){
33 png_destroy_read_struct(&png_read_ptr, &info_ptr, (png_infopp)NULL);
34 return 0;
35 }
37 png_init_io(png_read_ptr,fd);
38 png_read_info(png_read_ptr, info_ptr);
39 (*width)=png_get_image_width(png_read_ptr, info_ptr);
40 (*height)=png_get_image_height(png_read_ptr, info_ptr);
42 png_destroy_read_struct(&png_read_ptr, &info_ptr, NULL);
43 if (*width >0 && *height >0)
44 return 1;
45 else
46 return 0;
47 }