File: png-in-gif-proposal-20070413 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. C. Add paragraph 6 and renumber subsequent paragraphs: 6. PNG-in-GIF extension 6.1 Overview Section 6.3, below, is intended to be an extension to the GIF specification. It enhances GIF with the truecolor and alpha capabilities of PNG, while retaining the animation capabilities of GIF89a. Applications that do not recognize the PNG extension 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. 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. The top row of the Logical Screen is 0. 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 should 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 inverse of the PNG gamma value) 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. If the last four of those bytes contain ASCII 'IDAT' in that order the PNG Chunk Extension data should be inserted before the first of those bytes (at position 25 in the PNG Image Extension image data stream.) 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 which 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 should be ignored. 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. 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 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 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. ---end of proposal---