From 53f44acad409fe14b43116e2d9a186cc4daee4c7 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 4 Nov 2017 17:06:54 -0700 Subject: [PATCH] Fixed bug 3941 - SDL2_image sqrtf missing when building with SVG support on Linux Use SDL's C runtime functions instead of system functions to minimize dependencies. This requires the latest prerelease version of SDL, which adds some needed math functions. --- IMG_png.c | 9 +++++++++ IMG_svg.c | 28 +++++++++++++++++++++++++++- IMG_xcf.c | 6 +++--- Makefile.in | 6 ++++-- configure | 2 +- configure.in | 2 +- miniz.h | 17 ++++++----------- nanosvg.h | 2 ++ showimage.c | 6 +++--- 9 files changed, 56 insertions(+), 22 deletions(-) diff --git a/IMG_png.c b/IMG_png.c index a2795465..82af359b 100755 --- a/IMG_png.c +++ b/IMG_png.c @@ -598,6 +598,15 @@ static int IMG_SavePNG_RW_libpng(SDL_Surface *surface, SDL_RWops *dst, int freed #endif /* USE_LIBPNG */ +/* Replace C runtime functions with SDL C runtime functions for building on Windows */ +#define MINIZ_NO_STDIO +#define MINIZ_NO_TIME +#define MINIZ_SDL_MALLOC +#define MZ_ASSERT(x) SDL_assert(x) +#undef memset +#define memset SDL_memset +#define strlen SDL_strlen + #include "miniz.h" static int IMG_SavePNG_RW_miniz(SDL_Surface *surface, SDL_RWops *dst, int freedst) diff --git a/IMG_svg.c b/IMG_svg.c index a9beca08..1dd2324f 100755 --- a/IMG_svg.c +++ b/IMG_svg.c @@ -28,11 +28,37 @@ #ifdef LOAD_SVG /* Replace C runtime functions with SDL C runtime functions for building on Windows */ -#define strtoll SDL_strtoll +#define acosf SDL_acosf +#define atan2f SDL_atan2f +#define cosf SDL_cosf +#define fmodf SDL_fmodf +#define free SDL_free +#define malloc SDL_malloc +#undef memcpy +#define memcpy SDL_memcpy +#undef memset +#define memset SDL_memset +#define pow SDL_pow +#define qsort SDL_qsort +#define realloc SDL_realloc +#define sinf SDL_sinf +#define sqrt SDL_sqrt +#define sqrtf SDL_sqrtf #define sscanf SDL_sscanf +#define strchr SDL_strchr +#define strcmp SDL_strcmp +#define strncmp SDL_strncmp +#undef strncpy +#define strncpy SDL_strlcpy +#define strlen SDL_strlen +#define strstr SDL_strstr +#define strtol SDL_strtol +#define strtoll SDL_strtoll +#define tanf SDL_tanf #ifndef FLT_MAX #define FLT_MAX 3.402823466e+38F #endif +#undef HAVE_STDIO_H #define NANOSVG_IMPLEMENTATION #include "nanosvg.h" diff --git a/IMG_xcf.c b/IMG_xcf.c index f83f6ed7..2c6f6d75 100755 --- a/IMG_xcf.c +++ b/IMG_xcf.c @@ -633,7 +633,7 @@ do_layer_surface(SDL_Surface * surface, SDL_RWops * src, xcf_header * head, xcf_ } break; default: - fprintf(stderr, "Unknown Gimp image type (%d)\n", head->image_type); + SDL_Log("Unknown Gimp image type (%d)\n", head->image_type); if (hierarchy) { if (hierarchy->level_file_offsets) SDL_free(hierarchy->level_file_offsets); @@ -667,7 +667,7 @@ do_layer_surface(SDL_Surface * surface, SDL_RWops * src, xcf_header * head, xcf_ } break; default: - fprintf(stderr, "Unknown Gimp image type (%d)\n", head->image_type); + SDL_Log("Unknown Gimp image type (%d)\n", head->image_type); if (tile) free_xcf_tile(tile); if (level) @@ -733,7 +733,7 @@ SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src) load_tile = load_xcf_tile_rle; break; default: - fprintf (stderr, "Unsupported Compression.\n"); + SDL_Log("Unsupported Compression.\n"); free_xcf_header (head); return NULL; } diff --git a/Makefile.in b/Makefile.in index 7ada8ce9..9f10d670 100644 --- a/Makefile.in +++ b/Makefile.in @@ -141,7 +141,7 @@ am__DEPENDENCIES_1 = am__libSDL2_image_la_SOURCES_DIST = IMG.c IMG_bmp.c IMG_gif.c \ IMG_jpg.c IMG_lbm.c IMG_pcx.c IMG_png.c IMG_pnm.c IMG_svg.c \ IMG_tga.c IMG_tif.c IMG_xcf.c IMG_xpm.c IMG_xv.c IMG_webp.c \ - IMG_ImageIO.m miniz.h + IMG_ImageIO.m miniz.h nanosvg.h nanosvgrast.h @USE_IMAGEIO_TRUE@am__objects_1 = IMG_ImageIO.lo am_libSDL2_image_la_OBJECTS = IMG.lo IMG_bmp.lo IMG_gif.lo IMG_jpg.lo \ IMG_lbm.lo IMG_pcx.lo IMG_png.lo IMG_pnm.lo IMG_svg.lo \ @@ -419,7 +419,9 @@ libSDL2_image_la_SOURCES = \ IMG_xv.c \ IMG_webp.c \ $(IMAGEIO_SOURCE) \ - miniz.h + miniz.h \ + nanosvg.h \ + nanosvgrast.h EXTRA_DIST = \ Android.mk \ diff --git a/configure b/configure index 4ccc471b..e3ee70e8 100755 --- a/configure +++ b/configure @@ -12236,7 +12236,7 @@ find_lib() done } -SDL_VERSION=2.0.0 +SDL_VERSION=2.0.8 diff --git a/configure.in b/configure.in index 690836fb..e22f4bef 100644 --- a/configure.in +++ b/configure.in @@ -113,7 +113,7 @@ find_lib() } dnl Check for SDL -SDL_VERSION=2.0.0 +SDL_VERSION=2.0.8 AC_SUBST(SDL_VERSION) AM_PATH_SDL2($SDL_VERSION, :, diff --git a/miniz.h b/miniz.h index 1df067d4..93c59830 100644 --- a/miniz.h +++ b/miniz.h @@ -159,7 +159,7 @@ #ifndef MINIZ_HEADER_INCLUDED #define MINIZ_HEADER_INCLUDED -#include +/*#include */ // Defines to completely disable specific portions of miniz.c: // If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl. @@ -944,17 +944,12 @@ typedef unsigned char mz_validate_uint16[sizeof(mz_uint16)==2 ? 1 : -1]; typedef unsigned char mz_validate_uint32[sizeof(mz_uint32)==4 ? 1 : -1]; typedef unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 : -1]; -#include -#include - -// Defines to remove C runtime dependency -#undef memset -#define memset SDL_memset -#undef memcpy -#define memcpy SDL_memcpy +/*#include */ -//#define MZ_ASSERT(x) assert(x) -#define MZ_ASSERT(x) SDL_assert(x) +#ifndef MZ_ASSERT +#include +#define MZ_ASSERT(x) assert(x) +#endif #ifdef MINIZ_NO_MALLOC #define MZ_MALLOC(x) NULL diff --git a/nanosvg.h b/nanosvg.h index 7408354e..ec49eb7e 100755 --- a/nanosvg.h +++ b/nanosvg.h @@ -178,9 +178,11 @@ void nsvgDelete(NSVGimage* image); #ifdef NANOSVG_IMPLEMENTATION +/* #include #include #include +*/ #define NSVG_PI (3.14159265358979323846264338327f) #define NSVG_KAPPA90 (0.5522847493f) // Length proportional to radius of a cubic bezier handle for 90deg arcs. diff --git a/showimage.c b/showimage.c index 79934ed3..d3facdf4 100644 --- a/showimage.c +++ b/showimage.c @@ -70,7 +70,7 @@ int main(int argc, char *argv[]) flags = SDL_WINDOW_HIDDEN; for ( i=1; argv[i]; ++i ) { - if ( strcmp(argv[i], "-fullscreen") == 0 ) { + if ( SDL_strcmp(argv[i], "-fullscreen") == 0 ) { SDL_ShowCursor(0); flags |= SDL_WINDOW_FULLSCREEN; } @@ -87,11 +87,11 @@ int main(int argc, char *argv[]) } for ( i=1; argv[i]; ++i ) { - if ( strcmp(argv[i], "-fullscreen") == 0 ) { + if ( SDL_strcmp(argv[i], "-fullscreen") == 0 ) { continue; } - if ( strcmp(argv[i], "-save") == 0 && argv[i+1] ) { + if ( SDL_strcmp(argv[i], "-save") == 0 && argv[i+1] ) { ++i; saveFile = argv[i]; continue;