-
Notifications
You must be signed in to change notification settings - Fork 326
Add thumbnailing support for animated GIFs #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benkonrath
wants to merge
5
commits into
SmileyChris:master
Choose a base branch
from
benkonrath:animated-gif-p-mode
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+56
−5
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've struggled with Pillow APIs from the beginning, but reading the docs suggests that visiting these frames with seek should fix the mode, ist that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct. Seeking will fix the mode, but the loading behaviour can be modified by global Pillow setting.
I think we could also check
GifImagePlugin.LOADING_STRATEGYand skip this second seek loop if it's set correctly. But I'd need to test this. e.g.:Users would just need to set this to avoid the extra seek loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is seeking a big overhead? If it generates too much complexity for a not so big performance gain, I would strive for "settings to disable animation support", as processing all these frames before will be a real performance hit already? But that would be another PR, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it, seeking through the frames is basically converting the index colors (e.g. palette colors) to the RGB(A) image data in memory.
This is just an edge case for animated GIFs due to how Pillow
GifImagePluginworks. For animated GIFs, a FrameAware operation means the frames are read, operation applied and read again (to correct the mode). My view: It's probably not a big deal performance-wise, but if there's a way to reduce compute with an opt-in setting, that's great. I can image an application that works with animated GIFs a lot would want to try to be as efficient as possible and take this opt-in. (My guess isLoadingStrategy.RGB_ALWAYSuses more memory in some cases which is why it's not the default - this really is a decision for application developers to take.)I made an update to check the loading strategy as well in the if condition. It's also fine for me without that check. I think you have a better understanding of how the animation support fits together, so just let me know what you think is best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I would keep your solution. This probably needs (very little) documentation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok cool. I'll add some documentation either later today, or tomorrow morning.