Skip to content

Commit

Permalink
fix warnings when building with libpng-1.4/1.5 and --disable-png-shared
Browse files Browse the repository at this point in the history
ugly perhaps, but does the job.
closes https://bugzilla.libsdl.org/show_bug.cgi?id=4311
  • Loading branch information
sezero committed Oct 23, 2018
1 parent e62c4ad commit 155da23
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions IMG_png.c
Expand Up @@ -71,29 +71,46 @@
#include <png.h>

/* 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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 155da23

Please sign in to comment.