Fix the Animated WebP coder the frame blend index calculation issue, he end condition should be only endIndex
to match the behavior.
#22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Before we call
WebPDemuxNextFrame
, theiter.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 callsd_drawnWebpImageWithCanvas
once. But however, current code cause that callsd_blendWebpImageWithCanvas
twice. This is the problem.Solution
Change the end condition of that while loop, should just check
< endIndex