Skip to content

Commit

Permalink
Fixed bug 3941 - SDL2_image sqrtf missing when building with SVG supp…
Browse files Browse the repository at this point in the history
…ort 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.
  • Loading branch information
slouken committed Nov 5, 2017
1 parent 76e2c95 commit 53f44ac
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 22 deletions.
9 changes: 9 additions & 0 deletions IMG_png.c
Expand Up @@ -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)
Expand Down
28 changes: 27 additions & 1 deletion IMG_svg.c
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions IMG_xcf.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 4 additions & 2 deletions Makefile.in
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion configure
Expand Up @@ -12236,7 +12236,7 @@ find_lib()
done
}

SDL_VERSION=2.0.0
SDL_VERSION=2.0.8



Expand Down
2 changes: 1 addition & 1 deletion configure.in
Expand Up @@ -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,
:,
Expand Down
17 changes: 6 additions & 11 deletions miniz.h
Expand Up @@ -159,7 +159,7 @@
#ifndef MINIZ_HEADER_INCLUDED
#define MINIZ_HEADER_INCLUDED

#include <stdlib.h>
/*#include <stdlib.h>*/

// 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.
Expand Down Expand Up @@ -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 <string.h>
#include <assert.h>

// Defines to remove C runtime dependency
#undef memset
#define memset SDL_memset
#undef memcpy
#define memcpy SDL_memcpy
/*#include <string.h>*/

//#define MZ_ASSERT(x) assert(x)
#define MZ_ASSERT(x) SDL_assert(x)
#ifndef MZ_ASSERT
#include <assert.h>
#define MZ_ASSERT(x) assert(x)
#endif

#ifdef MINIZ_NO_MALLOC
#define MZ_MALLOC(x) NULL
Expand Down
2 changes: 2 additions & 0 deletions nanosvg.h
Expand Up @@ -178,9 +178,11 @@ void nsvgDelete(NSVGimage* image);

#ifdef NANOSVG_IMPLEMENTATION

/*
#include <string.h>
#include <stdlib.h>
#include <math.h>
*/

#define NSVG_PI (3.14159265358979323846264338327f)
#define NSVG_KAPPA90 (0.5522847493f) // Length proportional to radius of a cubic bezier handle for 90deg arcs.
Expand Down
6 changes: 3 additions & 3 deletions showimage.c
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down

0 comments on commit 53f44ac

Please sign in to comment.