File: png-in-gif-proposal-20070414 It is proposed to specify a PNG extension to GIF. It is proposed to document the GIF extension in the Extensions to the PNG 1.2 Specification, Version 1.3.0, as follows: A. Change document version to 1.4.0. B. Add paragraph 6 and renumber subsequent paragraphs: 6. PNG-in-GIF extensions 6.1 Overview Sections 6.3 and 6.4, below, are intended to be extensions to the GIF specification [GIF-SPEC]. They enhance GIF with the truecolor and alpha capabilities of PNG, while retaining the animation capabilities of GIF89a. Applications that do not recognize these PNG extensions or choose not to process it will fall back on a regular GIF animation or still image contained in the GIF file. 6.2 File Extension and MIME type Since a GIF with the PNG extension chunk meets the GIF file syntax specification, authors can present them as "image/gif" and use the ".gif" extension. Authors who wish to distinguish clearly between static images and animations should use MIME type "video/x-gif" for animated GIFs. 6.3 PNG Application Extension. a. Description. The PNG Application Extension contains a PNG image that may be displayed by a viewer in place of the following Image Descriptor image. The PNG image should be a higher quality version of the Image Descriptor image, an encoder may use an empty or minimal placeholder for the Image Descriptor image. b. Required Version. 89a. c. Syntax. 7 6 5 4 3 2 1 0 Field Name Type +---------------+ 0 | | Extension Introducer Byte +---------------+ 1 | | Extension Label Byte +---------------+ +---------------+ 0 | | Block Size Byte +---------------+ 1 | | +- -+ 2 | | +- -+ 3 | | PNG Image Identifier 8 Bytes +- -+ 4 | | +- -+ 5 | | +- -+ 6 | | +- -+ 7 | | +- -+ 8 | | +---------------+ 9 | | +- -+ 10 | | Authentication Code 3 Bytes +- -+ 11 | | +---------------+ +---------------+ 0 | | Header Block Size Byte +---------------+ 1 | | Image Left Position Unsigned +- -+ 2 | | +---------------+ 3 | | Image Top Position Unsigned +- -+ 4 | | +---------------+ +===============+ | | | | PNG Image Data Data Sub-blocks | | | | +===============+ +---------------+ 0 | | Block Terminator Byte +---------------+ i) Extension Introducer - Defines this block as an extension. This field contains the fixed value 0x21. ii) Application Extension Label - Identifies the block as an Application Extension. This field contains the fixed value 0xFF. iii) Block Size - Number of bytes in this extension block, following the Block Size field, up to but not including the beginning of the Header Block Data. This field contains the fixed value 11. iv) PNG Image Identifier - Sequence of eight printable ASCII characters used to identify the extension as a PNG Application Extension. This must contain the ASCII characters "PNGImage" v) Authentication Code - Sequence of three bytes used to authenticate the PNG Image Identifier. This must contain the decimal byte values 49, 46, 50 (ASCII "1.2"). vi) Header block size - Number of bytes in the following header block, up to but not including the beginning of the PNG Image Data. This field contains the fixed value 4. vii) Image Left Position - Column number, in pixels, of the left edge of the image, with respect to the left edge of the Logical Screen. This is a two-byte unsigned integer in little-endian order. The leftmost column of the Logical Screen is 0. viii) Image Top Position - Row number, in pixels, of the top edge of the image with respect to the top edge of the Logical Screen. This is a two-byte unsigned integer in little-endian order. The top row of the Logical Screen is 0. The image width and height are obtained from the PNG IHDR chunk, in the PNG Image Data. Decoders must ignore any part of the image falling outside of the Logical Screen width and height, from the Logical Screen Descriptor. ix) PNG Image Data. Data Sub-blocks containing a complete PNG image, as defined by ISO/IEC 15948:2003, except for the 8-byte PNG signature, which must be omitted. x) Block Terminator. A zero length data sub-block that terminates the PNG Image Data. This field contains the single byte value 0. d. Rendering the PNG Application Extension image must be performed by alpha composition of the image into the display. The alpha composition is expected to make the color components linear (using information from the relevant chunks such as gAMA, sRGB and iCCP) while doing this. This is described in more detail in ISO/IEC 15948:2003 e. Both the main GIF and the embedded PNG files may have colorspace information. Only one source of colorspace information may be used, in the following order of priority: 1. PNG sRGB chunk 2. PNG iCCP chunk 3. GIF ICCRGB01 extension 4. PNG gAMA and cHRM chunks 5. GIF GAMMANOW extension (note that this contains the reciprocal of the PNG gamma value) 6. If no colorspace information is present, assume sRGB. f. If the PNG Image Extension data contains an IDAT chunk immediately after the IHDR then a viewer must insert the contents of the preceding PNG Global Chunk Extension (if any) immediately after the IHDR. A decoder can detect this condition by processing bytes 25 through 32 (the 26th byte to the 33rd) specially. These bytes contain a 4-byte length field and the 4-byte name of the first chunk after the IHDR chunk. If the last four of those bytes (bytes 29 to 32) contain ASCII 'IDAT' (decimal byte values 73, 68, 65, 84) in that order the PNG Chunk Extension data must be inserted before the first of the length bytes (at position 25 in the PNG Image Extension image data stream.) If bytes 29 to 32 contain anything else, then the PNG Image contains its own ancillary chunks and the chunks in the PNG Global Chunk Extension are not used for that image. It is an error condition if the PNG Global Chunk Extension data contains chunks not permitted before IDAT, including IDAT itself. Decoders are not required to detect or handle this error condition; however, they must handle the error conditions that result if such data is inserted into a PNG Image Extension. g. Extensions and Scope. This block does not have scope. This block can be modified only by the PNG Global Chunk Extension. h. Recommendation. The extension should be followed by an Image Descriptor. The image in the extension may be used in place of the image in the Image Descriptor and is displayed in the same way as that image. If a Graphics Control Extension appears before the Image Descriptor it applies to the PNG Image regardless of whether it appears before or after the PNG image. The transparent color information (flag and index) applies only to the Image Descriptor, not the PNG Image, which has its own self-contained transparency/alpha information. If the PNG Application Extension is not followed by an Image Descriptor it must be ignored. 6.4 PNG Global Chunk Extension. a. Description. The PNG Global Chunk Extension contains a sequence of PNG chunks that provide color space (including palette, if required) and other information for the following PNG Image Extensions, when the PNG Image Extension does not contain its own header chunks. b. Required Version. 89a. c. Syntax. 7 6 5 4 3 2 1 0 Field Name Type +---------------+ 0 | | Extension Introducer Byte +---------------+ 1 | | Extension Label Byte +---------------+ +---------------+ 0 | | Block Size Byte +---------------+ 1 | | +- -+ 2 | | +- -+ 3 | | PNG Chunk Identifier 8 Bytes +- -+ 4 | | +- -+ 5 | | +- -+ 6 | | +- -+ 7 | | +- -+ 8 | | +---------------+ 9 | | +- -+ 10 | | Authentication Code 3 Bytes +- -+ 11 | | +---------------+ +===============+ | | | | PNG Chunk Data Data Sub-blocks | | | | +===============+ +---------------+ 0 | | Block Terminator Byte +---------------+ i) Extension Introducer - Defines this block as an extension. This field contains the fixed value 0x21. ii) Application Extension Label - Identifies the block as an Application Extension. This field contains the fixed value 0xFF. iii) Block Size - Number of bytes in this extension block, following the Block Size field, up to but not including the beginning of the Header Block Data. This field contains the fixed value 11. iv) PNG Global Chunk Identifier - Sequence of eight printable ASCII characters used to identify the extension as a PNG Application Extension. This must contain the ASCII characters "PNGChunk" v) Authentication Code - Sequence of three bytes used to authenticate the PNG Image Identifier. This must contain the decimal byte values 49, 46, 50 (ASCII "1.2"). vi) PNG Global Chunk Data. Data Sub-blocks containing data from the head of a PNG image stream, between the IHDR and first IDAT chunks and excluding those chunks, as defined by ISO/IEC 15948:2003. This field may be absent (i.e. of zero length.) vii) Block Terminator. A zero length data sub-block that terminates the PNG Image Data. This field contains the single byte value 0. d. Extensions and Scope. This block affects the interpretation of any PNG Image Extension following it up until the next PNG Global Chunk Extension block. The block cannot be modified by any other block. e. Recommendation. Encoders should use the PNG Global Chunk Extension when a sequence of PNG Image Extension images have a common header - most usually a common color space, including palette, PLTE, and transparency, tRNS, chunks if all of the images in the sequence have those and they have the same contents for all images. C. Add to the Appendix: Revision History * 15 May 2007 (version 1.4.0): * Added the PNG-in-GIF Extensions. D. Add to the References [GIF-SPEC] "Graphics Interchange Format 89a" available at http://www.w3.org/Graphics/GIF/spec-gif89a.txt ---end of proposal---