fix warnings when building with libpng-1.4/1.5 and --disable-png-shared SDL-1.2
authorOzkan Sezer <sezeroz@gmail.com>
Tue, 23 Oct 2018 23:00:02 +0300
branchSDL-1.2
changeset 61389225c8816d6
parent 611 b39ee38ead19
child 634 68f958f43339
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
     1.1 --- a/IMG_png.c	Thu Oct 18 11:55:14 2018 +0300
     1.2 +++ b/IMG_png.c	Tue Oct 23 23:00:02 2018 +0300
     1.3 @@ -71,29 +71,46 @@
     1.4  #include <png.h>
     1.5  
     1.6  /* Check for the older version of libpng */
     1.7 -#if (PNG_LIBPNG_VER_MAJOR == 1) 
     1.8 +#if (PNG_LIBPNG_VER_MAJOR == 1)
     1.9  #if (PNG_LIBPNG_VER_MINOR < 5)
    1.10  #define LIBPNG_VERSION_12
    1.11  typedef png_bytep png_const_bytep;
    1.12  #endif
    1.13 +#if (PNG_LIBPNG_VER_MINOR < 4)
    1.14 +typedef png_structp png_const_structp;
    1.15 +typedef png_infop png_const_infop;
    1.16 +#endif
    1.17  #if (PNG_LIBPNG_VER_MINOR < 6)
    1.18 -typedef png_structp png_const_structrp;
    1.19 -typedef png_infop png_const_inforp;
    1.20  typedef png_structp png_structrp;
    1.21  typedef png_infop png_inforp;
    1.22 +typedef png_const_structp png_const_structrp;
    1.23 +typedef png_const_infop png_const_inforp;
    1.24 +/* noconst15: version < 1.6 doesn't have const, >= 1.6 adds it */
    1.25 +/* noconst16: version < 1.6 does have const, >= 1.6 removes it */
    1.26 +typedef png_structp png_noconst15_structrp;
    1.27 +typedef png_inforp png_noconst15_inforp;
    1.28 +typedef png_const_inforp png_noconst16_inforp;
    1.29 +#else
    1.30 +typedef png_const_structp png_noconst15_structrp;
    1.31 +typedef png_const_inforp png_noconst15_inforp;
    1.32 +typedef png_inforp png_noconst16_inforp;
    1.33  #endif
    1.34 +#else
    1.35 +typedef png_const_structp png_noconst15_structrp;
    1.36 +typedef png_const_inforp png_noconst15_inforp;
    1.37 +typedef png_inforp png_noconst16_inforp;
    1.38  #endif
    1.39  
    1.40  static struct {
    1.41  	int loaded;
    1.42  	void *handle;
    1.43 -	png_infop (*png_create_info_struct) (png_const_structrp png_ptr);
    1.44 +	png_infop (*png_create_info_struct) (png_noconst15_structrp png_ptr);
    1.45  	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);
    1.46  	void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
    1.47 -	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);
    1.48 -	png_voidp (*png_get_io_ptr) (png_const_structrp png_ptr);
    1.49 +	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);
    1.50 +	png_voidp (*png_get_io_ptr) (png_noconst15_structrp png_ptr);
    1.51  	png_byte (*png_get_channels) (png_const_structrp png_ptr, png_const_inforp info_ptr);
    1.52 -	png_uint_32 (*png_get_PLTE) (png_const_structrp png_ptr, png_inforp info_ptr, png_colorp *palette, int *num_palette);
    1.53 +	png_uint_32 (*png_get_PLTE) (png_const_structrp png_ptr, png_noconst16_inforp info_ptr, png_colorp *palette, int *num_palette);
    1.54  	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);
    1.55  	png_uint_32 (*png_get_valid) (png_const_structrp png_ptr, png_const_inforp info_ptr, png_uint_32 flag);
    1.56  	void (*png_read_image) (png_structrp png_ptr, png_bytepp image);
    1.57 @@ -120,7 +137,7 @@
    1.58  			return -1;
    1.59  		}
    1.60  		lib.png_create_info_struct =
    1.61 -			(png_infop (*) (png_const_structrp))
    1.62 +			(png_infop (*) (png_noconst15_structrp))
    1.63  			SDL_LoadFunction(lib.handle, "png_create_info_struct");
    1.64  		if ( lib.png_create_info_struct == NULL ) {
    1.65  			SDL_UnloadObject(lib.handle);
    1.66 @@ -141,7 +158,7 @@
    1.67  			return -1;
    1.68  		}
    1.69  		lib.png_get_IHDR =
    1.70 -			(png_uint_32 (*) (png_const_structrp, png_const_inforp, png_uint_32 *, png_uint_32 *, int *, int *, int *, int *, int *))
    1.71 +			(png_uint_32 (*) (png_noconst15_structrp, png_noconst15_inforp, png_uint_32 *, png_uint_32 *, int *, int *, int *, int *, int *))
    1.72  			SDL_LoadFunction(lib.handle, "png_get_IHDR");
    1.73  		if ( lib.png_get_IHDR == NULL ) {
    1.74  			SDL_UnloadObject(lib.handle);
    1.75 @@ -155,14 +172,14 @@
    1.76  			return -1;
    1.77  		}
    1.78  		lib.png_get_io_ptr =
    1.79 -			(png_voidp (*) (png_const_structrp))
    1.80 +			(png_voidp (*) (png_noconst15_structrp))
    1.81  			SDL_LoadFunction(lib.handle, "png_get_io_ptr");
    1.82  		if ( lib.png_get_io_ptr == NULL ) {
    1.83  			SDL_UnloadObject(lib.handle);
    1.84  			return -1;
    1.85  		}
    1.86  		lib.png_get_PLTE =
    1.87 -			(png_uint_32 (*) (png_const_structrp, png_inforp, png_colorp *, int *))
    1.88 +			(png_uint_32 (*) (png_const_structrp, png_noconst16_inforp, png_colorp *, int *))
    1.89  			SDL_LoadFunction(lib.handle, "png_get_PLTE");
    1.90  		if ( lib.png_get_PLTE == NULL ) {
    1.91  			SDL_UnloadObject(lib.handle);