From 0cc80741566ace1747d85bf268198536c61904be Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 9 Jan 2026 03:44:55 +0300
Subject: [PATCH] define our own libpng_get_uint_32() macro, use it instead of
png_get_uint_32()
for better compatibility across libpng versions
---
src/IMG_libpng.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/IMG_libpng.c b/src/IMG_libpng.c
index fa5ca4e7..80274a91 100644
--- a/src/IMG_libpng.c
+++ b/src/IMG_libpng.c
@@ -179,6 +179,12 @@ static struct
void (*png_write_flush)(png_structrp png_ptr);
} lib;
+#define libpng_get_uint_32(buf) \
+ (((png_uint_32)( *(buf) ) << 24) + \
+ ((png_uint_32)(*((buf) + 1)) << 16) + \
+ ((png_uint_32)(*((buf) + 2)) << 8) + \
+ ((png_uint_32)(*((buf) + 3))))
+
#ifdef LOAD_LIBPNG_DYNAMIC
#define FUNCTION_LOADER_LIBPNG(FUNC, SIG) \
lib.FUNC = (SIG)SDL_LoadFunction(lib.handle_libpng, #FUNC); \
@@ -1730,7 +1736,7 @@ static png_bytep compress_surface_to_png_data(CompressionContext *context, SDL_S
break;
}
SDL_memcpy(context->chunk_header, context->mem_buffer_ptr + context->current_pos, 8);
- context->chunk_len = png_get_uint_32(context->chunk_header);
+ context->chunk_len = libpng_get_uint_32(context->chunk_header);
SDL_memcpy(context->chunk_type, context->chunk_header + 4, 4);
context->current_pos += 8;