undef jmpbuf to make compile work on AIX 5.1
[rrdtool.git] / src / pngsize.c
1 /*****************************************************************************
2  * RRDtool 1.2.0  Copyright by Tobi Oetiker, 1997-2005
3  *****************************************************************************
4  * pngsize.c  determine the size of a PNG image
5  *****************************************************************************/
6
7 #include <png.h>
8 #include "rrd_tool.h"
9
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);
19     
20   png_infop info_ptr = png_create_info_struct(png_read_ptr);
21
22   (*width)=0;
23   (*height)=0;
24
25 /* this is to make compile on aix work since they seem to define jmpbuf
26    to be _jmpbuf which breaks compilation */
27
28 #ifdef jmpbuf
29 #undef jmpbuf
30 #endif
31
32   if (setjmp(png_read_ptr->jmpbuf)){
33     png_destroy_read_struct(&png_read_ptr, &info_ptr, (png_infopp)NULL);
34     return 0;
35   }
36
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);
41   
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 }
48
49
50