fix warnings when building with libpng-1.4/1.5 and --disable-png-shared
authorOzkan Sezer <sezeroz@gmail.com>
Tue, 23 Oct 2018 23:00:50 +0300
changeset 614fa3c53a205a9
parent 612 ca95d0e31aec
child 615 923efa629d1c
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:57:19 2018 +0300
     1.2 +++ b/IMG_png.c	Tue Oct 23 23:00:50 2018 +0300
     1.3 @@ -70,30 +70,47 @@
     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  typedef png_color *png_const_colorp;
    1.13  #endif
    1.14 +#if (PNG_LIBPNG_VER_MINOR < 4)
    1.15 +typedef png_structp png_const_structp;
    1.16 +typedef png_infop png_const_infop;
    1.17 +#endif
    1.18  #if (PNG_LIBPNG_VER_MINOR < 6)
    1.19 -typedef png_structp png_const_structrp;
    1.20 -typedef png_infop png_const_inforp;
    1.21  typedef png_structp png_structrp;
    1.22  typedef png_infop png_inforp;
    1.23 +typedef png_const_structp png_const_structrp;
    1.24 +typedef png_const_infop png_const_inforp;
    1.25 +/* noconst15: version < 1.6 doesn't have const, >= 1.6 adds it */
    1.26 +/* noconst16: version < 1.6 does have const, >= 1.6 removes it */
    1.27 +typedef png_structp png_noconst15_structrp;
    1.28 +typedef png_inforp png_noconst15_inforp;
    1.29 +typedef png_const_inforp png_noconst16_inforp;
    1.30 +#else
    1.31 +typedef png_const_structp png_noconst15_structrp;
    1.32 +typedef png_const_inforp png_noconst15_inforp;
    1.33 +typedef png_inforp png_noconst16_inforp;
    1.34  #endif
    1.35 +#else
    1.36 +typedef png_const_structp png_noconst15_structrp;
    1.37 +typedef png_const_inforp png_noconst15_inforp;
    1.38 +typedef png_inforp png_noconst16_inforp;
    1.39  #endif
    1.40  
    1.41  static struct {
    1.42      int loaded;
    1.43      void *handle;
    1.44 -    png_infop (*png_create_info_struct) (png_const_structrp png_ptr);
    1.45 +    png_infop (*png_create_info_struct) (png_noconst15_structrp png_ptr);
    1.46      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.47      void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr);
    1.48 -    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.49 -    png_voidp (*png_get_io_ptr) (png_const_structrp png_ptr);
    1.50 +    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.51 +    png_voidp (*png_get_io_ptr) (png_noconst15_structrp png_ptr);
    1.52      png_byte (*png_get_channels) (png_const_structrp png_ptr, png_const_inforp info_ptr);
    1.53 -    png_uint_32 (*png_get_PLTE) (png_const_structrp png_ptr, png_inforp info_ptr, png_colorp *palette, int *num_palette);
    1.54 +    png_uint_32 (*png_get_PLTE) (png_const_structrp png_ptr, png_noconst16_inforp info_ptr, png_colorp *palette, int *num_palette);
    1.55      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.56      png_uint_32 (*png_get_valid) (png_const_structrp png_ptr, png_const_inforp info_ptr, png_uint_32 flag);
    1.57      void (*png_read_image) (png_structrp png_ptr, png_bytepp image);
    1.58 @@ -112,9 +129,9 @@
    1.59      png_structp (*png_create_write_struct) (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn);
    1.60      void (*png_destroy_write_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr);
    1.61      void (*png_set_write_fn) (png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn);
    1.62 -    void (*png_set_IHDR) (png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_type, int compression_type, int filter_type);
    1.63 -    void (*png_write_info) (png_structrp png_ptr, png_const_inforp info_ptr);
    1.64 -    void (*png_set_rows) (png_const_structrp png_ptr, png_inforp info_ptr, png_bytepp row_pointers);
    1.65 +    void (*png_set_IHDR) (png_noconst15_structrp png_ptr, png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_type, int compression_type, int filter_type);
    1.66 +    void (*png_write_info) (png_structrp png_ptr, png_noconst15_inforp info_ptr);
    1.67 +    void (*png_set_rows) (png_noconst15_structrp png_ptr, png_inforp info_ptr, png_bytepp row_pointers);
    1.68      void (*png_write_png) (png_structrp png_ptr, png_inforp info_ptr, int transforms, png_voidp params);
    1.69      void (*png_set_PLTE) (png_structrp png_ptr, png_inforp info_ptr, png_const_colorp palette, int num_palette);
    1.70  } lib;
    1.71 @@ -137,13 +154,13 @@
    1.72              return -1;
    1.73          }
    1.74  #endif
    1.75 -        FUNCTION_LOADER(png_create_info_struct, png_infop (*) (png_const_structrp png_ptr))
    1.76 +        FUNCTION_LOADER(png_create_info_struct, png_infop (*) (png_noconst15_structrp png_ptr))
    1.77          FUNCTION_LOADER(png_create_read_struct, png_structp (*) (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn))
    1.78          FUNCTION_LOADER(png_destroy_read_struct, void (*) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr))
    1.79 -        FUNCTION_LOADER(png_get_IHDR, png_uint_32 (*) (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.80 -        FUNCTION_LOADER(png_get_io_ptr, png_voidp (*) (png_const_structrp png_ptr))
    1.81 +        FUNCTION_LOADER(png_get_IHDR, png_uint_32 (*) (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.82 +        FUNCTION_LOADER(png_get_io_ptr, png_voidp (*) (png_noconst15_structrp png_ptr))
    1.83          FUNCTION_LOADER(png_get_channels, png_byte (*) (png_const_structrp png_ptr, png_const_inforp info_ptr))
    1.84 -        FUNCTION_LOADER(png_get_PLTE, png_uint_32 (*) (png_const_structrp png_ptr, png_inforp info_ptr, png_colorp *palette, int *num_palette))
    1.85 +        FUNCTION_LOADER(png_get_PLTE, png_uint_32 (*) (png_const_structrp png_ptr, png_noconst16_inforp info_ptr, png_colorp *palette, int *num_palette))
    1.86          FUNCTION_LOADER(png_get_tRNS, png_uint_32 (*) (png_const_structrp png_ptr, png_inforp info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values))
    1.87          FUNCTION_LOADER(png_get_valid, png_uint_32 (*) (png_const_structrp png_ptr, png_const_inforp info_ptr, png_uint_32 flag))
    1.88          FUNCTION_LOADER(png_read_image, void (*) (png_structrp png_ptr, png_bytepp image))
    1.89 @@ -162,9 +179,9 @@
    1.90          FUNCTION_LOADER(png_create_write_struct, png_structp (*) (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn))
    1.91          FUNCTION_LOADER(png_destroy_write_struct, void (*) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr))
    1.92          FUNCTION_LOADER(png_set_write_fn, void (*) (png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn))
    1.93 -        FUNCTION_LOADER(png_set_IHDR, void (*) (png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_type, int compression_type, int filter_type))
    1.94 -        FUNCTION_LOADER(png_write_info, void (*) (png_structrp png_ptr, png_const_inforp info_ptr))
    1.95 -        FUNCTION_LOADER(png_set_rows, void (*) (png_const_structrp png_ptr, png_inforp info_ptr, png_bytepp row_pointers))
    1.96 +        FUNCTION_LOADER(png_set_IHDR, void (*) (png_noconst15_structrp png_ptr, png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_type, int compression_type, int filter_type))
    1.97 +        FUNCTION_LOADER(png_write_info, void (*) (png_structrp png_ptr, png_noconst15_inforp info_ptr))
    1.98 +        FUNCTION_LOADER(png_set_rows, void (*) (png_noconst15_structrp png_ptr, png_inforp info_ptr, png_bytepp row_pointers))
    1.99          FUNCTION_LOADER(png_write_png, void (*) (png_structrp png_ptr, png_inforp info_ptr, int transforms, png_voidp params))
   1.100          FUNCTION_LOADER(png_set_PLTE, void (*) (png_structrp png_ptr, png_inforp info_ptr, png_const_colorp palette, int num_palette))
   1.101      }