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.
An overview of what we're going to do:
Create a png_struct and an info_struct for the animated image (the one we're reading).
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().
For each frame in the animated image:
Create a png_struct and an info_struct for the simple image (the one we're writing).
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.
Copy the standard chunks from the animated to the simple image.
Write the simple image info.
Read the image data for the next frame.
Write the image data.
Complete writing the image with the usual png_write_end()
Destroy the png_struct and an info_struct created for the simple image.