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, 2019, 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 <main role="main"> 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 <!DOCTYPE "javax_imageio_gif_stream_1.0" [ 57 58 <!ELEMENT "javax_imageio_gif_stream_1.0" (Version?, 59 LogicalScreenDescriptor?, GlobalColorTable?)> 60 61 <!ELEMENT "Version" EMPTY> 62 <!-- The file version, either 87a or 89a --> 63 <!ATTLIST "Version" "value" ("87a" | "89a") #REQUIRED> 64 <!-- The version string --> 65 66 <!ELEMENT "LogicalScreenDescriptor" EMPTY> 67 <!-- The logical screen descriptor, except for the global color table --> 68 <!ATTLIST "LogicalScreenDescriptor" "logicalScreenWidth" #CDATA 69 #REQUIRED> 70 <!-- The width in pixels of the whole picture --> 71 <!-- Data type: Integer --> 72 <!-- Min value: 1 (inclusive) --> 73 <!-- Max value: 65535 (inclusive) --> 74 <!ATTLIST "LogicalScreenDescriptor" "logicalScreenHeight" #CDATA 75 #REQUIRED> 76 <!-- The height in pixels of the whole picture --> 77 <!-- Data type: Integer --> 78 <!-- Min value: 1 (inclusive) --> 79 <!-- Max value: 65535 (inclusive) --> 80 <!ATTLIST "LogicalScreenDescriptor" "colorResolution" #CDATA 81 #REQUIRED> 82 <!-- The number of bits of color resolution, beteen 1 and 8 --> 83 <!-- Data type: Integer --> 84 <!-- Min value: 1 (inclusive) --> 85 <!-- Max value: 8 (inclusive) --> 86 <!ATTLIST "LogicalScreenDescriptor" "pixelAspectRatio" #CDATA 87 #REQUIRED> 88 <!-- If 0, indicates square pixels, else W/H = (value + 15)/64 --> 89 <!-- Data type: Integer --> 90 <!-- Min value: 0 (inclusive) --> 91 <!-- Max value: 255 (inclusive) --> 92 93 <!ELEMENT "GlobalColorTable" (ColorTableEntry)*> 94 <!-- The global color table --> 95 <!-- Min children: 2 --> 96 <!-- Max children: 256 --> 97 <!ATTLIST "GlobalColorTable" "sizeOfGlobalColorTable" ("2" | 98 "4" | "8" | "16" | "32" | "64" | "128" | "256") #REQUIRED> 99 <!-- The number of entries in the global color table --> 100 <!ATTLIST "GlobalColorTable" "backgroundColorIndex" #CDATA 101 #REQUIRED> 102 <!-- The index of the color table entry to be used as a background --> 103 <!-- Data type: Integer --> 104 <!-- Min value: 0 (inclusive) --> 105 <!-- Max value: 255 (inclusive) --> 106 <!ATTLIST "GlobalColorTable" "sortFlag" ("TRUE" | "FALSE") 107 #REQUIRED> 108 <!-- True if the global color table is sorted by frequency --> 109 110 <!ELEMENT "ColorTableEntry" EMPTY> 111 <!-- A global color table entry --> 112 <!ATTLIST "ColorTableEntry" "index" #CDATA #REQUIRED> 113 <!-- The index of the color table entry --> 114 <!-- Data type: Integer --> 115 <!-- Min value: 0 (inclusive) --> 116 <!-- Max value: 255 (inclusive) --> 117 <!ATTLIST "ColorTableEntry" "red" #CDATA #REQUIRED> 118 <!-- The red value for the color table entry --> 119 <!-- Data type: Integer --> 120 <!-- Min value: 0 (inclusive) --> 121 <!-- Max value: 255 (inclusive) --> 122 <!ATTLIST "ColorTableEntry" "green" #CDATA #REQUIRED> 123 <!-- The green value for the color table entry --> 124 <!-- Data type: Integer --> 125 <!-- Min value: 0 (inclusive) --> 126 <!-- Max value: 255 (inclusive) --> 127 <!ATTLIST "ColorTableEntry" "blue" #CDATA #REQUIRED> 128 <!-- The blue value for the color table entry --> 129 <!-- Data type: Integer --> 130 <!-- Min value: 0 (inclusive) --> 131 <!-- Max value: 255 (inclusive) --> 132 ]> 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 <!DOCTYPE "javax_imageio_gif_image_1.0" [ 176 177 <!ELEMENT "javax_imageio_gif_image_1.0" (ImageDescriptor?, 178 LocalColorTable?, GraphicControlExtension?, PlainTextExtension?, 179 ApplicationExtensions?, CommentExtensions?)> 180 181 <!ELEMENT "ImageDescriptor" EMPTY> 182 <!-- The image descriptor --> 183 <!ATTLIST "ImageDescriptor" "imageLeftPosition" #CDATA #REQUIRED> 184 <!-- The X offset of the image relative to the screen origin --> 185 <!-- Data type: Integer --> 186 <!-- Min value: 0 (inclusive) --> 187 <!-- Max value: 65535 (inclusive) --> 188 <!ATTLIST "ImageDescriptor" "imageTopPosition" #CDATA #REQUIRED> 189 <!-- The Y offset of the image relative to the screen origin --> 190 <!-- Data type: Integer --> 191 <!-- Min value: 0 (inclusive) --> 192 <!-- Max value: 65535 (inclusive) --> 193 <!ATTLIST "ImageDescriptor" "imageWidth" #CDATA #REQUIRED> 194 <!-- The width of the image --> 195 <!-- Data type: Integer --> 196 <!-- Min value: 1 (inclusive) --> 197 <!-- Max value: 65535 (inclusive) --> 198 <!ATTLIST "ImageDescriptor" "imageHeight" #CDATA #REQUIRED> 199 <!-- The height of the image --> 200 <!-- Data type: Integer --> 201 <!-- Min value: 1 (inclusive) --> 202 <!-- Max value: 65535 (inclusive) --> 203 <!ATTLIST "ImageDescriptor" "interlaceFlag" ("TRUE" | "FALSE") 204 #REQUIRED> 205 <!-- True if the image is stored using interlacing --> 206 207 <!ELEMENT "LocalColorTable" (ColorTableEntry)*> 208 <!-- The local color table --> 209 <!-- Min children: 2 --> 210 <!-- Max children: 256 --> 211 <!ATTLIST "LocalColorTable" "sizeOfLocalColorTable" ("2" | 212 "4" | "8" | "16" | "32" | "64" | "128" | "256") #REQUIRED> 213 <!-- The number of entries in the local color table --> 214 <!ATTLIST "LocalColorTable" "sortFlag" ("TRUE" | "FALSE") 215 #REQUIRED> 216 <!-- True if the local color table is sorted by frequency --> 217 218 <!ELEMENT "ColorTableEntry" EMPTY> 219 <!-- A local color table entry --> 220 <!ATTLIST "ColorTableEntry" "index" #CDATA #REQUIRED> 221 <!-- The index of the color table entry --> 222 <!-- Data type: Integer --> 223 <!-- Min value: 0 (inclusive) --> 224 <!-- Max value: 255 (inclusive) --> 225 <!ATTLIST "ColorTableEntry" "red" #CDATA #REQUIRED> 226 <!-- The red value for the color table entry --> 227 <!-- Data type: Integer --> 228 <!-- Min value: 0 (inclusive) --> 229 <!-- Max value: 255 (inclusive) --> 230 <!ATTLIST "ColorTableEntry" "green" #CDATA #REQUIRED> 231 <!-- The green value for the color table entry --> 232 <!-- Data type: Integer --> 233 <!-- Min value: 0 (inclusive) --> 234 <!-- Max value: 255 (inclusive) --> 235 <!ATTLIST "ColorTableEntry" "blue" #CDATA #REQUIRED> 236 <!-- The blue value for the color table entry --> 237 <!-- Data type: Integer --> 238 <!-- Min value: 0 (inclusive) --> 239 <!-- Max value: 255 (inclusive) --> 240 241 <!ELEMENT "GraphicControlExtension" EMPTY> 242 <!-- A graphic control extension --> 243 <!ATTLIST "GraphicControlExtension" "disposalMethod" ("none" | 244 "doNotDispose" | "restoreToBackgroundColor" | 245 "restoreToPrevious" | "undefinedDisposalMethod4" | 246 "undefinedDisposalMethod5" | "undefinedDisposalMethod6" | 247 "undefinedDisposalMethod7") #REQUIRED> 248 <!-- The disposal method for this frame --> 249 <!ATTLIST "GraphicControlExtension" "userInputFlag" ("TRUE" | 250 "FALSE") #REQUIRED> 251 <!-- True if the frame should be advanced based on user input --> 252 <!ATTLIST "GraphicControlExtension" "transparentColorFlag" ( 253 "TRUE" | "FALSE") #REQUIRED> 254 <!-- True if a transparent color exists --> 255 <!ATTLIST "GraphicControlExtension" "delayTime" #CDATA #REQUIRED> 256 <!-- The time to delay between frames, in hundredths of a second --> 257 <!-- Data type: Integer --> 258 <!-- Min value: 0 (inclusive) --> 259 <!-- Max value: 65535 (inclusive) --> 260 <!ATTLIST "GraphicControlExtension" "transparentColorIndex" 261 #CDATA #REQUIRED> 262 <!-- The transparent color, if transparentColorFlag is true --> 263 <!-- Data type: Integer --> 264 <!-- Min value: 0 (inclusive) --> 265 <!-- Max value: 255 (inclusive) --> 266 267 <!ELEMENT "PlainTextExtension" EMPTY> 268 <!-- A plain text (text grid) extension --> 269 <!ATTLIST "PlainTextExtension" "textGridLeft" #CDATA #REQUIRED> 270 <!-- The X offset of the text grid --> 271 <!-- Data type: Integer --> 272 <!-- Min value: 0 (inclusive) --> 273 <!-- Max value: 65535 (inclusive) --> 274 <!ATTLIST "PlainTextExtension" "textGridTop" #CDATA #REQUIRED> 275 <!-- The Y offset of the text grid --> 276 <!-- Data type: Integer --> 277 <!-- Min value: 0 (inclusive) --> 278 <!-- Max value: 65535 (inclusive) --> 279 <!ATTLIST "PlainTextExtension" "textGridWidth" #CDATA #REQUIRED> 280 <!-- The number of columns in the text grid --> 281 <!-- Data type: Integer --> 282 <!-- Min value: 1 (inclusive) --> 283 <!-- Max value: 65535 (inclusive) --> 284 <!ATTLIST "PlainTextExtension" "textGridHeight" #CDATA #REQUIRED> 285 <!-- The number of rows in the text grid --> 286 <!-- Data type: Integer --> 287 <!-- Min value: 1 (inclusive) --> 288 <!-- Max value: 65535 (inclusive) --> 289 <!ATTLIST "PlainTextExtension" "characterCellWidth" #CDATA 290 #REQUIRED> 291 <!-- The width of a character cell --> 292 <!-- Data type: Integer --> 293 <!-- Min value: 1 (inclusive) --> 294 <!-- Max value: 255 (inclusive) --> 295 <!ATTLIST "PlainTextExtension" "characterCellHeight" #CDATA 296 #REQUIRED> 297 <!-- The height of a character cell --> 298 <!-- Data type: Integer --> 299 <!-- Min value: 1 (inclusive) --> 300 <!-- Max value: 255 (inclusive) --> 301 <!ATTLIST "PlainTextExtension" "textForegroundColor" #CDATA 302 #REQUIRED> 303 <!-- The text foreground color index --> 304 <!-- Data type: Integer --> 305 <!-- Min value: 0 (inclusive) --> 306 <!-- Max value: 255 (inclusive) --> 307 <!ATTLIST "PlainTextExtension" "textBackgroundColor" #CDATA 308 #REQUIRED> 309 <!-- The text background color index --> 310 <!-- Data type: Integer --> 311 <!-- Min value: 0 (inclusive) --> 312 <!-- Max value: 255 (inclusive) --> 313 314 <!ELEMENT "ApplicationExtensions" (ApplicationExtension)*> 315 <!-- A set of application extensions --> 316 <!-- Min children: 1 --> 317 <!-- Max children: 2147483647 --> 318 319 <!ELEMENT "ApplicationExtension" EMPTY> 320 <!-- An application extension --> 321 <!-- User object: array of byte --> 322 <!-- Min length: 0 --> 323 <!-- Max length: 2147483647 --> 324 <!ATTLIST "ApplicationExtension" "applicationID" #CDATA 325 #REQUIRED> 326 <!-- The application ID --> 327 <!-- Data type: String --> 328 <!ATTLIST "ApplicationExtension" "authenticationCode" #CDATA 329 #REQUIRED> 330 <!-- The authentication code --> 331 <!-- Data type: String --> 332 333 <!ELEMENT "CommentExtensions" (CommentExtension)*> 334 <!-- A set of comments --> 335 <!-- Min children: 1 --> 336 <!-- Max children: 2147483647 --> 337 338 <!ELEMENT "CommentExtension" EMPTY> 339 <!-- A comment --> 340 <!ATTLIST "CommentExtension" "value" #CDATA #REQUIRED> 341 <!-- The comment --> 342 <!-- Data type: String --> 343 ]> 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 <thead> 351 <tr> 352 <th scope="col">Index</th> 353 <th scope="col">Standard Metadata Component</th> 354 <th scope="col">GIF Native Stream Metadata Component</th> 355 </tr> 356 </thead> 357 <tbody> 358 <tr> 359 <th scope="row">1</th> 360 <td>/Chroma/Palette/PaletteEntry@index</td> 361 <td>/GlobalColorTable/ColorTableEntry@index</td> 362 </tr> 363 <tr> 364 <th scope="row">2</th> 365 <td>/Chroma/Palette/PaletteEntry@red</td> 366 <td>/GlobalColorTable/ColorTableEntry@red</td> 367 </tr> 368 <tr> 369 <th scope="row">3</th> 370 <td>/Chroma/Palette/PaletteEntry@green</td> 371 <td>/GlobalColorTable/ColorTableEntry@green</td> 372 </tr> 373 <tr> 374 <th scope="row">4</th> 375 <td>/Chroma/Palette/PaletteEntry@blue</td> 376 <td>/GlobalColorTable/ColorTableEntry@blue</td> 377 </tr> 378 <tr> 379 <th scope="row">5</th> 380 <td>/Chroma/BackgroundIndex@value</td> 381 <td>/GlobalColorTable@backgroundColorIndex</td> 382 </tr> 383 <tr> 384 <th scope="row">6</th> 385 <td>/Data/BitsPerSample@value</td> 386 <td>/LogicalScreenDescriptor@colorResolution</td> 387 </tr> 388 <tr> 389 <th scope="row">7</th> 390 <td>/Dimension/PixelAspectRatio@value</td> 391 <td>/LogicalScreenDescriptor@pixelAspectRatio</td> 392 </tr> 393 <tr> 394 <th scope="row">8</th> 395 <td>/Dimension/HorizontalScreenSize@value</td> 396 <td>/LogicalScreenDescriptor@logicalScreenWidth</td> 397 </tr> 398 <tr> 399 <th scope="row">9</th> 400 <td>/Dimension/VerticalScreenSize@value</td> 401 <td>/LogicalScreenDescriptor@logicalScreenHeight</td> 402 </tr> 403 <tr> 404 <th scope="row">10</th> 405 <td>/Document/FormatVersion@value</td> 406 <td>/Version@value</td> 407 </tr> 408 </tbody> 409 </table> 410 411 <table border=1> 412 <caption><b>Mapping of Standard to GIF Native Image Metadata</b></caption> 413 <thead> 414 <tr> 415 <th scope="col">Index</th> 416 <th scope="col">Standard Metadata Component</th> 417 <th scope="col">GIF Native Image Metadata Component</th> 418 </tr> 419 </thead> 420 <tbody> 421 <tr> 422 <th scope="row">1</th> 423 <td>/Chroma/Palette/PaletteEntry@index</td> 424 <td>/LocalColorTable/ColorTableEntry@index</td> 425 </tr> 426 <tr> 427 <th scope="row">2</th> 428 <td>/Chroma/Palette/PaletteEntry@red</td> 429 <td>/LocalColorTable/ColorTableEntry@red</td> 430 </tr> 431 <tr> 432 <th scope="row">3</th> 433 <td>/Chroma/Palette/PaletteEntry@green</td> 434 <td>/LocalColorTable/ColorTableEntry@green</td> 435 </tr> 436 <tr> 437 <th scope="row">4</th> 438 <td>/Chroma/Palette/PaletteEntry@blue</td> 439 <td>/LocalColorTable/ColorTableEntry@blue</td> 440 </tr> 441 <tr> 442 <th scope="row">5</th> 443 <td>/Dimension/HorizontalPixelOffset@value</td> 444 <td>/ImageDescriptor@imageLeftPosition</td> 445 </tr> 446 <tr> 447 <th scope="row">6</th> 448 <td>/Dimension/VerticalPixelOffset@value</td> 449 <td>/ImageDescriptor@imageTopPosition</td> 450 </tr> 451 <tr> 452 <th scope="row">7</th> 453 <td>/Text/TextEntry@value</td> 454 <td>/CommentExtensions/CommentExtension@value</td> 455 </tr> 456 <tr> 457 <th scope="row">8</th> 458 <td>/Transparency/TransparentIndex@value</td> 459 <td>/GraphicControlExtension@transparentColorIndex 460 (/GraphicControlExtension@transparentColorFlag is also set to 461 "TRUE")</td> 462 </tr> 463 </tbody> 464 </table> 465 </main> 466 </body> 467 </html>