picdocument: fix rendering of animated GIFs #653
Merged
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.
pic.lua was returning each frame as-is. Very often, frames are just a mask to apply on previous frame, so we need to combine them and paste each one over the previous.
Adds support for transparency for that, and limited support for the rare other "dispose" modes of the GIF spec.
This makes the little (or full size) animated territories expansion maps (gray backround with a year displayed) found on these Wikipedia pages, when saved as a GIF, correctly displayed by PicDocument:
https://fr.wikipedia.org/wiki/Empire_romain https://upload.wikimedia.org/wikipedia/commons/thumb/e/ea/Roman_Republic_Empire_map.gif/220px-Roman_Republic_Empire_map.gif
https://fr.wikipedia.org/wiki/Saint-Empire_romain_germanique https://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/HRR.gif/220px-HRR.gif
https://fr.wikipedia.org/wiki/Empire_byzantin https://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Byzantine_Empire_animated.gif/220px-Byzantine_Empire_animated.gif
(Needs to clear cache if comparing previous/after.)
I was thinking about adding support for such animated GIF in ImageViewer (so we can view them from Wikipedia saved as EPUB), but I first had to see how they work. MuPDF (used to render images) has no support for multi-frames images. Had to have a look a ffi/pic.lua which uses giflib, that does have support for them. So I just fixed the handling of these animated gif in pic.lua, even if I guess hardly nobody uses that feature.