X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Fpngsize.c;h=b8dc35ba67146cd207c752397ca5595dcee75917;hp=e60b6fab0f9f8075b86d02cb2cb04b173e7473c8;hb=2a9b0ff9cf29cf82b7b12ea80889c59273d66008;hpb=0c87c2676bb826f8defb40d7d45e771ecd40550c diff --git a/src/pngsize.c b/src/pngsize.c index e60b6fa..b8dc35b 100644 --- a/src/pngsize.c +++ b/src/pngsize.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.1.x Copyright Tobias Oetiker, 1997 - 2002 + * RRDtool 1.4.2 Copyright by Tobi Oetiker, 1997-2009 ***************************************************************************** * pngsize.c determine the size of a PNG image *****************************************************************************/ @@ -7,37 +7,50 @@ #include #include "rrd_tool.h" -int -PngSize(FILE *fd, long *width, long *height) +int PngSize( + FILE * fd, + long *width, + long *height) { - png_structp png_read_ptr = - png_create_read_struct(PNG_LIBPNG_VER_STRING, - (png_voidp)NULL, - /* we would need to point to error handlers - here to do it properly */ - (png_error_ptr)NULL, (png_error_ptr)NULL); - - png_infop info_ptr = png_create_info_struct(png_read_ptr); - - (*width)=0; - (*height)=0; - - if (setjmp(png_read_ptr->jmpbuf)){ - png_destroy_read_struct(&png_read_ptr, &info_ptr, (png_infopp)NULL); - return 0; - } - - png_init_io(png_read_ptr,fd); - png_read_info(png_read_ptr, info_ptr); - (*width)=png_get_image_width(png_read_ptr, info_ptr); - (*height)=png_get_image_height(png_read_ptr, info_ptr); - - png_destroy_read_struct(&png_read_ptr, &info_ptr, NULL); - if (*width >0 && *height >0) - return 1; - else - return 0; + png_structp png_read_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, + (png_voidp) NULL, + /* we would need to point to error handlers + here to do it properly */ + (png_error_ptr) NULL, + (png_error_ptr) NULL); + + png_infop info_ptr = png_create_info_struct(png_read_ptr); + + (*width) = 0; + (*height) = 0; + +/* this is to make compile on aix work since they seem to define jmpbuf + to be _jmpbuf which breaks compilation */ + +#ifndef png_jmpbuf +#ifdef PNG_SETJMP_SUPPORTED +# define png_jmpbuf(png_ptr) ((png_ptr)->PNG_jmpbuf) +#else +#ifdef jmpbuf +#undef jmpbuf +#endif +# define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf) +#endif +#endif + + if (setjmp(png_jmpbuf(png_read_ptr))) { + png_destroy_read_struct(&png_read_ptr, &info_ptr, (png_infopp) NULL); + return 0; + } + + png_init_io(png_read_ptr, fd); + png_read_info(png_read_ptr, info_ptr); + (*width) = png_get_image_width(png_read_ptr, info_ptr); + (*height) = png_get_image_height(png_read_ptr, info_ptr); + + png_destroy_read_struct(&png_read_ptr, &info_ptr, NULL); + if (*width > 0 && *height > 0) + return 1; + else + return 0; } - - -