Skip to content
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

Add APNG support #4243

Merged
merged 21 commits into from Mar 31, 2020
Merged

Add APNG support #4243

merged 21 commits into from Mar 31, 2020

Conversation

pmrowla
Copy link
Contributor

@pmrowla pmrowla commented Dec 1, 2019

Fixes #3483.

Changes proposed in this pull request:

  • Implements support for reading APNG files

    • seek() tell() can be used for accessing frames, seek() rewinding is supported
    • If an APNG contains a default image that is not part of the actual animation sequence (i.e. IDAT chunks without an fcTL chunk), im.info["default_image"] will be set and True, and the default image can still be accessed as frame 0 (seek(0)).
      In this case, the first animation frame will be at seek(1), and n_frames will contain the number of frames plus 1 to account for the default image.
    • If im.info["default_image"] is not present or is False it means the APNG did not contain a separate default image
    • im.is_animated will always be True for APNG files, even if the animation only contains a single frame, to differentiate single frame APNG files from standard PNG files.
  • Implements partial support for writing APNG files

    • APNG animations can be written using save_all and append_images (same behavior as writing GIF sequences)
    • Loop and frame duration can also be specified (same behavior as GIF sequences)
    • APNG frame disposal method and frame blend method can be specified via disposal and blend parameters
    • All images from the append_frames sequence are expected to be the same size as the initial image, frame bounding box is calculated based on the differences between a given frame and the prior frame
    • Frame bounding boxes cannot be manually specified with this implemention
  • Tests are based on the browser compatibility tests from https://philip.html5.org/tests/apng/tests.html, which are the only tests currently listed at: https://wiki.mozilla.org/APNG_Specification

@pmrowla
Copy link
Contributor Author

pmrowla commented Dec 1, 2019

I've been doing some more testing and found a problem in the code for writing APNG sequences that occurs if it has to write multiple fdAT chunks in a row for one image frame. I'll try to get a fix and new tests pushed for that at some point in the next couple of days.

Tests/test_file_png.py Outdated Show resolved Hide resolved
Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor docs suggestions. Please could you also add release notes, linking to the docs for more info?

docs/handbook/image-file-formats.rst Outdated Show resolved Hide resolved
docs/handbook/image-file-formats.rst Outdated Show resolved Hide resolved
docs/handbook/image-file-formats.rst Outdated Show resolved Hide resolved
Tests/test_file_png.py Outdated Show resolved Hide resolved
@pmrowla

This comment has been minimized.

@pmrowla

This comment has been minimized.

@hugovk

This comment has been minimized.

@radarhere

This comment has been minimized.

pmrowla and others added 13 commits February 23, 2020 15:11
See python-pillow#3483

Adds support for reading APNG files and seeking through frames,
and adds basic support for writing APNG files.
Includes tests for reading and writing APNG files.

The tests for reading files are based on the APNG browser compatibility
tests from https://philip.html5.org/tests/apng/tests.html
(which is linked in the Tests section of https://wiki.mozilla.org/APNG_Specification)
[ci skip]
[ci skip]

Co-Authored-By: Andrew Murray <3112309+radarhere@users.noreply.github.com>
- Add changes requested by hugovk
This was referenced Mar 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add apng support
3 participants