GIF 元数据格式规范
GIF 流元数据格式规范
GIF 流元数据格式对存储在每个文件头中的信息进行编码,即文件版本、逻辑屏幕描述符和全局颜色表。
逻辑屏幕描述符描述动画文件的整体宽度和高度,以及有关颜色分辨率(每个像素的位数)和像素纵横比的信息。
全局颜色表包含一个颜色查找表,用于没有自己的本地颜色表的图像。
<!DOCTYPE "javax_imageio_gif_stream_1.0" [
<!ELEMENT "javax_imageio_gif_stream_1.0" (Version?,
LogicalScreenDescriptor?, GlobalColorTable?)>
<!ELEMENT "Version" EMPTY>
<!-- The file version, either 87a or 89a -->
<!ATTLIST "Version" "value" ("87a" | "89a") #REQUIRED>
<!-- The version string -->
<!ELEMENT "LogicalScreenDescriptor" EMPTY>
<!-- The logical screen descriptor, except for the global color table -->
<!ATTLIST "LogicalScreenDescriptor" "logicalScreenWidth" #CDATA
#REQUIRED>
<!-- The width in pixels of the whole picture -->
<!-- Data type: Integer -->
<!-- Min value: 1 (inclusive) -->
<!-- Max value: 65535 (inclusive) -->
<!ATTLIST "LogicalScreenDescriptor" "logicalScreenHeight" #CDATA
#REQUIRED>
<!-- The height in pixels of the whole picture -->
<!-- Data type: Integer -->
<!-- Min value: 1 (inclusive) -->
<!-- Max value: 65535 (inclusive) -->
<!ATTLIST "LogicalScreenDescriptor" "colorResolution" #CDATA
#REQUIRED>
<!-- The number of bits of color resolution, between 1 and 8 -->
<!-- Data type: Integer -->
<!-- Min value: 1 (inclusive) -->
<!-- Max value: 8 (inclusive) -->
<!ATTLIST "LogicalScreenDescriptor" "pixelAspectRatio" #CDATA
#REQUIRED>
<!-- If 0, indicates square pixels, else W/H = (value + 15)/64 -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ELEMENT "GlobalColorTable" (ColorTableEntry)*>
<!-- The global color table -->
<!-- Min children: 2 -->
<!-- Max children: 256 -->
<!ATTLIST "GlobalColorTable" "sizeOfGlobalColorTable" ("2" |
"4" | "8" | "16" | "32" | "64" | "128" | "256") #REQUIRED>
<!-- The number of entries in the global color table -->
<!ATTLIST "GlobalColorTable" "backgroundColorIndex" #CDATA
#REQUIRED>
<!-- The index of the color table entry to be used as a background -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ATTLIST "GlobalColorTable" "sortFlag" ("TRUE" | "FALSE")
#REQUIRED>
<!-- True if the global color table is sorted by frequency -->
<!ELEMENT "ColorTableEntry" EMPTY>
<!-- A global color table entry -->
<!ATTLIST "ColorTableEntry" "index" #CDATA #REQUIRED>
<!-- The index of the color table entry -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ATTLIST "ColorTableEntry" "red" #CDATA #REQUIRED>
<!-- The red value for the color table entry -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ATTLIST "ColorTableEntry" "green" #CDATA #REQUIRED>
<!-- The green value for the color table entry -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ATTLIST "ColorTableEntry" "blue" #CDATA #REQUIRED>
<!-- The blue value for the color table entry -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
]>
GIF 图像元数据格式规范
GIF 图像元数据格式对图像描述符、局部颜色表和与 GIF 文件(通常是动画帧)中的单个图像关联的扩展信息进行编码。
图像描述包含帧在流元数据中描述的逻辑屏幕内的偏移量,以及帧的宽度和高度以及是否使用隔行编码。
局部颜色表(如果存在)将取代当前框架的全局颜色表。
图形控件扩展包含有关如何将帧合并到动画中的信息。处理方法指示当前帧是否应保留在原位(doNotDispose),恢复为流元数据中指定的背景颜色(restoreToBackgroundColor),或者在显示后续帧之前恢复为之前的帧内容(restoreToPrevious)。
用户输入标志指示动画在前进到下一帧之前是否应暂停以等待用户输入。透明颜色标志和索引指示不应为其绘制帧的像素的颜色索引。延迟时间指示帧应显示多长时间,以百分之一秒为单位。如果设置了用户输入标志且延迟时间为 0,则帧旨在仅在用户输入时前进。
<!DOCTYPE "javax_imageio_gif_image_1.0" [
<!ELEMENT "javax_imageio_gif_image_1.0" (ImageDescriptor?,
LocalColorTable?, GraphicControlExtension?, PlainTextExtension?,
ApplicationExtensions?, CommentExtensions?)>
<!ELEMENT "ImageDescriptor" EMPTY>
<!-- The image descriptor -->
<!ATTLIST "ImageDescriptor" "imageLeftPosition" #CDATA #REQUIRED>
<!-- The X offset of the image relative to the screen origin -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 65535 (inclusive) -->
<!ATTLIST "ImageDescriptor" "imageTopPosition" #CDATA #REQUIRED>
<!-- The Y offset of the image relative to the screen origin -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 65535 (inclusive) -->
<!ATTLIST "ImageDescriptor" "imageWidth" #CDATA #REQUIRED>
<!-- The width of the image -->
<!-- Data type: Integer -->
<!-- Min value: 1 (inclusive) -->
<!-- Max value: 65535 (inclusive) -->
<!ATTLIST "ImageDescriptor" "imageHeight" #CDATA #REQUIRED>
<!-- The height of the image -->
<!-- Data type: Integer -->
<!-- Min value: 1 (inclusive) -->
<!-- Max value: 65535 (inclusive) -->
<!ATTLIST "ImageDescriptor" "interlaceFlag" ("TRUE" | "FALSE")
#REQUIRED>
<!-- True if the image is stored using interlacing -->
<!ELEMENT "LocalColorTable" (ColorTableEntry)*>
<!-- The local color table -->
<!-- Min children: 2 -->
<!-- Max children: 256 -->
<!ATTLIST "LocalColorTable" "sizeOfLocalColorTable" ("2" |
"4" | "8" | "16" | "32" | "64" | "128" | "256") #REQUIRED>
<!-- The number of entries in the local color table -->
<!ATTLIST "LocalColorTable" "sortFlag" ("TRUE" | "FALSE")
#REQUIRED>
<!-- True if the local color table is sorted by frequency -->
<!ELEMENT "ColorTableEntry" EMPTY>
<!-- A local color table entry -->
<!ATTLIST "ColorTableEntry" "index" #CDATA #REQUIRED>
<!-- The index of the color table entry -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ATTLIST "ColorTableEntry" "red" #CDATA #REQUIRED>
<!-- The red value for the color table entry -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ATTLIST "ColorTableEntry" "green" #CDATA #REQUIRED>
<!-- The green value for the color table entry -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ATTLIST "ColorTableEntry" "blue" #CDATA #REQUIRED>
<!-- The blue value for the color table entry -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ELEMENT "GraphicControlExtension" EMPTY>
<!-- A graphic control extension -->
<!ATTLIST "GraphicControlExtension" "disposalMethod" ("none" |
"doNotDispose" | "restoreToBackgroundColor" |
"restoreToPrevious" | "undefinedDisposalMethod4" |
"undefinedDisposalMethod5" | "undefinedDisposalMethod6" |
"undefinedDisposalMethod7") #REQUIRED>
<!-- The disposal method for this frame -->
<!ATTLIST "GraphicControlExtension" "userInputFlag" ("TRUE" |
"FALSE") #REQUIRED>
<!-- True if the frame should be advanced based on user input -->
<!ATTLIST "GraphicControlExtension" "transparentColorFlag" (
"TRUE" | "FALSE") #REQUIRED>
<!-- True if a transparent color exists -->
<!ATTLIST "GraphicControlExtension" "delayTime" #CDATA #REQUIRED>
<!-- The time to delay between frames, in hundredths of a second -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 65535 (inclusive) -->
<!ATTLIST "GraphicControlExtension" "transparentColorIndex"
#CDATA #REQUIRED>
<!-- The transparent color, if transparentColorFlag is true -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ELEMENT "PlainTextExtension" EMPTY>
<!-- A plain text (text grid) extension -->
<!ATTLIST "PlainTextExtension" "textGridLeft" #CDATA #REQUIRED>
<!-- The X offset of the text grid -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 65535 (inclusive) -->
<!ATTLIST "PlainTextExtension" "textGridTop" #CDATA #REQUIRED>
<!-- The Y offset of the text grid -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 65535 (inclusive) -->
<!ATTLIST "PlainTextExtension" "textGridWidth" #CDATA #REQUIRED>
<!-- The number of columns in the text grid -->
<!-- Data type: Integer -->
<!-- Min value: 1 (inclusive) -->
<!-- Max value: 65535 (inclusive) -->
<!ATTLIST "PlainTextExtension" "textGridHeight" #CDATA #REQUIRED>
<!-- The number of rows in the text grid -->
<!-- Data type: Integer -->
<!-- Min value: 1 (inclusive) -->
<!-- Max value: 65535 (inclusive) -->
<!ATTLIST "PlainTextExtension" "characterCellWidth" #CDATA
#REQUIRED>
<!-- The width of a character cell -->
<!-- Data type: Integer -->
<!-- Min value: 1 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ATTLIST "PlainTextExtension" "characterCellHeight" #CDATA
#REQUIRED>
<!-- The height of a character cell -->
<!-- Data type: Integer -->
<!-- Min value: 1 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ATTLIST "PlainTextExtension" "textForegroundColor" #CDATA
#REQUIRED>
<!-- The text foreground color index -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ATTLIST "PlainTextExtension" "textBackgroundColor" #CDATA
#REQUIRED>
<!-- The text background color index -->
<!-- Data type: Integer -->
<!-- Min value: 0 (inclusive) -->
<!-- Max value: 255 (inclusive) -->
<!ELEMENT "ApplicationExtensions" (ApplicationExtension)*>
<!-- A set of application extensions -->
<!-- Min children: 1 -->
<!-- Max children: 2147483647 -->
<!ELEMENT "ApplicationExtension" EMPTY>
<!-- An application extension -->
<!-- User object: array of byte -->
<!-- Min length: 0 -->
<!-- Max length: 2147483647 -->
<!ATTLIST "ApplicationExtension" "applicationID" #CDATA
#REQUIRED>
<!-- The application ID -->
<!-- Data type: String -->
<!ATTLIST "ApplicationExtension" "authenticationCode" #CDATA
#REQUIRED>
<!-- The authentication code -->
<!-- Data type: String -->
<!ELEMENT "CommentExtensions" (CommentExtension)*>
<!-- A set of comments -->
<!-- Min children: 1 -->
<!-- Max children: 2147483647 -->
<!ELEMENT "CommentExtension" EMPTY>
<!-- A comment -->
<!ATTLIST "CommentExtension" "value" #CDATA #REQUIRED>
<!-- The comment -->
<!-- Data type: String -->
]>
| 索引 | 标准元数据组件 | GIF 原生流元数据组件 |
|---|---|---|
| 1 | /色度/调色板/PaletteEntry@index | /GlobalColorTable/ColorTableEntry@index |
| 2 | /色度/调色板/PaletteEntry@red | /GlobalColorTable/ColorTableEntry@red |
| 3 | /色度/调色板/PaletteEntry@green | /GlobalColorTable/ColorTableEntry@green |
| 4 | /色度/调色板/PaletteEntry@blue | /GlobalColorTable/ColorTableEntry@blue |
| 5 | /色度/BackgroundIndex@value | /GlobalColorTable@backgroundColorIndex |
| 6 | /数据/BitsPerSample@value | /LogicalScreenDescriptor@colorResolution |
| 7 | /维度/PixelAspectRatio@value | /LogicalScreenDescriptor@pixelAspectRatio |
| 8 | /维度/HorizontalScreenSize@value | /LogicalScreenDescriptor@logicalScreenWidth |
| 9 | /维度/VerticalScreenSize@value | /LogicalScreenDescriptor@logicalScreenHeight |
| 10 | /文档/格式版本@值 | /版本@值 |
| 索引 | 标准元数据组件 | GIF 原生图像元数据组件 |
|---|---|---|
| 1 | /色度/调色板/PaletteEntry@index | /LocalColorTable/ColorTableEntry@index |
| 2 | /色度/调色板/PaletteEntry@red | /LocalColorTable/ColorTableEntry@red |
| 3 | /色度/调色板/PaletteEntry@green | /LocalColorTable/ColorTableEntry@green |
| 4 | /色度/调色板/PaletteEntry@blue | /LocalColorTable/ColorTableEntry@blue |
| 5 | /维度/HorizontalPixelOffset@value | /ImageDescriptor@imageLeftPosition |
| 6 | /维度/VerticalPixelOffset@value | /ImageDescriptor@imageTopPosition |
| 7 | /文本/TextEntry@value | /CommentExtensions/CommentExtension@value |
| 8 | /透明度/TransparentIndex@value | /GraphicControlExtension@transparentColorIndex(/GraphicControlExtension@transparentColorFlag 也设置为“TRUE”) |