1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 2<link rel="stylesheet" type="text/css" href="main.css"> 3<link rel="stylesheet" type="text/css" href="gif89a.css"> 4<script type="text/javascript" src="gif89a.js"></script> 5<title>Graphics Interchange Format Version 89a</title> 6</head> 7<body><h1>Graphics Interchange Format Version 89a</h1> 8<!-- source best viewed with tab width 4 --> 9 10<div id="notes"> 11 12<p>The document below is a copy of <a 13href="http://www.w3.org/Graphics/GIF/spec-gif89a.txt">http://www.w3.org/Graphics/GIF/spec-gif89a.txt</a>, 14reformatted into HTML to make it easier to read and print.</p> 15 16<p>Notable changes:</p> 17 18<ul> 19<li>moved chapter "Cover Sheet for the GIF89a Specification" from the 20 beginning to the end</li> 21<li>removed page numbers</li> 22<li>removed redundant rows from <a href="#quickreferencetable">Quick 23 Reference Table</a></li> 24</ul> 25 26You can also read <a href="gif89.txt">the original flat text.</a> 27</div> 28 29<hr> 30 31<p>© 1987, 1988, 1989, 1990</p> 32 33<p>Copyright<br> 34CompuServe Incorporated<br> 35Columbus, Ohio</p> 36 37<p>Graphics Interchange Format Programming Reference</p> 38 39<p>CompuServe Incorporated</p> 40 41<p>Document Date: 31 July 1990</p> 42 43<div class="togglevisall"> 44<span onclick="SetEveryVis(0);">hide all chapters</span> | 45<span onclick="SetEveryVis(1);">show all chapters</span> 46</div> 47 48<h2>Table of Contents <span onclick="ToggleVis(0);">(hide/show)</span></h2> 49 50<div id="p0"> 51 52<ol> 53 <li><a href="#disclaimer">Disclaimer</a> 54 </li><li><a href="#foreword">Foreword</a> 55 </li><li><a href="#licensing">Licensing</a> 56 </li><li><a href="#aboutthedocument">About the Document</a> 57 </li><li><a href="#generaldescription">General Description</a> 58 </li><li><a href="#versionnumbers">Version Numbers</a> 59 </li><li><a href="#encoder">The Encoder</a> 60 </li><li><a href="#decoder">The Decoder</a> 61 </li><li><a href="#compliance">Compliance</a> 62 </li><li><a href="#recommendations">About Recommendations</a> 63 </li><li><a href="#colortables">About Color Tables</a> 64 </li><li><a href="#blocksextensionsandscope">Blocks, Extensions and Scope</a> 65 </li><li><a href="#blocksizes">Block Sizes</a> 66 </li><li><a href="#embeddedprotocol">Using GIF as an embedded protocol</a> 67 </li><li><a href="#subblocks">Data Sub-blocks</a> 68 </li><li><a href="#blockterminator">Block Terminator</a> 69 </li><li><a href="#header">Header</a> 70 </li><li><a href="#logicalscreendescriptor">Logical Screen Descriptor</a> 71 </li><li><a href="#globalcolortable">Global Color Table</a> 72 </li><li><a href="#imagedescriptor">Image Descriptor</a> 73 </li><li><a href="#localcolortable">Local Color Table</a> 74 </li><li><a href="#tablebasedimagedata">Table Based Image Data</a> 75 </li><li><a href="#graphiccontrolextension">Graphic Control Extension</a> 76 </li><li><a href="#commentextension">Comment Extension</a> 77 </li><li><a href="#plaintextextension">Plain Text Extension</a> 78 </li><li><a href="#applicationextension">Application Extension</a> 79 </li><li><a href="#trailer">Trailer</a> 80</li></ol> 81 82<p>Appendices:</p> 83 84<ol style="list-style-type:upper-latin;"> 85 <li><a href="#quickreferencetable">Quick Reference Table</a> 86 </li><li><a href="#gifgrammar">GIF Grammar</a> 87 </li><li><a href="#glossary">Glossary</a> 88 </li><li><a href="#conventions">Conventions</a> 89 </li><li><a href="#interlacedimages">Interlaced Images</a> 90 </li><li><a href="#lzw">Variable-Length-Code LZW Compression</a> 91 </li><li><a href="#onlinecapabilities">On-line Capabilities Dialogue</a> 92</li></ol> 93 94<p>Other:</p> 95 96<ul> 97 <li><a href="#coversheet">Cover Sheet for the GIF89a Specification</a> 98</li></ul> 99 100</div> 101 102<h2 id="disclaimer">1. Disclaimer <span onclick="ToggleVis(1);">(hide/show)</span></h2> 103 104<div id="p1"> 105 106<p>The information provided herein is subject to change without notice. In no 107event will CompuServe Incorporated be liable for damages, including any loss of 108revenue, loss of profits or other incidental or consequential damages arising 109out of the use or inability to use the information; CompuServe Incorporated 110makes no claim as to the suitability of the information.</p> 111 112</div> 113 114<h2 id="foreword">2. Foreword <span onclick="ToggleVis(2);">(hide/show)</span></h2> 115 116<div id="p2"> 117 118<p>This document defines the Graphics Interchange Format℠. The 119specification given here defines version 89a, which is an extension of version 12087a.</p> 121 122<p>The Graphics Interchange Format℠ as specified here should be 123considered complete; any deviation from it should be considered invalid, 124including but not limited to, the use of reserved or undefined fields within 125control or data blocks, the inclusion of extraneous data within or between 126blocks, the use of methods or algorithms not specifically listed as part of the 127format, etc. In general, any and all deviations, extensions or modifications 128not specified in this document should be considered to be in violation of the 129format and should be avoided.</p> 130 131</div> 132 133<h2 id="licensing">3. Licensing <span onclick="ToggleVis(3);">(hide/show)</span></h2> 134 135<div id="p3"> 136 137<p>The Graphics Interchange Format© is the copyright property of 138CompuServe Incorporated. Only CompuServe Incorporated is authorized to define, 139redefine, enhance, alter, modify or change in any way the definition of the 140format.</p> 141 142<p>CompuServe Incorporated hereby grants a limited, non-exclusive, royalty-free 143license for the use of the Graphics Interchange Format℠ in computer 144software; computer software utilizing GIF℠ must acknowledge ownership of 145the Graphics Interchange Format and its Service Mark by CompuServe 146Incorporated, in User and Technical Documentation. Computer software utilizing 147GIF, which is distributed or may be distributed without User or Technical 148Documentation must display to the screen or printer a message acknowledging 149ownership of the Graphics Interchange Format and the Service Mark by CompuServe 150Incorporated; in this case, the acknowledgement may be displayed in an opening 151screen or leading banner, or a closing screen or trailing banner. A message 152such as the following may be used:</p> 153 154<blockquote> 155 <p><i>The Graphics Interchange Format© is the Copyright property of 156 CompuServe Incorporated. GIF℠ is a Service Mark property of 157 CompuServe Incorporated.</i></p> 158</blockquote> 159 160<p>For further information, please contact:</p> 161 162<blockquote> 163 <p>CompuServe Incorporated<br> 164 Graphics Technology Department<br> 165 5000 Arlington Center Boulevard<br> 166 Columbus, Ohio 43220<br> 167 U. S. A.</p> 168</blockquote> 169 170<p>CompuServe Incorporated maintains a mailing list with all those individuals 171and organizations who wish to receive copies of this document when it is 172corrected or revised. This service is offered free of charge; please provide us 173with your mailing address.</p> 174 175</div> 176 177<h2 id="aboutthedocument">4. About the Document <span onclick="ToggleVis(4);">(hide/show)</span></h2> 178 179<div id="p4"> 180 181<p>This document describes in detail the definition of the Graphics Interchange 182Format. This document is intended as a programming reference; it is recommended 183that the entire document be read carefully before programming, because of the 184interdependence of the various parts. There is an individual section for each 185of the Format blocks. Within each section, the sub-section labeled Required 186Version refers to the version number that an encoder will have to use if the 187corresponding block is used in the Data Stream. Within each section, a diagram 188describes the individual fields in the block; the diagrams are drawn 189vertically; top bytes in the diagram appear first in the Data Stream. Bits 190within a byte are drawn most significant on the left end. Multi-byte numeric 191fields are ordered Least Significant Byte first. Numeric constants are 192represented as Hexadecimal numbers, preceded by <tt>"0x"</tt>. Bit fields 193within a byte are described in order from most significant bits to least 194significant bits.</p> 195 196</div> 197 198<h2 id="generaldescription">5. General Description <span onclick="ToggleVis(5);">(hide/show)</span></h2> 199 200<div id="p5"> 201 202<p>The Graphics Interchange Format℠ defines a protocol intended for the 203on-line transmission and interchange of raster graphic data in a way that is 204independent of the hardware used in their creation or display.</p> 205 206<p>The Graphics Interchange Format is defined in terms of blocks and 207<a href="#subblocks">sub-blocks</a> which contain relevant parameters and data 208used in the reproduction of a graphic. A GIF Data Stream is a sequence of 209protocol blocks and sub-blocks representing a collection of graphics. In 210general, the graphics in a Data Stream are assumed to be related to some 211degree, and to share some control information; it is recommended that encoders 212attempt to group together related graphics in order to minimize hardware 213changes during processing and to minimize control information overhead. For the 214same reason, unrelated graphics or graphics which require resetting hardware 215parameters should be encoded separately to the extent possible.</p> 216 217<p>A Data Stream may originate locally, as when read from a file, or it may 218originate remotely, as when transmitted over a data communications line. The 219Format is defined with the assumption that an error-free Transport Level 220Protocol is used for communications; the Format makes no provisions for 221error-detection and error-correction.</p> 222 223<p>The GIF Data Stream must be interpreted in context, that is, the application 224program must rely on information external to the Data Stream to invoke the 225decoder process.</p> 226 227</div> 228 229<h2 id="versionnumbers">6. Version Numbers <span onclick="ToggleVis(6);">(hide/show)</span></h2> 230 231<div id="p6"> 232 233<p>The version number in the <a href="#header">Header</a> of a Data Stream is 234intended to identify the minimum set of capabilities required of a decoder in 235order to fully process the Data Stream. An encoder should use the earliest 236possible version number that includes all the blocks used in the Data Stream. 237Within each block section in this document, there is an entry labeled Required 238Version which specifies the earliest version number that includes the 239corresponding block. The encoder should make every attempt to use the earliest 240version number covering all the blocks in the Data Stream; the unnecessary use 241of later version numbers will hinder processing by some decoders.</p> 242 243</div> 244 245<h2 id="encoder">7. The Encoder <span onclick="ToggleVis(7);">(hide/show)</span></h2> 246 247<div id="p7"> 248 249<p>The Encoder is the program used to create a GIF Data Stream. From raster 250data and other information, the encoder produces the necessary control and data 251blocks needed for reproducing the original graphics.</p> 252 253<p>The encoder has the following primary responsibilities.</p> 254 255<ul> 256 <li>Include in the Data Stream all the necessary information to reproduce 257 the graphics. 258 </li><li>Insure that a Data Stream is labeled with the earliest possible Version 259 Number that will cover the definition of all the blocks in it; this is to 260 ensure that the largest number of decoders can process the Data Stream. 261 </li><li>Ensure encoding of the graphics in such a way that the decoding process 262 is optimized. Avoid redundant information as much as possible. 263 </li><li>To the extent possible, avoid grouping graphics which might require 264 resetting hardware parameters during the decoding process. 265 </li><li>Set to zero (off) each of the bits of each and every field designated 266 as reserved. Note that some fields in the Logical Screen Descriptor and the 267 <a href="#imagedescriptor">Image Descriptor</a> were reserved under Version 268 87a, but are used under version 89a. 269</li></ul> 270 271</div> 272 273<h2 id="decoder">8. The Decoder <span onclick="ToggleVis(8);">(hide/show)</span></h2> 274 275<div id="p8"> 276 277<p>The Decoder is the program used to process a GIF Data Stream. It processes 278the Data Stream sequentially, parsing the various blocks and 279<a href="#subblocks">sub-blocks</a>, using the control information to set 280hardware and process parameters and interpreting the data to render the 281graphics.</p> 282 283<p>The decoder has the following primary responsibilities.</p> 284 285<ul> 286 <li>Process each graphic in the Data Stream in sequence, without delays 287 other than those specified in the control information. 288 </li><li>Set its hardware parameters to fit, as closely as possible, the control 289 information contained in the Data Stream. 290</li></ul> 291 292</div> 293 294<h2 id="compliance">9. Compliance <span onclick="ToggleVis(9);">(hide/show)</span></h2> 295 296<div id="p9"> 297 298<p>An encoder or a decoder is said to comply with a given version of the 299Graphics Interchange Format if and only if it fully conforms with and correctly 300implements the definition of the standard associated with that version. An 301encoder or a decoder may be compliant with a given version number and not 302compliant with some subsequent version.</p> 303 304</div> 305 306<h2 id="recommendations">10. About Recommendations <span onclick="ToggleVis(10);">(hide/show)</span></h2> 307 308<div id="p10"> 309 310<p>Each block section in this document contains an entry labeled 311Recommendation; this section lists a set of recommendations intended to guide 312and organize the use of the particular blocks. Such recommendations are geared 313towards making the functions of encoders and decoders more efficient, as well 314as making optimal use of the communications bandwidth. It is advised that these 315recommendations be followed.</p> 316 317</div> 318 319<h2 id="colortables">11. About Color Tables <span onclick="ToggleVis(11);">(hide/show)</span></h2> 320 321<div id="p11"> 322 323<p>The GIF format utilizes color tables to render raster-based graphics. A 324color table can have one of two different scopes: global or local.</p> 325 326<p>A <a href="#globalcolortable">Global Color Table</a> is used by all those 327graphics in the Data Stream which do not have a 328<a href="#localcolortable">Local Color Table</a> associated with them. The 329scope of the Global Color Table is the entire Data Stream.</p> 330 331<p>A Local Color Table is always associated with the graphic that immediately 332follows it; the scope of a Local Color Table is limited to that single graphic. 333A Local Color Table supersedes a Global Color Table, that is, if a Data Stream 334contains a Global Color Table, and an image has a Local Color Table associated 335with it, the decoder must save the Global Color Table, use the Local Color 336Table to render the image, and then restore the Global Color Table.</p> 337 338<p>Both types of color tables are optional, making it possible for a Data 339Stream to contain numerous graphics without a color table at all. For this 340reason, it is recommended that the decoder save the last Global Color Table 341used until another Global Color Table is encountered. In this way, a Data 342Stream which does not contain either a Global Color Table or a Local Color 343Table may be processed using the last Global Color Table saved. If a Global 344Color Table from a previous Stream is used, that table becomes the Global Color 345Table of the present Stream. This is intended to reduce the overhead incurred 346by color tables. In particular, it is recommended that an encoder use only one 347Global Color Table if all the images in related Data Streams can be rendered 348with the same table. If no color table is available at all, the decoder is free 349to use a system color table or a table of its own. In that case, the decoder 350may use a color table with as many colors as its hardware is able to support; 351it is recommended that such a table have black and white as its first two 352entries, so that monochrome images can be rendered adequately.</p> 353 354<p>The Definition of the GIF Format allows for a Data Stream to contain only 355the <a href="#header">Header</a>, the 356<a href="#logicalscreendescriptor">Logical Screen Descriptor</a>, a Global 357Color Table and the <a href="#trailer">GIF Trailer</a>. Such a Data Stream 358would be used to load a decoder with a Global Color Table, in preparation for 359subsequent Data Streams without a color table at all.</p> 360 361</div> 362 363<h2 id="blocksextensionsandscope">12. Blocks, Extensions and Scope <span onclick="ToggleVis(12);">(hide/show)</span></h2> 364 365<div id="p12"> 366 367<p>Blocks can be classified into three groups: Control, Graphic-Rendering and 368Special Purpose.</p> 369 370<p>Control blocks, such as the <a href="#header">Header</a>, the Logical Screen 371Descriptor, the <a href="#graphiccontrolextension">Graphic Control 372Extension</a> and the <a href="#trailer">Trailer</a>, contain information used 373to control the process of the Data Stream or information used in setting 374hardware parameters.</p> 375 376<p>Graphic-Rendering blocks such as the <a href="#imagedescriptor">Image 377Descriptor</a> and the <a href="#plaintextextension">Plain Text Extension</a> 378contain information and data used to render a graphic on the display 379device.</p> 380 381<p>Special Purpose blocks such as the <a href="#commentextension">Comment 382Extension</a> and the <a href="#applicationextension">Application Extension</a> 383are neither used to control the process of the Data Stream nor do they contain 384information or data used to render a graphic on the display device.</p> 385 386<p>With the exception of the <a href="#logicalscreendescriptor">Logical Screen 387Descriptor</a> and the <a href="#globalcolortable">Global Color Table</a>, 388whose scope is the entire Data Stream, all other Control blocks have a limited 389scope, restricted to the Graphic-Rendering block that follows them. Special 390Purpose blocks do not delimit the scope of any Control blocks; Special Purpose 391blocks are transparent to the decoding process. Graphic-Rendering blocks and 392extensions are used as scope delimiters for Control blocks and extensions.</p> 393 394<p>The labels used to identify labeled blocks fall into three ranges:</p> 395 396<ul> 397 <li><tt>0x00</tt>–<tt>0x7F</tt> (0–127) are the Graphic 398 Rendering blocks, excluding the <a href="#trailer">Trailer</a> 399 (<tt>0x3B</tt>, 59) 400 </li><li><tt>0x80</tt>–<tt>0xF9</tt> (128–249) are the Control 401 blocks 402 </li><li><tt>0xFA</tt>–<tt>0xFF</tt> (250–255) are the Special 403 Purpose blocks 404</li></ul> 405 406<p>These ranges are defined so that decoders can handle block scope by 407appropriately identifying block labels, even when the block itself cannot be 408processed.</p> 409 410</div> 411 412<h2 id="blocksizes">13. Block Sizes <span onclick="ToggleVis(13);">(hide/show)</span></h2> 413 414<div id="p13"> 415 416<p>The Block Size field in a block, counts the number of bytes remaining in the 417block, not counting the Block Size field itself, and not counting the 418<a href="#blockterminator">Block Terminator</a>, if one is to follow. Blocks 419other than Data Blocks are intended to be of fixed length; the Block Size field 420is provided in order to facilitate skipping them, not to allow their size to 421change in the future. Data blocks and <a href="#subblocks">sub-blocks</a> are 422of variable length to accommodate the amount of data.</p> 423 424</div> 425 426<h2 id="embeddedprotocol">14. Using GIF as an embedded protocol <span onclick="ToggleVis(14);">(hide/show)</span></h2> 427 428<div id="p14"> 429 430<p>As an embedded protocol, GIF may be part of larger application protocols, 431within which GIF is used to render graphics. In such a case, the application 432protocol could define a block within which the GIF Data Stream would be 433contained. The application program would then invoke a GIF decoder upon 434encountering a block of type GIF. This approach is recommended in favor of 435using <a href="#applicationextension">Application Extensions</a>, which become 436overhead for all other applications that do not process them. Because a GIF 437Data Stream must be processed in context, the application must rely on some 438means of identifying the GIF Data Stream outside of the Stream itself.</p> 439 440</div> 441 442<h2 id="subblocks">15. Data Sub-blocks <span onclick="ToggleVis(15);">(hide/show)</span></h2> 443 444<div id="p15"> 445 446<h3>a. Description</h3> 447 448<p>Data Sub-blocks are units containing data. They do not have a label, these 449blocks are processed in the context of control blocks, wherever data blocks are 450specified in the format. The first byte of the Data sub-block indicates the 451number of data bytes to follow. A data sub-block may contain from 0 to 255 data 452bytes. The size of the block does not account for the size byte itself, 453therefore, the empty sub-block is one whose size field contains <tt>0x00</tt> 454(0).</p> 455 456<h3>b. Required Version</h3> 457 458<p>87a.</p> 459 460<h3>c. Syntax</h3> 461 462<table> 463 <tbody><tr> 464 <th>Byte # 465 </th><th>Field Name 466 </th><th>Type 467 </th></tr><tr> 468 <td style="text-align:center;">0 469 </td><td>Block Size 470 </td><td>Byte 471 </td></tr><tr> 472 <td style="text-align:center;">1 473 </td><td rowspan="5">Data Values 474 </td><td rowspan="5">Byte 475 </td></tr><tr> 476 <td style="text-align:center;">2 477 </td></tr><tr> 478 <td style="text-align:center;">3 479 </td></tr><tr> 480 <td style="text-align:center;">⋮ 481 </td></tr><tr> 482 <td style="text-align:center;">up to 255 483</td></tr></tbody></table> 484 485<ol style="list-style-type:lower-roman;"> 486 <li>Block Size: 487 <ul> 488 <li>Number of bytes in the Data Sub-block; the size must be within 0 489 and 255 bytes, inclusive. 490 </li></ul> 491 </li><li>Data Values: 492 <ul> 493 <li>Any 8-bit value. There must be exactly as many Data Values as 494 specified by the Block Size field. 495 </li></ul> 496</li></ol> 497 498<h3>d. Extensions and Scope</h3> 499 500<p>This type of block always occurs as part of a larger unit. It does not have 501a scope of itself.</p> 502 503<h3>e. Recommendation</h3> 504 505<p>None.</p> 506 507</div> 508 509<h2 id="blockterminator">16. Block Terminator <span onclick="ToggleVis(16);">(hide/show)</span></h2> 510 511<div id="p16"> 512 513<h3>a. Description</h3> 514 515<p>This zero-length <a href="#subblocks">Data Sub-block</a> is used to 516terminate a sequence of Data Sub-blocks. It contains a single byte in the 517position of the Block Size field and does not contain data.</p> 518 519<h3>b. Required Version</h3> 520 521<p>87a.</p> 522 523<h3>c. Syntax</h3> 524 525<table> 526 <tbody><tr> 527 <th>Byte # 528 </th><th>Field Name 529 </th><th>Type 530 </th></tr><tr> 531 <td style="text-align:center;">0 532 </td><td>Block Size 533 </td><td>Byte 534</td></tr></tbody></table> 535 536<ol style="list-style-type:lower-roman;"> 537 <li>Block Size: 538 <ul> 539 <li>Number of bytes in the Data Sub-block; this field contains the 540 fixed value <tt>0x00</tt> (0). 541 </li></ul> 542 </li><li>Data Values: 543 <ul> 544 <li>This block does not contain any data. 545 </li></ul> 546</li></ol> 547 548<h3>d. Extensions and Scope</h3> 549 550<p>This block terminates the immediately preceding sequence of Data Sub-blocks. 551This block cannot be modified by any extension.</p> 552 553<h3>e. Recommendation</h3> 554 555<p>None.</p> 556 557</div> 558 559<h2 id="header">17. Header <span onclick="ToggleVis(17);">(hide/show)</span></h2> 560 561<div id="p17"> 562 563<h3>a. Description</h3> 564 565<p>The Header identifies the GIF Data Stream in context. The Signature field 566marks the beginning of the Data Stream, and the Version field identifies the 567set of capabilities required of a decoder to fully process the Data Stream. 568This block is <i>required</i>; exactly one Header must be present per Data 569Stream.</p> 570 571<h3>b. Required Version</h3> 572 573<p>Not applicable. This block is not subject to a version number. This block 574must appear at the beginning of every Data Stream.</p> 575 576<h3>c. Syntax</h3> 577 578<table> 579 <tbody><tr> 580 <th>Byte # 581 </th><th>Field Name 582 </th><th>Type 583 </th></tr><tr> 584 <td style="text-align:center;">0 585 </td><td rowspan="3">Signature 586 </td><td rowspan="3">3 Bytes 587 </td></tr><tr> 588 <td style="text-align:center;">1 589 </td></tr><tr> 590 <td style="text-align:center;">2 591 </td></tr><tr> 592 <td style="text-align:center;">3 593 </td><td rowspan="3">Version 594 </td><td rowspan="3">3 Bytes 595 </td></tr><tr> 596 <td style="text-align:center;">4 597 </td></tr><tr> 598 <td style="text-align:center;">5 599</td></tr></tbody></table> 600 601<ol style="list-style-type:lower-roman;"> 602 <li>Signature: 603 <ul> 604 <li>Identifies the GIF Data Stream. This field contains the fixed value 605 <tt>'GIF'</tt> (<tt>0x47 0x49 0x46</tt>). 606 </li></ul> 607 </li><li>Version: 608 <ul> 609 <li>Version number used to format the data stream. Identifies the 610 minimum set of capabilities necessary to a decoder to fully process the 611 contents of the Data Stream. 612 </li><li>Version Numbers as of 10 July 1990: 613 <ul> 614 <li><tt>"87a"</tt> (<tt>0x38 0x37 0x61</tt>) – May 1987 615 </li><li><tt>"89a"</tt> (<tt>0x38 0x39 0x61</tt>) – July 1989 616 </li></ul> 617 </li><li>Version numbers are ordered numerically increasing on the first two 618 digits starting with 87 (87, 88, …, 99, 00, …, 85, 86) 619 and alphabetically increasing on the third character (a, …, z). 620 </li></ul> 621 </li><li>Extensions and Scope: 622 <ul> 623 <li>The scope of this block is the entire Data Stream. This block 624 cannot be modified by any extension. 625 </li></ul> 626</li></ol> 627 628<h3>d. Recommendations</h3> 629 630<ol style="list-style-type:lower-roman;"> 631 <li>Signature: 632 <ul> 633 <li>This field identifies the beginning of the GIF Data Stream; it is 634 not intended to provide a unique signature for the identification of 635 the data. It is recommended that the GIF Data Stream be identified 636 externally by the application. (Refer to <a href="#online">Appendix 637 G</a> for on-line identification of the GIF Data Stream.) 638 </li></ul> 639 </li><li>Version: 640 <ul> 641 <li>Encoder: An encoder should use the earliest possible version number 642 that defines all the blocks used in the Data Stream. When two or more 643 Data Streams are combined, the latest of the individual version numbers 644 should be used for the resulting Data Stream. 645 </li><li>Decoder: A decoder should attempt to process the data stream to the 646 best of its ability; if it encounters a version number which it is not 647 capable of processing fully, it should nevertheless, attempt to process 648 the data stream to the best of its ability, perhaps after warning the 649 user that the data may be incomplete. 650 </li></ul> 651</li></ol> 652 653</div> 654 655<h2 id="logicalscreendescriptor">18. Logical Screen Descriptor <span onclick="ToggleVis(18);">(hide/show)</span></h2> 656 657<div id="p18"> 658 659<h3>a. Description</h3> 660 661<p>The Logical Screen Descriptor contains the parameters necessary to define 662the area of the display device within which the images will be rendered. The 663coordinates in this block are given with respect to the top-left corner of the 664virtual screen; they do not necessarily refer to absolute coordinates on the 665display device. This implies that they could refer to window coordinates in a 666window-based environment or printer coordinates when a printer is used.</p> 667 668<p>This block is <i>required</i>; exactly one Logical Screen Descriptor must be 669present per Data Stream.</p> 670 671<h3>b. Required Version</h3> 672 673<p>Not applicable. This block is not subject to a version number. This block 674must appear immediately after the <a href="#header">Header</a>.</p> 675 676<h3>c. Syntax</h3> 677 678<table> 679 <tbody><tr> 680 <th rowspan="2">Byte # 681 </th><th colspan="8">Bits 682 </th><th rowspan="2">Field Name 683 </th><th rowspan="2">Type 684 </th></tr><tr> 685 <th>7 686 </th><th>6 687 </th><th>5 688 </th><th>4 689 </th><th>3 690 </th><th>2 691 </th><th>1 692 </th><th>0 693 </th></tr><tr> 694 <td style="text-align:center;">0 695 </td><td rowspan="2" colspan="8"> 696 </td><td rowspan="2">Logical Screen Width 697 </td><td rowspan="2">Unsigned 698 </td></tr><tr> 699 <td style="text-align:center;">1 700 </td></tr><tr> 701 <td style="text-align:center;">2 702 </td><td rowspan="2" colspan="8"> 703 </td><td rowspan="2">Logical Screen Height 704 </td><td rowspan="2">Unsigned 705 </td></tr><tr> 706 <td style="text-align:center;">3 707 </td></tr><tr> 708 <td style="text-align:center;">4 709 </td><td> 710 </td><td colspan="3"> 711 </td><td> 712 </td><td colspan="3"> 713 </td><td><Packed Fields> 714 </td><td>See below 715 </td></tr><tr> 716 <td style="text-align:center;">5 717 </td><td colspan="8"> 718 </td><td>Background Color Index 719 </td><td>Byte 720 </td></tr><tr> 721 <td style="text-align:center;">6 722 </td><td colspan="8"> 723 </td><td>Pixel Aspect Ratio 724 </td><td>Byte 725</td></tr></tbody></table> 726 727<p><Packed Fields> =</p> 728 729<table> 730<tbody><tr> 731 <td><a href="#globalcolortable">Global Color Table</a> Flag 732 </td><td>1 Bit 733</td></tr><tr> 734 <td>Color Resolution 735 </td><td>3 Bits 736</td></tr><tr> 737 <td>Sort Flag 738 </td><td>1 Bit 739</td></tr><tr> 740 <td>Size of Global Color Table 741 </td><td>3 Bits 742</td></tr></tbody></table> 743 744<ol style="list-style-type:lower-roman;"> 745 <li>Logical Screen Width: 746 <ul> 747 <li>Width, in pixels, of the Logical Screen where the images will be 748 rendered in the displaying device. 749 </li></ul> 750 </li><li>Logical Screen Height: 751 <ul> 752 <li>Height, in pixels, of the Logical Screen where the images will be 753 rendered in the displaying device. 754 </li></ul> 755 </li><li>Global Color Table Flag: 756 <ul> 757 <li>Flag indicating the presence of a Global Color Table; if the flag 758 is set, the Global Color Table will immediately follow the Logical 759 Screen Descriptor. This flag also selects the interpretation of the 760 Background Color Index; if the flag is set, the value of the Background 761 Color Index field should be used as the table index of the background 762 color. (This field is the most significant bit of the byte.) 763 </li><li>Values: 764 <ul> 765 <li>0: No Global Color Table follows, the Background Color Index 766 field is meaningless. 767 </li><li>1: A Global Color Table will immediately follow, the Background 768 Color Index field is meaningful. 769 </li></ul> 770 </li></ul> 771 </li><li>Color Resolution: 772 <ul> 773 <li>Number of bits per primary color available to the original image, 774 minus 1. This value represents the size of the entire palette from 775 which the colors in the graphic were selected, not the number of colors 776 actually used in the graphic. For example, if the value in this field 777 is 3, then the palette of the original image had 4 bits per primary 778 color available to create the image. This value should be set to 779 indicate the richness of the original palette, even if not every color 780 from the whole palette is available on the source machine. 781 </li></ul> 782 </li><li>Sort Flag: 783 <ul> 784 <li>Indicates whether the Global Color Table is sorted. If the flag is 785 set, the Global Color Table is sorted, in order of decreasing 786 importance. Typically, the order would be decreasing frequency, with 787 most frequent color first. This assists a decoder, with fewer available 788 colors, in choosing the best subset of colors; the decoder may use an 789 initial segment of the table to render the graphic. 790 </li><li>Values: 791 <ul> 792 <li>0: Not ordered. 793 </li><li>1: Ordered by decreasing importance, most important color 794 first. 795 </li></ul> 796 </li></ul> 797 </li><li>Size of Global Color Table: 798 <ul> 799 <li>If the Global Color Table Flag is set to 1, the value in this field 800 is used to calculate the number of bytes contained in the Global Color 801 Table. To determine that actual size of the color table, raise 2 to 802 [the value of the field + 1]. Even if there is no Global Color Table 803 specified, set this field according to the above formula so that 804 decoders can choose the best graphics mode to display the stream in. 805 (This field is made up of the 3 least significant bits of the byte.) 806 </li></ul> 807 </li><li>Background Color Index: 808 <ul> 809 <li>Index into the Global Color Table for the Background Color. The 810 Background Color is the color used for those pixels on the screen that 811 are not covered by an image. If the Global Color Table Flag is set to 812 (zero), this field should be zero and should be ignored. 813 </li></ul> 814 </li><li>Pixel Aspect Ratio: 815 <ul> 816 <li>Factor used to compute an approximation of the aspect ratio of the 817 pixel in the original image. If the value of the field is not 0, this 818 approximation of the aspect ratio is computed based on the formula:<br> 819 <img src="gif-aspectratio.png" alt="Aspect Ratio = (Pixel Aspect Ratio + 15) ÷ 64"> 820 </li><li>The Pixel Aspect Ratio is defined to be the quotient of the pixel's 821 width over its height. The value range in this field allows 822 specification of the widest pixel of 4:1 to the tallest pixel of 1:4 in 823 increments of <img src="gif-1over64.png" alt="1/64">. 824 </li><li>Values: 825 <ul> 826 <li>0: No aspect ratio information is given. 827 </li><li>1…255: Value used in the computation. 828 </li></ul> 829 </li></ul> 830</li></ol> 831 832<h3>d. Extensions and Scope</h3> 833 834<p>The scope of this block is the entire Data Stream. This block cannot be 835modified by any extension.</p> 836 837<h3>e. Recommendations</h3> 838 839<p>None.</p> 840 841</div> 842 843<h2 id="globalcolortable">19. Global Color Table <span onclick="ToggleVis(19);">(hide/show)</span></h2> 844 845<div id="p19"> 846 847<h3>a. Description</h3> 848 849<p>This block contains a color table, which is a sequence of bytes representing 850<span class="rcomp">red</span>-<span class="gcomp">green</span>-<span class="bcomp">blue</span> color triplets. The Global Color Table is used by 851images without a <a href="#localcolortable">Local Color Table</a> and by <a href="#plaintextextension">Plain Text Extensions</a>. Its presence is marked by 852the Global Color Table Flag being set to 1 in the <a href="#logicalscreendescriptor">Logical Screen Descriptor</a>; if present, it 853immediately follows the Logical Screen Descriptor and contains a number of 854bytes equal to:</p> 855 856<blockquote> 857 <p>3 × 2<sup>Size of Global Color Table + 1</sup></p> 858</blockquote> 859 860<p>This block is <i>optional</i>; at most one Global Color Table may be present 861per Data Stream.</p> 862 863<h3>b. Required Version</h3> 864 865<p>87a.</p> 866 867<h3>c. Syntax</h3> 868 869<table> 870 <tbody><tr> 871 <th>Byte # 872 </th><th>Field Name 873 </th><th>Type 874 </th></tr><tr> 875 <td style="text-align:center;">0 876 </td><td><span class="rcomp">Red</span> 0 877 </td><td>Byte 878 </td></tr><tr> 879 <td style="text-align:center;">1 880 </td><td><span class="gcomp">Green</span> 0 881 </td><td>Byte 882 </td></tr><tr> 883 <td style="text-align:center;">2 884 </td><td><span class="bcomp">Blue</span> 0 885 </td><td>Byte 886 </td></tr><tr> 887 <td style="text-align:center;">3 888 </td><td><span class="rcomp">Red</span> 1 889 </td><td>Byte 890 </td></tr><tr> 891 <td style="text-align:center;">4 892 </td><td><span class="gcomp">Green</span> 1 893 </td><td>Byte 894 </td></tr><tr> 895 <td style="text-align:center;">⋮ 896 </td><td style="text-align:center;">⋮ 897 </td><td style="text-align:center;">⋮ 898 </td></tr><tr> 899 <td style="text-align:center;">766 900 </td><td><span class="gcomp">Green</span> 255 901 </td><td>Byte 902 </td></tr><tr> 903 <td style="text-align:center;">up to 767 904 </td><td><span class="bcomp">Blue</span> 255 905 </td><td>Byte 906</td></tr></tbody></table> 907 908<h3>d. Extensions and Scope</h3> 909 910<p>The scope of this block is the entire Data Stream. This block cannot be 911modified by any extension.</p> 912 913<h3>e. Recommendation</h3> 914 915<p>None.</p> 916 917</div> 918 919<h2 id="imagedescriptor">20. Image Descriptor <span onclick="ToggleVis(20);">(hide/show)</span></h2> 920 921<div id="p20"> 922 923<h3>a. Description</h3> 924 925<p>Each image in the Data Stream is composed of an Image Descriptor, an 926optional <a href="#localcolortable">Local Color Table</a>, and the <a href="#tablebasedimagedata">image data</a>. Each image must fit within the 927boundaries of the Logical Screen, as defined in the <a href="#logicalscreendescriptor">Logical Screen Descriptor</a>.</p> 928 929<p>The Image Descriptor contains the parameters necessary to process a table 930based image. The coordinates given in this block refer to coordinates within 931the Logical Screen, and are given in pixels. This block is a Graphic-Rendering 932Block, optionally preceded by one or more Control blocks such as the <a href="#graphiccontrolextension">Graphic Control Extension</a>, and may be 933optionally followed by a Local Color Table; the Image Descriptor is always 934followed by the image data.</p> 935 936<p>This block is <i>required</i> for an image. Exactly one Image Descriptor 937must be present per image in the Data Stream. An unlimited number of images may 938be present per Data Stream.</p> 939 940<h3>b. Required Version</h3> 941 942<p>87a.</p> 943 944<h3>c. Syntax</h3> 945 946<table> 947 <tbody><tr> 948 <th rowspan="2">Byte # 949 </th><th colspan="8">Bits 950 </th><th rowspan="2">Field Name 951 </th><th rowspan="2">Type 952 </th></tr><tr> 953 <th>7 954 </th><th>6 955 </th><th>5 956 </th><th>4 957 </th><th>3 958 </th><th>2 959 </th><th>1 960 </th><th>0 961 </th></tr><tr> 962 <td style="text-align:center;">0 963 </td><td colspan="8"> 964 </td><td>Image Separator 965 </td><td>Byte 966 </td></tr><tr> 967 <td style="text-align:center;">1 968 </td><td rowspan="2" colspan="8"> 969 </td><td rowspan="2">Image Left Position 970 </td><td rowspan="2">Unsigned 971 </td></tr><tr> 972 <td style="text-align:center;">2 973 </td></tr><tr> 974 <td style="text-align:center;">3 975 </td><td rowspan="2" colspan="8"> 976 </td><td rowspan="2">Image Top Position 977 </td><td rowspan="2">Unsigned 978 </td></tr><tr> 979 <td style="text-align:center;">4 980 </td></tr><tr> 981 <td style="text-align:center;">5 982 </td><td rowspan="2" colspan="8"> 983 </td><td rowspan="2">Image Width 984 </td><td rowspan="2">Unsigned 985 </td></tr><tr> 986 <td style="text-align:center;">6 987 </td></tr><tr> 988 <td style="text-align:center;">7 989 </td><td rowspan="2" colspan="8"> 990 </td><td rowspan="2">Image Height 991 </td><td rowspan="2">Unsigned 992 </td></tr><tr> 993 <td style="text-align:center;">8 994 </td></tr><tr> 995 <td style="text-align:center;">9 996 </td><td> 997 </td><td> 998 </td><td> 999 </td><td colspan="2"> 1000 </td><td colspan="3"> 1001 </td><td><Packed Fields> 1002 </td><td>See below 1003</td></tr></tbody></table> 1004 1005<p><Packed Fields> =</p> 1006 1007<table> 1008 <tbody><tr> 1009 <td>Local Color Table Flag 1010 </td><td>1 Bit 1011 </td></tr><tr> 1012 <td>Interlace Flag 1013 </td><td>1 Bit 1014 </td></tr><tr> 1015 <td>Sort Flag 1016 </td><td>1 Bit 1017 </td></tr><tr> 1018 <td>Reserved 1019 </td><td>2 Bits 1020 </td></tr><tr> 1021 <td>Size of Local Color Table 1022 </td><td>3 Bits 1023</td></tr></tbody></table> 1024 1025<ol style="list-style-type:lower-roman;"> 1026 <li>Image Separator: 1027 <ul> 1028 <li>Identifies the beginning of an Image Descriptor. This field 1029 contains the fixed value <tt>0x2C</tt> (44, <tt>','</tt>). 1030 </li></ul> 1031 </li><li>Image Left Position: 1032 <ul> 1033 <li>Column number, in pixels, of the left edge of the image, with 1034 respect to the left edge of the Logical Screen. Leftmost column of the 1035 Logical Screen is 0. 1036 </li></ul> 1037 </li><li>Image Top Position: 1038 <ul> 1039 <li>Row number, in pixels, of the top edge of the image with respect to 1040 the top edge of the Logical Screen. Top row of the Logical Screen is 0. 1041 </li></ul> 1042 </li><li>Image Width: 1043 <ul> 1044 <li>Width of the image in pixels. 1045 </li></ul> 1046 </li><li>Image Height: 1047 <ul> 1048 <li>Height of the image in pixels. 1049 </li></ul> 1050 </li><li>Local Color Table Flag: 1051 <ul> 1052 <li>Indicates the presence of a Local Color Table immediately following 1053 this Image Descriptor. (This field is the most significant bit of the 1054 byte.) 1055 </li><li>Values: 1056 <ul> 1057 <li>0: Local Color Table is not present. Use <a href="#globalcolortable">Global Color Table</a> if available. 1058 </li><li>1: Local Color Table present, and to follow immediately after 1059 this Image Descriptor. 1060 </li></ul> 1061 </li></ul> 1062 </li><li>Interlace Flag: 1063 <ul> 1064 <li>Indicates if the image is interlaced. An image is interlaced in a 1065 four-pass interlace pattern; see <a href="#interlacedimages">Appendix 1066 E</a> for details. 1067 </li><li>Values: 1068 <ul> 1069 <li>0: Image is not interlaced. 1070 </li><li>1: Image is interlaced. 1071 </li></ul> 1072 </li></ul> 1073 </li><li>Sort Flag: 1074 <ul> 1075 <li>Indicates whether the Local Color Table is sorted. If the flag is 1076 set, the Local Color Table is sorted, in order of decreasing 1077 importance. Typically, the order would be decreasing frequency, with 1078 most frequent color first. This assists a decoder, with fewer available 1079 colors, in choosing the best subset of colors; the decoder may use an 1080 initial segment of the table to render the graphic. 1081 </li><li>Values: 1082 <ul> 1083 <li>0: Not ordered. 1084 </li><li>1: Ordered by decreasing importance, most important color 1085 first. 1086 </li></ul> 1087 </li></ul> 1088 </li><li>Size of Local Color Table: 1089 <ul> 1090 <li>If the Local Color Table Flag is set to 1, the value in this field 1091 is used to calculate the number of bytes contained in the Local Color 1092 Table. To determine that actual size of the color table, raise 2 to 1093 [the value of the field + 1]. This value should be 0 if there is no 1094 Local Color Table specified. (This field is made up of the 3 least 1095 significant bits of the byte.) 1096 </li></ul> 1097</li></ol> 1098 1099<h3>d. Extensions and Scope</h3> 1100 1101<p>The scope of this block is the Table-based Image Data Block that follows it. 1102This block may be modified by the Graphic Control Extension.</p> 1103 1104<h3>e. Recommendation</h3> 1105 1106<p>None.</p> 1107 1108</div> 1109 1110<h2 id="localcolortable">21. Local Color Table <span onclick="ToggleVis(21);">(hide/show)</span></h2> 1111 1112<div id="p21"> 1113 1114<h3>a. Description</h3> 1115 1116<p>This block contains a color table, which is a sequence of bytes representing 1117<span class="rcomp">red</span>-<span class="gcomp">green</span>-<span class="bcomp">blue</span> color triplets. The Local Color Table is used by the 1118image that immediately follows. Its presence is marked by the Local Color Table 1119Flag being set to 1 in the <a href="#imagedescriptor">Image Descriptor</a>; if 1120present, the Local Color Table immediately follows the Image Descriptor and 1121contains a number of bytes equal to:</p> 1122 1123<blockquote> 1124 <p>3 × 2<sup>Size of Local Color Table + 1</sup></p> 1125</blockquote> 1126 1127<p>If present, this color table temporarily becomes the active color table and 1128the following image should be processed using it. This block is 1129<i>optional</i>; at most one Local Color Table may be present per Image 1130Descriptor and its scope is the single image associated with the Image 1131Descriptor that precedes it.</p> 1132 1133<h3>b. Required Version</h3> 1134 1135<p>87a.</p> 1136 1137<h3>c. Syntax</h3> 1138 1139<table> 1140 <tbody><tr> 1141 <th>Byte # 1142 </th><th>Field Name 1143 </th><th>Type 1144 </th></tr><tr> 1145 <td style="text-align:center;">0 1146 </td><td><span class="rcomp">Red</span> 0 1147 </td><td>Byte 1148 </td></tr><tr> 1149 <td style="text-align:center;">1 1150 </td><td><span class="gcomp">Green</span> 0 1151 </td><td>Byte 1152 </td></tr><tr> 1153 <td style="text-align:center;">2 1154 </td><td><span class="bcomp">Blue</span> 0 1155 </td><td>Byte 1156 </td></tr><tr> 1157 <td style="text-align:center;">3 1158 </td><td><span class="rcomp">Red</span> 1 1159 </td><td>Byte 1160 </td></tr><tr> 1161 <td style="text-align:center;">4 1162 </td><td><span class="gcomp">Green</span> 1 1163 </td><td>Byte 1164 </td></tr><tr> 1165 <td style="text-align:center;">⋮ 1166 </td><td style="text-align:center;">⋮ 1167 </td><td style="text-align:center;">⋮ 1168 </td></tr><tr> 1169 <td style="text-align:center;">766 1170 </td><td><span class="gcomp">Green</span> 255 1171 </td><td>Byte 1172 </td></tr><tr> 1173 <td style="text-align:center;">up to 767 1174 </td><td><span class="bcomp">Blue</span> 255 1175 </td><td>Byte 1176</td></tr></tbody></table> 1177 1178<h3>d. Extensions and Scope</h3> 1179 1180<p>The scope of this block is the Table-based Image Data Block that immediately 1181follows it. This block cannot be modified by any extension.</p> 1182 1183<h3>e. Recommendations</h3> 1184 1185<p>None.</p> 1186 1187</div> 1188 1189<h2 id="tablebasedimagedata">22. Table Based Image Data <span onclick="ToggleVis(22);">(hide/show)</span></h2> 1190 1191<div id="p22"> 1192 1193<h3>a. Description</h3> 1194 1195<p>The image data for a table based image consists of a sequence of <a href="#subblocks">sub-blocks</a>, of size at most 255 bytes each, containing an 1196index into the active color table, for each pixel in the image. Pixel indices 1197are in order of left to right and from top to bottom. Each index must be within 1198the range of the size of the active color table, starting at 0. The sequence of 1199indices is encoded using the LZW Algorithm with variable-length code, as 1200described in <a href="#lzw">Appendix F</a>.</p> 1201 1202<h3>b. Required Version</h3> 1203 1204<p>87a.</p> 1205 1206<h3>c. Syntax</h3> 1207 1208<p>The image data format is as follows:</p> 1209 1210<table> 1211 <tbody><tr> 1212 <th>Byte # 1213 </th><th>Field Name 1214 </th><th>Type 1215 </th></tr><tr> 1216 <td style="text-align:center;">0 1217 </td><td>LZW Minimum Code Size 1218 </td><td>Byte 1219</td></tr></tbody></table> 1220 1221<p></p> 1222 1223<table> 1224 <tbody><tr> 1225 <th>Field Name 1226 </th><th>Type 1227 </th></tr><tr> 1228 <td>Image Data 1229 </td><td>Data Sub-blocks 1230</td></tr></tbody></table> 1231 1232<ol style="list-style-type:lower-roman;"> 1233 <li>LZW Minimum Code Size: 1234 <ul> 1235 <li>This byte determines the initial number of bits used for LZW codes 1236 in the image data, as described in Appendix F. 1237 </li></ul> 1238</li></ol> 1239 1240<h3>d. Extensions and Scope</h3> 1241 1242<p>This block has no scope, it contains raster data. Extensions intended to 1243modify a Table-based image must appear before the corresponding <a href="#imagedescriptor">Image Descriptor</a>.</p> 1244 1245<h3>e. Recommendations</h3> 1246 1247<p>None.</p> 1248 1249</div> 1250 1251<h2 id="graphiccontrolextension">23. Graphic Control Extension <span onclick="ToggleVis(23);">(hide/show)</span></h2> 1252 1253<div id="p23"> 1254 1255<h3>a. Description</h3> 1256 1257<p>The Graphic Control Extension contains parameters used when processing a 1258graphic rendering block. The scope of this extension is the first graphic 1259rendering block to follow. The extension contains only one <a href="#subblocks">data sub-block</a>.</p> 1260 1261<p>This block is <i>optional</i>; at most one Graphic Control Extension may 1262precede a graphic rendering block. This is the only limit to the number of 1263Graphic Control Extensions that may be contained in a Data Stream.</p> 1264 1265<h3>b. Required Version</h3> 1266 1267<p>89a.</p> 1268 1269<h3>c. Syntax</h3> 1270 1271<table> 1272 <tbody><tr> 1273 <th>Byte # 1274 </th><th>Field Name 1275 </th><th>Type 1276 </th></tr><tr> 1277 <td style="text-align:center;">0 1278 </td><td>Extension Introducer 1279 </td><td>Byte 1280 </td></tr><tr> 1281 <td style="text-align:center;">1 1282 </td><td>Graphic Control Label 1283 </td><td>Byte 1284</td></tr></tbody></table> 1285 1286<p></p> 1287 1288<table> 1289 <tbody><tr> 1290 <th rowspan="2">Byte # 1291 </th><th colspan="8">Bits 1292 </th><th rowspan="2">Field Name 1293 </th><th rowspan="2">Type 1294 </th></tr><tr> 1295 <th>7 1296 </th><th>6 1297 </th><th>5 1298 </th><th>4 1299 </th><th>3 1300 </th><th>2 1301 </th><th>1 1302 </th><th>0 1303 </th></tr><tr> 1304 <td style="text-align:center;">0 1305 </td><td colspan="8"> 1306 </td><td>Block Size 1307 </td><td>Byte 1308 </td></tr><tr> 1309 <td style="text-align:center;">1 1310 </td><td colspan="3"> 1311 </td><td colspan="3"> 1312 </td><td> 1313 </td><td> 1314 </td><td><Packed Fields> 1315 </td><td>See below 1316 </td></tr><tr> 1317 <td style="text-align:center;">2 1318 </td><td rowspan="2" colspan="8"> 1319 </td><td rowspan="2">Delay Time 1320 </td><td rowspan="2">Unsigned 1321 </td></tr><tr> 1322 <td style="text-align:center;">3 1323 </td></tr><tr> 1324 <td style="text-align:center;">4 1325 </td><td colspan="8"> 1326 </td><td>Transparent Color Index 1327 </td><td>Byte 1328</td></tr></tbody></table> 1329 1330<p></p> 1331 1332<table> 1333 <tbody><tr> 1334 <th>Byte # 1335 </th><th>Field Name 1336 </th><th>Type 1337 </th></tr><tr> 1338 <td style="text-align:center;">0 1339 </td><td><a href="#blockterminator">Block Terminator</a> 1340 </td><td>Byte 1341</td></tr></tbody></table> 1342 1343<p><Packed Fields> =</p> 1344 1345<table> 1346 <tbody><tr> 1347 <td>Reserved 1348 </td><td>3 Bits 1349 </td></tr><tr> 1350 <td>Disposal Method 1351 </td><td>3 Bits 1352 </td></tr><tr> 1353 <td>User Input Flag 1354 </td><td>1 Bit 1355 </td></tr><tr> 1356 <td>Transparent Color Flag 1357 </td><td>1 Bit 1358</td></tr></tbody></table> 1359 1360<ol style="list-style-type:lower-roman;"> 1361 <li>Extension Introducer: 1362 <ul> 1363 <li>Identifies the beginning of an extension block. This field contains 1364 the fixed value <tt>0x21</tt> (33, <tt>'!'</tt>). 1365 </li></ul> 1366 </li><li>Graphic Control Label: 1367 <ul> 1368 <li>Identifies the current block as a Graphic Control Extension. This 1369 field contains the fixed value <tt>0xF9</tt> (249). 1370 </li></ul> 1371 </li><li>Block Size: 1372 <ul> 1373 <li>Number of bytes in the block, after the Block Size field and up to 1374 but not including the Block Terminator. This field contains the fixed 1375 value <tt>0x04</tt> (4). 1376 </li></ul> 1377 </li><li>Disposal Method: 1378 <ul> 1379 <li>Indicates the way in which the graphic is to be treated after being 1380 displayed. 1381 </li><li>Values: 1382 <ul> 1383 <li>0: No disposal specified. The decoder is not required to take 1384 any action. 1385 </li><li>1: Do not dispose. The graphic is to be left in place. 1386 </li><li>2: Restore to background color. The area used by the graphic 1387 must be restored to the background color. 1388 </li><li>3: Restore to previous. The decoder is required to restore the 1389 area overwritten by the graphic with what was there prior to rendering the graphic. 1390 </li><li>4–7: To be defined. 1391 </li></ul> 1392 </li></ul> 1393 </li><li>User Input Flag: 1394 <ul> 1395 <li>Indicates whether or not user input is expected before continuing. 1396 If the flag is set, processing will continue when user input is 1397 entered. The nature of the User input is determined by the application 1398 (Carriage Return, Mouse Button Click, etc.). 1399 </li><li>Values: 1400 <ul> 1401 <li>0: User input is not expected. 1402 </li><li>1: User input is expected. 1403 </li></ul> 1404 </li><li>When a Delay Time is used and the User Input Flag is set, 1405 processing will continue when user input is received or when the delay 1406 time expires, whichever occurs first. 1407 </li></ul> 1408 </li><li>Transparency Flag: 1409 <ul> 1410 <li>Indicates whether a transparency index is given in the Transparent 1411 Index field. (This field is the least significant bit of the byte.) 1412 </li><li>Values: 1413 <ul> 1414 <li>0: Transparent Index is not given. 1415 </li><li>1: Transparent Index is given. 1416 </li></ul> 1417 </li></ul> 1418 </li><li>Delay Time: 1419 <ul> 1420 <li>If not 0, this field specifies the number of hundredths (<img src="gif-1over100.png" alt="1/100">) of a second to wait before 1421 continuing with the processing of the Data Stream. The clock starts 1422 ticking immediately after the graphic is rendered. This field may be 1423 used in conjunction with the User Input Flag field. 1424 </li></ul> 1425 </li><li>Transparency Index: 1426 <ul> 1427 <li>The Transparency Index is such that when encountered, the 1428 corresponding pixel of the display device is not modified and 1429 processing goes on to the next pixel. The index is present if and only 1430 if the Transparency Flag is set to 1. 1431 </li></ul> 1432 </li><li>Block Terminator: 1433 <ul> 1434 <li>This zero-length data block marks the end of the Graphic Control 1435 Extension. 1436 </li></ul> 1437</li></ol> 1438 1439<h3>d. Extensions and Scope</h3> 1440 1441<p>The scope of this Extension is the graphic rendering block that follows it; 1442it is possible for other extensions to be present between this block and its 1443target. This block can modify the <a href="#imagedescriptor">Image Descriptor 1444Block</a> and the <a href="#plaintextextension">Plain Text Extension</a>.</p> 1445 1446<h3>e. Recommendations</h3> 1447 1448<ol style="list-style-type:lower-roman;"> 1449 <li>Disposal Method: 1450 <ul> 1451 <li>The mode Restore To Previous is intended to be used in small 1452 sections of the graphic; the use of this mode imposes severe demands on 1453 the decoder to store the section of the graphic that needs to be saved. 1454 For this reason, this mode should be used sparingly. This mode is not 1455 intended to save an entire graphic or large areas of a graphic; when 1456 this is the case, the encoder should make every attempt to make the 1457 sections of the graphic to be restored be separate graphics in the data 1458 stream. In the case where a decoder is not capable of saving an area of 1459 a graphic marked as Restore To Previous, it is recommended that a 1460 decoder restore to the background color. 1461 </li></ul> 1462 </li><li>User Input Flag: 1463 <ul> 1464 <li>When the flag is set, indicating that user input is expected, the 1465 decoder may sound the bell (<tt>0x07</tt>, 7) to alert the user that 1466 input is being expected. In the absence of a specified Delay Time, the 1467 decoder should wait for user input indefinitely. It is recommended that 1468 the encoder not set the User Input Flag without a Delay Time specified. 1469 </li></ul> 1470</li></ol> 1471 1472</div> 1473 1474<h2 id="commentextension">24. Comment Extension <span onclick="ToggleVis(24);">(hide/show)</span></h2> 1475 1476<div id="p24"> 1477 1478<h3>a. Description</h3> 1479 1480<p>The Comment Extension contains textual information which is not part of the 1481actual graphics in the GIF Data Stream. It is suitable for including comments 1482about the graphics, credits, descriptions or any other type of non-control and 1483non-graphic data. The Comment Extension may be ignored by the decoder, or it 1484may be saved for later processing; under no circumstances should a Comment 1485Extension disrupt or interfere with the processing of the Data Stream.</p> 1486 1487<p>This block is <i>optional</i>; any number of them may appear in the Data 1488Stream.</p> 1489 1490<h3>b. Required Version</h3> 1491 1492<p>89a.</p> 1493 1494<h3>c. Syntax</h3> 1495 1496<table> 1497 <tbody><tr> 1498 <th>Byte # 1499 </th><th>Field Name 1500 </th><th>Type 1501 </th></tr><tr> 1502 <td style="text-align:center;">0 1503 </td><td>Extension Introducer 1504 </td><td>Byte 1505 </td></tr><tr> 1506 <td style="text-align:center;">1 1507 </td><td>Comment Label 1508 </td><td>Byte 1509</td></tr></tbody></table> 1510 1511<p></p> 1512 1513<table> 1514 <tbody><tr> 1515 <th>Byte # 1516 </th><th>Field Name 1517 </th><th>Type 1518 </th></tr><tr> 1519 <td style="text-align:center;">N 1520 </td><td>Comment Data 1521 </td><td><a href="#subblocks">Data Sub-blocks</a> 1522</td></tr></tbody></table> 1523 1524<p></p> 1525 1526<table> 1527 <tbody><tr> 1528 <th>Byte # 1529 </th><th>Field Name 1530 </th><th>Type 1531 </th></tr><tr> 1532 <td style="text-align:center;">0 1533 </td><td><a href="#blockterminator">Block Terminator</a> 1534 </td><td>Byte 1535</td></tr></tbody></table> 1536 1537<ol style="list-style-type:lower-roman;"> 1538 <li>Extension Introducer: 1539 <ul> 1540 <li>Identifies the beginning of an extension block. This field contains 1541 the fixed value <tt>0x21</tt> (33, <tt>'!'</tt>). 1542 </li></ul> 1543 </li><li>Comment Label: 1544 <ul> 1545 <li>Identifies the block as a Comment Extension. This field contains 1546 the fixed value <tt>0xFE</tt> (254). 1547 </li></ul> 1548 </li><li>Comment Data: 1549 <ul> 1550 <li>Sequence of sub-blocks, each of size at most 255 bytes and at least 1551 1 byte, with the size in a byte preceding the data. The end of the 1552 sequence is marked by the <a href="#blockterminator">Block 1553 Terminator</a>. 1554 </li></ul> 1555 </li><li>Block Terminator: 1556 <ul> 1557 <li>This zero-length data block marks the end of the Comment Extension. 1558 </li></ul> 1559</li></ol> 1560 1561<h3>d. Extensions and Scope</h3> 1562 1563<p>This block does not have scope. This block cannot be modified by any 1564extension.</p> 1565 1566<h3>e. Recommendations</h3> 1567 1568<ol style="list-style-type:lower-roman;"> 1569 <li>Data: 1570 <ul> 1571 <li>This block is intended for humans. It should contain text using the 1572 7-bit ASCII character set. This block should not be used to store 1573 control information for custom processing. 1574 </li></ul> 1575 </li><li>Position: 1576 <ul> 1577 <li>This block may appear at any point in the Data Stream at which a 1578 block can begin; however, it is recommended that Comment Extensions do 1579 not interfere with Control or Data blocks; they should be located at 1580 the beginning or at the end of the Data Stream to the extent possible. 1581 </li></ul> 1582</li></ol> 1583 1584</div> 1585 1586<h2 id="plaintextextension">25. Plain Text Extension <span onclick="ToggleVis(25);">(hide/show)</span></h2> 1587 1588<div id="p25"> 1589 1590<h3>a. Description</h3> 1591 1592<p>The Plain Text Extension contains textual data and the parameters necessary 1593to render that data as a graphic, in a simple form. The textual data will be 1594encoded with the 7-bit printable ASCII characters. Text data are rendered using 1595a grid of character cells defined by the parameters in the block fields. Each 1596character is rendered in an individual cell. The textual data in this block is 1597to be rendered as mono-spaced characters, one character per cell, with a best 1598fitting font and size. For further information, see the section on 1599Recommendations below.</p> 1600 1601<p>The data characters are taken sequentially from the data portion of the 1602block and rendered within a cell, starting with the upper left cell in the grid 1603and proceeding from left to right and from top to bottom. Text data is rendered 1604until the end of data is reached or the character grid is filled. The Character 1605Grid contains an integral number of cells; in the case that the cell dimensions 1606do not allow for an integral number, fractional cells must be discarded; an 1607encoder must be careful to specify the grid dimensions accurately so that this 1608does not happen.</p> 1609 1610<p>This block requires a <a href="#globalcolortable">Global Color Table</a> to 1611be available; the colors used by this block reference the Global Color Table in 1612the Stream if there is one, or the Global Color Table from a previous Stream, 1613if one was saved.</p> 1614 1615<p>This block is a graphic rendering block, therefore it may be modified by a 1616<a href="#graphiccontrolextension">Graphic Control Extension</a>.</p> 1617 1618<p>This block is <i>optional</i>; any number of them may appear in the Data 1619Stream.</p> 1620 1621<h3>b. Required Version</h3> 1622 1623<p>89a.</p> 1624 1625<h3>c. Syntax</h3> 1626 1627<table> 1628 <tbody><tr> 1629 <th>Byte # 1630 </th><th>Field Name 1631 </th><th>Type 1632 </th></tr><tr> 1633 <td style="text-align:center;">0 1634 </td><td>Extension Introducer 1635 </td><td>Byte 1636 </td></tr><tr> 1637 <td style="text-align:center;">1 1638 </td><td>Plain Text Label 1639 </td><td>Byte 1640</td></tr></tbody></table> 1641 1642<p></p> 1643 1644<table> 1645 <tbody><tr> 1646 <th>Byte # 1647 </th><th>Field Name 1648 </th><th>Type 1649 </th></tr><tr> 1650 <td style="text-align:center;">0 1651 </td><td>Block Size 1652 </td><td>Byte 1653 </td></tr><tr> 1654 <td style="text-align:center;">1 1655 </td><td rowspan="2">Text Grid Left Position 1656 </td><td rowspan="2">Unsigned 1657 </td></tr><tr> 1658 <td style="text-align:center;">2 1659 </td></tr><tr> 1660 <td style="text-align:center;">3 1661 </td><td rowspan="2">Text Grid Top Position 1662 </td><td rowspan="2">Unsigned 1663 </td></tr><tr> 1664 <td style="text-align:center;">4 1665 </td></tr><tr> 1666 <td style="text-align:center;">5 1667 </td><td rowspan="2">Text Grid Width 1668 </td><td rowspan="2">Unsigned 1669 </td></tr><tr> 1670 <td style="text-align:center;">6 1671 </td></tr><tr> 1672 <td style="text-align:center;">7 1673 </td><td rowspan="2">Text Grid Height 1674 </td><td rowspan="2">Unsigned 1675 </td></tr><tr> 1676 <td style="text-align:center;">8 1677 </td></tr><tr> 1678 <td style="text-align:center;">9 1679 </td><td>Character Cell Width 1680 </td><td>Byte 1681 </td></tr><tr> 1682 <td style="text-align:center;">10 1683 </td><td>Character Cell Height 1684 </td><td>Byte 1685 </td></tr><tr> 1686 <td style="text-align:center;">11 1687 </td><td>Text Foreground Color Index 1688 </td><td>Byte 1689 </td></tr><tr> 1690 <td style="text-align:center;">12 1691 </td><td>Text Background Color Index 1692 </td><td>Byte 1693</td></tr></tbody></table> 1694 1695<p></p> 1696 1697<table> 1698 <tbody><tr> 1699 <th>Byte # 1700 </th><th>Field Name 1701 </th><th>Type 1702 </th></tr><tr> 1703 <td style="text-align:center;">N 1704 </td><td>Plain Text Data 1705 </td><td>Data Sub-blocks 1706</td></tr></tbody></table> 1707 1708<p></p> 1709 1710<table> 1711 <tbody><tr> 1712 <th>Byte # 1713 </th><th>Field Name 1714 </th><th>Type 1715 </th></tr><tr> 1716 <td style="text-align:center;">0 1717 </td><td><a href="#blockterminator">Block Terminator</a> 1718 </td><td>Byte 1719</td></tr></tbody></table> 1720 1721<ol style="list-style-type:lower-roman;"> 1722 <li>Extension Introducer: 1723 <ul> 1724 <li>Identifies the beginning of an extension block. This field contains 1725 the fixed value <tt>0x21</tt> (33, <tt>'!'</tt>). 1726 </li></ul> 1727 </li><li>Plain Text Label: 1728 <ul> 1729 <li>Identifies the current block as a Plain Text Extension. This field 1730 contains the fixed value <tt>0x01</tt> (1). 1731 </li></ul> 1732 </li><li>Block Size: 1733 <ul> 1734 <li>Number of bytes in the extension, after the Block Size field and up 1735 to but not including the beginning of the data portion. This field 1736 contains the fixed value <tt>0x0C</tt> (12). 1737 </li></ul> 1738 </li><li>Text Grid Left Position: 1739 <ul> 1740 <li>Column number, in pixels, of the left edge of the text grid, with 1741 respect to the left edge of the Logical Screen. 1742 </li></ul> 1743 </li><li>Text Grid Top Position: 1744 <ul> 1745 <li>Row number, in pixels, of the top edge of the text grid, with 1746 respect to the top edge of the Logical Screen. 1747 </li></ul> 1748 </li><li>Image Grid Width: 1749 <ul> 1750 <li>Width of the text grid in pixels. 1751 </li></ul> 1752 </li><li>Image Grid Height: 1753 <ul> 1754 <li>Height of the text grid in pixels. 1755 </li></ul> 1756 </li><li>Character Cell Width: 1757 <ul> 1758 <li>Width, in pixels, of each cell in the grid. 1759 </li></ul> 1760 </li><li>Character Cell Height: 1761 <ul> 1762 <li>Height, in pixels, of each cell in the grid. 1763 </li></ul> 1764 </li><li>Text Foreground Color Index: 1765 <ul> 1766 <li>Index into the Global Color Table to be used to render the text 1767 foreground. 1768 </li></ul> 1769 </li><li>Text Background Color Index: 1770 <ul> 1771 <li>Index into the Global Color Table to be used to render the text 1772 background. 1773 </li></ul> 1774 </li><li>Plain Text Data: 1775 <ul> 1776 <li>Sequence of sub-blocks, each of size at most 255 bytes and at least 1777 1 byte, with the size in a byte preceding the data. The end of the 1778 sequence is marked by the Block Terminator. 1779 </li></ul> 1780 </li><li>Block Terminator: 1781 <ul> 1782 <li>This zero-length data block marks the end of the Plain Text Data 1783 Blocks. 1784 </li></ul> 1785</li></ol> 1786 1787<h3>d. Extensions and Scope</h3> 1788 1789<p>The scope of this block is the Plain Text Data Block contained in it. This 1790block may be modified by the Graphic Control Extension.</p> 1791 1792<h3 id="p25e">e. Recommendations</h3> 1793 1794<p>The data in the Plain Text Extension is assumed to be preformatted. The 1795selection of font and size is left to the discretion of the decoder. If 1796characters less than <tt>0x20</tt> (32) or greater than <tt>0xF7</tt> (247) are 1797encountered, it is recommended that the decoder display a Space character 1798(<tt>0x20</tt>, 32). The encoder should use grid and cell dimensions such that 1799an integral number of cells fit in the grid both horizontally as well as 1800vertically. For broadest compatibility, character cell dimensions should be 1801around 8×8 or 8×16 (width × height); consider an image for 1802unusual sized text.</p> 1803 1804<p><i>Editor's (Kalle's) note: the upper limit for a printable character, 1805<tt>0xF7</tt>, seems odd. Maybe they meant <tt>0x7E</tt> (126, <tt>'~'</tt>, 1806the last printable 7-bit ASCII character)?</i></p> 1807 1808</div> 1809 1810<h2 id="applicationextension">26. Application Extension <span onclick="ToggleVis(26);">(hide/show)</span></h2> 1811 1812<div id="p26"> 1813 1814<h3>a. Description</h3> 1815 1816<p>The Application Extension contains application-specific information; it 1817conforms with the extension block syntax, as described below, and its block 1818label is <tt>0xFF</tt> (255).</p> 1819 1820<h3>b. Required Version</h3> 1821 1822<p>89a.</p> 1823 1824<h3>c. Syntax</h3> 1825 1826<table> 1827 <tbody><tr> 1828 <th>Byte # 1829 </th><th>Field Name 1830 </th><th>Type 1831 </th></tr><tr> 1832 <td style="text-align:center;">0 1833 </td><td>Extension Introducer 1834 </td><td>Byte 1835 </td></tr><tr> 1836 <td style="text-align:center;">1 1837 </td><td>Extension Label 1838 </td><td>Byte 1839</td></tr></tbody></table> 1840 1841<p></p> 1842 1843<table> 1844 <tbody><tr> 1845 <th>Byte # 1846 </th><th>Field Name 1847 </th><th>Type 1848 </th></tr><tr> 1849 <td style="text-align:center;">0 1850 </td><td>Block Size 1851 </td><td>Byte 1852 </td></tr><tr> 1853 <td style="text-align:center;">1…8 1854 </td><td>Application Identifier 1855 </td><td>8 Bytes 1856 </td></tr><tr> 1857 <td style="text-align:center;">9…11 1858 </td><td>Application Authentication Code 1859 </td><td>3 Bytes 1860</td></tr></tbody></table> 1861 1862<p></p> 1863 1864<table> 1865 <tbody><tr> 1866 <th>Field Name 1867 </th><th>Type 1868 </th></tr><tr> 1869 <td>Application Data 1870 </td><td><a href="#subblocks">Data Sub-blocks</a> 1871</td></tr></tbody></table> 1872 1873<p></p> 1874 1875<table> 1876 <tbody><tr> 1877 <th>Byte # 1878 </th><th>Field Name 1879 </th><th>Type 1880 </th></tr><tr> 1881 <td style="text-align:center;">0 1882 </td><td><a href="#blockterminator">Block Terminator</a> 1883 </td><td>Byte 1884</td></tr></tbody></table> 1885 1886<ol style="list-style-type:lower-roman;"> 1887 <li>Extension Introducer: 1888 <ul> 1889 <li>Defines this block as an extension. This field contains the fixed 1890 value <tt>0x21</tt> (33, <tt>'!'</tt>). 1891 </li></ul> 1892 </li><li>Application Extension Label: 1893 <ul> 1894 <li>Identifies the block as an Application Extension. This field 1895 contains the fixed value <tt>0xFF</tt> (255). 1896 </li></ul> 1897 </li><li>Block Size: 1898 <ul> 1899 <li>Number of bytes in this extension block, following the Block Size 1900 field, up to but not including the beginning of the Application Data. 1901 This field contains the fixed value <tt>0x0B</tt> (11). 1902 </li></ul> 1903 </li><li>Application Identifier: 1904 <ul> 1905 <li>Sequence of eight printable ASCII characters used to identify the 1906 application owning the Application Extension. 1907 </li></ul> 1908 </li><li>Application Authentication Code: 1909 <ul> 1910 <li>Sequence of three bytes used to authenticate the Application 1911 Identifier. An Application program may use an algorithm to compute a 1912 binary code that uniquely identifies it as the application owning the 1913 Application Extension. 1914 </li></ul> 1915</li></ol> 1916 1917<h3>d. Extensions and Scope</h3> 1918 1919<p>This block does not have scope. This block cannot be modified by any extension.</p> 1920 1921<h3>e. Recommendation</h3> 1922 1923<p>None.</p> 1924 1925</div> 1926 1927<h2 id="trailer">27. Trailer <span onclick="ToggleVis(27);">(hide/show)</span></h2> 1928 1929<div id="p27"> 1930 1931<h3>a. Description</h3> 1932 1933<p>This block is a single-field block indicating the end of the GIF Data 1934Stream. It contains the fixed value <tt>0x3B</tt> (59, <tt>';'</tt>).</p> 1935 1936<h3>b. Required Version</h3> 1937 1938<p>87a.</p> 1939 1940<h3>c. Syntax</h3> 1941 1942<table> 1943 <tbody><tr> 1944 <th>Byte # 1945 </th><th>Field Name 1946 </th><th>Type 1947 </th></tr><tr> 1948 <td style="text-align:center;">0 1949 </td><td>GIF Trailer 1950 </td><td>Byte 1951</td></tr></tbody></table> 1952 1953<h3>d. Extensions and Scope</h3> 1954 1955<p>This block does not have scope, it terminates the GIF Data Stream. This 1956block may not be modified by any extension.</p> 1957 1958<h3>e. Recommendations</h3> 1959 1960<p>None.</p> 1961 1962</div> 1963 1964<h2 id="quickreferencetable">Appendix A. Quick Reference Table <span onclick="ToggleVis(28);">(hide/show)</span></h2> 1965 1966<div id="p28"> 1967 1968<table> 1969 <tbody><tr> 1970 <th>Block Name 1971 </th><th>Required? 1972 </th><th>Label 1973 </th><th>Extension 1974 </th><th>Version 1975 </th></tr><tr> 1976 <th colspan="5">Unlabeled Blocks 1977 </th></tr><tr> 1978 <td><a href="#header">Header</a> 1979 </td><td>required (one occurrence) 1980 </td><td style="text-align:center;">none 1981 </td><td style="text-align:center;">no 1982 </td><td style="text-align:center;">N/A 1983 </td></tr><tr> 1984 <td><a href="#logicalscreendescriptor">Logical Screen Descriptor</a> 1985 </td><td>required (one occurrence) 1986 </td><td style="text-align:center;">none 1987 </td><td style="text-align:center;">no 1988 </td><td style="text-align:center;">87a (89a) 1989 </td></tr><tr> 1990 <td><a href="#globalcolortable">Global Color Table</a> 1991 </td><td>optional (at most one occurrence) 1992 </td><td style="text-align:center;">none 1993 </td><td style="text-align:center;">no 1994 </td><td style="text-align:center;">87a 1995 </td></tr><tr> 1996 <td><a href="#localcolortable">Local Color Table</a> 1997 </td><td>optional (zero or more occurrences) 1998 </td><td style="text-align:center;">none 1999 </td><td style="text-align:center;">no 2000 </td><td style="text-align:center;">87a 2001 </td></tr><tr> 2002 <th colspan="5">Graphic-Rendering Blocks 2003 </th></tr><tr> 2004 <td><a href="#plaintextextension">Plain Text Extension</a> 2005 </td><td>optional (zero or more occurrences) 2006 </td><td style="text-align:center;"><tt>0x01</tt> (1) 2007 </td><td style="text-align:center;">yes 2008 </td><td style="text-align:center;">89a 2009 </td></tr><tr> 2010 <td><a href="#imagedescriptor">Image Descriptor</a> 2011 </td><td>optional (zero or more occurrences) 2012 </td><td style="text-align:center;"><tt>0x2C</tt> (44, <tt>','</tt>) 2013 </td><td style="text-align:center;">no 2014 </td><td style="text-align:center;">87a (89a) 2015 </td></tr><tr> 2016 <th colspan="5">Control Blocks 2017 </th></tr><tr> 2018 <td><a href="#graphiccontrolextension">Graphic Control Extension</a> 2019 </td><td>optional (zero or more occurrences) 2020 </td><td style="text-align:center;"><tt>0xF9</tt> (249) 2021 </td><td style="text-align:center;">yes 2022 </td><td style="text-align:center;">89a 2023 </td></tr><tr> 2024 <th colspan="5">Special Purpose Blocks 2025 </th></tr><tr> 2026 <td><a href="#trailer">Trailer</a> 2027 </td><td>required (one occurrence) 2028 </td><td style="text-align:center;"><tt>0x3B</tt> (59, <tt>';'</tt>) 2029 </td><td style="text-align:center;">no 2030 </td><td style="text-align:center;">87a 2031 </td></tr><tr> 2032 <td><a href="#commentextension">Comment Extension</a> 2033 </td><td>optional (zero or more occurrences) 2034 </td><td style="text-align:center;"><tt>0xFE</tt> (254) 2035 </td><td style="text-align:center;">yes 2036 </td><td style="text-align:center;">89a 2037 </td></tr><tr> 2038 <td><a href="#applicationextension">Application Extension</a> 2039 </td><td>optional (zero or more occurrences) 2040 </td><td style="text-align:center;"><tt>0xFF</tt> (255) 2041 </td><td style="text-align:center;">yes 2042 </td><td style="text-align:center;">89a 2043</td></tr></tbody></table> 2044 2045<p>Notes:</p> 2046 2047<ul> 2048 <li>The Header is not subject to Version Numbers. 2049 </li><li>(89a) The Logical Screen Descriptor and the Image Descriptor retained 2050 their syntax from version 87a to version 89a, but some fields reserved 2051 under version 87a are used under version 89a. 2052</li></ul> 2053 2054</div> 2055 2056<h2 id="gifgrammar">Appendix B. GIF Grammar <span onclick="ToggleVis(29);">(hide/show)</span></h2> 2057 2058<div id="p29"> 2059 2060<p>A Grammar is a form of notation to represent the sequence in which certain 2061objects form larger objects. A grammar is also used to represent the number of 2062objects that can occur at a given position. The grammar given here represents 2063the sequence of blocks that form the GIF Data Stream. A grammar is given by 2064listing its rules. Each rule consists of the left-hand side, followed by some 2065form of equals sign, followed by the right-hand side. In a rule, the right-hand 2066side describes how the left-hand side is defined. The right-hand side consists 2067of a sequence of entities, with the possible presence of special symbols. The 2068following legend defines the symbols used in this grammar for GIF.</p> 2069 2070<p>Legend:</p> 2071 2072<table> 2073 <tbody><tr> 2074 <td style="text-align:center;">< > 2075 </td><td>grammar word 2076 </td></tr><tr> 2077 <td style="text-align:center;">::= 2078 </td><td>defines symbol 2079 </td></tr><tr> 2080 <td style="text-align:center;">* 2081 </td><td>zero or more occurrences 2082 </td></tr><tr> 2083 <td style="text-align:center;">+ 2084 </td><td>one or more occurrences 2085 </td></tr><tr> 2086 <td style="text-align:center;">| 2087 </td><td>alternate element 2088 </td></tr><tr> 2089 <td style="text-align:center;">[ ] 2090 </td><td>optional element 2091</td></tr></tbody></table> 2092 2093<p>Example:</p> 2094 2095<blockquote> 2096 <p><GIF Data Stream> ::= <a href="#header">Header</a> <Logical 2097 Screen> <Data>* <a href="#trailer">Trailer</a></p> 2098</blockquote> 2099 2100<p>This rule defines the entity <GIF Data Stream> as follows. It must 2101begin with a Header. The Header is followed by an entity called Logical Screen, 2102which is defined below by another rule. The Logical Screen is followed by the 2103entity Data, which is also defined below by another rule. Finally, the entity 2104Data is followed by the Trailer. Since there is no rule defining the Header or 2105the Trailer, this means that these blocks are defined in the document. The 2106entity Data has a special symbol (*) following it which means that, at this 2107position, the entity Data may be repeated any number of times, including 0 2108times. For further reading on this subject, refer to a standard text on 2109Programming Languages.</p> 2110 2111<h3>The Grammar</h3> 2112 2113<table class="invisible"> 2114 <tbody><tr> 2115 <td><GIF Data Stream> 2116 </td><td>::= 2117 </td><td>Header <Logical Screen> <Data>* Trailer 2118 </td></tr><tr> 2119 <td><Logical Screen> 2120 </td><td>::= 2121 </td><td><a href="#logicalscreendescriptor">Logical Screen Descriptor</a> 2122 [<a href="#globalcolortable">Global Color Table</a>] 2123 </td></tr><tr> 2124 <td><Data> 2125 </td><td>::= 2126 </td><td><Graphic Block> | <Special-Purpose Block> 2127 </td></tr><tr> 2128 <td><Graphic Block> 2129 </td><td>::= 2130 </td><td>[<a href="#graphiccontrolextension">Graphic Control Extension</a>] 2131 <Graphic-Rendering Block> 2132 </td></tr><tr> 2133 <td><Graphic-Rendering Block> 2134 </td><td>::= 2135 </td><td><Table-Based Image> | <a href="#plaintextextension">Plain 2136 Text Extension</a> 2137 </td></tr><tr> 2138 <td><Table-Based Image> 2139 </td><td>::= 2140 </td><td><a href="#imagedescriptor">Image Descriptor</a> [<a href="#localcolortable">Local Color Table</a>] <a href="#tablebasedimagedata">Image Data</a> 2141 </td></tr><tr> 2142 <td><Special-Purpose Block> 2143 </td><td>::= 2144 </td><td><a href="#applicationextension">Application Extension</a> | <a href="#commentextension">Comment Extension</a> 2145</td></tr></tbody></table> 2146 2147<p><i>Note:</i> The grammar indicates that it is possible for a GIF Data Stream 2148to contain the Header, the Logical Screen Descriptor, a Global Color Table and 2149the GIF Trailer. This special case is used to load a GIF decoder with a Global 2150Color Table, in preparation for subsequent Data Streams without color tables at 2151all.</p> 2152 2153</div> 2154 2155<h2 id="glossary">Appendix C. Glossary <span onclick="ToggleVis(30);">(hide/show)</span></h2> 2156 2157<div id="p30"> 2158 2159<table> 2160 <tbody><tr> 2161 <td>Active Color Table 2162 </td><td>Color table used to render the next graphic. If the next graphic is 2163 an image which has a <a href="#localcolortable">Local Color Table</a> 2164 associated with it, the active color table becomes the Local Color 2165 Table associated with that image. If the next graphic is an image 2166 without a Local Color Table, or a <a href="#plaintextextension">Plain 2167 Text Extension</a>, the active color table is the <a href="#globalcolortable">Global Color Table</a> associated with the 2168 Data Stream, if there is one; if there is no Global Color Table in the 2169 Data Stream, the active color table is a color table saved from a 2170 previous Data Stream, or one supplied by the decoder. 2171 </td></tr><tr> 2172 <td>Block 2173 </td><td>Collection of bytes forming a protocol unit. In general, the term 2174 includes labeled and unlabeled blocks, as well as Extensions. 2175 </td></tr><tr> 2176 <td>Data Stream 2177 </td><td>The GIF Data Stream is composed of blocks and <a href="#subblocks">sub-blocks</a> representing images and graphics, 2178 together with control information to render them on a display device. 2179 All control and data blocks in the Data Stream must follow the <a href="#header">Header</a> and must precede the <a href="#trailer">Trailer</a>. 2180 </td></tr><tr> 2181 <td>Decoder 2182 </td><td>A program capable of processing a GIF Data Stream to render the 2183 images and graphics contained in it. 2184 </td></tr><tr> 2185 <td>Encoder 2186 </td><td>A program capable of capturing and formatting image and graphic 2187 raster data, following the definitions of the Graphics Interchange 2188 Format. 2189 </td></tr><tr> 2190 <td>Extension 2191 </td><td>A protocol block labeled by the Extension Introducer <tt>0x21</tt> 2192 (33, <tt>'!'</tt>). 2193 </td></tr><tr> 2194 <td>Extension Introducer 2195 </td><td>Label (<tt>0x21</tt>, 33, <tt>'!'</tt>) defining an Extension. 2196 </td></tr><tr> 2197 <td>Graphic 2198 </td><td>Data which can be rendered on the screen by virtue of some 2199 algorithm. The term graphic is more general than the term image; in 2200 addition to images, the term graphic also includes data such as text, 2201 which is rendered using character bit-maps. 2202 </td></tr><tr> 2203 <td>Image 2204 </td><td>Data representing a picture or a drawing; an image is represented 2205 by an array of pixels called the raster of the image. 2206 </td></tr><tr> 2207 <td>Raster 2208 </td><td>Array of pixel values representing an image. 2209</td></tr></tbody></table> 2210 2211</div> 2212 2213<h2 id="conventions">Appendix D. Conventions <span onclick="ToggleVis(31);">(hide/show)</span></h2> 2214 2215<div id="p31"> 2216 2217<table> 2218 <tbody><tr> 2219 <td>Animation 2220 </td><td>The Graphics Interchange Format is not intended as a platform for 2221 animation, even though it can be done in a limited way. 2222 </td></tr><tr> 2223 <td>Byte Ordering 2224 </td><td>Unless otherwise stated, multi-byte numeric fields are ordered with 2225 the Least Significant Byte first. 2226 </td></tr><tr> 2227 <td>Color Indices 2228 </td><td>Color indices always refer to the active color table, either the <a href="#globalcolortable">Global Color Table</a> or the <a href="#localcolortable">Local Color Table</a>. 2229 </td></tr><tr> 2230 <td>Color Order 2231 </td><td>Unless otherwise stated, all triple-component RGB color values are 2232 specified in <span class="rcomp">Red</span>-<span class="gcomp">Green</span>-<span class="bcomp">Blue</span> order. 2233 </td></tr><tr> 2234 <td>Color Tables 2235 </td><td>Both color tables, the Global and the Local, are optional; if 2236 present, the Global Color Table is to be used with every image in the 2237 Data Stream for which a Local Color Table is not given; if present, a 2238 Local Color Table overrides the Global Color Table. However, if neither 2239 color table is present, the application program is free to use an 2240 arbitrary color table. If the graphics in several Data Streams are 2241 related and all use the same color table, an encoder could place the 2242 color table as the Global Color Table in the first Data Stream and 2243 leave subsequent Data Streams without a Global Color Table or any Local 2244 Color Tables; in this way, the overhead for the table is eliminated. It 2245 is recommended that the decoder save the previous Global Color Table to 2246 be used with the Data Stream that follows, in case it does not contain 2247 either a Global Color Table or any Local Color Tables. In general, this 2248 allows the application program to use past color tables, significantly 2249 reducing transmission overhead. 2250 </td></tr><tr> 2251 <td>Extension Blocks 2252 </td><td>Extensions are defined using the Extension Introducer code 2253 (<tt>0x21</tt>, 33, <tt>'!'</tt>) to mark the beginning of the block, 2254 followed by a block label, identifying the type of extension. Extension 2255 Codes are numbers in the range from <tt>0x00</tt> (0) to <tt>0xFF</tt> 2256 (255), inclusive. Special purpose extensions are transparent to the 2257 decoder and may be omitted when transmitting the Data Stream on-line. 2258 The GIF capabilities dialogue makes the provision for the receiver to 2259 request the transmission of all blocks; the default state in this 2260 regard is no transmission of Special purpose blocks. 2261 </td></tr><tr> 2262 <td>Reserved Fields 2263 </td><td>All Reserved Fields are expected to have each bit set to zero 2264 (off). 2265</td></tr></tbody></table> 2266 2267</div> 2268 2269<h2 id="interlacedimages">Appendix E. Interlaced Images <span onclick="ToggleVis(32);">(hide/show)</span></h2> 2270 2271<div id="p32"> 2272 2273<p>The rows of an Interlaced images are arranged in the following order:</p> 2274 2275<table> 2276 <tbody><tr> 2277 <td>Group 1 2278 </td><td>Pass 1 2279 </td><td>Every 8th row, starting with row 0 2280 </td></tr><tr> 2281 <td>Group 2 2282 </td><td>Pass 2 2283 </td><td>Every 8th row, starting with row 4 2284 </td></tr><tr> 2285 <td>Group 3 2286 </td><td>Pass 3 2287 </td><td>Every 4th row, starting with row 2 2288 </td></tr><tr> 2289 <td>Group 4 2290 </td><td>Pass 4 2291 </td><td>Every 2nd row, starting with row 1 2292</td></tr></tbody></table> 2293 2294<p>The following example illustrates how the rows of an interlaced image are 2295ordered.</p> 2296 2297<table id="interlace"> 2298 <tbody><tr> 2299 <th>Row Number 2300 </th><th colspan="4">Interlace Pass 2301 </th></tr><tr> 2302 <td>0 2303 </td><td>1 2304 </td><td> 2305 </td><td> 2306 </td><td> 2307 </td></tr><tr> 2308 <td>1 2309 </td><td> 2310 </td><td> 2311 </td><td> 2312 </td><td>4 2313 </td></tr><tr> 2314 <td>2 2315 </td><td> 2316 </td><td> 2317 </td><td>3 2318 </td><td> 2319 </td></tr><tr> 2320 <td>3 2321 </td><td> 2322 </td><td> 2323 </td><td> 2324 </td><td>4 2325 </td></tr><tr> 2326 <td>4 2327 </td><td> 2328 </td><td>2 2329 </td><td> 2330 </td><td> 2331 </td></tr><tr> 2332 <td>5 2333 </td><td> 2334 </td><td> 2335 </td><td> 2336 </td><td>4 2337 </td></tr><tr> 2338 <td>6 2339 </td><td> 2340 </td><td> 2341 </td><td>3 2342 </td><td> 2343 </td></tr><tr> 2344 <td>7 2345 </td><td> 2346 </td><td> 2347 </td><td> 2348 </td><td>4 2349 </td></tr><tr> 2350 <td>8 2351 </td><td>1 2352 </td><td> 2353 </td><td> 2354 </td><td> 2355 </td></tr><tr> 2356 <td>9 2357 </td><td> 2358 </td><td> 2359 </td><td> 2360 </td><td>4 2361 </td></tr><tr> 2362 <td>10 2363 </td><td> 2364 </td><td> 2365 </td><td>3 2366 </td><td> 2367 </td></tr><tr> 2368 <td>11 2369 </td><td> 2370 </td><td> 2371 </td><td> 2372 </td><td>4 2373 </td></tr><tr> 2374 <td>12 2375 </td><td> 2376 </td><td>2 2377 </td><td> 2378 </td><td> 2379 </td></tr><tr> 2380 <td>13 2381 </td><td> 2382 </td><td> 2383 </td><td> 2384 </td><td>4 2385 </td></tr><tr> 2386 <td>14 2387 </td><td> 2388 </td><td> 2389 </td><td>3 2390 </td><td> 2391 </td></tr><tr> 2392 <td>15 2393 </td><td> 2394 </td><td> 2395 </td><td> 2396 </td><td>4 2397 </td></tr><tr> 2398 <td>16 2399 </td><td>1 2400 </td><td> 2401 </td><td> 2402 </td><td> 2403 </td></tr><tr> 2404 <td>17 2405 </td><td> 2406 </td><td> 2407 </td><td> 2408 </td><td>4 2409 </td></tr><tr> 2410 <td>18 2411 </td><td> 2412 </td><td> 2413 </td><td>3 2414 </td><td> 2415 </td></tr><tr> 2416 <td>19 2417 </td><td> 2418 </td><td> 2419 </td><td> 2420 </td><td>4 2421</td></tr></tbody></table> 2422 2423</div> 2424 2425<h2 id="lzw">Appendix F. Variable-Length-Code LZW Compression <span onclick="ToggleVis(33);">(hide/show)</span></h2> 2426 2427<div id="p33"> 2428 2429<p>The Variable-Length-Code LZW Compression is a variation of the Lempel-Ziv 2430Compression algorithm in which variable-length codes are used to replace 2431patterns detected in the original data. The algorithm uses a code or 2432translation table constructed from the patterns encountered in the original 2433data; each new pattern is entered into the table and its index is used to 2434replace it in the compressed stream.</p> 2435 2436<p>The compressor takes the data from the input stream and builds a code or 2437translation table with the patterns as it encounters them; each new pattern is 2438entered into the code table and its index is added to the output stream; when a 2439pattern is encountered which had been detected since the last code table 2440refresh, its index from the code table is put on the output stream, thus 2441achieving the data compression. The expander takes input from the compressed 2442data stream and builds the code or translation table from it; as the compressed 2443data stream is processed, codes are used to index into the code table and the 2444corresponding data is put on the decompressed output stream, thus achieving 2445data decompression. The details of the algorithm are explained below. The 2446Variable-Length-Code aspect of the algorithm is based on an initial code size 2447(LZW-initial code size), which specifies the initial number of bits used for 2448the compression codes. When the number of patterns detected by the compressor 2449in the input stream exceeds the number of patterns encodable with the current 2450number of bits, the number of bits per LZW code is increased by one.</p> 2451 2452<p>The Raster Data stream that represents the actual output image can be 2453represented as:</p> 2454 2455<table> 2456 <tbody><tr> 2457 <th>Field name 2458 </th></tr><tr> 2459 <td>LZW code size 2460</td></tr></tbody></table> 2461 2462<p></p> 2463 2464<table> 2465 <tbody><tr> 2466 <th>Field name 2467 </th><th> 2468 </th></tr><tr> 2469 <td>block size 2470 </td><td rowspan="2">Repeated as many times as necessary. 2471 </td></tr><tr> 2472 <td>data bytes 2473</td></tr></tbody></table> 2474 2475<p>(The code that terminates the LZW compressed data must appear before <a href="#blockterminator">Block Terminator</a>.)</p> 2476 2477<table> 2478 <tbody><tr> 2479 <th>Field name 2480 </th></tr><tr> 2481 <td>Block Terminator (<tt>0x00</tt>, 0) 2482</td></tr></tbody></table> 2483 2484<p>The conversion of the image from a series of pixel values to a transmitted 2485or stored character stream involves several steps. In brief these steps 2486are:</p> 2487 2488<ol> 2489 <li>Establish the Code Size – Define the number of bits needed to 2490 represent the actual data. 2491 </li><li>Compress the Data – Compress the series of image pixels to a 2492 series of compression codes. 2493 </li><li>Build a Series of Bytes – Take the set of compression codes and 2494 convert to a string of 8-bit bytes. 2495 </li><li>Package the Bytes – Package sets of bytes into blocks preceded by 2496 character counts and output. 2497</li></ol> 2498 2499<h3>1. Establish Code Size</h3> 2500 2501<p>The first byte of the Compressed Data stream is a value indicating the 2502minimum number of bits required to represent the set of actual pixel values. 2503Normally this will be the same as the number of color bits. Because of some 2504algorithmic constraints however, black & white images which have one color 2505bit must be indicated as having a code size of 2. This code size value also 2506implies that the compression codes must start out one bit longer.</p> 2507 2508<h3>2. Compression</h3> 2509 2510<p>The LZW algorithm converts a series of data values into a series of codes 2511which may be raw values or a code designating a series of values. Using text 2512characters as an analogy, the output code consists of a character or a code 2513representing a string of characters.</p> 2514 2515<p>The LZW algorithm used in GIF matches algorithmically with the standard LZW 2516algorithm with the following differences:</p> 2517 2518<ol> 2519 <li>A special Clear code is defined which resets all 2520 compression/decompression parameters and tables to a start-up state. The 2521 value of this code is 2<sup><code size></sup>. For example if the 2522 code size indicated was 4 (image was 4 bits/pixel) the Clear code value 2523 would be 16 (<tt>10000</tt> binary). The Clear code can appear at any point 2524 in the image data stream and therefore requires the LZW algorithm to 2525 process succeeding codes as if a new data stream was starting. Encoders 2526 should output a Clear code as the first code of each image data stream. 2527 </li><li>An End of Information code is defined that explicitly indicates the end 2528 of the image data stream. LZW processing terminates when this code is 2529 encountered. It must be the last code output by the encoder for an image. 2530 The value of this code is <Clear code>+1. 2531 </li><li>The first available compression code value is <Clear code> + 2. 2532 </li><li>The output codes are of variable length, starting at <code size> 2533 + 1 bits per code, up to 12 bits per code. This defines a maximum code 2534 value of 4095 (<tt>0xFFF</tt>). Whenever the LZW code value would exceed 2535 the current code length, the code length is increased by one. The 2536 packing/unpacking of these codes must then be altered to reflect the new 2537 code length. 2538</li></ol> 2539 2540<p><i>Editor's (Kalle's) note: see also the <a href="#coversheet">Cover 2541Sheet</a>.</i></p> 2542 2543<h3>3. Build 8-bit Bytes</h3> 2544 2545<p>Because the LZW compression used for GIF creates a series of variable length 2546codes, of between 3 and 12 bits each, these codes must be reformed into a 2547series of 8-bit bytes that will be the characters actually stored or 2548transmitted. This provides additional compression of the image. The codes are 2549formed into a stream of bits as if they were packed right to left and then 2550picked off 8 bits at a time to be output.</p> 2551 2552<p>Assuming a character array of 8 bits per character and using 5 bit codes to 2553be packed, an example layout would be similar to:</p> 2554 2555<table> 2556 <tbody><tr> 2557 <th>Byte # 2558 </th><th>Bits 2559 </th></tr><tr> 2560 <td style="text-align:center;">0 2561 </td><td><tt>bbbaaaaa</tt> 2562 </td></tr><tr> 2563 <td style="text-align:center;">1 2564 </td><td><tt>dcccccbb</tt> 2565 </td></tr><tr> 2566 <td style="text-align:center;">2 2567 </td><td><tt>eeeedddd</tt> 2568 </td></tr><tr> 2569 <td style="text-align:center;">3 2570 </td><td><tt>ggfffffe</tt> 2571 </td></tr><tr> 2572 <td style="text-align:center;">4 2573 </td><td><tt>hhhhhggg</tt> 2574 </td></tr><tr> 2575 <td style="text-align:center;">⋮ 2576 </td><td><tt></tt> 2577 </td></tr><tr> 2578 <td style="text-align:center;">N 2579 </td><td> 2580</td></tr></tbody></table> 2581 2582<p>Note that the physical packing arrangement will change as the number of bits 2583per compression code change but the concept remains the same.</p> 2584 2585<h3>4. Package the Bytes</h3> 2586 2587<p>Once the bytes have been created, they are grouped into blocks for output by 2588preceding each block of 0 to 255 bytes with a character count byte. A block 2589with a zero byte count terminates the Raster Data stream for a given image. 2590These blocks are what are actually output for the GIF image. This block format 2591has the side effect of allowing a decoding program the ability to read past the 2592actual image data if necessary by reading block counts and then skipping over 2593the data.</p> 2594 2595<h3>Further Reading</h3> 2596 2597<ol> 2598 <li>Ziv, J. and Lempel, A.: <i>A Universal Algorithm for Sequential Data 2599 Compression</i>, IEEE Transactions on Information Theory, May 1977 2600 </li><li>Welch, T.: <i>A Technique for High-Performance Data Compression</i>, 2601 Computer, June 1984 2602 </li><li>Nelson, M.R.: <i>LZW Data Compression</i>, Dr. Dobb's Journal, October 2603 1989 2604</li></ol> 2605 2606<p><i>Editor's (Kalle's) note: see also <a href="https://web.archive.org/web/20160304075538/http://en.wikipedia.org/wiki/Lempel%E2%80%93Ziv%E2%80%93Welch">Wikipedia – 2607Lempel–Ziv–Welch</a>.</i></p> 2608 2609</div> 2610 2611<h2 id="onlinecapabilities">Appendix G. On-line Capabilities Dialogue <span onclick="ToggleVis(34);">(hide/show)</span></h2> 2612 2613<div id="p34"> 2614 2615<p><i>Note:</i> This section is currently (10 July 1990) under revision; the 2616information provided here should be used as general guidelines. Code written 2617based on this information should be designed in a flexible way to accommodate 2618any changes resulting from the revisions.</p> 2619 2620<p>The following sequences are defined for use in mediating control between a 2621GIF sender and GIF receiver over an interactive communications line. These 2622sequences do not apply to applications that involve downloading of static GIF 2623files and are not considered part of a GIF file.</p> 2624 2625<h3>GIF Capabilities Enquiry</h3> 2626 2627<p>The GIF Capabilities Enquiry sequence is issued from a host and requests an 2628interactive GIF decoder to return a response message that defines the graphics 2629parameters for the decoder. This involves returning information about available 2630screen sizes, number of bits/color supported and the amount of color detail 2631supported. The escape sequence for the GIF Capabilities Enquiry is defined 2632as:</p> 2633 2634<table> 2635 <tbody><tr> 2636 <td style="text-align:center;"><tt>ESC</tt> 2637 </td><td style="text-align:center;"><tt>0x1B</tt> (27) 2638 </td></tr><tr> 2639 <td style="text-align:center;"><tt>[</tt> 2640 </td><td style="text-align:center;"><tt>0x5B</tt> (91) 2641 </td></tr><tr> 2642 <td style="text-align:center;"><tt>></tt> 2643 </td><td style="text-align:center;"><tt>0x3E</tt> (62) 2644 </td></tr><tr> 2645 <td style="text-align:center;"><tt>0</tt> 2646 </td><td style="text-align:center;"><tt>0x30</tt> (48) 2647 </td></tr><tr> 2648 <td style="text-align:center;"><tt>g</tt> 2649 </td><td style="text-align:center;"><tt>0x67</tt> (103) 2650</td></tr></tbody></table> 2651 2652<h3>GIF Capabilities Response</h3> 2653 2654<p>The GIF Capabilities Response message is returned by an interactive GIF 2655decoder and defines the decoder's display capabilities for all graphics modes 2656that are supported by the software. Note that this can also include graphics 2657printers as well as a monitor screen. The general format of this message 2658is:</p> 2659 2660<p>#version;protocol{;dev, width, height, color-bits, 2661color-res}…<CR></p> 2662 2663<table> 2664 <tbody><tr> 2665 <td><tt>'#'</tt> 2666 </td><td>GIF Capabilities Response identifier character. 2667 </td></tr><tr> 2668 <td>version 2669 </td><td>GIF format version number; initially <tt>'87a'</tt>. 2670 </td></tr><tr> 2671 <td>protocol=<tt>'0'</tt> 2672 </td><td>No end-to-end protocol supported by decoder Transfer as direct 2673 8-bit data stream. 2674 </td></tr><tr> 2675 <td>protocol=<tt>'1'</tt> 2676 </td><td>Can use CIS B+ error correction protocol to transfer GIF data 2677 interactively from the host directly to the display. 2678 </td></tr><tr> 2679 <td>dev=<tt>'0'</tt> 2680 </td><td>Screen parameter set follows. 2681 </td></tr><tr> 2682 <td>dev=<tt>'1'</tt> 2683 </td><td>Printer parameter set follows. 2684 </td></tr><tr> 2685 <td>width 2686 </td><td>Maximum supported display width in pixels. 2687 </td></tr><tr> 2688 <td>height 2689 </td><td>Maximum supported display height in pixels. 2690 </td></tr><tr> 2691 <td>color-bits 2692 </td><td>Number of bits per pixel supported. The number of supported colors 2693 is therefore 2<sup>color-bits</sup>. 2694 </td></tr><tr> 2695 <td>color-res 2696 </td><td>Number of bits per color component supported in the hardware color 2697 palette. If color-res is <tt>'0'</tt> then no hardware palette table is 2698 available. 2699</td></tr></tbody></table> 2700 2701<p>Note that all values in the GIF Capabilities Response are returned as ASCII 2702decimal numbers and the message is terminated by a Carriage Return character 2703(<tt>0x0D</tt>, 13).</p> 2704 2705<p>The following GIF Capabilities Response message describes three standard IBM 2706PC <a href="https://web.archive.org/web/20160304075538/http://en.wikipedia.org/wiki/Enhanced_Graphics_Adapter">Enhanced 2707Graphics Adapter</a> configurations with no printer; the GIF data stream can be 2708processed within an error correcting protocol:</p> 2709 2710<blockquote> 2711 <p><tt>#87a;1;0,320,200,4,0;0,640,200,2,2;0,640,350,4,2<CR></tt></p> 2712</blockquote> 2713 2714<h3>Enter GIF Graphics Mode</h3> 2715 2716<p>Two sequences are currently defined to invoke an interactive GIF decoder 2717into action. The only difference between them is that different output media 2718are selected. These sequences are:</p> 2719 2720<table> 2721 <tbody><tr> 2722 <td style="text-align:center;"><tt>ESC</tt> 2723 </td><td style="text-align:center;"><tt>0x1B</tt> (27) 2724 </td><td rowspan="5">Display GIF image on screen 2725 </td></tr><tr> 2726 <td style="text-align:center;"><tt>[</tt> 2727 </td><td style="text-align:center;"><tt>0x5B</tt> (91) 2728 </td></tr><tr> 2729 <td style="text-align:center;"><tt>></tt> 2730 </td><td style="text-align:center;"><tt>0x3E</tt> (62) 2731 </td></tr><tr> 2732 <td style="text-align:center;"><tt>1</tt> 2733 </td><td style="text-align:center;"><tt>0x31</tt> (49) 2734 </td></tr><tr> 2735 <td style="text-align:center;"><tt>g</tt> 2736 </td><td style="text-align:center;"><tt>0x67</tt> (103) 2737</td></tr></tbody></table> 2738 2739<p></p> 2740 2741<table> 2742 <tbody><tr> 2743 <td style="text-align:center;"><tt>ESC</tt> 2744 </td><td style="text-align:center;"><tt>0x1B</tt> (27) 2745 </td><td rowspan="5">Display image directly to an attached graphics printer. 2746 The image may optionally be displayed on the screen as well. 2747 </td></tr><tr> 2748 <td style="text-align:center;"><tt>[</tt> 2749 </td><td style="text-align:center;"><tt>0x5B</tt> (91) 2750 </td></tr><tr> 2751 <td style="text-align:center;"><tt>></tt> 2752 </td><td style="text-align:center;"><tt>0x3E</tt> (62) 2753 </td></tr><tr> 2754 <td style="text-align:center;"><tt>2</tt> 2755 </td><td style="text-align:center;"><tt>0x32</tt> (50) 2756 </td></tr><tr> 2757 <td style="text-align:center;"><tt>g</tt> 2758 </td><td style="text-align:center;"><tt>0x67</tt> (103) 2759</td></tr></tbody></table> 2760 2761<p>Note that the <tt>'g'</tt> character terminating each sequence is in 2762lowercase.</p> 2763 2764<h3>Interactive Environment</h3> 2765 2766<p>The assumed environment for the transmission of GIF image data from an 2767interactive application is a full 8-bit data stream from host to micro. All 256 2768character codes must be transferrable. The establishing of an 8-bit data path 2769for communications will normally be taken care of by the host application 2770programs. It is however up to the receiving communications programs supporting 2771GIF to be able to receive and pass on all 256 8-bit codes to the GIF decoder 2772software.</p> 2773 2774</div> 2775 2776<h2 id="coversheet">Cover Sheet for the GIF89a Specification <span onclick="ToggleVis(35);">(hide/show)</span></h2> 2777 2778<div id="p35"> 2779 2780<h3>Deferred clear code in LZW compression</h3> 2781 2782<p>There has been confusion about where clear codes can be found in the data 2783stream. As the specification says, they may appear at anytime. There is not a 2784requirement to send a clear code when the string table is full.</p> 2785 2786<p>It is the encoder's decision as to when the table should be cleared. When 2787the table is full, the encoder can chose to use the table as is, making no 2788changes to it until the encoder chooses to clear it. The encoder during this 2789time sends out codes that are of the maximum Code Size.</p> 2790 2791<p>As we can see from the above, when the decoder's table is full, it must not 2792change the table until a clear code is received. The Code Size is that of the 2793maximum Code Size. Processing other than this is done normally.</p> 2794 2795<p>Because of a large base of decoders that do not handle the decompression in 2796this manner, we ask developers of GIF encoding software to <i>not</i> implement 2797this feature until at least January 1991 and later if they see that their 2798particular market is not ready for it. This will give developers of GIF 2799decoding software time to implement this feature and to get it into the hands 2800of their clients before the decoders start "breaking" on the new GIF's. It is 2801not required that encoders change their software to take advantage of the 2802deferred clear code, but it is for decoders.</p> 2803 2804<h3>Application Extension Block – Application Identifier</h3> 2805 2806<p>There will be a Courtesy Directory file located on CompuServe in the PICS 2807forum. This directory will contain Application Identifiers for <a href="#applicationextension">Application Extension Blocks</a> that have been 2808used by developers of GIF applications. This file is intended to help keep 2809developers that wish to create Application Extension Blocks from using the same 2810Application Identifiers. This is not an official directory; it is for voluntary 2811participation only and does not guarantee that someone will not use the same 2812identifier.</p> 2813 2814<p>E-Mail can be sent to Larry Wood (forum manager of PICS) indicating the 2815request for inclusion in this file with an identifier.</p> 2816 2817</div> 2818<hr> 2819</body> 2820</html> 2821