Skip to content

Conversation

dreampiggy
Copy link
Contributor

Issue

See Bug demo: https://github.com/krze/SDWebImage-WebP-Bug
Issue: SDWebImage/SDWebImage#2835

Bug Reason

I found the logic bug. The code comment does not match what it do.

// Draw from range: [startIndex, endIndex) while ((size_t)iter.frame_num < endIndex && WebPDemuxNextFrame(&iter)); 

Before we call WebPDemuxNextFrame, the iter.frame_num is the 0-based previous frame index + 1. So the endIndex should not use +1 as well.

For example:

request index == 1
frame.fromIndex == 0
frame.endIndex == 1

it should only call sd_blendWebpImageWithCanvas once, then call sd_drawnWebpImageWithCanvas once. But however, current code cause that call sd_blendWebpImageWithCanvas twice. This is the problem.

Solution

Change the end condition of that while loop, should just check < endIndex

…the end condition should be only `endIndex` to match the behavior.
@kinarobin kinarobin merged commit c5b98c4 into master Sep 12, 2019
@kinarobin kinarobin deleted the fix_animated_webp_frame_blend_issue branch September 12, 2019 04:06
@dreampiggy
Copy link
Contributor Author

Do not merge. There are still cases that cause issue. It's the dispose method issue.

@dreampiggy
Copy link
Contributor Author

frame 1 (first request):
dispose method: background (clear canvas after this frame drawn)

frame 1 (again):
This cause issue, because the canvas already been cleared. We need to redraw from 0 index. (This waste time, but it's correct)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants