Writing

In this section we will read several non-animated PNG images and create an animated PNG image out of them. To keep things simple, it is assumed that every image given on the command-line is of the same configuration (number of bits per pixel, pallete, etc). To create the source images you can use your favourite image editor to create one regular PNG image, then make some changes to it and save it with a different name, make some more changes, and so on.

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 writing).

  2. Once the information from the first image is read:

    1. Fill the general PNG information in the animated image using the info from the first simple image given on the command line

    2. Set the acTl chunk for the animation and the fcTl chunk for the first frame

    3. Write the animated image info

  3. For each png image given on the command line (image data from each will end up beng a frame):

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

    2. Read the simple image information

    3. Read the simple image data

    4. png_write_frame_head()

    5. Write the image data

    6. png_write_frame_tail()

    7. Destroy the structs used for reading the simple image

  4. png_write_end()

For simplicity's sake the frame information is set to minimalistic values for each frame: no offset, 1 second delay and only the APNG_RENDER_OP_DISPOSE_BACKGROUND render flag.

The commented out png_write_frame_head() call should give you an idea about how to give each frame different settings if you so desire.