File: gif_lib.html

package info (click to toggle)
giflib 5.1.9-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,648 kB
  • sloc: ansic: 6,970; xml: 2,474; makefile: 340; sh: 4
file content (518 lines) | stat: -rw-r--r-- 50,281 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>The GIFLIB Library</title><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /></head><body><div class="article"><div class="titlepage"><div><div><h2 class="title"><a id="idm1"></a>The GIFLIB Library</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Eric</span> <span class="othername">Steven</span> <span class="surname">Raymond</span></h3><div class="affiliation"><span class="orgname"><a class="ulink" href="http://catb.org/~esr/" target="_top">
    Thyrsus Enterprises</a><br /></span><div class="address"><p><br />
    <code class="email">&lt;<a class="email" href="mailto:esr@thyrsus.com">esr@thyrsus.com</a>&gt;</code><br />
    </p></div></div></div></div><div><p class="copyright">Copyright © 2012 Eric S. Raymond</p></div></div><hr /></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="sect1"><a href="#idm16">Introduction</a></span></dt><dt><span class="sect1"><a href="#idm21">Credit and Blame</a></span></dt><dt><span class="sect1"><a href="#idm27">The GIF descriptor</a></span></dt><dt><span class="sect1"><a href="#idm55">Decoding (dgif_lib.c)</a></span></dt><dt><span class="sect1"><a href="#idm73">Encoding (egif_lib.c)</a></span></dt><dt><span class="sect1"><a href="#idm84">Color map handling and allocation routines</a></span></dt><dt><span class="sect1"><a href="#idm94">Graphics control extension handling</a></span></dt><dt><span class="sect1"><a href="#idm99">Error Handling (gif_err.c)</a></span></dt><dt><span class="sect1"><a href="#idm103">The GIF Utility Font</a></span></dt><dt><span class="sect1"><a href="#idm116">Error codes</a></span></dt><dd><dl><dt><span class="sect2"><a href="#idm119">Encoding errors</a></span></dt><dt><span class="sect2"><a href="#idm172">Decoding errors</a></span></dt></dl></dd><dt><span class="sect1"><a href="#idm240">Utility support library</a></span></dt><dd><dl><dt><span class="sect2"><a href="#idm243">Error Handling</a></span></dt><dt><span class="sect2"><a href="#idm247">Command Line Parsing</a></span></dt></dl></dd><dt><span class="sect1"><a href="#sequential">Sequential access</a></span></dt><dd><dl><dt><span class="sect2"><a href="#idm260">Sequential reading</a></span></dt><dt><span class="sect2"><a href="#idm319">Sequential writing</a></span></dt></dl></dd><dt><span class="sect1"><a href="#compatibility">Forward and Backward Compatibility</a></span></dt><dd><dl><dt><span class="sect2"><a href="#idm389">General behavior</a></span></dt><dt><span class="sect2"><a href="#idm399">In documented functions:</a></span></dt><dt><span class="sect2"><a href="#idm412">In undocumented functions:</a></span></dt><dt><span class="sect2"><a href="#idm419">Error handling:</a></span></dt></dl></dd><dt><span class="sect1"><a href="#idm428">Skeletons of GIF filters</a></span></dt><dt><span class="sect1"><a href="#idm433">Unimplemented features</a></span></dt></dl></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm16"></a>Introduction</h2></div></div></div><p>The Graphics Interchange Format(c) is the Copyright property of
CompuServe Incorporated.  GIF(sm) is a Service Mark property of CompuServe
Incorporated.</p><p>This document explains the GIF library code in directory `lib'.  The
code is collected into a service library which is used in all the utilities in
`util'.  It can be used in any application needs to read/write the GIF
file format.  This document does <span class="emphasis"><em>not</em></span> explain the GIF file
format and assumes you know it, at least to the level of the GIF file
structure.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm21"></a>Credit and Blame</h2></div></div></div><p>Gershon wrote: "This library was written because I couldn't find
anything similar and I wanted one.  I was inspired by the RLE Utah tool kit,
which I hoped to port to an IBM PC, but found it to be too machine specific,
and its compression ratio too low.  I compromised on the GIF format, but I am
not sure how long 8 bits per pixel will be enough."</p><p>During his first spell of maintainership between 1989 and 1994, Eric
S. Raymond (aka "ESR") ported the code to Unix, wrote the high-level
DGIfSlurp()/EGifSpew() interface, rationalized the internal data
structures, and did a lot of general cleanup and refactoring to
improve the code quality.</p><p>Between 1994 and 2012 Toshio Kuratomi fixed various tool bugs,
build-recipe problems and rare segfaults. He partially untangled the
somewhat misdesigned extension-block handling in earlier versions. 
The core code was very stable during this period.</p><p>During his second spell of maintainership, ESR fixed the
extension API, made the library re-entrant and thread-safe, wrote a
regression-test suite, greatly improved the documentation, and
discarded a lot of obsolete code.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm27"></a>The GIF descriptor</h2></div></div></div><p>When a GIF file is opened, a GIF file descriptor is created which
is a pointer to GifFileType structure as follows:</p><pre class="programlisting">
typedef struct GifFileType {
    GifWord SWidth, SHeight;         /* Size of virtual canvas */
    GifWord SColorResolution;        /* How many colors can we generate? */
    GifWord SBackGroundColor;        /* Background color for virtual canvas */
    GifByteType AspectByte;	     /* Used to compute pixel aspect ratio */
    ColorMapObject *SColorMap;       /* Global colormap, NULL if nonexistent. */
    int ImageCount;                  /* Number of current image (both APIs) */
    GifImageDesc Image;              /* Current image (low-level API) */
    SavedImage *SavedImages;         /* Image sequence (high-level API) */
    int ExtensionBlockCount;         /* Count extensions past last image */
    ExtensionBlock *ExtensionBlocks; /* Extensions past last image */    
    int Error;			     /* Last error condition reported */
    void *UserData;                  /* hook to attach user data (TVT) */
    void *Private;                   /* Don't mess with this! */
} GifFileType;
</pre><p>This structure was copied from gif_lib.h - the header file for the GIF
library.  Any application program that uses the libgif.a library should
include it.  Members beginning with S refer to the GIF screen; others hold
properties of the current image (a GIF file may have more than one image)
or point to allocated store used by various routines.</p><p>The user almost never writes into this structure (exception: it
may occasionally be useful to alter things in the SavedImages array and
Trailing member), but can read any of these items at any time it is
valid (Image information is invalid until the first image has been read;
read; SavedImages information is valid only after a DGifSlurp() call).</p><p>As the library needs to keep its own internal data, a Private pointer
to hidden data is included. Applications should ignore this.</p><p>The library allocates its own memory dynamically, on opening of files,
and releases that once closed.  The user is never required to allocate
any memory for any of the functions of this library, and is almost never
required to free them directly. The "almost" in the latter clause is because
one manual free() call may be required on a failed file close; see the
documentation of DGifClose() and EGifClose() for details.</p><p>Here is a module summary:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">egif_lib.c</span></dt><dd><p>Encoding routines, all prefixed with E.</p></dd><dt><span class="term">dgif_lib.c</span></dt><dd><p>Decoding routines, all prefixed with D.</p></dd><dt><span class="term">gifalloc.c</span></dt><dd><p>Routines for colormap handling and GIF record allocation.</p></dd><dt><span class="term">gif_font.c</span></dt><dd><p>The 8x8 font table for the GIF utility font.</p></dd></dl></div><p>The library includes a sixth file of hash-function code which is accessed
internally only.</p><p>Most of the routines return GIF_ERROR (see gif_lib.h) if something
went wrong, GIF_OK otherwise.  After an error return, all routines that
take a pointer-to-GifFileType argument set the Error member with a code that
can be interpreted into an explanatory string with the function 
GifErrorString() in gif_err.c. (The exception to this is the
DGifClose() and EGifClose() routines, which deallocate that structure
and must therefore return any error code through a pointer argument.)</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm55"></a>Decoding (dgif_lib.c)</h2></div></div></div><p>The following functions are used to set up input from a GIF:</p><a id="DGifOpenFileName"></a><pre class="programlisting">
GifFileType *DGifOpenFileName(char *GifFileName, int *ErrorCode)
</pre><p>Open a new GIF file (in binary mode, if under Windows) using the
given GifFileName, and read its Screen information.</p><p>If any error occurs, NULL is returned and ErrorCode is set (if
non-NULL).</p><a id="DGifOpenFileHandle"></a><pre class="programlisting">
GifFileType *DGifOpenFileHandle(int FileHandle, int *ErrorCode)
</pre><p>Open a new GIF file using the given FileHandle, and read its Screen
information.</p><p>If any error occurs, NULL is returned and ErrorCode is set (if
non-NULL).</p><p>Once you have acquired a handle on a GIF, the high-level
function</p><a id="DGifSlurp"></a><pre class="programlisting">
int DGifSlurp(GifFileType)
</pre><p>reads the rest of a complete (possibly multi-image) GIF file from the
indicated file handle into in-core allocated structures.  It returns
GIF_OK on success, GIF_ERROR on failure; on failure, the Error member 
will be set.</p><p>Once you have done this, all image, raster, and extension-block
data in the GIF is accessable in the SavedImages member (see the
structures in gif_lib.h).  When you have modified the image to taste,
write it out with EGifSpew().</p><p>One detail that may not be clear from just looking at the
structures is how extension blocks and sub-blocks are stored.  Each
ExtensionBlock structure represents an extension data block.  Those
with a zero function code represent continuation data blocks attached
to previous blocks with nonzero function codes.</p><p>You can read from a GIF file through a function hook. Initialize
with </p><a id="DGifOpen"></a><pre class="programlisting">
GifFileType *DGifOpen(void *userPtr, InputFunc readFunc, int *ErrorCode)
</pre><p>and see the library header file for the type of InputFunc.</p><p>There is also a set of deprecated functions for sequential I/O,
described in a later section.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm73"></a>Encoding (egif_lib.c)</h2></div></div></div><p>The high-level function</p><a id="EGifSpew"></a><pre class="programlisting">
int EGifSpew(GifFileType *GifFile)
</pre><p>writes a complete (possibly multi-image) GIF file to the indicated file
handle from in-core allocated structures created by a previous DGifSlurp()
or equivalent operations.  Its argument is a GIF file descriptor, which
imnplicitly points to storage previously allocated by DGifSlurp().</p><p>The file is written with a GIF87 stamp unless it contains one of the four
special extension blocks defined in GIF89, in which case it is written
with a GIF89 stamp.</p><p>EGifSpew() finishes by closing the GIF (writing a termination
record to it) and deallocating the associated storage.</p><p>You can write to a GIF file through a function hook. Initialize
with </p><a id="EGifOpen"></a><pre class="programlisting">
GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc, int *ErrorCode)
</pre><p>and see the library header file for the type of OutputFunc.</p><p>There is also a set of deprecated functions for sequential I/O,
described in a later section.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm84"></a>Color map handling and allocation routines</h2></div></div></div><a id="GifMakeMapObject"></a><pre class="programlisting">
ColorMapObject *GifMakeMapObject(int ColorCount, GifColorType *ColorMap)
</pre><p>Allocate storage for a color map object with the given number of
RGB triplet slots.  If the second argument is non-NULL, initialize
the color table portion of the new map from it.  Returns NULL if
memory is exhausted or if the size is not a power of 2 &lt;= 256.</p><a id="GifFreeMapObject"></a><pre class="programlisting">
void GifFreeMapObject(ColorMapObject *Object)
</pre><p>Free the storage occupied by a ColorMapObject that is no longer
needed.</p><a id="GifUnionColorMap"></a><pre class="programlisting">
ColorMapObject *GifUnionColorMap(
        ColorMapObject *ColorIn1, ColorMapObject *ColorIn2,
        GifPixelType ColorTransIn2[])
</pre><p>Create the union of two given color maps and return it.  If the result
won't fit into 256 colors, NULL is returned, the allocated union
otherwise.  ColorIn1 is copied as it to ColorUnion, while colors from
ColorIn2 are copied iff they didn't exist before.  ColorTransIn2 maps
the old ColorIn2 into ColorUnion color map table.</p><a id="GifAttachImage"></a><pre class="programlisting">
SavedImage *GifAttachImage(GifFileType *GifFile)
</pre><p>Add an image block to the SavedImages array.  The image block is
initially zeroed out.  This image block will be seen by any following
EGifSpew() calls.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm94"></a>Graphics control extension handling</h2></div></div></div><p>GIF89 added a graphics control extension block, but versions
of GIFLIB before 5.0 weren't much help in reading or modifying them.  
This lack has been remedied with the following structure and functions:</p><pre class="programlisting">
typedef struct GraphicsControlBlock {
    int DisposalMode;
#define DISPOSAL_UNSPECIFIED      0       /* No disposal specified. */
#define DISPOSE_DO_NOT            1       /* Leave image in place */
#define DISPOSE_BACKGROUND        2       /* Set area too background color */
#define DISPOSE_PREVIOUS          3       /* Restore to previous content */
    bool UserInputFlag;      /* User confirmation required before disposal */
    int DelayTime;           /* pre-display delay in 0.01sec units */
    int TransparentColor;    /* Palette index for transparency, -1 if none */
#define NO_TRANSPARENT_COLOR	-1
} GraphicsControlBlock;

int DGifSavedExtensionToGCB(GifFileType *GifFile, 
			    int ImageIndex, 
			    GraphicsControlBlock *GCB);
int EGifGCBToSavedExtension(const GraphicsControlBlock *GCB, 
			    GifFileType *GifFile, 
			    int ImageIndex);
</pre><p>With these functions you can extract the data from a graphics
control extension associated with a saved image into a
GraphicsControlBlock, modify it, and write it back out.  Note that if
the specified saved image doesn't have a graphics control extension,
DGifSavedExtensionToGCB() will fill the GCB with default values and
return GIF_ERROR (which can be ignored); EGifGCBToSavedExtension()
will create a new leading extension block.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm99"></a>Error Handling (gif_err.c)</h2></div></div></div><pre class="programlisting">
int GifErrorString(int ErrCode)
</pre><p>Returns a sting describing the specified GIFLIB error code.
Return NULL if the argument is not a valid error code.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm103"></a>The GIF Utility Font</h2></div></div></div><p>The 8x8 utility font used in gifecho and gifcolor lives in the library
module gif_font.c, in a table called GifAsciiTable.  The library header file
includes suitable externs and defines.</p><p>The GIF utility font support includes entry points for drawing legends
on in-core images, drawing boxes and rectangles, and boxing text.
These entry points are as follows:</p><a id="GifDrawText"></a><pre class="programlisting">
void GifDrawText8x8(
        SavedImage *Image,
        const int x, const int y,
        const char *legend,
        const int color)
</pre><p>Draw text using the 8x8 utility font on the saved image.  Upper
left corner of the text is at image pixel (x, y).  Use the specified
color index.</p><a id="GifDrawBox"></a><pre class="programlisting">
void GifDrawBox(SavedImage *Image,
        const int x, const int y,
        const int w, const int h,
        const int color)
</pre><p>Draw a box on the saved image.  Upper left corner of the box is at
image pixels (x, y), width is w, height is h.  Use the specified color
index.</p><a id="GifDrawRectangle"></a><pre class="programlisting">
void GifDrawRectangle(SavedImage *Image,
        const int x, const int y,
        const int w, const int h,
        const int color)
</pre><p>Draw a (filled) rectangle on the saved image.  Upper left corner of
the box is at image pixels (x, y), width is w, height is h.  Use the
specified color index.</p><a id="GifDrawBoxedText"></a><pre class="programlisting">
void GifDrawBoxedText8x8(SavedImage *Image,
        const int x, const int y,
        const char *legend,
        const int border,
        const int bg, const int fg)
</pre><p>Draw text on a filled rectangle.  The rectangle will be sized to fit
the text, with upper left hand corner at (x, y) on the saved image.
The `border' argument specifies a pixel margin around the text.  The
`bg' argument is the color table index to fill the rectangle with;
`fg' is the color table index to draw the text with.</p><p>This function interprets some characters in the legend string
specially.  A tab (\t) is interpreted as a command to center the
following text in the box.  A carriage return (\r) is interpreted
as a request for a line break.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm116"></a>Error codes</h2></div></div></div><p>Errors as reported from the GIFLIB library are divided to two major
categories: the encoder (errors prefixed by E_GIF_ERR), and the
decoder (errors prefixed by D_GIF_ERR).  This document explains them
briefly.</p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="idm119"></a>Encoding errors</h3></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorname">E_GIF_ERR_OPEN_FAILED</span></span></dt><dd><p>Message printed using PrintGifError: "Failed to open given file"
   IO error result when attempt to open the given GIF file.</p></dd><dt><span class="term"><span class="errorname">E_GIF_ERR_WRITE_FAILED</span></span></dt><dd><p>Message printed using PrintGifError: "Failed to Write to given file"
   IO error result when attempt to write to the given GIF file.</p></dd><dt><span class="term"><span class="errorname">E_GIF_ERR_HAS_SCRN_DSCR</span></span></dt><dd><p>Message printed using PrintGifError: "Screen Descriptor
   already been set" Attempt to write second screen descriptor to same
   GIF file. GIF file should have exactly one screen descriptor which
   should be set directly after the file is opened.</p></dd><dt><span class="term"><span class="errorname">E_GIF_ERR_HAS_IMAG_DSCR</span></span></dt><dd><p>Message printed using PrintGifError: "Image Descriptor is still active"
   Image descriptor should be sent before and image dump, and no second
   image descriptor should be sent before current image dump ended. This error
   occurred probably because current image was not complete.</p></dd><dt><span class="term"><span class="errorname">E_GIF_ERR_NO_COLOR_MAP</span></span></dt><dd><p>Message printed using PrintGifError: "Neither Global Nor
   Local color map" An image must have either global (screen) or local
   (image) color map.  Neither were given in this case.</p></dd><dt><span class="term"><span class="errorname">E_GIF_ERR_DATA_TOO_BIG</span></span></dt><dd><p>Message printed using PrintGifError: "#Pixels bigger than
   Width * Height" The number of pixels dumped for this image is
   bigger than specified by image Height times image Width.</p></dd><dt><span class="term"><span class="errorname">E_GIF_ERR_NOT_ENOUGH_MEM</span></span></dt><dd><p>Message printed using PrintGifError: "Fail to allocate
   required memory" Once an attemp is made to open GIF file, special
   structures are allocated to hold internal data for it. If
   allocation fails this error is returned.</p></dd><dt><span class="term"><span class="errorname">E_GIF_ERR_DISK_IS_FULL</span></span></dt><dd><p>Message printed using PrintGifError: "Write failed (disk full?)"
   Writing encoded data failed.</p></dd><dt><span class="term"><span class="errorname">E_GIF_ERR_CLOSE_FAILED</span></span></dt><dd><p>Message printed using PrintGifError: "Failed to close given file"
   Closing file failed.</p></dd><dt><span class="term"><span class="errorname"> E_GIF_ERR_NOT_WRITEABLE</span></span></dt><dd><p>Message printed using PrintGifError: "Given file was not
   opened for write" GIF files can be opened both for read (DGIF part
   of library) and write (EGIF part of library). This error occurs
   when a file is opened for read (using DGIF) is given to one of the
   encoding (EGIF) routines.</p></dd></dl></div></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="idm172"></a>Decoding errors</h3></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorname">D_GIF_ERR_OPEN_FAILED</span></span></dt><dd><p>Message printed using PrintGifError: "Failed to open given file"
   IO error result when attempt to open the given GIF file.</p></dd><dt><span class="term"><span class="errorname">D_GIF_ERR_READ_FAILED</span></span></dt><dd><p>Message printed using PrintGifError: "Failed to read from given file"
   IO error result when attempt to write to the given GIF file.</p></dd><dt><span class="term"><span class="errorname">D_GIF_ERR_NOT_GIF_FILE</span></span></dt><dd><p>Message printed using PrintGifError: "Data is not a GIF file"
   GIF files should have special stamp identifies them as such, If that stamp
   is not found, this error is issued.</p></dd><dt><span class="term"><span class="errorname">D_GIF_ERR_NO_SCRN_DSCR</span></span></dt><dd><p>Message printed using PrintGifError: "No screen descriptor detected"
   Each GIF file should have screen descriptor in its header. This error will
   be generated if no such descriptor was found.</p></dd><dt><span class="term"><span class="errorname">D_GIF_ERR_NO_IMAG_DSCR</span></span></dt><dd><p>Message printed using PrintGifError: "No image descriptor detected"
   Each image should have image descriptor in its header. This error will
   be generated if no such descriptor was found.</p></dd><dt><span class="term"><span class="errorname">D_GIF_ERR_NO_COLOR_MAP</span></span></dt><dd><p>Message printed using PrintGifError: "Neither global nor
   local color map" An image must have either global (screen) or local
   (image) color map.  Neither were given in this case.</p></dd><dt><span class="term"><span class="errorname">D_GIF_ERR_WRONG_RECORD</span></span></dt><dd><p>Message printed using PrintGifError: "Wrong record type detected"
   Each record in a GIF file has a special identifier in its header. If the
   record has an unrecognized identifier, this error is generated.</p></dd><dt><span class="term"><span class="errorname">D_GIF_ERR_DATA_TOO_BIG</span></span></dt><dd><p>Message printed using PrintGifError: "Number of pixels bigger than
   width * height" The number of pixels dumped for this image is
   bigger than specified by image Height times image Width.</p></dd><dt><span class="term"><span class="errorname">D_GIF_ERR_NOT_ENOUGH_MEM</span></span></dt><dd><p>Message printed using PrintGifError: "Failed to allocate
   required memory" Once an attemp is made to open GIF file, special
   structures are allocated to hold internal data for it. If
   allocation fails this error is returned.</p></dd><dt><span class="term"><span class="errorname">D_GIF_ERR_CLOSE_FAILED</span></span></dt><dd><p>Message printed using PrintGifError: "Failed to close given file"
   Closing file failed.</p></dd><dt><span class="term"><span class="errorname">D_GIF_ERR_NOT_READABLE</span></span></dt><dd><p>Message printed using PrintGifError: "Given file was not
   opened for read" GIF files can be opened both for read (DGIF part
   of library) and write (EGIF part of library). This error occurs
   when a file is opened for write (using EGIF) is given to one of the
   decoding (DGIF) routines.</p></dd><dt><span class="term"><span class="errorname">D_GIF_ERR_IMAGE_DEFECT</span></span></dt><dd><p>Message printed using PrintGifError: "Image is defective,
   decoding aborted" This error is generated, once the decoding failed
   - probably image is defect.</p></dd><dt><span class="term"><span class="errorname">D_GIF_ERR_EOF_TOO_SOON</span></span></dt><dd><p>Message printed using PrintGifError: "Image EOF detected,
   before image complete" This error is generated once EOF errorname
   is detected in encoded image before all the pixels (Width *
   Height) has be decoded.</p></dd></dl></div></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm240"></a>Utility support library</h2></div></div></div><p>These functions are not part of the core GIF library.  They are part
of the getarg library that supports the utilities.</p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="idm243"></a>Error Handling</h3></div></div></div><a id="PrintGifError"></a><pre class="programlisting">
void PrintGifError(void)
</pre><p>Print a one-line diagnostic on the last giflib error to stderr.</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="idm247"></a>Command Line Parsing</h3></div></div></div><a id="GAGetArgs"></a><pre class="programlisting">
bool GAGetArgs(int argc, char **argv, char *CtrlStr, ...)
</pre><p>Main routine of this module.  Given argc &amp; argv as received by
the main procedure, the command line CtrlStr, and the addresses of
all parameters, parse the command line, and update the parameters.</p><p>The CtrlStr defines what types of variables should follow. Look at the
beginning of getarg.c for exact usage.</p><p>Returns false if successful, returns true on failure.</p><a id="GAPrintErrMsg"></a><pre class="programlisting">
void GAPrintErrMsg(int Error)
</pre><p>If an error occurred in GAGetARgs, this routine may be used to print
one line diagnostic to stderr.</p><a id="GAPrintHowTo"></a><pre class="programlisting">
void GAPrintHowTo(char *CtrlStr)
</pre><p>Given the same CtrlStr as for GAGetArgs, can be used to print a one line
'how to use'. </p></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="sequential"></a>Sequential access</h2></div></div></div><p>If you are handling large images on an extremely memory-limited
machine, you may need to use the following functions for sequential
read and write. It's better to avoid them and use the simpler 
DGifSlurp()/EGifSpew() interface.</p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="idm260"></a>Sequential reading</h3></div></div></div><a id="DGifGetScreenDesc"></a><pre class="programlisting">
int DGifGetScreenDesc(GifFileType *GifFile)
</pre><p>Reads the screen information into the GifFile structure. Note this
routine is automatically called once a file is opened, and therefore
usually need not be called explicitly.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="DGifGetRecordType"></a><pre class="programlisting">
int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType)
</pre><p>As the GIF file can have different records in arbitrary order, this
routine should be called once the file was open to detect the next
record type, and act upon it.  It can return these types in GifType:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term">1. UndefinedRecordType </span></dt><dd><p>something is wrong!</p></dd><dt><span class="term">2. ScreenDescRecordType </span></dt><dd><p>screen information.  As the screen info is automatically read in when the file is open, this should not happen.</p></dd><dt><span class="term">3. ImageDescRecordType </span></dt><dd><p> next record is an image descriptor.</p></dd><dt><span class="term">4. ExtensionRecordType</span></dt><dd><p> next record is extension block.</p></dd><dt><span class="term">5. TrailerRecordType</span></dt><dd><p>last record reached, can close the file.</p></dd></dl></div><p>The first two types can usually be ignored. The function
returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="DGifGetImageDesc"></a><pre class="programlisting">
int DGifGetImageDesc(GifFileType *GifFile)
</pre><p>Reads image information into the GifFile structure.
Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="DGifGetLine"></a><pre class="programlisting">
int DGifGetLine(GifFileType *GifFile, PixelType *GifLine, int GifLineLen)
</pre><p>Load a block of pixels from the GIF file.  The line can be
of any length.  More than that, this routine may be interleaved with
DGifGetPixel until all pixels have been read.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><pre class="programlisting">
int DGifGetPixel(GifFileType *GifFile, PixelType GifPixel)
</pre><p>Loads one pixel from the GIF file.  This routine may be interleaved
with <a class="link" href="#DGifGetLine">DGifGetLine()</a>, until all pixels are
read.  Because of the overhead per each call, use of this routine is
not recommended.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><pre class="programlisting">
int DGifGetExtension(
        GifFileType *GifFile,
        int *GifExtCode,
        ByteType **GifExtension)
</pre><p>Loads an extension block from the GIF file.  Extension blocks
are optional in GIF files.  This routine should be followed by
<a class="link" href="#DGifGetExtensionNext">DGifGetExtensionNext</a>.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><p><a id="DGifGetExtensionNext"></a></p><pre class="programlisting">
int DGifGetExtensionNext(GifFileType *GifFile, ByteType **GifExtension)
</pre><p>

As extensions may contain more than one block, use this routine to
continue after DGifGetExtension, until *GifExtension is NULL.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><pre class="programlisting">
int DGifGetCode(
        GifFileType *GifFile, 
        int *GifCodeSize, ByteType **GifCodeBlock)
</pre><p>It sometimes may be desired to read the compressed code as is
without decoding it.  This routine does exactly that (with
DGifGetCodeNext), and can be used instead of DGifGetLine.</p><p>This compressed code information can be written out using the
EGifPutCode/EGifPutCodeNext sequence (see gifpos.c for example).
Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="DGifGetCodeNext"></a><pre class="programlisting">
int DGifGetCodeNext(GifFileType *GifFile, ByteType **GifCodeBlock)
</pre><p>See DGifGetCode above.</p><a id="DGifGetLZCodes"></a><pre class="programlisting">
int DGifGetLZCodes(GifFileType *GifFile, int *GifCode)
</pre><p>This routine can be called instead of DGifGetLine/DGifGetPixel or
DGifGetCode/DGifGetCodeNext to get the 12 bits LZ codes of the images.
It will be used mainly for debugging purposes (see GifText.c for
example).</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="DGifCloseFile"></a><pre class="programlisting">
int DGifCloseFile(GifFileType *GifFile, int *ErrorCode)
</pre><p>Write a termination block to the GIF, close the GIF file and
free all memory allocated for managing it. GifFile should not be used after
this routine has been called.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise. When
GIF_ERROR is returned, the diagnostic error code is left in ErrorCode.
The GifFile structure is unconditionally freed.</p><p>(Note: In versions before 5.1.0, the ErrorCode argument was
absent and the GifFile structure was not freed so that the
diagnostic error code will remain accessible in GifFile-&gt;Error.
This behavior was changed because it caused problems for the
implementation of library wrappers in dynamic languages.)</p><a id="DGetGifVersion"></a><pre class="programlisting">
const char * DGifGetGifVersion(GifFileType *GifFile)
</pre><p>Get the GIF version collected during sequential read. This is
handy for sequential API users who want to set an encoder's version
from a decoder (e.g. for gif resizing). For the all-at-once users this
isn't necessary because gif encoder inspects all the extension blocks,
but sequential users do not have that luxury.</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="idm319"></a>Sequential writing</h3></div></div></div><p>If you are handling large images on a memory-limited machine, you may need
to use the following functions for sequential write.</p><a id="EGifOpenFileName"></a><pre class="programlisting">
GifFileType *EGifOpenFileName(char *GifFileName, bool GifTestExistance, int *ErrorCode)
</pre><p>Open a new GIF file using the given GifFileName (in binary mode,
if under Windows).  If GifTestExistance is TRUE, and file exists, the
file is not destroyed, and NULL returned.</p><p>If any error occurs, NULL is returned and the ErrorCode is set.</p><a id="EGifOpenFileHandle"></a><pre class="programlisting">
GifFileType *EGifOpenFileHandle(int GifFileHandle, int *ErrorCode)
</pre><p>Open a new GIF file using the given GifFileHandle.</p><p>If any error occurs, NULL is returned and ErrorCode is set.</p><p>The file is opened in binary mode, and its buffer size is set to
FILE_BUFFER_SIZE bytes.</p><pre class="programlisting">
char *EGifGetGifVersion(GifFileType *GifFile)
</pre><p>That version computation is available through this function.</p><a id="EGifSetGifVersion"></a><pre class="programlisting">
void EGifSetGifVersion(GifFileType *GifFile, bool gif89)
</pre><p>Set the GIF type, to GIF89 if the argument is true and GIF87 if
it is false.  The default type is GIF87. This function may be called
aftert the GifFile record is allocated but before
EGifPutScreenDesc().</p><pre class="programlisting">
int EGifPutScreenDesc(GifFileType *GifFile,
        const int GifWidth, const GifHeight,
        const int GifColorRes, const int GifBackGround,
        ColorMapObject *GifColorMap)
</pre><p>Update the GifFile Screen parameters, in GifFile structure and in
the real file.  If error occurs, returns GIF_ERROR (see gif_lib.h),
otherwise GIF_OK.</p><p>This routine should be called immediately after the GIF file was
opened.</p><pre class="programlisting">
int EGifPutImageDesc(GifFileType *GifFile,
        const int GifLeft, const int GifTop,
        const int GifWidth, const GifHeight,
        const bool GifInterlace,
        ColorMapObject *GifColorMap)
</pre><p>Update GifFile Image parameters, in GifFile structure and in the real
file. if error occurs returns GIF_ERROR (see gif_lib.h), otherwise
GIF_OK.</p><p>This routine should be called each time a new image must be
dumped to the file.</p><a id="EGifPutLine"></a><pre class="programlisting">
int EGifPutLine(GifFileType *GifFile, PixelType *GifLine, int GifLineLen)
</pre><p>Dumps a block of pixels out to the GIF file.  The slab can be of
any length.  More than that, this routine may be interleaved with
<a class="link" href="#EGifPutPixel">EGifPutPixel()</a>, until all pixels
have been sent.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="EGifPutPixel"></a><pre class="programlisting">
int EGifPutPixel(GifFileType *GifFile, const PixelType GifPixel)
</pre><p>Dumps one pixel to the GIF file.  This routine may be interleaved with
<a class="link" href="#EGifPutLine">EGifPutLine()</a>, until all pixels were sent.
Because of the overhead for each call, use of this routine is not
recommended.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="EGifPutComment"></a><pre class="programlisting">
int EGifPutComment(GifFileType *GifFile, char *GifComment)
</pre><p>Uses extension GIF records to save a string as a comment is the file.
The extension code is 'C' (for Comment).</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="EGifPutExtension"></a><pre class="programlisting">
int EGifPutExtension(
        GifFileType *GifFile,
        const int GifExtCode,
        const int GifExtLen,
        void *GifExtension)
</pre><p>Dumps the given extension block into the GIF file. Extension blocks
are optional in GIF file. Extension blocks of more than 255 bytes or
more than one block are not supported in this function.  Please use
EGifPutExtensionFirst, EGifPutExtensionBlock, and EGifPutExtensionTrailer
if your extension blocks may fall into this category.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="EGifPutExtensionLeader"></a><pre class="programlisting">
int EGifPutExtensionLeader(
        GifFileType * GifFile,
        const int GifExtCode)
</pre><p>Dumps the beginning of a GIF extension block to a GIF file.
Extension blocks are optional in GIF files.  This function outputs the
type code information necessary for a GIF extension block.</p><p>Further blocks of the GIF Extension should be dumped using
EGifPutExtensionBlock.  When finished with this extension block,
EGifPutExtensionTrailer should be called to output the block termination.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="EGifPutExtensionBlock"></a><pre class="programlisting">
int EGifPutExtensionBlock(
        GifFileType * GifFile,
        const int GifExtLen,
        const VoidPtr GifExtension)
</pre><p>Dumps a subblock of a GIF extension to a GIF File; should be
used only following an initializing call to EGifPutExtensionLeader().
Extension blocks are optional in GIF files.  This function will write
the Extension Data in GifExtension to the file as a subblock of the
preceding Extension Block.  Repeat calling of this function until all
data subblocks have been output.</p><p>Note that EGifPutExtensionLeader needs to be called before any
calls to this function.  EGifPutExtensionTrailer should be called to
finish the Extension block after all data subblocks have been
output.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="EGifPutExtensionTrailer"></a><pre class="programlisting">
int EGifPutExtensionTrailer(
        GifFileType * GifFile,
        const VoidPtr GifExtension)
</pre><p>Dumps the GIF extension block terminator to a GIF File to end
the current Extension block.</p><p>Note that a call to EGifPutExtensionLeader is needed to open the GIF
Extension Block prior to calling this function.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="EGifPutCode"></a><pre class="programlisting">
int EGifPutCode(
        GifFileType *GifFile,
        int *GifCodeSize,
        ByteType **GifCodeBlock)
</pre><p>It sometimes may be desired to write the compressed code as is
without decoding it.  For example a filter for a GIF file that change
only screen size (GifPos), does not need the exact pixel values.
Piping out the compressed image as is makes this process much
faster.</p><p>This routine does exactly that (with EGifPutCodeNext), and can be
used instead of EGifPutLine.  You'll usually use this with the
DGifGetCode/DgifGetCodeNext routines, which reads the compressed
code, while EGifPutCode/EGifPutCodeNext write it out.  See gifpos.c
for example.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="EGifPutCodeNext"></a><pre class="programlisting">
int EGifPutCodeNext(GifFileType *GifFile, ByteType **GifCodeBlock)
</pre><p>See EGifPutCode above.</p><a id="EGifCloseFile"></a><pre class="programlisting">
int EGifCloseFile(GifFileType *GifFile)
</pre><p>Write a termination block to the GIF, close the GIF file, and
free all memory allocated for managing it. GifFile should not be used
after this routine has been called.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise. When
GIF_ERROR is returned, the diagnostic error code is left in ErrorCode.
The GifFile structure is unconditionally freed.</p><p>(Note: In versions before 5.1.0, the ErrorCode argument was
absent and the GifFile structure was not freed so that the
diagnostic error code will remain accessible in GifFile-&gt;Error.
This behavior was changed because it caused problems for the
implementation of library wrappers in dynamic languages.)</p></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="compatibility"></a>Forward and Backward Compatibility</h2></div></div></div><p>Except for some details of extension-block handling and the addition
of read/write function hooks, the DGifSlurp()/EGifSpew() interface has
been stable since 1990.  It is expected to remain so.</p><p>However, the signatures of the file-opener functions were changed in 5.0
in order to make the library fully reentrant and thread-safe - earlier library
versions did not feature the final pointer-to-error-code argument in 
DGifOpen() and friends.  For the same reason, the static storage queried by
GifLastError() in older versions is gone, and that function abolished.</p><p>The library header contains some version #defines you can use if you
need to condition your code so it can compile with different library 
versions</p><p>Versions up to 4.1.6 defined a GIF_LIB_VERSION macro that was
string-valued with a tricky format to parse.  This macro has been
retired.</p><p>Versions after 4.1.6 define integer-valued GIFLIB_MAJOR, GIFLIB_MINOR,
and GIFLIB_RELEASE macros for the three components of the version. See the
NEWS file in the GIFLIB distribution to track API changes.</p><p>The following functions are entirely new:</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>New functions DGifSavedExtensionToGCB() and
EGifGCBToSavedExtension() make it easy to read and edit GIF89 graphics
control blocks in saved images.</p></li><li class="listitem"><p>The new function DGifGetGifVersion() is convenient
for people doing sequential reads.</p></li></ul></div><p>A few changes in behavior were introduced in 5.0:</p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="idm389"></a>General behavior</h3></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>The library is now fully re-entrant and
thread-safe.</p></li></ul></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>  All functions exported by this library now have DGif,
EGif, or Gif as a name prefix.</p></li><li class="listitem"><p>The default GIF version to write is now computed at
write time from the types of an image's extension blocks. (Formerly
EGifSpew() behaved this way, but the sequential-writing code didn't.)
The result of this computation is available through the new function
EGifGetGifVersion().</p></li></ul></div></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="idm399"></a>In documented functions:</h3></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>GIF file openers and closers - DGifOpenFileName(),
DGifOpenFileHandle(), DGifOpen(), DGifClose(), EGifOpenFileName(),
EGifOpenFileHandle(), EGifOpen(), and EGifClose() - all now take a
final integer address argument.  If non-null, this is used to pass
back an error code when the function returns NULL.</p></li><li class="listitem"><p>EGifSlurp() and EGifSpew() read and write
extension blocks trailing after the last image, handle interlaced 
images properly.</p></li><li class="listitem"><p>EGifPutExtensionFirst() has been replaced by
EGifPutExtensionLeader(); the difference is the new function doesn't
take an optional block, it just writes a block
leader.</p></li><li class="listitem"><p>EGifPutExtensionNext() has been replaced by
EGifPutExtensionBlock(); the difference is that the new function does
not take and then discard a function code argument.</p></li><li class="listitem"><p>EGifPutExtensionLast() has been replaced by
EGifPutExtensionTrailer(); all it does is write the terminator
block.  Split your old EGifPutExtensionLast() calls into
EGifPutExtensionBlock() followed by
EGifPutExtensionTrailer().</p></li></ul></div></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="idm412"></a>In undocumented functions:</h3></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>Some undocumented functions have been renamed. 
AddExtensionBlock() is now GifAddExtensionBlock(), and takes an additional
function code argument.  ApplyTranslation() is now GifApplyTranslation();
FreeExtension() has become GifFreeExtensions() and takes a different argument
type; MakeSavedImage() is now GifMakeSavedImage(), FreeSavedImages() is
now GifFreeSavedImages(), and BitSize() is now GifBitSize().</p></li><li class="listitem"><p>Three documented functions - MakeMapObject(),
FreeMapObject(), and UnionColorMap() - have been renamed to
GifMakeMapObject(), GifFreeMapObject(), and GifUnionColorMap()
respectively.</p></li></ul></div></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="idm419"></a>Error handling:</h3></div></div></div><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>Library error handling no longer uses a static cell to
store the last error code registered; that made the library
thread-unsafe.</p></li><li class="listitem"><p>For functions other than GIF file openers, the Error
code is now put in an Error member of the GifFileType
structure.</p></li><li class="listitem"><p>The GifError() and
GifLastError() functions that referenced that static cell are gone,
and the GifErrorString() function introduced in the 4.2 release now
takes an explicit error code argument.</p></li></ul></div></div></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm428"></a>Skeletons of GIF filters</h2></div></div></div><p>If you are developing on a virtual-memory OS such as most flavors of
UNIX, or are otherwise sure of having enough memory to keep all of GIFs you
need to operate in core, writing a filter is trivial.   See the file
gifsponge.c in util.</p><p>A sequential filter skeleton will usually look like the example file
giffilter.c in util.</p><p>Please look at the utilities in the util directory for more ideas once
you feel comfortable with these skeletons.  Also try to follow the coding
standards of this package if you want the maintainer to officially add your new
utility to it.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="idm433"></a>Unimplemented features</h2></div></div></div><p>Some features of the original GIF specification have not stood the
test of time.  This library mostly ignores them, but they are described
here for completeness.</p><p>The GIF standard fails to be explicit about a small but crucial detail:
the unsigned two-byte integer fields in it are little-endian.</p><p>The GIF format seems to have been designed with the idea that viewers
would render multiple images in a GIF on a common canvas, giving an effect like
a picture wall.  The 'logical screen descriptor block' (LSDB), 6 bytes right
after the 6-byte GIF stamp and version header at the beginning of a
GIF file, includes both two-byte canvas width and canvas height
fields and a canvas background color.  Each image, besides height and
width, also has 'left' and 'top' cordinates specifying where it is to
be placed on the canvas.</p><p>GIFLIB can read and set these fields; the gifpos and giftool
utilities will enable you to script such changes.  But browsers and
modern image viewers ignore them. Nowadays multiple-image GIFs are 
generally used either as animations in which each sub-image is a frame
or as image libraries, with the GIF client handling compositing into
some canvas about which the GIF format holds no information.</p><p>Another feature of the LSDB that is generally ignored is the
pixel aspect ratio byte.  Until 5.0, GIFLIB ignored this flag on input
and zeroed it on output; now it is read and preserved if present.  The
GIF standard doesn't give a rationale for it, but it seems likely that
the designers intended it for representing image captures from the
analog television of the day, which had rectangular pixel-equivalents.</p><p>Yet another ignored feature of both the LSDB and sub-images is
the sort flag, which is supposed to signal whether the colors in the
associated color map are sorted by decreasing importance in case the
display device can only render a limited number of them.  This feature
reflected the high cost of dual-port memory at the time the GIF
specification was written in the late 1980s.  That kind of limit
disappeared in the mid-1990s.  Until 5.0, GIFLIB ignored this flag on
input and zeroed it on output; now it is read and preserved if
present.</p><p>Finally, the plaintext extension block. This is an extension block 
that contains instructions for overlaying text captions on a following image.
GIFLIB treats these blocks as raw data, not attempting to parse out the 
location and text data.</p></div></div></body></html>