Proposed revision to the GIF conversion chunks It is proposed that the gIFx, gIFg, and gIFt chunks be made obsolete, and that they be replaced with new chunks, respectively gIFa, gIFc, and gIFp. The new chunks each have a Sequence_number field that can be used to ensure that when a GIF is reconstructed, or when a viewer acts upon the GIF conversion chunks, they will be applied in the intended order, even if a PNG editor has rearranged them as allowed by the chunk ordering rules. The gIFp chunk also adds alpha samples to the foreground and background colors, because there are circumstances under which this information can be lost when the gIFt chunk is used. gIFa GIF Application Extension The gIFa chunk is provided for backwards compatibility with the GIF89a Application Extension. The Application Extension contains application-specific information. The contents of this chunk are: Sequence_number: 1 byte Application_identifier: 8 bytes Authentication_code: 3 bytes Application_data: n bytes The Sequence_number indicates the position of the original block in the GIF file, relative to other GIF extension blocks. There can be two groups of extension blocks, one group before the image block, which will be converted to GIF conversion chunks that appear ahead of the IDAT chunks and one group after the image block, which will be converted to GIF conversion chunks that appear after the IDAT chunks. When converting the GIF to a PNG, each instance of any GIF extension block is assigned a sequence number, starting with zero at the beginning of each of the two groups. This number is recorded in the Sequence_number field of the gIFa, gIFc, or gIFp chunk. Since the PNG chunk copying rules forbid moving unknown safe-to-copy chunks across the IDAT chunk, the chunks are guaranteed to remain in the right group. But editors are permitted to rearrange the chunks appearing ahead of IDAT, and to rearrange those appearing after IDAT. The Sequence_number preserves the information needed to restore the original arrangement within each group, if the gIFa, gIFc, and gIFp chunks happen to have been rearranged. If you have a total of more than 256 GIF extension blocks in either group, you probably ought to be converting the file to a multiple-image format instead of to PNG. You can, however, assign Sequence_number=255 to all the remaining chunks in the group and try to avoid editing the PNG file with editors that might rearrange them. The Application_identifier is a sequence of eight printable ASCII characters used to identify the application creating the Application Extension. The Authentication_code is three additional bytes that the application may use to further validate the Application Extension. The remainder of the chunk is application-specific data whose content is not defined by the GIF specification. Note that GIF-to-PNG converters should not attempt to perform byte reordering on the contents of the Application Extension. The data is simply transcribed without any processing except for de-blocking GIF sub-blocks. Applications that formerly used GIF Application Extensions may define special-purpose PNG chunks to replace their application extensions. If a GIF-to-PNG converter recognizes the Application_identifier and is aware of a corresponding PNG chunk, it may choose to convert the Application Extension into that PNG chunk type rather than using gIFa. gIFc GIF Graphic Control Extension The gIFc chunk is provided for backwards compatibility with the GIF89a Graphic Control Extension. The contents of this chunk are: Sequence_number: 1 byte (see gIFa) Disposal_method: 1 byte User_input: 1 byte Delay_time: 2 bytes (byte order converted from GIF) Disposal_method indicates the way in which the graphic is to be treated after being displayed. User_input indicates whether user input is required before continuing. Delay_time specifies the number of hundredths (1/100) of a second to delay before continuing with the processing of the datastream. Note that this field is to be byte-order-converted. The Transparent Color Flag and Transparency Index fields found in the GIF89a Graphic Control Extension are omitted from gIFc. These fields should be converted using the transparency features of basic PNG. gIFg GIF Graphic Control (obsolete) The gIFg chunk is obsolete, and has been replaced by the gIFc chunk. Its contents are the same as those of the gIFc chunk, except that there is no Sequence_number: Disposal_method: 1 byte User_input: 1 byte Delay_time: 2 bytes (byte order converted from GIF) The chunk variables have the same meaning as those in the gIFc chunk. gIFp GIF Plain Text Extension The gIFp chunk is provided for backwards compatibility with the GIF89a Plain Text Extension. The contents of this chunk are: Sequence_number: 1 byte (see gIFc) Text_grid_left_position: 4 bytes (signed integer, byte order and size converted) Text_grid_top_position: 4 bytes (signed integer, byte order and size converted) Text_grid_width: 4 bytes (unsigned integer, byte order and size converted) Text_grid_height: 4 bytes (unsigned integer, byte order and size converted) Character_cell_width: 1 byte Character_cell_height: 1 byte Text_foreground_color: 4 bytes (R,G,B,A samples) Text_background_color: 4 bytes (R,G,B,A samples) Plain_text_data: n bytes Text_grid_left_position, Text_grid_top_position, Text_grid_width, and Text_grid_height specify the text area position and size in pixels. The converter must reformat these fields from 2 bytes LSB-first unsigned integers to 4 bytes MSB-first signed or unsigned integers. Note that GIF defines the position to be relative to the upper left corner of the logical screen. If an oFFs chunk is also present with Unit_specifier = 0 (pixels), a decoder should assume that the oFFs chunk defines the offset of the image relative to the GIF logical screen; hence subtracting the oFFs values from the Text_grid_left_position and Text_grid_top_position gives the text area position relative to the main PNG image (when converting a GIF that has a text rendering block to PNG, it is best to convert the local image Left and Top values to oFFs values in pixels, rather than in micrometers.) Character_cell_width and Character_cell_height give the dimensions of each character in pixels. Text_foreground_color and Text_background_color give the colors to be used to render text foreground and background. Note that the GIF-to-PNG converter must replace the palette index values found in the GIF Plain Text Extension block with the corresponding palette entry, and write either Alpha=0 or Alpha=255, depending on whether the corresponding palette index value represents an opaque or transparent color. The remainder of the chunk is the text to be displayed. Note that this data is not in GIF sub-block format, but is a continuous datastream. gIFt GIF Plain Text Extension (obsolete) The gIFt chunk is obsolete. It has been replaced by the gIFp chunk. Its contents are the same as those of the gIFp chunk, except that there is no Sequence_number, and the Text_foreground_color and Text_background_color fields lack an alpha sample: Text_grid_left_position: 4 bytes (signed integer, byte order and size converted) Text_grid_top_position: 4 bytes (signed integer, byte order and size converted) Text_grid_width: 4 bytes (unsigned integer, byte order and size converted) Text_grid_height: 4 bytes (unsigned integer, byte order and size converted) Character_cell_width: 1 byte Character_cell_height: 1 byte Text_foreground_color: 3 bytes (R,G,B samples) Text_background_color: 3 bytes (R,G,B samples) Plain_text_data: n bytes The chunk variables have the same meaning as those in the gIFp chunk. The Text_foreground_color and Text_background_color are both fully opaque. gIFx GIF Application Extension (obsolete) This gIFx chunk is obsolete. It has been replaced by the gIFa chunk. The contents of this chunk are the same as those of gIFa chunk, except that there is no Sequence_number: Application_identifier: 8 bytes Authentication_code: 3 bytes Application_data: n bytes The chunk variables have the same meaning as those in the gIFa chunk.