From 0b43b1ff93ea6569bf4da954662edd6b5619f990 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Tue, 21 Oct 2025 11:00:47 -0700
Subject: [PATCH] Cleanup
---
src/IMG_avif.c | 4 +++-
src/IMG_gif.c | 32 ++++++++++++++------------------
src/IMG_libpng.c | 2 ++
src/IMG_webp.c | 2 +-
4 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/src/IMG_avif.c b/src/IMG_avif.c
index 36a4cde9..e0c8de1d 100644
--- a/src/IMG_avif.c
+++ b/src/IMG_avif.c
@@ -22,6 +22,8 @@
/* This is a AVIF image file loading framework */
#include <SDL3_image/SDL_image.h>
+
+#include "IMG_avif.h"
#include "IMG_anim_encoder.h"
#include "IMG_anim_decoder.h"
#include "xmlman.h"
@@ -1211,7 +1213,7 @@ struct IMG_AnimationEncoderContext
SDL_PropertiesID metadata;
};
-static bool AnimationEncoder_AddFrame(struct IMG_AnimationEncoder *encoder, SDL_Surface *surface, Uint64 duration)
+static bool AnimationEncoder_AddFrame(IMG_AnimationEncoder *encoder, SDL_Surface *surface, Uint64 duration)
{
avifImage *image = NULL;
avifRGBImage rgb;
diff --git a/src/IMG_gif.c b/src/IMG_gif.c
index 469ac8b5..c22438be 100644
--- a/src/IMG_gif.c
+++ b/src/IMG_gif.c
@@ -22,6 +22,8 @@
/* This is a GIF image file loading framework */
#include <SDL3_image/SDL_image.h>
+
+#include "IMG_gif.h"
#include "IMG_anim_encoder.h"
#include "IMG_anim_decoder.h"
@@ -2546,7 +2548,7 @@ static int writeGifTrailer(SDL_IOStream *io)
return 0;
}
-static bool AnimationEncoder_AddFrame(struct IMG_AnimationEncoder *encoder, SDL_Surface *surface, Uint64 duration)
+static bool AnimationEncoder_AddFrame(IMG_AnimationEncoder *encoder, SDL_Surface *surface, Uint64 duration)
{
IMG_AnimationEncoderContext *ctx = encoder->ctx;
SDL_IOStream *io = encoder->dst;
@@ -2698,7 +2700,7 @@ static bool AnimationEncoder_AddFrame(struct IMG_AnimationEncoder *encoder, SDL_
return false;
}
-static bool AnimationEncoder_End(struct IMG_AnimationEncoder *encoder)
+static bool AnimationEncoder_End(IMG_AnimationEncoder *encoder)
{
IMG_AnimationEncoderContext *ctx = encoder->ctx;
SDL_IOStream *io = encoder->dst;
@@ -2724,13 +2726,9 @@ static bool AnimationEncoder_End(struct IMG_AnimationEncoder *encoder)
return success;
}
-#endif /* SAVE_GIF */
-bool IMG_CreateGIFAnimationEncoder(struct IMG_AnimationEncoder *encoder, SDL_PropertiesID props)
+bool IMG_CreateGIFAnimationEncoder(IMG_AnimationEncoder *encoder, SDL_PropertiesID props)
{
-#if !SAVE_GIF
- return SDL_SetError("GIF animation saving is not enabled in this build.");
-#else
IMG_AnimationEncoderContext *ctx;
int transparent_index = -1;
uint16_t num_global_colors = 256;
@@ -2738,21 +2736,17 @@ bool IMG_CreateGIFAnimationEncoder(struct IMG_AnimationEncoder *encoder, SDL_Pro
transparent_index = (int)SDL_GetNumberProperty(props, "transparent_color_index", -1);
Sint64 globalcolors = SDL_GetNumberProperty(props, "num_colors", 256);
if (globalcolors <= 1 || (globalcolors & (globalcolors - 1)) != 0 || globalcolors > 256) {
- SDL_SetError("GIF stream property 'num_colors' must be a power of 2 (starting from 2, up to 256).");
- return false;
+ return SDL_SetError("GIF stream property 'num_colors' must be a power of 2 (starting from 2, up to 256).");
}
num_global_colors = (uint16_t)globalcolors;
if (transparent_index >= (int)num_global_colors) {
- SDL_SetError("Transparent color index %d exceeds palette size %d",
- transparent_index, num_global_colors);
- return false;
+ return SDL_SetError("Transparent color index %d exceeds palette size %d", transparent_index, num_global_colors);
}
ctx = (IMG_AnimationEncoderContext *)SDL_calloc(1, sizeof(IMG_AnimationEncoderContext));
if (!ctx) {
- SDL_SetError("Failed to allocate animation stream context.");
return false;
}
@@ -2765,12 +2759,10 @@ bool IMG_CreateGIFAnimationEncoder(struct IMG_AnimationEncoder *encoder, SDL_Pro
if (!ignoreProps) {
ctx->metadata = SDL_CreateProperties();
if (!ctx->metadata) {
- SDL_SetError("Failed to create metadata properties for GIF encoder.");
SDL_free(ctx);
return false;
}
if (!SDL_CopyProperties(props, ctx->metadata)) {
- SDL_SetError("Failed to copy properties to GIF encoder metadata.");
SDL_DestroyProperties(ctx->metadata);
SDL_free(ctx);
return false;
@@ -2789,11 +2781,8 @@ bool IMG_CreateGIFAnimationEncoder(struct IMG_AnimationEncoder *encoder, SDL_Pro
encoder->Close = AnimationEncoder_End;
return true;
-#endif /*!SAVE_GIF*/
}
-#ifdef SAVE_GIF
-
bool IMG_SaveGIF_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
{
IMG_AnimationEncoder *encoder = IMG_CreateAnimationEncoder_IO(dst, closeio, "gif");
@@ -2825,6 +2814,13 @@ bool IMG_SaveGIF(SDL_Surface *surface, const char *file)
#else
+bool IMG_CreateGIFAnimationEncoder(IMG_AnimationEncoder *encoder, SDL_PropertiesID props)
+{
+ (void)encoder;
+ (void)props;
+ return SDL_SetError("SDL_image built without GIF save support");
+}
+
bool IMG_SaveGIF_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
{
(void)surface;
diff --git a/src/IMG_libpng.c b/src/IMG_libpng.c
index 8253c9b8..c97f6384 100644
--- a/src/IMG_libpng.c
+++ b/src/IMG_libpng.c
@@ -28,6 +28,8 @@
*******************************************************************************/
#include <SDL3_image/SDL_image.h>
+
+#include "IMG_libpng.h"
#include "IMG_anim_encoder.h"
#include "IMG_anim_decoder.h"
diff --git a/src/IMG_webp.c b/src/IMG_webp.c
index 62b0d12f..6563705a 100644
--- a/src/IMG_webp.c
+++ b/src/IMG_webp.c
@@ -23,9 +23,9 @@
#include <SDL3_image/SDL_image.h>
+#include "IMG_webp.h"
#include "IMG_anim_encoder.h"
#include "IMG_anim_decoder.h"
-#include "IMG_webp.h"
#include "xmlman.h"
// We will have the saving WEBP feature by default