Changes

Jump to: navigation, search

APNG Specification

363 bytes added, 01:56, 23 March 2007
Describe the treatment of the placeholder image consistently
APNG is an extension of the [PNG][pngspec] format, adding support for animated images. It is intended to be a replacement for simple animated images that have traditionally used the [GIF][gifspec] format, while adding support for 24-bit images and 8-bit transparency. APNG is a simpler alternative to MNG, providing a spec suitable for the most common usage of animated images on the Internet.
APNG is backwards-compatible with PNG; any PNG decoder should be able to decode ignore the first frame of an APNG -specific chunks and treat it as display a normal single-frame PNGimage.
= Structure =
An APNG stream is a normal PNG stream as defined in the [PNG Specification][pngspec], with three additional chunk types describing the animation and providing additional frame data. The first frame of an animation, frame 0, is encoded as a normal PNG. This frame is what decoders that do not understand the APNG chunks will display.
The size of the first frame placeholder image defines the boundaries of the entire animation; hence, the placeholder image should be appropriately padded with fully transparent pixels if extra space will be needed for later frames that is unused in the first frame, the first frame should be appropriately padded with fully transparent regions.
To be recognized as an APNG, an `acTL` chunk must appear in the stream before any `IDAT` chunks. The `acTL` structure is described in the next section.
An The placeholder image may be treated as the first frame of the animation by the presence of a single `fcTL` chunk may also appear before `IDAT`. Otherwise, providing frame information for the first frame encoded in placeholder image is not part of the PNG stream's `IDAT` chunksanimation, known as frame 0. If there is no fcTL chunk before IDAT, then frame 0 is intialized and the output buffer must be completely initialized to RGBA(0,0,0,0) and at the IDAT chunks are not usedbeginning of each iteration.
Subsequent frames are encoded in `fdAT` chunks containing almost the same structure of content as `IDAT ` chunks. Information for each frame about placement and rendering is stored in `fcTL` chunks. The full layout of `fdAT` and `fcTL` chunks is described below.
Note: For purposes of chunk descriptions, an == Terminology == The "unsigned intplaceholder image" shall be a 32-bit unsigned integer in network byte order limited to is the image described by the standard `IDAT` chunks, and is the range 0 to (2^31)-1; an "unsigned short" shall be a 16-bit unsigned integer in network byte order; a "byte" shall be an 8-bit unsigned integerimage that displayed by decoders that do not support APNG.
== Terminology ==The "canvas" is the area on the output device on which the frames are to be displayed. The contents of the canvas are not necessarily available to the decoder.
The "canvasoutput buffer" is a pixel array with dimensions specified by the width and height parameters of the area on PNG IHDR chunk. Conceptually, each frame is constructed in the output device on which buffer before being composited onto the images are to be writtencanvas. The contents of the canvas output buffer are not available to the decoder. The corner pixels of the output buffer are mapped to the corners of the canvas.
The For purposes of chunk descriptions, an "output bufferunsigned int" is shall be a pixel array with dimensions specified by the width and height parameters of the PNG IHDR chunk. Conceptually, the images are constructed 32-bit unsigned integer in the output buffer and then written network byte order limited to the canvas. The contents of the output buffer are available range 0 to the decoder. The corner pixels of the output buffer are mapped to the corners of the canvas(2^31)-1; an "unsigned short" shall be a 16-bit unsigned integer in network byte order; a "byte" shall be an 8-bit unsigned integer.
== Chunk Sequence Numbers ==
The `fcTL` and `fdAT` chunks have a 4 byte sequence number. Both chunk types share the sequence. The purpose of this number is to detect (and optionally correct) sequence errors in an Animated PNG, since the PNG specification does not impose orderng restrictions on ancillary chunks.
The first `fcTL ` chunk must contain sequence number 0, and the sequence numbers in the remaining `fcTL ` and `fdAT ` chunks must be in order, with no gaps or duplicates. The tables below illustrates the use of sequence numbers for images with more than one frame and more than one `fdAT` chunk.
The table below illustrates If the use of sequence numbers for images with more than one placeholder image is the first frame and more than one `fdAT` chunk:
Sequence number Chunk
0 `fcTL` describing first frame 0(before `IDAT`) 1 `fcTL` describing second frame 1 2 first `fdAT` for second frame 1 3 second `fdAT` for second frame 1
....
or, when frame 0 If the placeholder image is implicitly a transparent black framenot part of the animation:
Sequence number Chunk
0 `fcTL describing ` first frame 1 1 first `fdAT ` for first frame 1 2 second `fdAT ` for first frame 1
....
APNG viewers must abandon the APNG chunks in a datastream with out-of-order APNG chunks and display frame 0 insteadthe placeholder image. APNG-aware PNG editors should restore them to correct order using the sequence numbers.
== `acTL`: The Animation Control Chunk ==
4 num_iterations (unsigned int) Number of times to loop this APNG. 0 indicates infinite looping.
`num_frames` indicates the total number of frames in the animation. This should equal the number of `fcTL` chunks. 0 is not a valid value. 1 is a valid value for a single-frame APNG. In case this number does not match the actual number of frames, behaviour of the implementation is not specified.
`num_iterations` indicates the number of iterations that this animation should play; if it is 0, the animation should play indefinitely. If nonzero, the animation should come to rest on the final non-skipped frame at the end of the last iteration.
== `fcTL`: The Frame Control Chunk ==
The `fcTL` chunk is an ancillary chunk as defined in the PNG Specification. It must appear before the `IDAT` or `fdAT` chunks of the frame to which it applies, specifically:
* For the first frameplaceholder image, if the a `fcTL ` chunk is present it must appear before the first `IDAT` chunk. Position relative to the `acTL` chunk is not specified.* For the first non-placeholder frame (which may be either the first or second frame), the `fcTL` chunk must appear after the all `IDAT` chunks from the first frame and before the `fdAT ` chunks for the second frame.* For any all subsequent frames, the `fcTL` chunk for the frame N must appear after the `fdAT` chunks from the frame N-1 and before the `fdAT ` chunks for the frame N.* Other ancillary chunks are allowed to appear among the APNG chunks, including between `fdAT ` chunks.
The Exactly one `fcTL ` chunk is mandatory for every frame except for frame 0. When it is present for frame 0, decoders must render frame 0 from the data in the IDAT chunks. When it is not present required for each frame 0, frame 0 is a transparent black frame (all pixels are RGBA(0,0,0,0)) and the IDAT chunks are ignored. More than one fcTL chunk per frame is not allowed.
Format:
25 blend_op (byte) Type of frame area rendering for this frame
The frame must be rendered within the region defined by the `widthx_offset`, `heighty_offset`, `x_offsetwidth` , and `y_offset` from the `fcTL`, and the width and height from the `IHDR` chunk. The width and height offsets must be greater than zero and non-negative, the dimensions must not be bigger than (respectively) positive, and the width and height specified in region may not fall outside of the IHDR chunk.placeholder image:
For frame `x_offset` >= 0 `y_offset` >= 0 the `width and ` > 0 `height fields must equal the ` > 0 `x_offset` + `width and height from the ` <= `IHDR` chunk. Also for frame 0 the width `y_offset` + `x_offsetheight` and <= `y_offsetIHDR` fields must be 0. No part of the region may fall outside the area defined by frame 0.height
The `delay_num` and `delay_den` parameters together specify a fraction indicating the delay after the current frame, in seconds. If the denominator is 0, it is to be treated as if it were 100 (that is, `delay_num ` then specifies 1/100ths of a second). If the the value of the numerator is 0 the decoder should render the next frame as quickly as possible, though viewers may impose a reasonable lower bound on the delay.
Valid values for `dispose_op` are:
2 APNG_DISPOSE_OP_PREVIOUS
* APNG_DISPOSE_OP_NONE: no disposal is done on this frame before rendering the next; its contents are left on the output buffer. This is the default.* APNG_DISPOSE_OP_BACKGROUND: the frame's region of the output buffer is to be cleared to the background color. If no bKGD chunk is specified, the result is fully transparent black (r, g, b, and a all 0).* APNG_DISPOSE_OP_PREVIOUS: the frame's region of the output buffer is to be reverted to the previous contents. `blend_op` specifies whether the frame is to be alpha blended into the current output buffer content, or whether it should completely replace its region in the output buffer.
`blend_op` specifies whether the frame is to be alpha blended into the current output buffer content, or whether it should completely replace its region in the output buffer. Valid values for `blend_op` values are:
value
APNG_BLEND_OP_OVER is not valid for color types 0 (greyscale without alpha) or 2 (truecolor without alpha). It is valid for type 3 (indexed) images; however, the resulting pixel values may not be present in the specified palette. It is always valid for type 4 (greyscale with alpha) and type 6 (truecolor with alpha) images.
The `fcTL` chunk corresponding to the placeholder image has additional restrictions, if it exists:* The `x_offset` and `y_offset` fields must be 0.* The `width` and `height` fields must equal the corresponding fields from the `IHDR` chunk.* `blend_op` must be APNG_BLEND_OP_SOURCE for frame * `dispose_op` must not be APNG_DISPOSE_OP_PREVIOUS As noted earlier, if a `fcTL` chunk does not precede `IDAT`, the placeholder image is not part of the animation, and the output buffer must be completely initialized to RGBA(0,0,0,0) at the beginning of each iteration. Together these requirements serve to ensure that each iteration of the animation will be identical.
== `fdAT`: The Frame Data Chunk ==
The `fdAT` chunk has the same purpose as an `IDAT` chunk. It has the same data structure as an `IDAT` chunk, except preceded by a sequence number is appended in the beginning.
Each frame must contain at least one `fdAT ` chunk. The compressed datastream is then the concatenation of the contents of the data fields of all the `fdAT ` chunks within a frame. When decompressed, the datastream is a complete PNG image, including the filter byte at the beginning of each scanline. It utilizes the same bit depth, color type, compression method, filter method, interlace method, and palette (if any) as the main placeholder image.
Format:
4 frame_data X bytes Frame data for this frame
Each frame inherits every property except the width and the height specified by any critical or ancillary chunks before the first `IDAT ` in the file, except the width and height, which come from the `fcTL` chunk.
If the PNG `oFFs ` chunk is present, it supplies offsets of the canvas that are in addition to the frame's "`x_offset" ` and "`y_offset"`.
If the PNG `pHYs ` chunk is present, the APNG images and their "`x_offset" ` and "`y_offset" ` values must be scaled in the same way as the main image. Conceptually, such scaling occurs while mapping the output buffer onto the canvas.
= Revisions to this Specification =
18
edits

Navigation menu