From 767d17b7a3d8206fcd75d65c0e98c87693fae3d3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 22 Oct 2017 14:40:31 -0700 Subject: [PATCH] Fixed warnings building 64-bit with Visual Studio --- IMG_jpg.c | 177 ++++++---------------------------- IMG_png.c | 274 ++++++++--------------------------------------------- IMG_svg.c | 4 +- IMG_tif.c | 80 ++++------------ IMG_webp.c | 89 +++++------------ IMG_xcf.c | 2 +- IMG_xpm.c | 2 +- 7 files changed, 114 insertions(+), 514 deletions(-) diff --git a/IMG_jpg.c b/IMG_jpg.c index fe59160d..44d4f265 100755 --- a/IMG_jpg.c +++ b/IMG_jpg.c @@ -68,125 +68,39 @@ static struct { } lib; #ifdef LOAD_JPG_DYNAMIC +#define FUNCTION_LOADER(FUNC, SIG) \ + lib.FUNC = (SIG) SDL_LoadFunction(lib.handle, #FUNC); \ + if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return -1; } +#else +#define FUNCTION_LOADER(FUNC, SIG) \ + lib.FUNC = FUNC; +#endif + int IMG_InitJPG() { if ( lib.loaded == 0 ) { +#ifdef LOAD_JPG_DYNAMIC lib.handle = SDL_LoadObject(LOAD_JPG_DYNAMIC); if ( lib.handle == NULL ) { return -1; } - lib.jpeg_calc_output_dimensions = - (void (*) (j_decompress_ptr)) - SDL_LoadFunction(lib.handle, "jpeg_calc_output_dimensions"); - if ( lib.jpeg_calc_output_dimensions == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_CreateDecompress = - (void (*) (j_decompress_ptr, int, size_t)) - SDL_LoadFunction(lib.handle, "jpeg_CreateDecompress"); - if ( lib.jpeg_CreateDecompress == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_destroy_decompress = - (void (*) (j_decompress_ptr)) - SDL_LoadFunction(lib.handle, "jpeg_destroy_decompress"); - if ( lib.jpeg_destroy_decompress == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_finish_decompress = - (boolean (*) (j_decompress_ptr)) - SDL_LoadFunction(lib.handle, "jpeg_finish_decompress"); - if ( lib.jpeg_finish_decompress == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_read_header = - (int (*) (j_decompress_ptr, boolean)) - SDL_LoadFunction(lib.handle, "jpeg_read_header"); - if ( lib.jpeg_read_header == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_read_scanlines = - (JDIMENSION (*) (j_decompress_ptr, JSAMPARRAY, JDIMENSION)) - SDL_LoadFunction(lib.handle, "jpeg_read_scanlines"); - if ( lib.jpeg_read_scanlines == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_resync_to_restart = - (boolean (*) (j_decompress_ptr, int)) - SDL_LoadFunction(lib.handle, "jpeg_resync_to_restart"); - if ( lib.jpeg_resync_to_restart == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_start_decompress = - (boolean (*) (j_decompress_ptr)) - SDL_LoadFunction(lib.handle, "jpeg_start_decompress"); - if ( lib.jpeg_start_decompress == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_CreateCompress = - (void (*) (j_compress_ptr, int, size_t)) - SDL_LoadFunction(lib.handle, "jpeg_CreateCompress"); - if ( lib.jpeg_CreateCompress == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_start_compress = - (void (*) (j_compress_ptr cinfo, boolean write_all_tables)) - SDL_LoadFunction(lib.handle, "jpeg_start_compress"); - if ( lib.jpeg_start_compress == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_set_quality = - (void(*) (j_compress_ptr cinfo, int quality, boolean force_baseline)) - SDL_LoadFunction(lib.handle, "jpeg_set_quality"); - if ( lib.jpeg_set_quality == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_set_defaults = - (void(*) (j_compress_ptr cinfo)) - SDL_LoadFunction(lib.handle, "jpeg_set_defaults"); - if ( lib.jpeg_set_defaults == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_write_scanlines = - (JDIMENSION (*) (j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)) - SDL_LoadFunction(lib.handle, "jpeg_write_scanlines"); - if ( lib.jpeg_write_scanlines == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_finish_compress = - (void (*) (j_compress_ptr cinfo)) - SDL_LoadFunction(lib.handle, "jpeg_finish_compress"); - if ( lib.jpeg_finish_compress == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_destroy_compress = - (void (*) (j_compress_ptr cinfo)) - SDL_LoadFunction(lib.handle, "jpeg_destroy_compress"); - if ( lib.jpeg_destroy_compress == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.jpeg_std_error = - (struct jpeg_error_mgr * (*) (struct jpeg_error_mgr *)) - SDL_LoadFunction(lib.handle, "jpeg_std_error"); - if ( lib.jpeg_std_error == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } +#endif + FUNCTION_LOADER(jpeg_calc_output_dimensions, void (*) (j_decompress_ptr cinfo)) + FUNCTION_LOADER(jpeg_CreateDecompress, void (*) (j_decompress_ptr cinfo, int version, size_t structsize)) + FUNCTION_LOADER(jpeg_destroy_decompress, void (*) (j_decompress_ptr cinfo)) + FUNCTION_LOADER(jpeg_finish_decompress, boolean (*) (j_decompress_ptr cinfo)) + FUNCTION_LOADER(jpeg_read_header, int (*) (j_decompress_ptr cinfo, boolean require_image)) + FUNCTION_LOADER(jpeg_read_scanlines, JDIMENSION (*) (j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)) + FUNCTION_LOADER(jpeg_resync_to_restart, boolean (*) (j_decompress_ptr cinfo, int desired)) + FUNCTION_LOADER(jpeg_start_decompress, boolean (*) (j_decompress_ptr cinfo)) + FUNCTION_LOADER(jpeg_CreateCompress, void (*) (j_compress_ptr cinfo, int version, size_t structsize)) + FUNCTION_LOADER(jpeg_start_compress, void (*) (j_compress_ptr cinfo, boolean write_all_tables)) + FUNCTION_LOADER(jpeg_set_quality, void (*) (j_compress_ptr cinfo, int quality, boolean force_baseline)) + FUNCTION_LOADER(jpeg_set_defaults, void (*) (j_compress_ptr cinfo)) + FUNCTION_LOADER(jpeg_write_scanlines, JDIMENSION (*) (j_compress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION num_lines)) + FUNCTION_LOADER(jpeg_finish_compress, void (*) (j_compress_ptr cinfo)) + FUNCTION_LOADER(jpeg_destroy_compress, void (*) (j_compress_ptr cinfo)) + FUNCTION_LOADER(jpeg_std_error, struct jpeg_error_mgr * (*) (struct jpeg_error_mgr * err)) } ++lib.loaded; @@ -198,45 +112,12 @@ void IMG_QuitJPG() return; } if ( lib.loaded == 1 ) { +#ifdef LOAD_JPG_DYNAMIC SDL_UnloadObject(lib.handle); +#endif } --lib.loaded; } -#else -int IMG_InitJPG() -{ - if ( lib.loaded == 0 ) { - lib.jpeg_calc_output_dimensions = jpeg_calc_output_dimensions; - lib.jpeg_CreateDecompress = jpeg_CreateDecompress; - lib.jpeg_destroy_decompress = jpeg_destroy_decompress; - lib.jpeg_finish_decompress = jpeg_finish_decompress; - lib.jpeg_read_header = jpeg_read_header; - lib.jpeg_read_scanlines = jpeg_read_scanlines; - lib.jpeg_resync_to_restart = jpeg_resync_to_restart; - lib.jpeg_start_decompress = jpeg_start_decompress; - lib.jpeg_CreateCompress = jpeg_CreateCompress; - lib.jpeg_start_compress = jpeg_start_compress; - lib.jpeg_set_quality = jpeg_set_quality; - lib.jpeg_set_defaults = jpeg_set_defaults; - lib.jpeg_write_scanlines = jpeg_write_scanlines; - lib.jpeg_finish_compress = jpeg_finish_compress; - lib.jpeg_destroy_compress = jpeg_destroy_compress; - lib.jpeg_std_error = jpeg_std_error; - } - ++lib.loaded; - - return 0; -} -void IMG_QuitJPG() -{ - if ( lib.loaded == 0 ) { - return; - } - if ( lib.loaded == 1 ) { - } - --lib.loaded; -} -#endif /* LOAD_JPG_DYNAMIC */ /* See if an image is contained in a data source */ int IMG_isJPG(SDL_RWops *src) @@ -329,7 +210,7 @@ static boolean fill_input_buffer (j_decompress_ptr cinfo) my_source_mgr * src = (my_source_mgr *) cinfo->src; int nbytes; - nbytes = SDL_RWread(src->ctx, src->buffer, 1, INPUT_BUFFER_SIZE); + nbytes = (int)SDL_RWread(src->ctx, src->buffer, 1, INPUT_BUFFER_SIZE); if (nbytes <= 0) { /* Insert a fake EOI marker */ src->buffer[0] = (Uint8) 0xFF; diff --git a/IMG_png.c b/IMG_png.c index e12da499..a2795465 100755 --- a/IMG_png.c +++ b/IMG_png.c @@ -116,204 +116,52 @@ static struct { } lib; #ifdef LOAD_PNG_DYNAMIC +#define FUNCTION_LOADER(FUNC, SIG) \ + lib.FUNC = (SIG) SDL_LoadFunction(lib.handle, #FUNC); \ + if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return -1; } +#else +#define FUNCTION_LOADER(FUNC, SIG) \ + lib.FUNC = FUNC; +#endif + int IMG_InitPNG() { if ( lib.loaded == 0 ) { +#ifdef LOAD_PNG_DYNAMIC lib.handle = SDL_LoadObject(LOAD_PNG_DYNAMIC); if ( lib.handle == NULL ) { return -1; } - lib.png_create_info_struct = - (png_infop (*) (png_const_structrp)) - SDL_LoadFunction(lib.handle, "png_create_info_struct"); - if ( lib.png_create_info_struct == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_create_read_struct = - (png_structrp (*) (png_const_charp, png_voidp, png_error_ptr, png_error_ptr)) - SDL_LoadFunction(lib.handle, "png_create_read_struct"); - if ( lib.png_create_read_struct == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_destroy_read_struct = - (void (*) (png_structpp, png_infopp, png_infopp)) - SDL_LoadFunction(lib.handle, "png_destroy_read_struct"); - if ( lib.png_destroy_read_struct == NULL ) { - SDL_UnloadObject(lib.handle); - 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 *)) - SDL_LoadFunction(lib.handle, "png_get_IHDR"); - if ( lib.png_get_IHDR == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_get_channels = - (png_byte (*) (png_const_structrp, png_const_inforp)) - SDL_LoadFunction(lib.handle, "png_get_channels"); - if ( lib.png_get_channels == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_get_io_ptr = - (png_voidp (*) (png_const_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 *)) - SDL_LoadFunction(lib.handle, "png_get_PLTE"); - if ( lib.png_get_PLTE == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_get_tRNS = - (png_uint_32 (*) (png_const_structrp, png_inforp, png_bytep *, int *, png_color_16p *)) - SDL_LoadFunction(lib.handle, "png_get_tRNS"); - if ( lib.png_get_tRNS == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_get_valid = - (png_uint_32 (*) (png_const_structrp, png_const_inforp, png_uint_32)) - SDL_LoadFunction(lib.handle, "png_get_valid"); - if ( lib.png_get_valid == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_read_image = - (void (*) (png_structrp, png_bytepp)) - SDL_LoadFunction(lib.handle, "png_read_image"); - if ( lib.png_read_image == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_read_info = - (void (*) (png_structrp, png_inforp)) - SDL_LoadFunction(lib.handle, "png_read_info"); - if ( lib.png_read_info == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_read_update_info = - (void (*) (png_structrp, png_inforp)) - SDL_LoadFunction(lib.handle, "png_read_update_info"); - if ( lib.png_read_update_info == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_set_expand = - (void (*) (png_structrp)) - SDL_LoadFunction(lib.handle, "png_set_expand"); - if ( lib.png_set_expand == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_set_gray_to_rgb = - (void (*) (png_structrp)) - SDL_LoadFunction(lib.handle, "png_set_gray_to_rgb"); - if ( lib.png_set_gray_to_rgb == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_set_packing = - (void (*) (png_structrp)) - SDL_LoadFunction(lib.handle, "png_set_packing"); - if ( lib.png_set_packing == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_set_read_fn = - (void (*) (png_structrp, png_voidp, png_rw_ptr)) - SDL_LoadFunction(lib.handle, "png_set_read_fn"); - if ( lib.png_set_read_fn == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_set_strip_16 = - (void (*) (png_structrp)) - SDL_LoadFunction(lib.handle, "png_set_strip_16"); - if ( lib.png_set_strip_16 == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_sig_cmp = - (int (*) (png_const_bytep, png_size_t, png_size_t)) - SDL_LoadFunction(lib.handle, "png_sig_cmp"); - if ( lib.png_sig_cmp == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } +#endif + FUNCTION_LOADER(png_create_info_struct, png_infop (*) (png_const_structrp png_ptr)) + 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)) + FUNCTION_LOADER(png_destroy_read_struct, void (*) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr)) + 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)) + FUNCTION_LOADER(png_get_io_ptr, png_voidp (*) (png_const_structrp png_ptr)) + FUNCTION_LOADER(png_get_channels, png_byte (*) (png_const_structrp png_ptr, png_const_inforp info_ptr)) + FUNCTION_LOADER(png_get_PLTE, png_uint_32 (*) (png_const_structrp png_ptr, png_inforp info_ptr, png_colorp *palette, int *num_palette)) + 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)) + FUNCTION_LOADER(png_get_valid, png_uint_32 (*) (png_const_structrp png_ptr, png_const_inforp info_ptr, png_uint_32 flag)) + FUNCTION_LOADER(png_read_image, void (*) (png_structrp png_ptr, png_bytepp image)) + FUNCTION_LOADER(png_read_info, void (*) (png_structrp png_ptr, png_inforp info_ptr)) + FUNCTION_LOADER(png_read_update_info, void (*) (png_structrp png_ptr, png_inforp info_ptr)) + FUNCTION_LOADER(png_set_expand, void (*) (png_structrp png_ptr)) + FUNCTION_LOADER(png_set_gray_to_rgb, void (*) (png_structrp png_ptr)) + FUNCTION_LOADER(png_set_packing, void (*) (png_structrp png_ptr)) + FUNCTION_LOADER(png_set_read_fn, void (*) (png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn)) + FUNCTION_LOADER(png_set_strip_16, void (*) (png_structrp png_ptr)) + FUNCTION_LOADER(png_sig_cmp, int (*) (png_const_bytep sig, png_size_t start, png_size_t num_to_check)) #ifndef LIBPNG_VERSION_12 - lib.png_set_longjmp_fn = - (jmp_buf * (*) (png_structrp, png_longjmp_ptr, size_t)) - SDL_LoadFunction(lib.handle, "png_set_longjmp_fn"); - if ( lib.png_set_longjmp_fn == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } + FUNCTION_LOADER(png_set_longjmp_fn, jmp_buf* (*) (png_structrp, png_longjmp_ptr, size_t)) #endif - lib.png_create_write_struct = - (png_structp (*) (png_const_charp, png_voidp, png_error_ptr, png_error_ptr)) - SDL_LoadFunction(lib.handle, "png_create_write_struct"); - if ( lib.png_create_write_struct == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_destroy_write_struct = - (void (*) (png_structpp, png_infopp)) - SDL_LoadFunction(lib.handle, "png_destroy_write_struct"); - if ( lib.png_destroy_write_struct == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_set_write_fn = - (void (*) (png_structp, png_voidp, png_rw_ptr, png_flush_ptr)) - SDL_LoadFunction(lib.handle, "png_set_write_fn"); - if ( lib.png_set_write_fn == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_set_IHDR = - (void (*) (png_structp, png_infop, png_uint_32, png_uint_32, int, int, int, int, int)) - SDL_LoadFunction(lib.handle, "png_set_IHDR"); - if ( lib.png_set_IHDR == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_write_info = - (void (*) (png_structp, png_infop)) - SDL_LoadFunction(lib.handle, "png_write_info"); - if ( lib.png_write_info == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_set_rows = - (void (*) (png_structp, png_infop, png_bytepp)) - SDL_LoadFunction(lib.handle, "png_set_rows"); - if ( lib.png_set_rows == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_write_png = - (void (*) (png_structp, png_infop, int, png_voidp)) - SDL_LoadFunction(lib.handle, "png_write_png"); - if ( lib.png_write_png == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_set_PLTE = - (void (*) (png_structp, png_infop, png_colorp, int)) - SDL_LoadFunction(lib.handle, "png_set_PLTE"); - if ( lib.png_set_PLTE == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } + 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)) + FUNCTION_LOADER(png_destroy_write_struct, void (*) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)) + 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)) + 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)) + FUNCTION_LOADER(png_write_info, void (*) (png_structrp png_ptr, png_const_inforp info_ptr)) + FUNCTION_LOADER(png_set_rows, void (*) (png_const_structrp png_ptr, png_inforp info_ptr, png_bytepp row_pointers)) + FUNCTION_LOADER(png_write_png, void (*) (png_structrp png_ptr, png_inforp info_ptr, int transforms, png_voidp params)) + FUNCTION_LOADER(png_set_PLTE, void (*) (png_structrp png_ptr, png_inforp info_ptr, png_const_colorp palette, int num_palette)) } ++lib.loaded; @@ -325,58 +173,12 @@ void IMG_QuitPNG() return; } if ( lib.loaded == 1 ) { +#ifdef LOAD_PNG_DYNAMIC SDL_UnloadObject(lib.handle); - } - --lib.loaded; -} -#else -int IMG_InitPNG() -{ - if ( lib.loaded == 0 ) { - lib.png_create_info_struct = png_create_info_struct; - lib.png_create_read_struct = png_create_read_struct; - lib.png_destroy_read_struct = png_destroy_read_struct; - lib.png_get_IHDR = png_get_IHDR; - lib.png_get_channels = png_get_channels; - lib.png_get_io_ptr = png_get_io_ptr; - lib.png_get_PLTE = png_get_PLTE; - lib.png_get_tRNS = png_get_tRNS; - lib.png_get_valid = png_get_valid; - lib.png_read_image = png_read_image; - lib.png_read_info = png_read_info; - lib.png_read_update_info = png_read_update_info; - lib.png_set_expand = png_set_expand; - lib.png_set_gray_to_rgb = png_set_gray_to_rgb; - lib.png_set_packing = png_set_packing; - lib.png_set_read_fn = png_set_read_fn; - lib.png_set_strip_16 = png_set_strip_16; - lib.png_sig_cmp = png_sig_cmp; -#ifndef LIBPNG_VERSION_12 - lib.png_set_longjmp_fn = png_set_longjmp_fn; #endif - lib.png_create_write_struct = png_create_write_struct; - lib.png_destroy_write_struct = png_destroy_write_struct; - lib.png_set_write_fn = png_set_write_fn; - lib.png_set_IHDR = png_set_IHDR; - lib.png_write_info = png_write_info; - lib.png_set_rows = png_set_rows; - lib.png_write_png = png_write_png; - lib.png_set_PLTE = png_set_PLTE; - } - ++lib.loaded; - - return 0; -} -void IMG_QuitPNG() -{ - if ( lib.loaded == 0 ) { - return; - } - if ( lib.loaded == 1 ) { } --lib.loaded; } -#endif /* LOAD_PNG_DYNAMIC */ /* See if an image is contained in a data source */ int IMG_isPNG(SDL_RWops *src) diff --git a/IMG_svg.c b/IMG_svg.c index afa8c333..a9beca08 100755 --- a/IMG_svg.c +++ b/IMG_svg.c @@ -28,8 +28,8 @@ #ifdef LOAD_SVG /* Replace C runtime functions with SDL C runtime functions for building on Windows */ -#define strtoll SDL_strtoll -#define sscanf SDL_sscanf +#define strtoll SDL_strtoll +#define sscanf SDL_sscanf #ifndef FLT_MAX #define FLT_MAX 3.402823466e+38F #endif diff --git a/IMG_tif.c b/IMG_tif.c index ae27b8f7..a0b077fd 100755 --- a/IMG_tif.c +++ b/IMG_tif.c @@ -40,48 +40,28 @@ static struct { } lib; #ifdef LOAD_TIF_DYNAMIC +#define FUNCTION_LOADER(FUNC, SIG) \ + lib.FUNC = (SIG) SDL_LoadFunction(lib.handle, #FUNC); \ + if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return -1; } +#else +#define FUNCTION_LOADER(FUNC, SIG) \ + lib.FUNC = FUNC; +#endif + int IMG_InitTIF() { if ( lib.loaded == 0 ) { +#ifdef LOAD_TIF_DYNAMIC lib.handle = SDL_LoadObject(LOAD_TIF_DYNAMIC); if ( lib.handle == NULL ) { return -1; } - lib.TIFFClientOpen = - (TIFF* (*)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc)) - SDL_LoadFunction(lib.handle, "TIFFClientOpen"); - if ( lib.TIFFClientOpen == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.TIFFClose = - (void (*)(TIFF*)) - SDL_LoadFunction(lib.handle, "TIFFClose"); - if ( lib.TIFFClose == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.TIFFGetField = - (int (*)(TIFF*, ttag_t, ...)) - SDL_LoadFunction(lib.handle, "TIFFGetField"); - if ( lib.TIFFGetField == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.TIFFReadRGBAImageOriented = - (int (*)(TIFF*, uint32, uint32, uint32*, int, int)) - SDL_LoadFunction(lib.handle, "TIFFReadRGBAImageOriented"); - if ( lib.TIFFReadRGBAImageOriented == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.TIFFSetErrorHandler = - (TIFFErrorHandler (*)(TIFFErrorHandler)) - SDL_LoadFunction(lib.handle, "TIFFSetErrorHandler"); - if ( lib.TIFFSetErrorHandler == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } +#endif + FUNCTION_LOADER(TIFFClientOpen, TIFF * (*)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc)) + FUNCTION_LOADER(TIFFClose, void (*)(TIFF*)) + FUNCTION_LOADER(TIFFGetField, int (*)(TIFF*, ttag_t, ...)) + FUNCTION_LOADER(TIFFReadRGBAImageOriented, int (*)(TIFF*, uint32, uint32, uint32*, int, int)) + FUNCTION_LOADER(TIFFSetErrorHandler, TIFFErrorHandler (*)(TIFFErrorHandler)) } ++lib.loaded; @@ -93,34 +73,12 @@ void IMG_QuitTIF() return; } if ( lib.loaded == 1 ) { +#ifdef LOAD_TIF_DYNAMIC SDL_UnloadObject(lib.handle); +#endif } --lib.loaded; } -#else -int IMG_InitTIF() -{ - if ( lib.loaded == 0 ) { - lib.TIFFClientOpen = TIFFClientOpen; - lib.TIFFClose = TIFFClose; - lib.TIFFGetField = TIFFGetField; - lib.TIFFReadRGBAImageOriented = TIFFReadRGBAImageOriented; - lib.TIFFSetErrorHandler = TIFFSetErrorHandler; - } - ++lib.loaded; - - return 0; -} -void IMG_QuitTIF() -{ - if ( lib.loaded == 0 ) { - return; - } - if ( lib.loaded == 1 ) { - } - --lib.loaded; -} -#endif /* LOAD_TIF_DYNAMIC */ /* * These are the thunking routine to use the SDL_RWops* routines from @@ -129,7 +87,7 @@ void IMG_QuitTIF() static tsize_t tiff_read(thandle_t fd, tdata_t buf, tsize_t size) { - return SDL_RWread((SDL_RWops*)fd, buf, 1, size); + return (tsize_t)SDL_RWread((SDL_RWops*)fd, buf, 1, size); } static toff_t tiff_seek(thandle_t fd, toff_t offset, int origin) @@ -139,7 +97,7 @@ static toff_t tiff_seek(thandle_t fd, toff_t offset, int origin) static tsize_t tiff_write(thandle_t fd, tdata_t buf, tsize_t size) { - return SDL_RWwrite((SDL_RWops*)fd, buf, 1, size); + return (tsize_t)SDL_RWwrite((SDL_RWops*)fd, buf, 1, size); } static int tiff_close(thandle_t fd) diff --git a/IMG_webp.c b/IMG_webp.c index d17a038d..88a6426f 100755 --- a/IMG_webp.c +++ b/IMG_webp.c @@ -44,43 +44,32 @@ static struct { int loaded; void *handle; - VP8StatusCode (*webp_get_features_internal) (const uint8_t *data, size_t data_size, WebPBitstreamFeatures* features, int decoder_abi_version); - uint8_t* (*webp_decode_rgb_into) (const uint8_t* data, size_t data_size, uint8_t* output_buffer, size_t output_buffer_size, int output_stride); - uint8_t* (*webp_decode_rgba_into) (const uint8_t* data, size_t data_size, uint8_t* output_buffer, size_t output_buffer_size, int output_stride); + VP8StatusCode (*WebPGetFeaturesInternal) (const uint8_t *data, size_t data_size, WebPBitstreamFeatures* features, int decoder_abi_version); + uint8_t* (*WebPDecodeRGBInto) (const uint8_t* data, size_t data_size, uint8_t* output_buffer, size_t output_buffer_size, int output_stride); + uint8_t* (*WebPDecodeRGBAInto) (const uint8_t* data, size_t data_size, uint8_t* output_buffer, size_t output_buffer_size, int output_stride); } lib; #ifdef LOAD_WEBP_DYNAMIC +#define FUNCTION_LOADER(FUNC, SIG) \ + lib.FUNC = (SIG) SDL_LoadFunction(lib.handle, #FUNC); \ + if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return -1; } +#else +#define FUNCTION_LOADER(FUNC, SIG) \ + lib.FUNC = FUNC; +#endif + int IMG_InitWEBP() { if ( lib.loaded == 0 ) { +#ifdef LOAD_WEBP_DYNAMIC lib.handle = SDL_LoadObject(LOAD_WEBP_DYNAMIC); if ( lib.handle == NULL ) { return -1; } - - lib.webp_get_features_internal = - ( VP8StatusCode (*) (const uint8_t *, size_t, WebPBitstreamFeatures*, int) ) - SDL_LoadFunction(lib.handle, "WebPGetFeaturesInternal" ); - if ( lib.webp_get_features_internal == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - - lib.webp_decode_rgb_into = - ( uint8_t* (*) (const uint8_t*, size_t, uint8_t*, size_t, int ) ) - SDL_LoadFunction(lib.handle, "WebPDecodeRGBInto" ); - if ( lib.webp_decode_rgb_into == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - - lib.webp_decode_rgba_into = - ( uint8_t* (*) (const uint8_t*, size_t, uint8_t*, size_t, int ) ) - SDL_LoadFunction(lib.handle, "WebPDecodeRGBAInto" ); - if ( lib.webp_decode_rgba_into == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } +#endif + FUNCTION_LOADER(WebPGetFeaturesInternal, VP8StatusCode (*) (const uint8_t *data, size_t data_size, WebPBitstreamFeatures* features, int decoder_abi_version)) + FUNCTION_LOADER(WebPDecodeRGBInto, uint8_t * (*) (const uint8_t* data, size_t data_size, uint8_t* output_buffer, size_t output_buffer_size, int output_stride)) + FUNCTION_LOADER(WebPDecodeRGBAInto, uint8_t * (*) (const uint8_t* data, size_t data_size, uint8_t* output_buffer, size_t output_buffer_size, int output_stride)) } ++lib.loaded; @@ -92,42 +81,12 @@ void IMG_QuitWEBP() return; } if ( lib.loaded == 1 ) { +#ifdef LOAD_WEBP_DYNAMIC SDL_UnloadObject(lib.handle); +#endif } --lib.loaded; } -#else -int IMG_InitWEBP() -{ - if ( lib.loaded == 0 ) { -#ifdef __MACOSX__ - extern VP8StatusCode WebPGetFeaturesInternal(const uint8_t*, size_t, WebPBitstreamFeatures*, int) __attribute__((weak_import)); - if ( WebPGetFeaturesInternal == NULL ) - { - /* Missing weakly linked framework */ - IMG_SetError("Missing webp.framework"); - return -1; - } -#endif // __MACOSX__ - - lib.webp_get_features_internal = WebPGetFeaturesInternal; - lib.webp_decode_rgb_into = WebPDecodeRGBInto; - lib.webp_decode_rgba_into = WebPDecodeRGBAInto; - } - ++lib.loaded; - - return 0; -} -void IMG_QuitWEBP() -{ - if ( lib.loaded == 0 ) { - return; - } - if ( lib.loaded == 1 ) { - } - --lib.loaded; -} -#endif /* LOAD_WEBP_DYNAMIC */ static int webp_getinfo( SDL_RWops *src, int *datasize ) { Sint64 start; @@ -157,7 +116,7 @@ static int webp_getinfo( SDL_RWops *src, int *datasize ) { #endif is_WEBP = 1; if ( datasize ) { - *datasize = (int)SDL_RWseek(src, 0, RW_SEEK_END) - start; + *datasize = (int)(SDL_RWseek(src, 0, RW_SEEK_END) - start); } } } @@ -205,11 +164,11 @@ SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src) raw_data = (uint8_t*) SDL_malloc( raw_data_size ); if ( raw_data == NULL ) { - error = "Failed to allocate enought buffer for WEBP"; + error = "Failed to allocate enough buffer for WEBP"; goto error; } - r = SDL_RWread(src, raw_data, 1, raw_data_size ); + r = (int)SDL_RWread(src, raw_data, 1, raw_data_size ); if ( r != raw_data_size ) { error = "Failed to read WEBP"; goto error; @@ -224,7 +183,7 @@ SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src) } #endif - if ( lib.webp_get_features_internal( raw_data, raw_data_size, &features, WEBP_DECODER_ABI_VERSION ) != VP8_STATUS_OK ) { + if ( lib.WebPGetFeaturesInternal( raw_data, raw_data_size, &features, WEBP_DECODER_ABI_VERSION ) != VP8_STATUS_OK ) { error = "WebPGetFeatures has failed"; goto error; } @@ -255,9 +214,9 @@ SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src) } if ( features.has_alpha ) { - ret = lib.webp_decode_rgba_into( raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h, surface->pitch ); + ret = lib.WebPDecodeRGBAInto( raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h, surface->pitch ); } else { - ret = lib.webp_decode_rgb_into( raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h, surface->pitch ); + ret = lib.WebPDecodeRGBInto( raw_data, raw_data_size, (uint8_t *)surface->pixels, surface->pitch * surface->h, surface->pitch ); } if ( !ret ) { diff --git a/IMG_xcf.c b/IMG_xcf.c index 9bb053f4..f83f6ed7 100755 --- a/IMG_xcf.c +++ b/IMG_xcf.c @@ -647,7 +647,7 @@ do_layer_surface(SDL_Surface * surface, SDL_RWops * src, xcf_header * head, xcf_ break; case 1: /* Indexed / Greyscale */ - switch (head->image_type) { + switch (head->image_type) { case IMAGE_INDEXED: for (x = tx; x < tx + ox; x++) { *row++ = 0xFF000000 diff --git a/IMG_xpm.c b/IMG_xpm.c index 3b498c8d..c2df08d8 100755 --- a/IMG_xpm.c +++ b/IMG_xpm.c @@ -1083,7 +1083,7 @@ static SDL_Surface *load_xpm(char **xpm, SDL_RWops *src) if (nametype == 's') continue; /* skip symbolic colour names */ - if (!color_to_rgb(colname, p - colname, &rgb)) + if (!color_to_rgb(colname, (int)(p - colname), &rgb)) continue; SDL_memcpy(nextkey, line, cpp);