1 <!doctype html>
   2 <html lang="en">
   3 <head>
   4   <meta charset="utf-8"/>
   5   <title>GIF Metadata Format Specification</title>
   6 </head>
   7 <!--
   8 Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
   9 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  10 
  11 This code is free software; you can redistribute it and/or modify it
  12 under the terms of the GNU General Public License version 2 only, as
  13 published by the Free Software Foundation.  Oracle designates this
  14 particular file as subject to the "Classpath" exception as provided
  15 by Oracle in the LICENSE file that accompanied this code.
  16 
  17 This code is distributed in the hope that it will be useful, but WITHOUT
  18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  19 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  20 version 2 for more details (a copy is included in the LICENSE file that
  21 accompanied this code).
  22 
  23 You should have received a copy of the GNU General Public License version
  24 2 along with this work; if not, write to the Free Software Foundation,
  25 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  26 
  27 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  28 or visit www.oracle.com if you need additional information or have any
  29 questions.
  30 -->
  31 
  32 <body>
  33 
  34 <h1>GIF Metadata Format Specification</h1>
  35 <a id="gif_stream_metadata_format"></a>
  36 <h2>GIF Stream Metadata Format Specification</h2>
  37 
  38 <p>
  39 
  40 The GIF stream metadata format encodes the information stored in the
  41 per-file header, namely the file version, logical screen descriptor,
  42 and the global color table.
  43 
  44 <p>
  45 
  46 The logical screen descriptor describes the overall width and height
  47 of an animated file, as well as information about the color resolution
  48 (number of bits per pixel) and pixel aspect ratio.
  49 
  50 <p>
  51 
  52 The global color table contains a color lookup table that is used for
  53 images that do not have their own local color table.
  54 
  55 <pre>
  56 &lt;!DOCTYPE "javax_imageio_gif_stream_1.0" [
  57 
  58   &lt;!ELEMENT "javax_imageio_gif_stream_1.0" (Version?,
  59     LogicalScreenDescriptor?, GlobalColorTable?)&gt;
  60 
  61     &lt;!ELEMENT "Version" EMPTY&gt;
  62       &lt;!-- The file version, either 87a or 89a --&gt;
  63       &lt;!ATTLIST "Version" "value" ("87a" | "89a") #REQUIRED&gt;
  64         &lt;!-- The version string --&gt;
  65 
  66     &lt;!ELEMENT "LogicalScreenDescriptor" EMPTY&gt;
  67       &lt;!-- The logical screen descriptor, except for the global color table --&gt;
  68       &lt;!ATTLIST "LogicalScreenDescriptor" "logicalScreenWidth" #CDATA
  69          #REQUIRED&gt;
  70         &lt;!-- The width in pixels of the whole picture --&gt;
  71         &lt;!-- Data type: Integer --&gt;
  72         &lt;!-- Min value: 1 (inclusive) --&gt;
  73         &lt;!-- Max value: 65535 (inclusive) --&gt;
  74       &lt;!ATTLIST "LogicalScreenDescriptor" "logicalScreenHeight" #CDATA
  75          #REQUIRED&gt;
  76         &lt;!-- The height in pixels of the whole picture --&gt;
  77         &lt;!-- Data type: Integer --&gt;
  78         &lt;!-- Min value: 1 (inclusive) --&gt;
  79         &lt;!-- Max value: 65535 (inclusive) --&gt;
  80       &lt;!ATTLIST "LogicalScreenDescriptor" "colorResolution" #CDATA
  81          #REQUIRED&gt;
  82         &lt;!-- The number of bits of color resolution, beteen 1 and 8 --&gt;
  83         &lt;!-- Data type: Integer --&gt;
  84         &lt;!-- Min value: 1 (inclusive) --&gt;
  85         &lt;!-- Max value: 8 (inclusive) --&gt;
  86       &lt;!ATTLIST "LogicalScreenDescriptor" "pixelAspectRatio" #CDATA
  87          #REQUIRED&gt;
  88         &lt;!-- If 0, indicates square pixels, else W/H = (value + 15)/64 --&gt;
  89         &lt;!-- Data type: Integer --&gt;
  90         &lt;!-- Min value: 0 (inclusive) --&gt;
  91         &lt;!-- Max value: 255 (inclusive) --&gt;
  92 
  93     &lt;!ELEMENT "GlobalColorTable" (ColorTableEntry)*&gt;
  94       &lt;!-- The global color table --&gt;
  95       &lt;!-- Min children: 2 --&gt;
  96       &lt;!-- Max children: 256 --&gt;
  97       &lt;!ATTLIST "GlobalColorTable" "sizeOfGlobalColorTable" ("2" |
  98         "4" | "8" | "16" | "32" | "64" | "128" | "256") #REQUIRED&gt;
  99         &lt;!-- The number of entries in the global color table --&gt;
 100       &lt;!ATTLIST "GlobalColorTable" "backgroundColorIndex" #CDATA
 101          #REQUIRED&gt;
 102         &lt;!-- The index of the color table entry to be used as a background --&gt;
 103         &lt;!-- Data type: Integer --&gt;
 104         &lt;!-- Min value: 0 (inclusive) --&gt;
 105         &lt;!-- Max value: 255 (inclusive) --&gt;
 106       &lt;!ATTLIST "GlobalColorTable" "sortFlag" ("TRUE" | "FALSE")
 107          #REQUIRED&gt;
 108         &lt;!-- True if the global color table is sorted by frequency --&gt;
 109 
 110       &lt;!ELEMENT "ColorTableEntry" EMPTY&gt;
 111         &lt;!-- A global color table entry --&gt;
 112         &lt;!ATTLIST "ColorTableEntry" "index" #CDATA #REQUIRED&gt;
 113           &lt;!-- The index of the color table entry --&gt;
 114           &lt;!-- Data type: Integer --&gt;
 115           &lt;!-- Min value: 0 (inclusive) --&gt;
 116           &lt;!-- Max value: 255 (inclusive) --&gt;
 117         &lt;!ATTLIST "ColorTableEntry" "red" #CDATA #REQUIRED&gt;
 118           &lt;!-- The red value for the color table entry --&gt;
 119           &lt;!-- Data type: Integer --&gt;
 120           &lt;!-- Min value: 0 (inclusive) --&gt;
 121           &lt;!-- Max value: 255 (inclusive) --&gt;
 122         &lt;!ATTLIST "ColorTableEntry" "green" #CDATA #REQUIRED&gt;
 123           &lt;!-- The green value for the color table entry --&gt;
 124           &lt;!-- Data type: Integer --&gt;
 125           &lt;!-- Min value: 0 (inclusive) --&gt;
 126           &lt;!-- Max value: 255 (inclusive) --&gt;
 127         &lt;!ATTLIST "ColorTableEntry" "blue" #CDATA #REQUIRED&gt;
 128           &lt;!-- The blue value for the color table entry --&gt;
 129           &lt;!-- Data type: Integer --&gt;
 130           &lt;!-- Min value: 0 (inclusive) --&gt;
 131           &lt;!-- Max value: 255 (inclusive) --&gt;
 132 ]&gt;
 133 </pre>
 134 <a id="gif_image_metadata_format"></a>
 135 <h2>GIF Image Metadata Format Specification</h2>
 136 <p>
 137 
 138 The GIF image metadata format encodes the image descriptor, local
 139 color table, and extension information assciated with a single image
 140 within a GIF file, typically a frame of an animation.
 141 
 142 <p>
 143 
 144 The image description contains the offset of the frame within the
 145 logical screen described in the stream metadata, as well as the width
 146 and height of the frame and whether it is used interlaced encoding.
 147 
 148 <p>
 149 
 150 The local color table, if present, supersedes the global color table
 151 for the frame at hand.
 152 
 153 <p>
 154 
 155 The graphic control extension contains information on how the frame is
 156 to be incorporated into the animation.  The disposal method indicates
 157 whether the current frame should remain in place
 158 (<code>doNotDispose</code>), be restored to the backgound color as
 159 specified in the stream metadata
 160 (<code>restoreToBackgroundColor</code>), or be restored to the
 161 previous frame contents (<code>restoreToPrevious</code>) prior to
 162 displaying the subsequent frame.
 163 
 164 <p>
 165 
 166 The user input flag indicates whether the animation should pause for
 167 user input before advancing to the next frame.  The transparent color
 168 flag and index indicate a color index for which pixels of the frame
 169 should not be drawn.  The delay time indicates how long the frame
 170 should be displayed, in hundredths of a second.  If the user input
 171 flag is set and the delay time is 0, the frame is intended to be
 172 advanced only on user input.
 173 
 174 <pre>
 175 &lt;!DOCTYPE "javax_imageio_gif_image_1.0" [
 176 
 177   &lt;!ELEMENT "javax_imageio_gif_image_1.0" (ImageDescriptor?,
 178     LocalColorTable?, GraphicControlExtension?, PlainTextExtension?,
 179     ApplicationExtensions?, CommentExtensions?)&gt;
 180 
 181     &lt;!ELEMENT "ImageDescriptor" EMPTY&gt;
 182       &lt;!-- The image descriptor --&gt;
 183       &lt;!ATTLIST "ImageDescriptor" "imageLeftPosition" #CDATA #REQUIRED&gt;
 184         &lt;!-- The X offset of the image relative to the screen origin --&gt;
 185         &lt;!-- Data type: Integer --&gt;
 186         &lt;!-- Min value: 0 (inclusive) --&gt;
 187         &lt;!-- Max value: 65535 (inclusive) --&gt;
 188       &lt;!ATTLIST "ImageDescriptor" "imageTopPosition" #CDATA #REQUIRED&gt;
 189         &lt;!-- The Y offset of the image relative to the screen origin --&gt;
 190         &lt;!-- Data type: Integer --&gt;
 191         &lt;!-- Min value: 0 (inclusive) --&gt;
 192         &lt;!-- Max value: 65535 (inclusive) --&gt;
 193       &lt;!ATTLIST "ImageDescriptor" "imageWidth" #CDATA #REQUIRED&gt;
 194         &lt;!-- The width of the image --&gt;
 195         &lt;!-- Data type: Integer --&gt;
 196         &lt;!-- Min value: 1 (inclusive) --&gt;
 197         &lt;!-- Max value: 65535 (inclusive) --&gt;
 198       &lt;!ATTLIST "ImageDescriptor" "imageHeight" #CDATA #REQUIRED&gt;
 199         &lt;!-- The height of the image --&gt;
 200         &lt;!-- Data type: Integer --&gt;
 201         &lt;!-- Min value: 1 (inclusive) --&gt;
 202         &lt;!-- Max value: 65535 (inclusive) --&gt;
 203       &lt;!ATTLIST "ImageDescriptor" "interlaceFlag" ("TRUE" | "FALSE")
 204          #REQUIRED&gt;
 205         &lt;!-- True if the image is stored using interlacing --&gt;
 206 
 207     &lt;!ELEMENT "LocalColorTable" (ColorTableEntry)*&gt;
 208       &lt;!-- The local color table --&gt;
 209       &lt;!-- Min children: 2 --&gt;
 210       &lt;!-- Max children: 256 --&gt;
 211       &lt;!ATTLIST "LocalColorTable" "sizeOfLocalColorTable" ("2" |
 212         "4" | "8" | "16" | "32" | "64" | "128" | "256") #REQUIRED&gt;
 213         &lt;!-- The number of entries in the local color table --&gt;
 214       &lt;!ATTLIST "LocalColorTable" "sortFlag" ("TRUE" | "FALSE")
 215          #REQUIRED&gt;
 216         &lt;!-- True if the local color table is sorted by frequency --&gt;
 217 
 218       &lt;!ELEMENT "ColorTableEntry" EMPTY&gt;
 219         &lt;!-- A local color table entry --&gt;
 220         &lt;!ATTLIST "ColorTableEntry" "index" #CDATA #REQUIRED&gt;
 221           &lt;!-- The index of the color table entry --&gt;
 222           &lt;!-- Data type: Integer --&gt;
 223           &lt;!-- Min value: 0 (inclusive) --&gt;
 224           &lt;!-- Max value: 255 (inclusive) --&gt;
 225         &lt;!ATTLIST "ColorTableEntry" "red" #CDATA #REQUIRED&gt;
 226           &lt;!-- The red value for the color table entry --&gt;
 227           &lt;!-- Data type: Integer --&gt;
 228           &lt;!-- Min value: 0 (inclusive) --&gt;
 229           &lt;!-- Max value: 255 (inclusive) --&gt;
 230         &lt;!ATTLIST "ColorTableEntry" "green" #CDATA #REQUIRED&gt;
 231           &lt;!-- The green value for the color table entry --&gt;
 232           &lt;!-- Data type: Integer --&gt;
 233           &lt;!-- Min value: 0 (inclusive) --&gt;
 234           &lt;!-- Max value: 255 (inclusive) --&gt;
 235         &lt;!ATTLIST "ColorTableEntry" "blue" #CDATA #REQUIRED&gt;
 236           &lt;!-- The blue value for the color table entry --&gt;
 237           &lt;!-- Data type: Integer --&gt;
 238           &lt;!-- Min value: 0 (inclusive) --&gt;
 239           &lt;!-- Max value: 255 (inclusive) --&gt;
 240 
 241     &lt;!ELEMENT "GraphicControlExtension" EMPTY&gt;
 242       &lt;!-- A graphic control extension --&gt;
 243       &lt;!ATTLIST "GraphicControlExtension" "disposalMethod" ("none" |
 244         "doNotDispose" | "restoreToBackgroundColor" |
 245         "restoreToPrevious" | "undefinedDisposalMethod4" |
 246         "undefinedDisposalMethod5" | "undefinedDisposalMethod6" |
 247         "undefinedDisposalMethod7") #REQUIRED&gt;
 248         &lt;!-- The disposal method for this frame --&gt;
 249       &lt;!ATTLIST "GraphicControlExtension" "userInputFlag" ("TRUE" |
 250         "FALSE") #REQUIRED&gt;
 251         &lt;!-- True if the frame should be advanced based on user input --&gt;
 252       &lt;!ATTLIST "GraphicControlExtension" "transparentColorFlag" (
 253         "TRUE" | "FALSE") #REQUIRED&gt;
 254         &lt;!-- True if a transparent color exists --&gt;
 255       &lt;!ATTLIST "GraphicControlExtension" "delayTime" #CDATA #REQUIRED&gt;
 256         &lt;!-- The time to delay between frames, in hundredths of a second --&gt;
 257         &lt;!-- Data type: Integer --&gt;
 258         &lt;!-- Min value: 0 (inclusive) --&gt;
 259         &lt;!-- Max value: 65535 (inclusive) --&gt;
 260       &lt;!ATTLIST "GraphicControlExtension" "transparentColorIndex"
 261          #CDATA #REQUIRED&gt;
 262         &lt;!-- The transparent color, if transparentColorFlag is true --&gt;
 263         &lt;!-- Data type: Integer --&gt;
 264         &lt;!-- Min value: 0 (inclusive) --&gt;
 265         &lt;!-- Max value: 255 (inclusive) --&gt;
 266 
 267     &lt;!ELEMENT "PlainTextExtension" EMPTY&gt;
 268       &lt;!-- A plain text (text grid) extension --&gt;
 269       &lt;!ATTLIST "PlainTextExtension" "textGridLeft" #CDATA #REQUIRED&gt;
 270         &lt;!-- The X offset of the text grid --&gt;
 271         &lt;!-- Data type: Integer --&gt;
 272         &lt;!-- Min value: 0 (inclusive) --&gt;
 273         &lt;!-- Max value: 65535 (inclusive) --&gt;
 274       &lt;!ATTLIST "PlainTextExtension" "textGridTop" #CDATA #REQUIRED&gt;
 275         &lt;!-- The Y offset of the text grid --&gt;
 276         &lt;!-- Data type: Integer --&gt;
 277         &lt;!-- Min value: 0 (inclusive) --&gt;
 278         &lt;!-- Max value: 65535 (inclusive) --&gt;
 279       &lt;!ATTLIST "PlainTextExtension" "textGridWidth" #CDATA #REQUIRED&gt;
 280         &lt;!-- The number of columns in the text grid --&gt;
 281         &lt;!-- Data type: Integer --&gt;
 282         &lt;!-- Min value: 1 (inclusive) --&gt;
 283         &lt;!-- Max value: 65535 (inclusive) --&gt;
 284       &lt;!ATTLIST "PlainTextExtension" "textGridHeight" #CDATA #REQUIRED&gt;
 285         &lt;!-- The number of rows in the text grid --&gt;
 286         &lt;!-- Data type: Integer --&gt;
 287         &lt;!-- Min value: 1 (inclusive) --&gt;
 288         &lt;!-- Max value: 65535 (inclusive) --&gt;
 289       &lt;!ATTLIST "PlainTextExtension" "characterCellWidth" #CDATA
 290          #REQUIRED&gt;
 291         &lt;!-- The width of a character cell --&gt;
 292         &lt;!-- Data type: Integer --&gt;
 293         &lt;!-- Min value: 1 (inclusive) --&gt;
 294         &lt;!-- Max value: 65535 (inclusive) --&gt;
 295       &lt;!ATTLIST "PlainTextExtension" "characterCellHeight" #CDATA
 296          #REQUIRED&gt;
 297         &lt;!-- The height of a character cell --&gt;
 298         &lt;!-- Data type: Integer --&gt;
 299         &lt;!-- Min value: 1 (inclusive) --&gt;
 300         &lt;!-- Max value: 65535 (inclusive) --&gt;
 301       &lt;!ATTLIST "PlainTextExtension" "textForegroundColor" #CDATA
 302          #REQUIRED&gt;
 303         &lt;!-- The text foreground color index --&gt;
 304         &lt;!-- Data type: Integer --&gt;
 305         &lt;!-- Min value: 0 (inclusive) --&gt;
 306         &lt;!-- Max value: 255 (inclusive) --&gt;
 307       &lt;!ATTLIST "PlainTextExtension" "textBackgroundColor" #CDATA
 308          #REQUIRED&gt;
 309         &lt;!-- The text background color index --&gt;
 310         &lt;!-- Data type: Integer --&gt;
 311         &lt;!-- Min value: 0 (inclusive) --&gt;
 312         &lt;!-- Max value: 255 (inclusive) --&gt;
 313 
 314     &lt;!ELEMENT "ApplicationExtensions" (ApplicationExtension)*&gt;
 315       &lt;!-- A set of application extensions --&gt;
 316       &lt;!-- Min children: 1 --&gt;
 317       &lt;!-- Max children: 2147483647 --&gt;
 318 
 319       &lt;!ELEMENT "ApplicationExtension" EMPTY&gt;
 320         &lt;!-- An application extension --&gt;
 321         &lt;!-- User object: array of byte --&gt;
 322         &lt;!-- Min length: 0 --&gt;
 323         &lt;!-- Max length: 2147483647 --&gt;
 324         &lt;!ATTLIST "ApplicationExtension" "applicationID" #CDATA
 325            #REQUIRED&gt;
 326           &lt;!-- The application ID --&gt;
 327           &lt;!-- Data type: String --&gt;
 328         &lt;!ATTLIST "ApplicationExtension" "authenticationCode" #CDATA
 329            #REQUIRED&gt;
 330           &lt;!-- The authentication code --&gt;
 331           &lt;!-- Data type: String --&gt;
 332 
 333     &lt;!ELEMENT "CommentExtensions" (CommentExtension)*&gt;
 334       &lt;!-- A set of comments --&gt;
 335       &lt;!-- Min children: 1 --&gt;
 336       &lt;!-- Max children: 2147483647 --&gt;
 337 
 338       &lt;!ELEMENT "CommentExtension" EMPTY&gt;
 339         &lt;!-- A comment --&gt;
 340         &lt;!ATTLIST "CommentExtension" "value" #CDATA #REQUIRED&gt;
 341           &lt;!-- The comment --&gt;
 342           &lt;!-- Data type: String --&gt;
 343 ]&gt;
 344 </pre>
 345 
 346 <p>
 347 <a id="mapping"></a>
 348 <table border=1>
 349 <caption><b>Mapping of Standard to GIF Native Stream Metadata</b></caption>
 350 <tr>
 351 <th>Standard Metadata Component</th>
 352 <th>GIF Native Stream Metadata Component</th>
 353 </tr>
 354 <tr>
 355 <td>/Chroma/Palette/PaletteEntry@index</td>
 356 <td>/GlobalColorTable/ColorTableEntry@index</td>
 357 </tr>
 358 <tr>
 359 <td>/Chroma/Palette/PaletteEntry@red</td>
 360 <td>/GlobalColorTable/ColorTableEntry@red</td>
 361 </tr>
 362 <tr>
 363 <td>/Chroma/Palette/PaletteEntry@green</td>
 364 <td>/GlobalColorTable/ColorTableEntry@green</td>
 365 </tr>
 366 <tr>
 367 <td>/Chroma/Palette/PaletteEntry@blue</td>
 368 <td>/GlobalColorTable/ColorTableEntry@blue</td>
 369 </tr>
 370 <tr>
 371 <td>/Chroma/BackgroundIndex@value</td>
 372 <td>/GlobalColorTable@backgroundColorIndex</td>
 373 </tr>
 374 <tr>
 375 <td>/Data/BitsPerSample@value</td>
 376 <td>/LogicalScreenDescriptor@colorResolution</td>
 377 </tr>
 378 <tr>
 379 <td>/Dimension/PixelAspectRatio@value</td>
 380 <td>/LogicalScreenDescriptor@pixelAspectRatio</td>
 381 </tr>
 382 <tr>
 383 <td>/Dimension/HorizontalScreenSize@value</td>
 384 <td>/LogicalScreenDescriptor@logicalScreenWidth</td>
 385 </tr>
 386 <tr>
 387 <td>/Dimension/VerticalScreenSize@value</td>
 388 <td>/LogicalScreenDescriptor@logicalScreenHeight</td>
 389 </tr>
 390 <tr>
 391 <td>/Document/FormatVersion@value</td>
 392 <td>/Version@value</td>
 393 </tr>
 394 </table>
 395 
 396 <table border=1>
 397 <caption><b>Mapping of Standard to GIF Native Image Metadata</b></caption>
 398 <tr>
 399 <th>Standard Metadata Component</th>
 400 <th>GIF Native Image Metadata Component</th>
 401 </tr>
 402 <tr>
 403 <td>/Chroma/Palette/PaletteEntry@index</td>
 404 <td>/LocalColorTable/ColorTableEntry@index</td>
 405 </tr>
 406 <tr>
 407 <td>/Chroma/Palette/PaletteEntry@red</td>
 408 <td>/LocalColorTable/ColorTableEntry@red</td>
 409 </tr>
 410 <tr>
 411 <td>/Chroma/Palette/PaletteEntry@green</td>
 412 <td>/LocalColorTable/ColorTableEntry@green</td>
 413 </tr>
 414 <tr>
 415 <td>/Chroma/Palette/PaletteEntry@blue</td>
 416 <td>/LocalColorTable/ColorTableEntry@blue</td>
 417 </tr>
 418 <tr>
 419 <td>/Dimension/HorizontalPixelOffset@value</td>
 420 <td>/ImageDescriptor@imageLeftPosition</td>
 421 </tr>
 422 <tr>
 423 <td>/Dimension/VerticalPixelOffset@value</td>
 424 <td>/ImageDescriptor@imageTopPosition</td>
 425 </tr>
 426 <tr>
 427 <td>/Text/TextEntry@value</td>
 428 <td>/CommentExtensions/CommentExtension@value</td>
 429 </tr>
 430 <tr>
 431 <td>/Transparency/TransparentIndex@value</td>
 432 <td>/GraphicControlExtension@transparentColorIndex
 433 (/GraphicControlExtension@transparentColorFlag is also set to
 434 "TRUE")</td>
 435 </tr>
 436 </table>
 437 
 438 </body>
 439 </html>