From 155da23c1e7fcfbd2f99744e60858cfe91443c40 Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Tue, 23 Oct 2018 23:00:02 +0300 Subject: [PATCH] fix warnings when building with libpng-1.4/1.5 and --disable-png-shared ugly perhaps, but does the job. closes https://bugzilla.libsdl.org/show_bug.cgi?id=4311 --- IMG_png.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/IMG_png.c b/IMG_png.c index f03d8311..3c44d2da 100644 --- a/IMG_png.c +++ b/IMG_png.c @@ -71,29 +71,46 @@ #include /* Check for the older version of libpng */ -#if (PNG_LIBPNG_VER_MAJOR == 1) +#if (PNG_LIBPNG_VER_MAJOR == 1) #if (PNG_LIBPNG_VER_MINOR < 5) #define LIBPNG_VERSION_12 typedef png_bytep png_const_bytep; #endif +#if (PNG_LIBPNG_VER_MINOR < 4) +typedef png_structp png_const_structp; +typedef png_infop png_const_infop; +#endif #if (PNG_LIBPNG_VER_MINOR < 6) -typedef png_structp png_const_structrp; -typedef png_infop png_const_inforp; typedef png_structp png_structrp; typedef png_infop png_inforp; +typedef png_const_structp png_const_structrp; +typedef png_const_infop png_const_inforp; +/* noconst15: version < 1.6 doesn't have const, >= 1.6 adds it */ +/* noconst16: version < 1.6 does have const, >= 1.6 removes it */ +typedef png_structp png_noconst15_structrp; +typedef png_inforp png_noconst15_inforp; +typedef png_const_inforp png_noconst16_inforp; +#else +typedef png_const_structp png_noconst15_structrp; +typedef png_const_inforp png_noconst15_inforp; +typedef png_inforp png_noconst16_inforp; #endif +#else +typedef png_const_structp png_noconst15_structrp; +typedef png_const_inforp png_noconst15_inforp; +typedef png_inforp png_noconst16_inforp; #endif static struct { int loaded; void *handle; - png_infop (*png_create_info_struct) (png_const_structrp png_ptr); + png_infop (*png_create_info_struct) (png_noconst15_structrp png_ptr); png_structp (*png_create_read_struct) (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn); void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr); - png_uint_32 (*png_get_IHDR) (png_const_structrp png_ptr, png_const_inforp info_ptr, png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, int *interlace_method, int *compression_method, int *filter_method); - png_voidp (*png_get_io_ptr) (png_const_structrp png_ptr); + png_uint_32 (*png_get_IHDR) (png_noconst15_structrp png_ptr, png_noconst15_inforp info_ptr, png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, int *interlace_method, int *compression_method, int *filter_method); + png_voidp (*png_get_io_ptr) (png_noconst15_structrp png_ptr); png_byte (*png_get_channels) (png_const_structrp png_ptr, png_const_inforp info_ptr); - png_uint_32 (*png_get_PLTE) (png_const_structrp png_ptr, png_inforp info_ptr, png_colorp *palette, int *num_palette); + png_uint_32 (*png_get_PLTE) (png_const_structrp png_ptr, png_noconst16_inforp info_ptr, png_colorp *palette, int *num_palette); png_uint_32 (*png_get_tRNS) (png_const_structrp png_ptr, png_inforp info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values); png_uint_32 (*png_get_valid) (png_const_structrp png_ptr, png_const_inforp info_ptr, png_uint_32 flag); void (*png_read_image) (png_structrp png_ptr, png_bytepp image); @@ -120,7 +137,7 @@ int IMG_InitPNG() return -1; } lib.png_create_info_struct = - (png_infop (*) (png_const_structrp)) + (png_infop (*) (png_noconst15_structrp)) SDL_LoadFunction(lib.handle, "png_create_info_struct"); if ( lib.png_create_info_struct == NULL ) { SDL_UnloadObject(lib.handle); @@ -141,7 +158,7 @@ int IMG_InitPNG() return -1; } lib.png_get_IHDR = - (png_uint_32 (*) (png_const_structrp, png_const_inforp, png_uint_32 *, png_uint_32 *, int *, int *, int *, int *, int *)) + (png_uint_32 (*) (png_noconst15_structrp, png_noconst15_inforp, png_uint_32 *, png_uint_32 *, int *, int *, int *, int *, int *)) SDL_LoadFunction(lib.handle, "png_get_IHDR"); if ( lib.png_get_IHDR == NULL ) { SDL_UnloadObject(lib.handle); @@ -155,14 +172,14 @@ int IMG_InitPNG() return -1; } lib.png_get_io_ptr = - (png_voidp (*) (png_const_structrp)) + (png_voidp (*) (png_noconst15_structrp)) SDL_LoadFunction(lib.handle, "png_get_io_ptr"); if ( lib.png_get_io_ptr == NULL ) { SDL_UnloadObject(lib.handle); return -1; } lib.png_get_PLTE = - (png_uint_32 (*) (png_const_structrp, png_inforp, png_colorp *, int *)) + (png_uint_32 (*) (png_const_structrp, png_noconst16_inforp, png_colorp *, int *)) SDL_LoadFunction(lib.handle, "png_get_PLTE"); if ( lib.png_get_PLTE == NULL ) { SDL_UnloadObject(lib.handle);