SDL_image: Updated for SDL3 version changes

From c6aac6535805c113efc29edb1ad609647a060090 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 15 May 2024 12:34:05 -0700
Subject: [PATCH] Updated for SDL3 version changes

---
 .wikiheaders-options                          |  2 +-
 .../cmake/sdl3_image-config-version.cmake     |  8 ++---
 .../CMake/sdl3_image-config-version.cmake     |  8 ++---
 build-scripts/android-prefab.sh               |  4 +--
 build-scripts/test-versioning.sh              |  2 +-
 build-scripts/wikiheaders.pl                  | 12 +++----
 docs/release_checklist.md                     |  2 +-
 external/SDL                                  |  2 +-
 include/SDL3_image/SDL_image.h                | 35 ++++---------------
 src/IMG.c                                     | 26 +++++---------
 10 files changed, 35 insertions(+), 66 deletions(-)

diff --git a/.wikiheaders-options b/.wikiheaders-options
index 5019da39..1740a897 100644
--- a/.wikiheaders-options
+++ b/.wikiheaders-options
@@ -7,7 +7,7 @@ mainincludefname = SDL3_image/SDL_image.h
 versionfname = include/SDL3_image/SDL_image.h
 versionmajorregex = \A\#define\s+SDL_IMAGE_MAJOR_VERSION\s+(\d+)\Z
 versionminorregex = \A\#define\s+SDL_IMAGE_MINOR_VERSION\s+(\d+)\Z
-versionpatchregex = \A\#define\s+SDL_IMAGE_PATCHLEVEL\s+(\d+)\Z
+versionmicroregex = \A\#define\s+SDL_IMAGE_MICRO_VERSION\s+(\d+)\Z
 selectheaderregex = \ASDL_image\.h\Z
 projecturl = https://libsdl.org/projects/SDL_image
 wikiurl = https://wiki.libsdl.org/SDL_image
diff --git a/VisualC/pkg-support/cmake/sdl3_image-config-version.cmake b/VisualC/pkg-support/cmake/sdl3_image-config-version.cmake
index 1cbe1c73..7c01743e 100644
--- a/VisualC/pkg-support/cmake/sdl3_image-config-version.cmake
+++ b/VisualC/pkg-support/cmake/sdl3_image-config-version.cmake
@@ -13,10 +13,10 @@ string(REGEX MATCH "#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)" _sdl_maj
 set(_sdl_major "${CMAKE_MATCH_1}")
 string(REGEX MATCH "#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)" _sdl_minor_re "${_sdl_image_h}")
 set(_sdl_minor "${CMAKE_MATCH_1}")
-string(REGEX MATCH "#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)" _sdl_patch_re "${_sdl_image_h}")
-set(_sdl_patch "${CMAKE_MATCH_1}")
-if(_sdl_major_re AND _sdl_minor_re AND _sdl_patch_re)
-    set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_patch}")
+string(REGEX MATCH "#define[ \t]+SDL_IMAGE_MICRO_VERSION[ \t]+([0-9]+)" _sdl_micro_re "${_sdl_image_h}")
+set(_sdl_micro "${CMAKE_MATCH_1}")
+if(_sdl_major_re AND _sdl_minor_re AND _sdl_micro_re)
+    set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_micro}")
 else()
     message(AUTHOR_WARNING "Could not extract version from SDL_image.h.")
     return()
diff --git a/Xcode/pkg-support/resources/CMake/sdl3_image-config-version.cmake b/Xcode/pkg-support/resources/CMake/sdl3_image-config-version.cmake
index fa056a1c..cd3c96aa 100644
--- a/Xcode/pkg-support/resources/CMake/sdl3_image-config-version.cmake
+++ b/Xcode/pkg-support/resources/CMake/sdl3_image-config-version.cmake
@@ -13,10 +13,10 @@ string(REGEX MATCH "#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)" _sdl_maj
 set(_sdl_major "${CMAKE_MATCH_1}")
 string(REGEX MATCH "#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)" _sdl_minor_re "${_sdl_image_h}")
 set(_sdl_minor "${CMAKE_MATCH_1}")
-string(REGEX MATCH "#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)" _sdl_patch_re "${_sdl_image_h}")
-set(_sdl_patch "${CMAKE_MATCH_1}")
-if(_sdl_major_re AND _sdl_minor_re AND _sdl_patch_re)
-    set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_patch}")
+string(REGEX MATCH "#define[ \t]+SDL_IMAGE_MICRO_VERSION[ \t]+([0-9]+)" _sdl_micro_re "${_sdl_image_h}")
+set(_sdl_micro "${CMAKE_MATCH_1}")
+if(_sdl_major_re AND _sdl_minor_re AND _sdl_micro_re)
+    set(PACKAGE_VERSION "${_sdl_major}.${_sdl_minor}.${_sdl_micro}")
 else()
     message(AUTHOR_WARNING "Could not extract version from SDL_image.h.")
     return()
diff --git a/build-scripts/android-prefab.sh b/build-scripts/android-prefab.sh
index 33a60495..dec712c6 100755
--- a/build-scripts/android-prefab.sh
+++ b/build-scripts/android-prefab.sh
@@ -42,8 +42,8 @@ android_stl="c++_shared"
 
 sdlimage_major=$(sed -ne 's/^#define SDL_IMAGE_MAJOR_VERSION  *//p' "${sdlimage_root}/include/SDL3_image/SDL_image.h")
 sdlimage_minor=$(sed -ne 's/^#define SDL_IMAGE_MINOR_VERSION  *//p' "${sdlimage_root}/include/SDL3_image/SDL_image.h")
-sdlimage_patch=$(sed -ne 's/^#define SDL_IMAGE_PATCHLEVEL  *//p' "${sdlimage_root}/include/SDL3_image/SDL_image.h")
-sdlimage_version="${sdlimage_major}.${sdlimage_minor}.${sdlimage_patch}"
+sdlimage_micro=$(sed -ne 's/^#define SDL_IMAGE_MICRO_VERSION  *//p' "${sdlimage_root}/include/SDL3_image/SDL_image.h")
+sdlimage_version="${sdlimage_major}.${sdlimage_minor}.${sdlimage_micro}"
 echo "Building Android prefab package for SDL_image version $sdlimage_version"
 
 if test ! -d "${sdl_build_root}"; then
diff --git a/build-scripts/test-versioning.sh b/build-scripts/test-versioning.sh
index 66a25494..bc0e1ba6 100755
--- a/build-scripts/test-versioning.sh
+++ b/build-scripts/test-versioning.sh
@@ -12,7 +12,7 @@ export LC_CTYPE=C
 header=include/SDL3_image/SDL_image.h
 ref_major=$(sed -ne 's/^#define SDL_IMAGE_MAJOR_VERSION  *//p' $header)
 ref_minor=$(sed -ne 's/^#define SDL_IMAGE_MINOR_VERSION  *//p' $header)
-ref_micro=$(sed -ne 's/^#define SDL_IMAGE_PATCHLEVEL  *//p' $header)
+ref_micro=$(sed -ne 's/^#define SDL_IMAGE_MICRO_VERSION  *//p' $header)
 ref_version="${ref_major}.${ref_minor}.${ref_micro}"
 
 tests=0
diff --git a/build-scripts/wikiheaders.pl b/build-scripts/wikiheaders.pl
index 185701b4..050dd3cb 100755
--- a/build-scripts/wikiheaders.pl
+++ b/build-scripts/wikiheaders.pl
@@ -16,7 +16,7 @@
 my $versionfname = 'include/SDL_version.h';
 my $versionmajorregex = '\A\#define\s+SDL_MAJOR_VERSION\s+(\d+)\Z';
 my $versionminorregex = '\A\#define\s+SDL_MINOR_VERSION\s+(\d+)\Z';
-my $versionpatchregex = '\A\#define\s+SDL_PATCHLEVEL\s+(\d+)\Z';
+my $versionmicroregex = '\A\#define\s+SDL_MICRO_VERSION\s+(\d+)\Z';
 my $mainincludefname = 'SDL.h';
 my $selectheaderregex = '\ASDL.*?\.h\Z';
 my $projecturl = 'https://libsdl.org/';
@@ -92,7 +92,7 @@
             $readmesubdir = $val, next if $key eq 'readmesubdir';
             $versionmajorregex = $val, next if $key eq 'versionmajorregex';
             $versionminorregex = $val, next if $key eq 'versionminorregex';
-            $versionpatchregex = $val, next if $key eq 'versionpatchregex';
+            $versionmicroregex = $val, next if $key eq 'versionmicroregex';
             $versionfname = $val, next if $key eq 'versionfname';
             $mainincludefname = $val, next if $key eq 'mainincludefname';
             $selectheaderregex = $val, next if $key eq 'selectheaderregex';
@@ -2036,19 +2036,19 @@ sub print_undocumented_section {
     open(FH, '<', "$srcpath/$versionfname") or die("Can't open '$srcpath/$versionfname': $!\n");
     my $majorver = 0;
     my $minorver = 0;
-    my $patchver = 0;
+    my $microver = 0;
     while (<FH>) {
         chomp;
         if (/$versionmajorregex/) {
             $majorver = int($1);
         } elsif (/$versionminorregex/) {
             $minorver = int($1);
-        } elsif (/$versionpatchregex/) {
-            $patchver = int($1);
+        } elsif (/$versionmicroregex/) {
+            $microver = int($1);
         }
     }
     close(FH);
-    my $fullversion = "$majorver.$minorver.$patchver";
+    my $fullversion = "$majorver.$minorver.$microver";
 
     foreach (keys %headersyms) {
         my $sym = $_;
diff --git a/docs/release_checklist.md b/docs/release_checklist.md
index 189fd43b..f418c2bb 100644
--- a/docs/release_checklist.md
+++ b/docs/release_checklist.md
@@ -7,7 +7,7 @@
 * Bump version number to 3.EVEN.0 in all these locations:
 
     * `include/SDL3_image/SDL_image.h`:
-        `SDL_IMAGE_MAJOR_VERSION`, `SDL_IMAGE_MINOR_VERSION`, `SDL_IMAGE_PATCHLEVEL`
+        `SDL_IMAGE_MAJOR_VERSION`, `SDL_IMAGE_MINOR_VERSION`, `SDL_IMAGE_MICRO_VERSION`
     * `CMakeLists.txt`:
         `MAJOR_VERSION`, `MINOR_VERSION`, `MICRO_VERSION`
     * `src/version.rc`:
diff --git a/external/SDL b/external/SDL
index 863a9029..4b3b5fb5 160000
--- a/external/SDL
+++ b/external/SDL
@@ -1 +1 @@
-Subproject commit 863a9029ae50bd136e5144bc1ce2ea53a6b37ccc
+Subproject commit 4b3b5fb56c3aab094e431d3620d6cc36200430b8
diff --git a/include/SDL3_image/SDL_image.h b/include/SDL3_image/SDL_image.h
index 969633cb..4eb15d36 100644
--- a/include/SDL3_image/SDL_image.h
+++ b/include/SDL3_image/SDL_image.h
@@ -38,37 +38,17 @@ extern "C" {
 #endif
 
 /**
- * Printable format: "%d.%d.%d", MAJOR, MINOR, PATCHLEVEL
+ * Printable format: "%d.%d.%d", MAJOR, MINOR, MICRO
  */
 #define SDL_IMAGE_MAJOR_VERSION 3
 #define SDL_IMAGE_MINOR_VERSION 0
-#define SDL_IMAGE_PATCHLEVEL    0
-
-/**
- * This macro can be used to fill a version structure with the compile-time
- * version of the SDL_image library.
- */
-#define SDL_IMAGE_VERSION(X)                        \
-{                                                   \
-    (X)->major = SDL_IMAGE_MAJOR_VERSION;           \
-    (X)->minor = SDL_IMAGE_MINOR_VERSION;           \
-    (X)->patch = SDL_IMAGE_PATCHLEVEL;              \
-}
-
-#if SDL_IMAGE_MAJOR_VERSION < 3 && SDL_MAJOR_VERSION < 3
+#define SDL_IMAGE_MICRO_VERSION 0
 
 /**
  * This is the version number macro for the current SDL_image version.
- *
- * In versions higher than 2.9.0, the minor version overflows into the
- * thousands digit: for example, 2.23.0 is encoded as 4300. This macro will
- * not be available in SDL 3.x or SDL_image 3.x.
- *
- * Deprecated, use SDL_IMAGE_VERSION_ATLEAST or SDL_IMAGE_VERSION instead.
  */
-#define SDL_IMAGE_COMPILEDVERSION \
-    SDL_VERSIONNUM(SDL_IMAGE_MAJOR_VERSION, SDL_IMAGE_MINOR_VERSION, SDL_IMAGE_PATCHLEVEL)
-#endif /* SDL_IMAGE_MAJOR_VERSION < 3 && SDL_MAJOR_VERSION < 3 */
+#define SDL_IMAGE_VERSION \
+    SDL_VERSIONNUM(SDL_IMAGE_MAJOR_VERSION, SDL_IMAGE_MINOR_VERSION, SDL_IMAGE_MICRO_VERSION)
 
 /**
  * This macro will evaluate to true if compiled with SDL_image at least X.Y.Z.
@@ -76,17 +56,14 @@ extern "C" {
 #define SDL_IMAGE_VERSION_ATLEAST(X, Y, Z) \
     ((SDL_IMAGE_MAJOR_VERSION >= X) && \
      (SDL_IMAGE_MAJOR_VERSION > X || SDL_IMAGE_MINOR_VERSION >= Y) && \
-     (SDL_IMAGE_MAJOR_VERSION > X || SDL_IMAGE_MINOR_VERSION > Y || SDL_IMAGE_PATCHLEVEL >= Z))
+     (SDL_IMAGE_MAJOR_VERSION > X || SDL_IMAGE_MINOR_VERSION > Y || SDL_IMAGE_MICRO_VERSION >= Z))
 
 /**
  * This function gets the version of the dynamically linked SDL_image library.
  *
- * it should NOT be used to fill a version structure, instead you should use
- * the SDL_IMAGE_VERSION() macro.
- *
  * \returns SDL_image version
  */
-extern DECLSPEC const SDL_Version * SDLCALL IMG_Linked_Version(void);
+extern DECLSPEC int SDLCALL IMG_Version(void);
 
 /**
  * Initialization flags
diff --git a/src/IMG.c b/src/IMG.c
index 25a2a5e9..75f2249e 100644
--- a/src/IMG.c
+++ b/src/IMG.c
@@ -28,28 +28,22 @@
 #include <emscripten/emscripten.h>
 #endif
 
-#if defined(SDL_BUILD_MAJOR_VERSION) && defined(SDL_COMPILE_TIME_ASSERT)
+#if defined(SDL_BUILD_MAJOR_VERSION)
 SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MAJOR_VERSION,
                         SDL_IMAGE_MAJOR_VERSION == SDL_BUILD_MAJOR_VERSION);
 SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MINOR_VERSION,
                         SDL_IMAGE_MINOR_VERSION == SDL_BUILD_MINOR_VERSION);
 SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MICRO_VERSION,
-                        SDL_IMAGE_PATCHLEVEL == SDL_BUILD_MICRO_VERSION);
+                        SDL_IMAGE_MICRO_VERSION == SDL_BUILD_MICRO_VERSION);
 #endif
 
-#if defined(SDL_COMPILE_TIME_ASSERT)
+/* Limited by its encoding in SDL_VERSIONNUM */
 SDL_COMPILE_TIME_ASSERT(SDL_IMAGE_MAJOR_VERSION_min, SDL_IMAGE_MAJOR_VERSION >= 0);
-/* Limited only by the need to fit in SDL_Version */
-SDL_COMPILE_TIME_ASSERT(SDL_IMAGE_MAJOR_VERSION_max, SDL_IMAGE_MAJOR_VERSION <= 255);
-
+SDL_COMPILE_TIME_ASSERT(SDL_IMAGE_MAJOR_VERSION_max, SDL_IMAGE_MAJOR_VERSION <= 10);
 SDL_COMPILE_TIME_ASSERT(SDL_IMAGE_MINOR_VERSION_min, SDL_IMAGE_MINOR_VERSION >= 0);
-/* Limited only by the need to fit in SDL_Version */
-SDL_COMPILE_TIME_ASSERT(SDL_IMAGE_MINOR_VERSION_max, SDL_IMAGE_MINOR_VERSION <= 255);
-
-SDL_COMPILE_TIME_ASSERT(SDL_IMAGE_PATCHLEVEL_min, SDL_IMAGE_PATCHLEVEL >= 0);
-/* Limited by its encoding in SDL_VERSIONNUM and in the ABI versions */
-SDL_COMPILE_TIME_ASSERT(SDL_IMAGE_PATCHLEVEL_max, SDL_IMAGE_PATCHLEVEL <= 99);
-#endif
+SDL_COMPILE_TIME_ASSERT(SDL_IMAGE_MINOR_VERSION_max, SDL_IMAGE_MINOR_VERSION <= 999);
+SDL_COMPILE_TIME_ASSERT(SDL_IMAGE_MICRO_VERSION_min, SDL_IMAGE_MICRO_VERSION >= 0);
+SDL_COMPILE_TIME_ASSERT(SDL_IMAGE_MICRO_VERSION_max, SDL_IMAGE_MICRO_VERSION <= 999);
 
 /* Table of image detection and loading functions */
 static struct {
@@ -90,11 +84,9 @@ static struct {
     { "WEBP", IMG_isWEBP, IMG_LoadWEBPAnimation_IO },
 };
 
-const SDL_Version *IMG_Linked_Version(void)
+int IMG_Version(void)
 {
-    static SDL_Version linked_version;
-    SDL_IMAGE_VERSION(&linked_version)
-    return(&linked_version);
+    return SDL_IMAGE_VERSION;
 }
 
 static int initialized = 0;