Fixed bug 3941 - SDL2_image sqrtf missing when building with SVG support on Linux
authorSam Lantinga <slouken@libsdl.org>
Sat, 04 Nov 2017 17:06:54 -0700
changeset 5456ea5a39bf73a
parent 544 a2302a9c20ab
child 546 25feccc8964d
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
IMG_svg.c
IMG_xcf.c
Makefile.in
configure
configure.in
miniz.h
nanosvg.h
showimage.c
     1.1 --- a/IMG_png.c	Mon Oct 23 12:40:19 2017 -0700
     1.2 +++ b/IMG_png.c	Sat Nov 04 17:06:54 2017 -0700
     1.3 @@ -598,6 +598,15 @@
     1.4  
     1.5  #endif /* USE_LIBPNG */
     1.6  
     1.7 +/* Replace C runtime functions with SDL C runtime functions for building on Windows */
     1.8 +#define MINIZ_NO_STDIO
     1.9 +#define MINIZ_NO_TIME
    1.10 +#define MINIZ_SDL_MALLOC
    1.11 +#define MZ_ASSERT(x) SDL_assert(x)
    1.12 +#undef memset
    1.13 +#define memset	SDL_memset
    1.14 +#define strlen	SDL_strlen
    1.15 +
    1.16  #include "miniz.h"
    1.17  
    1.18  static int IMG_SavePNG_RW_miniz(SDL_Surface *surface, SDL_RWops *dst, int freedst)
     2.1 --- a/IMG_svg.c	Mon Oct 23 12:40:19 2017 -0700
     2.2 +++ b/IMG_svg.c	Sat Nov 04 17:06:54 2017 -0700
     2.3 @@ -28,11 +28,37 @@
     2.4  #ifdef LOAD_SVG
     2.5  
     2.6  /* Replace C runtime functions with SDL C runtime functions for building on Windows */
     2.7 +#define acosf   SDL_acosf
     2.8 +#define atan2f  SDL_atan2f
     2.9 +#define cosf    SDL_cosf
    2.10 +#define fmodf   SDL_fmodf
    2.11 +#define free    SDL_free
    2.12 +#define malloc  SDL_malloc
    2.13 +#undef memcpy
    2.14 +#define memcpy  SDL_memcpy
    2.15 +#undef memset
    2.16 +#define memset  SDL_memset
    2.17 +#define pow     SDL_pow
    2.18 +#define qsort   SDL_qsort
    2.19 +#define realloc SDL_realloc
    2.20 +#define sinf    SDL_sinf
    2.21 +#define sqrt    SDL_sqrt
    2.22 +#define sqrtf   SDL_sqrtf
    2.23 +#define sscanf  SDL_sscanf
    2.24 +#define strchr  SDL_strchr
    2.25 +#define strcmp  SDL_strcmp
    2.26 +#define strncmp SDL_strncmp
    2.27 +#undef strncpy
    2.28 +#define strncpy SDL_strlcpy
    2.29 +#define strlen  SDL_strlen
    2.30 +#define strstr  SDL_strstr
    2.31 +#define strtol  SDL_strtol
    2.32  #define strtoll SDL_strtoll
    2.33 -#define sscanf  SDL_sscanf
    2.34 +#define tanf    SDL_tanf
    2.35  #ifndef FLT_MAX
    2.36  #define FLT_MAX     3.402823466e+38F
    2.37  #endif
    2.38 +#undef HAVE_STDIO_H
    2.39  
    2.40  #define NANOSVG_IMPLEMENTATION
    2.41  #include "nanosvg.h"
     3.1 --- a/IMG_xcf.c	Mon Oct 23 12:40:19 2017 -0700
     3.2 +++ b/IMG_xcf.c	Sat Nov 04 17:06:54 2017 -0700
     3.3 @@ -633,7 +633,7 @@
     3.4                          }
     3.5                          break;
     3.6                      default:
     3.7 -                        fprintf(stderr, "Unknown Gimp image type (%d)\n", head->image_type);
     3.8 +                        SDL_Log("Unknown Gimp image type (%d)\n", head->image_type);
     3.9                          if (hierarchy) {
    3.10                              if (hierarchy->level_file_offsets)
    3.11                                  SDL_free(hierarchy->level_file_offsets);
    3.12 @@ -667,7 +667,7 @@
    3.13                          }
    3.14                          break;
    3.15                      default:
    3.16 -                        fprintf(stderr, "Unknown Gimp image type (%d)\n", head->image_type);
    3.17 +                        SDL_Log("Unknown Gimp image type (%d)\n", head->image_type);
    3.18                          if (tile)
    3.19                              free_xcf_tile(tile);
    3.20                          if (level)
    3.21 @@ -733,7 +733,7 @@
    3.22      load_tile = load_xcf_tile_rle;
    3.23      break;
    3.24    default:
    3.25 -    fprintf (stderr, "Unsupported Compression.\n");
    3.26 +    SDL_Log("Unsupported Compression.\n");
    3.27      free_xcf_header (head);
    3.28      return NULL;
    3.29    }
     4.1 --- a/Makefile.in	Mon Oct 23 12:40:19 2017 -0700
     4.2 +++ b/Makefile.in	Sat Nov 04 17:06:54 2017 -0700
     4.3 @@ -141,7 +141,7 @@
     4.4  am__libSDL2_image_la_SOURCES_DIST = IMG.c IMG_bmp.c IMG_gif.c \
     4.5  	IMG_jpg.c IMG_lbm.c IMG_pcx.c IMG_png.c IMG_pnm.c IMG_svg.c \
     4.6  	IMG_tga.c IMG_tif.c IMG_xcf.c IMG_xpm.c IMG_xv.c IMG_webp.c \
     4.7 -	IMG_ImageIO.m miniz.h
     4.8 +	IMG_ImageIO.m miniz.h nanosvg.h nanosvgrast.h
     4.9  @USE_IMAGEIO_TRUE@am__objects_1 = IMG_ImageIO.lo
    4.10  am_libSDL2_image_la_OBJECTS = IMG.lo IMG_bmp.lo IMG_gif.lo IMG_jpg.lo \
    4.11  	IMG_lbm.lo IMG_pcx.lo IMG_png.lo IMG_pnm.lo IMG_svg.lo \
    4.12 @@ -419,7 +419,9 @@
    4.13  	IMG_xv.c		\
    4.14  	IMG_webp.c		\
    4.15  	$(IMAGEIO_SOURCE)	\
    4.16 -	miniz.h
    4.17 +	miniz.h			\
    4.18 +	nanosvg.h		\
    4.19 +	nanosvgrast.h
    4.20  
    4.21  EXTRA_DIST = \
    4.22  	Android.mk		\
     5.1 --- a/configure	Mon Oct 23 12:40:19 2017 -0700
     5.2 +++ b/configure	Sat Nov 04 17:06:54 2017 -0700
     5.3 @@ -12236,7 +12236,7 @@
     5.4      done
     5.5  }
     5.6  
     5.7 -SDL_VERSION=2.0.0
     5.8 +SDL_VERSION=2.0.8
     5.9  
    5.10  
    5.11  
     6.1 --- a/configure.in	Mon Oct 23 12:40:19 2017 -0700
     6.2 +++ b/configure.in	Sat Nov 04 17:06:54 2017 -0700
     6.3 @@ -113,7 +113,7 @@
     6.4  }
     6.5  
     6.6  dnl Check for SDL
     6.7 -SDL_VERSION=2.0.0
     6.8 +SDL_VERSION=2.0.8
     6.9  AC_SUBST(SDL_VERSION)
    6.10  AM_PATH_SDL2($SDL_VERSION,
    6.11              :,
     7.1 --- a/miniz.h	Mon Oct 23 12:40:19 2017 -0700
     7.2 +++ b/miniz.h	Sat Nov 04 17:06:54 2017 -0700
     7.3 @@ -159,7 +159,7 @@
     7.4  #ifndef MINIZ_HEADER_INCLUDED
     7.5  #define MINIZ_HEADER_INCLUDED
     7.6  
     7.7 -#include <stdlib.h>
     7.8 +/*#include <stdlib.h>*/
     7.9  
    7.10  // Defines to completely disable specific portions of miniz.c:
    7.11  // If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl.
    7.12 @@ -944,17 +944,12 @@
    7.13  typedef unsigned char mz_validate_uint32[sizeof(mz_uint32)==4 ? 1 : -1];
    7.14  typedef unsigned char mz_validate_uint64[sizeof(mz_uint64)==8 ? 1 : -1];
    7.15  
    7.16 -#include <string.h>
    7.17 +/*#include <string.h>*/
    7.18 +
    7.19 +#ifndef MZ_ASSERT
    7.20  #include <assert.h>
    7.21 -
    7.22 -// Defines to remove C runtime dependency
    7.23 -#undef memset
    7.24 -#define memset SDL_memset
    7.25 -#undef memcpy
    7.26 -#define memcpy SDL_memcpy
    7.27 -
    7.28 -//#define MZ_ASSERT(x) assert(x)
    7.29 -#define MZ_ASSERT(x) SDL_assert(x)
    7.30 +#define MZ_ASSERT(x) assert(x)
    7.31 +#endif
    7.32  
    7.33  #ifdef MINIZ_NO_MALLOC
    7.34    #define MZ_MALLOC(x) NULL
     8.1 --- a/nanosvg.h	Mon Oct 23 12:40:19 2017 -0700
     8.2 +++ b/nanosvg.h	Sat Nov 04 17:06:54 2017 -0700
     8.3 @@ -178,9 +178,11 @@
     8.4  
     8.5  #ifdef NANOSVG_IMPLEMENTATION
     8.6  
     8.7 +/*
     8.8  #include <string.h>
     8.9  #include <stdlib.h>
    8.10  #include <math.h>
    8.11 +*/
    8.12  
    8.13  #define NSVG_PI (3.14159265358979323846264338327f)
    8.14  #define NSVG_KAPPA90 (0.5522847493f)	// Length proportional to radius of a cubic bezier handle for 90deg arcs.
     9.1 --- a/showimage.c	Mon Oct 23 12:40:19 2017 -0700
     9.2 +++ b/showimage.c	Sat Nov 04 17:06:54 2017 -0700
     9.3 @@ -70,7 +70,7 @@
     9.4  
     9.5      flags = SDL_WINDOW_HIDDEN;
     9.6      for ( i=1; argv[i]; ++i ) {
     9.7 -        if ( strcmp(argv[i], "-fullscreen") == 0 ) {
     9.8 +        if ( SDL_strcmp(argv[i], "-fullscreen") == 0 ) {
     9.9              SDL_ShowCursor(0);
    9.10              flags |= SDL_WINDOW_FULLSCREEN;
    9.11          }
    9.12 @@ -87,11 +87,11 @@
    9.13      }
    9.14  
    9.15      for ( i=1; argv[i]; ++i ) {
    9.16 -        if ( strcmp(argv[i], "-fullscreen") == 0 ) {
    9.17 +        if ( SDL_strcmp(argv[i], "-fullscreen") == 0 ) {
    9.18              continue;
    9.19          }
    9.20  
    9.21 -        if ( strcmp(argv[i], "-save") == 0 && argv[i+1] ) {
    9.22 +        if ( SDL_strcmp(argv[i], "-save") == 0 && argv[i+1] ) {
    9.23              ++i;
    9.24              saveFile = argv[i];
    9.25              continue;