dhewm3/neo/renderer/stblib_impls.c
Daniel Gibson e8b8f5c02d Always optimize code of some integrated libraries, even in Debug builds
the stb libs, miniz and minizip are now always optimized to speed up
performance, esp. level loading times, in debug builds.

So far the stb libs implementation were dragged into the source file
that uses them, now I created additional source files just for them so
those can be optimized while the engine source files using those libs
can remain unoptimized in debug builds.
2024-06-05 21:40:59 +02:00

40 lines
1.4 KiB
C

// this source file includes the implementations of stb_image and stb_image_write
// having it in a separate source file allows optimizing it in debug builds (for faster load times)
// without hurting the debugability of the source files stb_image(_write) is used in
// include this first, otherwise build breaks because of use_idStr_* #defines in Str.h
#if defined(__APPLE__) && !defined(__clang__) && defined(__GNUC__) && __GNUC__ < 5
// Extra-Hack for ancient GCC 4.2-based Apple compilers that don't support __thread
#define STBI_NO_THREAD_LOCALS
#endif
#define STB_IMAGE_IMPLEMENTATION
#define STBI_NO_HDR
#define STBI_NO_LINEAR
#define STBI_ONLY_JPEG // at least for now, only use it for JPEG
#define STBI_NO_STDIO // images are passed as buffers
#include "stb_image.h"
#include "framework/miniz/miniz.h"
static unsigned char* compress_for_stbiw(unsigned char* data, int data_len, int* out_len, int quality)
{
uLongf bufSize = compressBound(data_len);
// note that buf will be free'd by stb_image_write.h
// with STBIW_FREE() (plain free() by default)
unsigned char* buf = (unsigned char*)malloc(bufSize);
if (buf == NULL) return NULL;
if (compress2(buf, &bufSize, data, data_len, quality) != Z_OK)
{
free(buf);
return NULL;
}
*out_len = bufSize;
return buf;
}
#define STB_IMAGE_WRITE_IMPLEMENTATION
#define STBIW_ZLIB_COMPRESS compress_for_stbiw
#include "stb_image_write.h"