SDL_image icon indicating copy to clipboard operation
SDL_image copied to clipboard

IMG_webp: Incorrect frame composition in animated WebP loading

Open inigomonyota opened this issue 10 months ago • 1 comments

The current animated WebP loader in SDL_image has incorrect frame composition behavior, leading to visual artifacts in animated WebP files. This is particularly noticeable in WebP animations that use transparency or have overlapping frames with different disposal methods.

Current Behavior

  • Frame disposal operations occur at the wrong time in the composition sequence
  • Transparency and background color handling does not respect the WebP alpha channel status
  • Frames are blended incorrectly, causing remnants of previous frames to persist
  • WEBP_MUX_DISPOSE_BACKGROUND is not properly clearing frame regions

Expected Behavior

  1. Frame disposal should occur before drawing the new frame
  2. Initial canvas state should:
    • Use transparency for WebPs with alpha channel
    • Use background color for non-alpha WebPs
  3. Frame composition should use SDL_BLENDMODE_NONE to ensure accurate pixel replacement
  4. Frame disposal should only affect the region of the disposed frame

Technical Details

The core issue is in IMG_LoadWEBPAnimation_RW where the frame composition logic doesn't match the WebP specification requirements

Test Case

Any animated WebP with: -Transparent regions -Overlapping frames -Mixed disposal methods (WEBP_MUX_DISPOSE_BACKGROUND and WEBP_MUX_DISPOSE_NONE)

https://github.com/inigomonyota/SDL_image/commit/7ace470f25c63870bbede11a261607c09484cb57

inigomonyota avatar Feb 13 '25 17:02 inigomonyota

Can you create a PR and add links to test images?

Thanks!

slouken avatar Feb 13 '25 19:02 slouken