Sequencial Reading

In this section we will read an animated PNG image using the sequencial reader and create a regular PNG image out of every frame. For testing you can use sample images from the APNG Implementation page or create them yourself using the writer in a following chapter.

Overview

An overview of what we're going to do:

  1. Create a png_struct and an info_struct for the animated image (the one we're reading).

  2. Read the image info and check to make sure it has an acTl chunk. The presence of this chunk is required in order to use png_read_frame_head() and png_get_next_frame_fcTl().

  3. For each frame in the animated image:

    1. Create a png_struct and an info_struct for the simple image (the one we're writing).

    2. png_read_frame_head()

    3. The next step is not done properly in the example, it is to get the contents of the fcTl chunk for the next frame and do the appropriate thing with compositing the new frame over the old one. This is only so in the example because compositing the image is not the point of this tutorial. The APNG spec requires that you do the compositing according to the contents of the fcTl chunk.

    4. Copy the standard chunks from the animated to the simple image.

    5. Write the simple image info.

    6. Read the image data for the next frame.

    7. Write the image data.

    8. Complete writing the image with the usual png_write_end()

    9. Destroy the png_struct and an info_struct created for the simple image.