From 7fffb97c691f0b7f2d212813276da045f4105859 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 8 Jan 2026 10:36:09 -0800
Subject: [PATCH] webp: don't clear the whole frame, just the portion that
changed
Fixes https://github.com/inigomonyota/webptestimages/blob/main/Mike_Tysons_Punchout.webp
---
src/IMG_webp.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/IMG_webp.c b/src/IMG_webp.c
index 79206437..481e9055 100644
--- a/src/IMG_webp.c
+++ b/src/IMG_webp.c
@@ -485,10 +485,6 @@ static bool IMG_AnimationDecoderGetNextFrame_Internal(IMG_AnimationDecoder *deco
WebPIterator *iter = &decoder->ctx->iter;
SDL_Surface *retval = NULL;
- if (totalFrames == availableFrames || dispose_method == WEBP_MUX_DISPOSE_BACKGROUND) {
- SDL_FillSurfaceRect(canvas, NULL, iter->has_alpha ? 0 : bgcolor);
- }
-
SDL_Surface *curr = SDL_CreateSurface(iter->width, iter->height, SDL_PIXELFORMAT_RGBA32);
if (!curr) {
return SDL_SetError("Failed to create surface for the frame");
@@ -512,6 +508,9 @@ static bool IMG_AnimationDecoderGetNextFrame_Internal(IMG_AnimationDecoder *deco
return SDL_SetError("Failed to set blend mode for WEBP frame");
}
}
+ if (totalFrames == availableFrames || dispose_method == WEBP_MUX_DISPOSE_BACKGROUND) {
+ SDL_FillSurfaceRect(canvas, &dst, iter->has_alpha ? 0 : bgcolor);
+ }
if (!SDL_BlitSurface(curr, NULL, canvas, &dst)) {
SDL_DestroySurface(curr);
return SDL_SetError("Failed to blit WEBP frame to canvas");