Skip to content

Commit

Permalink
TexMgr_Downsample : stb_image_resize routine uses internally-alocated…
Browse files Browse the repository at this point in the history
… memory, so plug our allocators in

(plus some cosmetic re-arrangements in STB-related config in image.c, for redability)
  • Loading branch information
vsonnier committed Jun 28, 2024
1 parent 2eeb2c0 commit 1d92131
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
11 changes: 9 additions & 2 deletions Quake/gl_texmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,23 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "SDL.h"
#endif

#define STB_IMAGE_RESIZE_IMPLEMENTATION
#define STB_IMAGE_RESIZE_STATIC
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#elif defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable : 4505)
#endif

#define STB_IMAGE_RESIZE_IMPLEMENTATION
#define STB_IMAGE_RESIZE_STATIC
// STB_IMAGERESIZE config:
// plug our Mem_Alloc in stb_image_resize:
// use comma operator to evaluate c, to avoid "unused parameter" warnings
#define STBIR_MALLOC(sz, c) ((void)(c), Mem_Alloc (sz))
#define STBIR_FREE(p, c) ((void)(c), Mem_Free (p))
#include "stb_image_resize.h"

#if defined(__GNUC__)
#pragma GCC diagnostic pop
#elif defined(_MSC_VER)
Expand Down
25 changes: 12 additions & 13 deletions Quake/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static byte *Image_LoadPCX (FILE *f, int *width, int *height);
static byte *Image_LoadLMP (FILE *f, int *width, int *height);

#ifdef _MSC_VER
// Disable warning C4505: Unused functions
#pragma warning(push)
#pragma warning(disable : 4505)
#endif

#ifdef __GNUC__
// Suppress unused function warnings on GCC/clang
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#endif

// STB_IMAGE config:
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_STATIC
Expand All @@ -40,19 +52,6 @@ static byte *Image_LoadLMP (FILE *f, int *width, int *height);
#define STBI_MALLOC(sz) Mem_Alloc (sz)
#define STBI_REALLOC(p, newsz) Mem_Realloc (p, newsz)
#define STBI_FREE(p) Mem_Free (p)

#ifdef _MSC_VER
// Disable warning C4505: Unused functions
#pragma warning(push)
#pragma warning(disable : 4505)
#endif

#ifdef __GNUC__
// Suppress unused function warnings on GCC/clang
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#endif

#include "stb_image.h"

#ifdef __GNUC__
Expand Down

0 comments on commit 1d92131

Please sign in to comment.