SDL_image: IMG_png.c, miniz.h: fixed -Wunused-function warnings.

From 3830a38b5329836565118495cf70f85bdb19aa02 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 27 May 2022 14:11:10 +0300
Subject: [PATCH] IMG_png.c, miniz.h: fixed -Wunused-function warnings.

---
 IMG_png.c |  3 ++-
 miniz.h   | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/IMG_png.c b/IMG_png.c
index 451ecb33..b5c60827 100644
--- a/IMG_png.c
+++ b/IMG_png.c
@@ -695,6 +695,7 @@ static int IMG_SavePNG_RW_libpng(SDL_Surface *surface, SDL_RWops *dst, int freed
 #else
 #define MINIZ_LITTLE_ENDIAN 0
 #endif
+#define MINIZ_SDL_NOUNUSED
 #include "miniz.h"
 
 static int IMG_SavePNG_RW_miniz(SDL_Surface *surface, SDL_RWops *dst, int freedst)
@@ -718,7 +719,7 @@ static int IMG_SavePNG_RW_miniz(SDL_Surface *surface, SDL_RWops *dst, int freeds
             if (SDL_RWwrite(dst, png, size, 1)) {
                 result = 0;
             }
-            SDL_free(png);
+            mz_free(png); /* calls SDL_free() */
         } else {
             IMG_SetError("Failed to convert and save image");
         }
diff --git a/miniz.h b/miniz.h
index d22f0ca3..5af30f65 100644
--- a/miniz.h
+++ b/miniz.h
@@ -172,6 +172,12 @@
 // The current downside is the times written to your archives will be from 1979.
 #define MINIZ_NO_TIME
 
+// Define MINIZ_NO_DEFLATE_APIS to disable all compression API's.
+//#define MINIZ_NO_DEFLATE_APIS
+
+// Define MINIZ_NO_INFLATE_APIS to disable all decompression API's.
+#define MINIZ_NO_INFLATE_APIS
+
 // Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's.
 #define MINIZ_NO_ARCHIVE_APIS
 
@@ -191,6 +197,14 @@
 //#define MINIZ_NO_MALLOC
 #define MINIZ_SDL_MALLOC
 
+#ifdef MINIZ_NO_INFLATE_APIS
+#define MINIZ_NO_ARCHIVE_APIS
+#endif
+
+#ifdef MINIZ_NO_DEFLATE_APIS
+#define MINIZ_NO_ARCHIVE_WRITING_APIS
+#endif
+
 // Define MINIZ_STATIC_FUNCTIONS to make all functions static. You probably
 // want this if you're using miniz in a library
 #define MINIZ_STATIC_FUNCTIONS
@@ -315,6 +329,8 @@ typedef mz_stream *mz_streamp;
 // Returns the version string of miniz.c.
 MINIZ_STATIC const char *mz_version(void);
 
+#ifndef MINIZ_NO_DEFLATE_APIS
+
 // mz_deflateInit() initializes a compressor with default options:
 // Parameters:
 //  pStream must point to an initialized mz_stream struct.
@@ -367,6 +383,10 @@ MINIZ_STATIC int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const u
 // mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress().
 MINIZ_STATIC mz_ulong mz_compressBound(mz_ulong source_len);
 
+#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
+
+#ifndef MINIZ_NO_INFLATE_APIS
+
 // Initializes a decompressor.
 MINIZ_STATIC int mz_inflateInit(mz_streamp pStream);
 
@@ -396,6 +416,7 @@ MINIZ_STATIC int mz_inflateEnd(mz_streamp pStream);
 // Single-call decompression.
 // Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure.
 MINIZ_STATIC int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
+#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
 
 // Returns a string description of the specified error code, or NULL if the error code is invalid.
 MINIZ_STATIC const char *mz_error(int err);
@@ -446,6 +467,7 @@ MINIZ_STATIC const char *mz_error(int err);
   #define free_func             mz_free_func
   #define internal_state        mz_internal_state
   #define z_stream              mz_stream
+#ifndef MINIZ_NO_DEFLATE_APIS
   #define deflateInit           mz_deflateInit
   #define deflateInit2          mz_deflateInit2
   #define deflateReset          mz_deflateReset
@@ -455,11 +477,15 @@ MINIZ_STATIC const char *mz_error(int err);
   #define compress              mz_compress
   #define compress2             mz_compress2
   #define compressBound         mz_compressBound
+#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
+
+#ifndef MINIZ_NO_INFLATE_APIS
   #define inflateInit           mz_inflateInit
   #define inflateInit2          mz_inflateInit2
   #define inflate               mz_inflate
   #define inflateEnd            mz_inflateEnd
   #define uncompress            mz_uncompress
+#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
   #define crc32                 mz_crc32
   #define adler32               mz_adler32
   #define MAX_WBITS             15
@@ -692,6 +718,7 @@ MINIZ_STATIC void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename
 #endif // #ifndef MINIZ_NO_ARCHIVE_APIS
 
 // ------------------- Low-level Decompression API Definitions
+#ifndef MINIZ_NO_INFLATE_APIS
 
 // Decompression flags used by tinfl_decompress().
 // TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream.
@@ -783,8 +810,10 @@ struct tinfl_decompressor_tag
   tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
   mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
 };
+#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
 
 // ------------------- Low-level Compression API Definitions
+#ifndef MINIZ_NO_DEFLATE_APIS
 
 // Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently).
 #define TDEFL_LESS_MEMORY 0
@@ -817,6 +846,7 @@ enum
   TDEFL_FORCE_ALL_RAW_BLOCKS          = 0x80000
 };
 
+#ifndef MINIZ_SDL_NOUNUSED
 // High level compression functions:
 // tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc().
 // On entry:
@@ -831,6 +861,7 @@ MINIZ_STATIC void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_b
 // tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory.
 // Returns 0 on failure.
 MINIZ_STATIC size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags);
+#endif /* MINIZ_SDL_NOUNUSED */
 
 // Compresses an image to a compressed PNG file in memory.
 // On entry:
@@ -848,8 +879,10 @@ MINIZ_STATIC void *tdefl_write_image_to_png_file_in_memory(const void *pImage, i
 // Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
 typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
 
+#ifndef MINIZ_SDL_NOUNUSED
 // tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally.
 MINIZ_STATIC mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
+#endif
 
 //enum { TDEFL_MAX_HUFF_TABLES = 3, TDEFL_MAX_HUFF_SYMBOLS_0 = 288, TDEFL_MAX_HUFF_SYMBOLS_1 = 32, TDEFL_MAX_HUFF_SYMBOLS_2 = 19, TDEFL_LZ_DICT_SIZE = 32768, TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, TDEFL_MIN_MATCH_LEN = 3, TDEFL_MAX_MATCH_LEN = 258 };
 #define TDEFL_MAX_HUFF_TABLES	3
@@ -928,8 +961,10 @@ MINIZ_STATIC tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_bu
 // tdefl_compress_buffer() always consumes the entire input buffer.
 MINIZ_STATIC tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush);
 
+#ifndef MINIZ_SDL_NOUNUSED
 MINIZ_STATIC tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
 MINIZ_STATIC mz_uint32 tdefl_get_adler32(tdefl_compressor *d);
+#endif
 
 // Can't use tdefl_create_comp_flags_from_zip_params if MINIZ_NO_ZLIB_APIS isn't defined, because it uses some of its macros.
 #ifndef MINIZ_NO_ZLIB_APIS
@@ -940,6 +975,8 @@ MINIZ_STATIC mz_uint32 tdefl_get_adler32(tdefl_compressor *d);
 MINIZ_STATIC mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
 #endif // #ifndef MINIZ_NO_ZLIB_APIS
 
+#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
+
 #ifdef __cplusplus
 }
 #endif
@@ -1050,6 +1087,8 @@ const char *mz_version(void)
   return MZ_VERSION;
 }
 
+#ifndef MINIZ_NO_DEFLATE_APIS
+
 int mz_deflateInit(mz_streamp pStream, int level)
 {
   return mz_deflateInit2(pStream, level, MZ_DEFLATED, MZ_DEFAULT_WINDOW_BITS, 9, MZ_DEFAULT_STRATEGY);
@@ -1200,6 +1239,10 @@ mz_ulong mz_compressBound(mz_ulong source_len)
   return mz_deflateBound(NULL, source_len);
 }
 
+#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
+
+#ifndef MINIZ_NO_INFLATE_APIS
+
 typedef struct
 {
   tinfl_decompressor m_decomp;
@@ -1376,6 +1419,8 @@ int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char
   return mz_inflateEnd(&stream);
 }
 
+#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
+
 const char *mz_error(int err)
 {
   static struct { int m_err; const char *m_pDesc; } s_error_descs[] =
@@ -1390,6 +1435,7 @@ const char *mz_error(int err)
 #endif //MINIZ_NO_ZLIB_APIS
 
 // ------------------- Low-level Decompression (completely independent from all compression API's)
+#ifndef MINIZ_NO_INFLATE_APIS
 
 #define TINFL_MEMCPY(d, s, l) memcpy(d, s, l)
 #define TINFL_MEMSET(p, c, l) memset(p, c, l)
@@ -1798,8 +1844,10 @@ int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size,
   *pIn_buf_size = in_buf_ofs;
   return result;
 }
+#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
 
 // ------------------- Low-level Compression (independent from all decompression API's)
+#ifndef MINIZ_NO_DEFLATE_APIS
 
 // Purposely making these tables static for faster init and thread safety.
 static const mz_uint16 s_tdefl_len_sym[256] = {
@@ -2754,6 +2802,7 @@ tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_fun
   return TDEFL_STATUS_OKAY;
 }
 
+#ifndef MINIZ_SDL_NOUNUSED
 tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d)
 {
   return d->m_prev_return_status;
@@ -2772,6 +2821,7 @@ mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put
   succeeded = succeeded && (tdefl_compress_buffer(pComp, pBuf, buf_len, TDEFL_FINISH) == TDEFL_STATUS_DONE);
   MZ_FREE(pComp); return succeeded;
 }
+#endif /* MINIZ_SDL_NOUNUSED */
 
 typedef struct
 {
@@ -2795,6 +2845,7 @@ static mz_bool tdefl_output_buffer_putter(const void *pBuf, int len, void *pUser
   return MZ_TRUE;
 }
 
+#ifndef MINIZ_SDL_NOUNUSED
 void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
 {
   tdefl_output_buffer out_buf; MZ_CLEAR_OBJ(out_buf);
@@ -2812,6 +2863,7 @@ size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void
   if (!tdefl_compress_mem_to_output(pSrc_buf, src_buf_len, tdefl_output_buffer_putter, &out_buf, flags)) return 0;
   return out_buf.m_size;
 }
+#endif /* MINIZ_SDL_NOUNUSED */
 
 #ifndef MINIZ_NO_ZLIB_APIS
 static const mz_uint s_tdefl_num_probes[11] = { 0, 1, 6, 32,  16, 32, 128, 256,  512, 768, 1500 };
@@ -2899,6 +2951,7 @@ MINIZ_STATIC void *tdefl_write_image_to_png_file_in_memory(const void *pImage, i
 #ifdef _MSC_VER
 #pragma warning (pop)
 #endif
+#endif /*#ifndef MINIZ_NO_DEFLATE_APIS*/
 
 // ------------------- .ZIP archive reading