Debian Codegraph @

doc/gif_lib.xml

raw
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE article PUBLIC
3 "-//OASIS//DTD DocBook XML V4.1.2//EN"
4 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
5 <!ENTITY homepage "http://catb.org/~esr/">
6 <!ENTITY email "[email protected]">
7 ]>
8 <article><title>The GIFLIB Library</title>
9
10 <articleinfo>
11
12 <author>
13 <firstname>Eric</firstname>
14 <othername>Steven</othername>
15 <surname>Raymond</surname>
16 <affiliation>
17 <orgname><ulink url="&homepage;">
18 Thyrsus Enterprises</ulink></orgname>
19 <address>
20 <email>&email;</email>
21 </address>
22 </affiliation>
23 </author>
24 <copyright>
25 <year>2012</year>
26 <holder role="mailto:&email;">Eric S. Raymond</holder>
27 </copyright>
28
29 </articleinfo>
30
31 <!--
32 Gershon Elber, May 1991
33 Eric S. Raymond, Sep 1992
34 Toshio Kuratomi, May 2004
35 -->
36
37 <sect1><title>Introduction</title>
38
39 <para>The Graphics Interchange Format(c) is the Copyright property of
40 CompuServe Incorporated. GIF(sm) is a Service Mark property of CompuServe
41 Incorporated.</para>
42
43 <para>This document explains the GIF library code in directory `lib'. The
44 code is collected into a service library which is used in all the utilities in
45 `util'. It can be used in any application needs to read/write the GIF
46 file format. This document does <emphasis>not</emphasis> explain the GIF file
47 format and assumes you know it, at least to the level of the GIF file
48 structure.</para>
49
50 </sect1>
51 <sect1><title>Credit and Blame</title>
52
53 <para>Gershon wrote: "This library was written because I couldn't find
54 anything similar and I wanted one. I was inspired by the RLE Utah tool kit,
55 which I hoped to port to an IBM PC, but found it to be too machine specific,
56 and its compression ratio too low. I compromised on the GIF format, but I am
57 not sure how long 8 bits per pixel will be enough."</para>
58
59 <para>During his first spell of maintainership between 1989 and 1994, Eric
60 S. Raymond (aka "ESR") ported the code to Unix, wrote the high-level
61 DGifSlurp()/EGifSpew() interface, rationalized the internal data
62 structures, and did a lot of general cleanup and refactoring to
63 improve the code quality.</para>
64
65 <para>Between 1994 and 2012 Toshio Kuratomi fixed various tool bugs,
66 build-recipe problems and rare segfaults. He partially untangled the
67 somewhat misdesigned extension-block handling in earlier versions.
68 The core code was very stable during this period.</para>
69
70 <para>During his second spell of maintainership, ESR fixed the
71 extension API, made the library re-entrant and thread-safe, wrote a
72 regression-test suite, greatly improved the documentation, and
73 discarded a lot of obsolete code.</para>
74
75 </sect1>
76 <sect1><title>The GIF descriptor</title>
77
78 <para>When a GIF file is opened, a GIF file descriptor is created which
79 is a pointer to GifFileType structure as follows:</para>
80
81 <programlisting>
82 typedef struct GifFileType {
83 GifWord SWidth, SHeight; /* Size of virtual canvas */
84 GifWord SColorResolution; /* How many colors can we generate? */
85 GifWord SBackGroundColor; /* Background color for virtual canvas */
86 GifByteType AspectByte; /* Used to compute pixel aspect ratio */
87 ColorMapObject *SColorMap; /* Global colormap, NULL if nonexistent. */
88 int ImageCount; /* Number of current image (both APIs) */
89 GifImageDesc Image; /* Current image (low-level API) */
90 SavedImage *SavedImages; /* Image sequence (high-level API) */
91 int ExtensionBlockCount; /* Count extensions past last image */
92 ExtensionBlock *ExtensionBlocks; /* Extensions past last image */
93 int Error; /* Last error condition reported */
94 void *UserData; /* hook to attach user data (TVT) */
95 void *Private; /* Don't mess with this! */
96 } GifFileType;
97 </programlisting>
98
99 <para>This structure was copied from gif_lib.h - the header file for the GIF
100 library. Any application program that uses the libgif.a library should
101 include it. Members beginning with S refer to the GIF screen; others hold
102 properties of the current image (a GIF file may have more than one image)
103 or point to allocated store used by various routines.</para>
104
105 <para>The user almost never writes into this structure (exception: it
106 may occasionally be useful to alter things in the SavedImages array and
107 Trailing member), but can read any of these items at any time it is
108 valid (Image information is invalid until the first image has been read;
109 read; SavedImages information is valid only after a DGifSlurp() call).</para>
110
111 <para>As the library needs to keep its own internal data, a Private pointer
112 to hidden data is included. Applications should ignore this.</para>
113
114 <para>The library allocates its own memory dynamically, on opening of files,
115 and releases that once closed. The user is never required to allocate
116 any memory for any of the functions of this library, and is almost never
117 required to free them directly. The "almost" in the latter clause is because
118 one manual free() call may be required on a failed file close; see the
119 documentation of DGifClose() and EGifClose() for details.</para>
120
121 <para>Here is a module summary:</para>
122
123 <variablelist>
124 <varlistentry>
125 <term>egif_lib.c</term>
126 <listitem>
127 <para>Encoding routines, all prefixed with E.</para>
128 </listitem>
129 </varlistentry>
130
131 <varlistentry>
132 <term>dgif_lib.c</term>
133 <listitem>
134 <para>Decoding routines, all prefixed with D.</para>
135 </listitem>
136 </varlistentry>
137
138 <varlistentry>
139 <term>gifalloc.c</term>
140 <listitem>
141 <para>Routines for colormap handling and GIF record allocation.</para>
142 </listitem>
143 </varlistentry>
144
145 <varlistentry>
146 <term>gif_font.c</term>
147 <listitem>
148 <para>The 8x8 font table for the GIF utility font.</para>
149 </listitem>
150 </varlistentry>
151 </variablelist>
152
153 <para>The library includes a sixth file of hash-function code which is accessed
154 internally only.</para>
155
156 <para>Most of the routines return GIF_ERROR (see gif_lib.h) if something
157 went wrong, GIF_OK otherwise. After an error return, all routines that
158 take a pointer-to-GifFileType argument set the Error member with a code that
159 can be interpreted into an explanatory string with the function
160 GifErrorString() in gif_err.c. (The exception to this is the
161 DGifClose() and EGifClose() routines, which deallocate that structure
162 and must therefore return any error code through a pointer argument.)</para>
163
164 </sect1>
165 <sect1><title>Decoding (dgif_lib.c)</title>
166
167 <para>The following functions are used to set up input from a GIF:</para>
168
169 <programlisting id="DGifOpenFileName">
170 GifFileType *DGifOpenFileName(char *GifFileName, int *ErrorCode)
171 </programlisting>
172
173 <para>Open a new GIF file (in binary mode, if under Windows) using the
174 given GifFileName, and read its Screen information.</para>
175
176 <para>If any error occurs, NULL is returned and ErrorCode is set (if
177 non-NULL).</para>
178
179 <programlisting id="DGifOpenFileHandle">
180 GifFileType *DGifOpenFileHandle(int FileHandle, int *ErrorCode)
181 </programlisting>
182
183 <para>Open a new GIF file using the given FileHandle, and read its Screen
184 information.</para>
185
186 <para>If any error occurs, NULL is returned and ErrorCode is set (if
187 non-NULL).</para>
188
189 <para>Once you have acquired a handle on a GIF, the high-level
190 function</para>
191
192 <programlisting id="DGifSlurp">
193 int DGifSlurp(GifFileType)
194 </programlisting>
195
196 <para>reads the rest of a complete (possibly multi-image) GIF file from the
197 indicated file handle into in-core allocated structures. It returns
198 GIF_OK on success, GIF_ERROR on failure; on failure, the Error member
199 will be set.</para>
200
201 <para>Once you have done this, all image, raster, and extension-block
202 data in the GIF is accessible in the SavedImages member (see the
203 structures in gif_lib.h). When you have modified the image to taste,
204 write it out with EGifSpew().</para>
205
206 <para>One detail that may not be clear from just looking at the
207 structures is how extension blocks and sub-blocks are stored. Each
208 ExtensionBlock structure represents an extension data block. Those
209 with a zero function code represent continuation data blocks attached
210 to previous blocks with nonzero function codes.</para>
211
212 <para>You can read from a GIF file through a function hook. Initialize
213 with </para>
214
215 <programlisting id="DGifOpen">
216 GifFileType *DGifOpen(void *userPtr, InputFunc readFunc, int *ErrorCode)
217 </programlisting>
218
219 <para>and see the library header file for the type of InputFunc.</para>
220
221 <para>There is also a set of deprecated functions for sequential I/O,
222 described in a later section.</para>
223 </sect1>
224 <sect1><title>Encoding (egif_lib.c)</title>
225
226 <para>The high-level function</para>
227
228 <programlisting id="EGifSpew">
229 int EGifSpew(GifFileType *GifFile, int *ErrorCode)
230 </programlisting>
231
232 <para>writes a complete (possibly multi-image) GIF file to the indicated file
233 handle from in-core allocated structures created by a previous DGifSlurp()
234 or equivalent operations. Its argument is a GIF file descriptor, which
235 implicitly points to storage previously allocated by DGifSlurp().</para>
236
237 <para>If ErrorCode is non-NULL, it returns a GIFLIB error code on failure;
238 otherwise it may be NULL. The function returns GIF_OK or GIF_ERROR.</para>
239
240 <para>The file is written with a GIF87 stamp unless it contains one of the four
241 special extension blocks defined in GIF89, in which case it is written
242 with a GIF89 stamp.</para>
243
244 <para>EGifSpew() finishes by closing the GIF (writing a termination
245 record to it) and deallocating the associated storage.</para>
246
247 <para>You can write to a GIF file through a function hook. Initialize
248 with </para>
249
250 <programlisting id="EGifOpen">
251 GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc, int *ErrorCode)
252 </programlisting>
253
254 <para>and see the library header file for the type of OutputFunc.</para>
255
256 <para>There is also a set of deprecated functions for sequential I/O,
257 described in a later section.</para>
258 </sect1>
259 <sect1><title>Color map handling and allocation routines</title>
260
261 <programlisting id="GifMakeMapObject">
262 ColorMapObject *GifMakeMapObject(int ColorCount, GifColorType *ColorMap)
263 </programlisting>
264
265 <para>Allocate storage for a color map object with the given number of
266 RGB triplet slots. If the second argument is non-NULL, initialize
267 the color table portion of the new map from it. Returns NULL if
268 memory is exhausted or if the size is not a power of 2 &lt;= 256.</para>
269
270 <programlisting id="GifFreeMapObject">
271 void GifFreeMapObject(ColorMapObject *Object)
272 </programlisting>
273
274 <para>Free the storage occupied by a ColorMapObject that is no longer
275 needed.</para>
276
277 <programlisting id="GifUnionColorMap">
278 ColorMapObject *GifUnionColorMap(
279 ColorMapObject *ColorIn1, ColorMapObject *ColorIn2,
280 GifPixelType ColorTransIn2[])
281 </programlisting>
282
283 <para>Create the union of two given color maps and return it. If the
284 result won't fit into 256 colors, NULL is returned, the allocated
285 union otherwise. ColorIn1 is copied as it to ColorUnion, while colors
286 from ColorIn2 are copied if and only if they didn't exist before.
287 ColorTransIn2 maps the old ColorIn2 into ColorUnion color map
288 table.</para>
289
290 <programlisting id="GifAttachImage">
291 SavedImage *GifAttachImage(GifFileType *GifFile)
292 </programlisting>
293
294 <para>Add an image block to the SavedImages array. The image block is
295 initially zeroed out. This image block will be seen by any following
296 EGifSpew() calls.</para>
297
298 </sect1>
299 <sect1><title>Graphics control extension handling</title>
300
301 <para>GIF89 added a graphics control extension block, but versions
302 of GIFLIB before 5.0 weren't much help in reading or modifying them.
303 This lack has been remedied with the following structure and functions:</para>
304
305 <programlisting>
306 typedef struct GraphicsControlBlock {
307 int DisposalMode;
308 #define DISPOSAL_UNSPECIFIED 0 /* No disposal specified. */
309 #define DISPOSE_DO_NOT 1 /* Leave image in place */
310 #define DISPOSE_BACKGROUND 2 /* Set area too background color */
311 #define DISPOSE_PREVIOUS 3 /* Restore to previous content */
312 bool UserInputFlag; /* User confirmation required before disposal */
313 int DelayTime; /* pre-display delay in 0.01sec units */
314 int TransparentColor; /* Palette index for transparency, -1 if none */
315 #define NO_TRANSPARENT_COLOR -1
316 } GraphicsControlBlock;
317
318 int DGifSavedExtensionToGCB(GifFileType *GifFile,
319 int ImageIndex,
320 GraphicsControlBlock *GCB);
321 int EGifGCBToSavedExtension(const GraphicsControlBlock *GCB,
322 GifFileType *GifFile,
323 int ImageIndex);
324 </programlisting>
325
326 <para>With these functions you can extract the data from a graphics
327 control extension associated with a saved image into a
328 GraphicsControlBlock, modify it, and write it back out. Note that if
329 the specified saved image doesn't have a graphics control extension,
330 DGifSavedExtensionToGCB() will fill the GCB with default values and
331 return GIF_ERROR (which can be ignored); EGifGCBToSavedExtension()
332 will create a new leading extension block.</para>
333
334 </sect1>
335 <sect1><title>Error Handling (gif_err.c)</title>
336
337 <programlisting>
338 int GifErrorString(int ErrorCode)
339 </programlisting>
340
341 <para>Returns a string describing the specified GIFLIB error code.
342 Return NULL if the argument is not a valid error code.</para>
343
344 </sect1>
345 <sect1><title>The GIF Utility Font</title>
346
347 <para>The 8x8 utility font used in the (obsolete, no longer installed)
348 gifecho and gifcolor lives in the library module gif_font.c, in a
349 table called GifAsciiTable. The library header file includes suitable
350 externs and defines.</para>
351
352 <para>The GIF utility font support includes entry points for drawing legends
353 on in-core images, drawing boxes and rectangles, and boxing text.
354 These entry points are as follows:</para>
355
356 <programlisting id="GifDrawText">
357 void GifDrawText8x8(
358 SavedImage *Image,
359 const int x, const int y,
360 const char *legend,
361 const int color)
362 </programlisting>
363
364 <para>Draw text using the 8x8 utility font on the saved image. Upper
365 left corner of the text is at image pixel (x, y). Use the specified
366 color index.</para>
367
368 <programlisting id="GifDrawBox">
369 void GifDrawBox(SavedImage *Image,
370 const int x, const int y,
371 const int w, const int h,
372 const int color)
373 </programlisting>
374
375 <para>Draw a box on the saved image. Upper left corner of the box is at
376 image pixels (x, y), width is w, height is h. Use the specified color
377 index.</para>
378
379 <programlisting id="GifDrawRectangle">
380 void GifDrawRectangle(SavedImage *Image,
381 const int x, const int y,
382 const int w, const int h,
383 const int color)
384 </programlisting>
385
386 <para>Draw a (filled) rectangle on the saved image. Upper left corner of
387 the box is at image pixels (x, y), width is w, height is h. Use the
388 specified color index.</para>
389
390 <programlisting id="GifDrawBoxedText">
391 void GifDrawBoxedText8x8(SavedImage *Image,
392 const int x, const int y,
393 const char *legend,
394 const int border,
395 const int bg, const int fg)
396 </programlisting>
397
398 <para>Draw text on a filled rectangle. The rectangle will be sized to fit
399 the text, with upper left hand corner at (x, y) on the saved image.
400 The `border' argument specifies a pixel margin around the text. The
401 `bg' argument is the color table index to fill the rectangle with;
402 `fg' is the color table index to draw the text with.</para>
403
404 <para>This function interprets some characters in the legend string
405 specially. A tab (\t) is interpreted as a command to center the
406 following text in the box. A carriage return (\r) is interpreted
407 as a request for a line break.</para>
408
409 </sect1>
410 <sect1><title>Error codes</title>
411
412 <para>Errors as reported from the GIFLIB library are divided to two major
413 categories: the encoder (errors prefixed by E_GIF_ERR), and the
414 decoder (errors prefixed by D_GIF_ERR). This document explains them
415 briefly.</para>
416
417 <sect2><title>Encoding errors</title>
418
419 <variablelist>
420 <varlistentry>
421 <term><errorname>E_GIF_ERR_OPEN_FAILED</errorname></term>
422 <listitem>
423 <para>Message printed using PrintGifError: "Failed to open given file"
424 IO error result when attempt to open the given GIF file.</para>
425 </listitem>
426 </varlistentry>
427
428 <varlistentry>
429 <term><errorname>E_GIF_ERR_WRITE_FAILED</errorname></term>
430 <listitem>
431 <para>Message printed using PrintGifError: "Failed to Write to given file"
432 IO error result when attempt to write to the given GIF file.</para>
433 </listitem>
434 </varlistentry>
435
436 <varlistentry>
437 <term><errorname>E_GIF_ERR_HAS_SCRN_DSCR</errorname></term>
438 <listitem>
439 <para>Message printed using PrintGifError: "Screen Descriptor
440 already been set" Attempt to write second screen descriptor to same
441 GIF file. GIF file should have exactly one screen descriptor which
442 should be set directly after the file is opened.</para>
443 </listitem>
444 </varlistentry>
445
446 <varlistentry>
447 <term><errorname>E_GIF_ERR_HAS_IMAG_DSCR</errorname></term>
448 <listitem>
449 <para>Message printed using PrintGifError: "Image Descriptor is still active"
450 Image descriptor should be sent before and image dump, and no second
451 image descriptor should be sent before current image dump ended. This error
452 occurred probably because current image was not complete.</para>
453 </listitem>
454 </varlistentry>
455
456 <varlistentry>
457 <term><errorname>E_GIF_ERR_NO_COLOR_MAP</errorname></term>
458 <listitem>
459 <para>Message printed using PrintGifError: "Neither Global Nor
460 Local color map" An image must have either global (screen) or local
461 (image) color map. Neither were given in this case.</para>
462 </listitem>
463 </varlistentry>
464
465 <varlistentry>
466 <term><errorname>E_GIF_ERR_DATA_TOO_BIG</errorname></term>
467 <listitem>
468 <para>Message printed using PrintGifError: "#Pixels bigger than
469 Width * Height" The number of pixels dumped for this image is
470 bigger than specified by image Height times image Width.</para>
471 </listitem>
472 </varlistentry>
473
474 <varlistentry>
475 <term><errorname>E_GIF_ERR_NOT_ENOUGH_MEM</errorname></term>
476 <listitem>
477 <para>Message printed using PrintGifError: "Fail to allocate
478 required memory" Once an attempt is made to open GIF file, special
479 structures are allocated to hold internal data for it. If
480 allocation fails this error is returned.</para>
481 </listitem>
482 </varlistentry>
483
484 <varlistentry>
485 <term><errorname>E_GIF_ERR_DISK_IS_FULL</errorname></term>
486 <listitem>
487 <para>Message printed using PrintGifError: "Write failed (disk full?)"
488 Writing encoded data failed.</para>
489 </listitem>
490 </varlistentry>
491
492 <varlistentry>
493 <term><errorname>E_GIF_ERR_CLOSE_FAILED</errorname></term>
494 <listitem>
495 <para>Message printed using PrintGifError: "Failed to close given file"
496 Closing file failed.</para>
497 </listitem>
498 </varlistentry>
499
500 <varlistentry>
501 <term><errorname> E_GIF_ERR_NOT_WRITEABLE</errorname></term>
502 <listitem>
503 <para>Message printed using PrintGifError: "Given file was not
504 opened for write" GIF files can be opened both for read (DGIF part
505 of library) and write (EGIF part of library). This error occurs
506 when a file is opened for read (using DGIF) is given to one of the
507 encoding (EGIF) routines.</para>
508 </listitem>
509 </varlistentry>
510
511 </variablelist>
512
513 </sect2>
514 <sect2><title>Decoding errors</title>
515
516 <variablelist>
517 <varlistentry>
518 <term><errorname>D_GIF_ERR_OPEN_FAILED</errorname></term>
519 <listitem>
520 <para>Message printed using PrintGifError: "Failed to open given file"
521 IO error result when attempt to open the given GIF file.</para>
522 </listitem>
523 </varlistentry>
524
525 <varlistentry>
526 <term><errorname>D_GIF_ERR_READ_FAILED</errorname></term>
527 <listitem>
528 <para>Message printed using PrintGifError: "Failed to read from given file"
529 IO error result when attempt to write to the given GIF file.</para>
530 </listitem>
531 </varlistentry>
532
533 <varlistentry>
534 <term><errorname>D_GIF_ERR_NOT_GIF_FILE</errorname></term>
535 <listitem>
536 <para>Message printed using PrintGifError: "Data is not a GIF file"
537 GIF files should have special stamp identifies them as such, If that stamp
538 is not found, this error is issued.</para>
539 </listitem>
540 </varlistentry>
541
542 <varlistentry>
543 <term><errorname>D_GIF_ERR_NO_SCRN_DSCR</errorname></term>
544 <listitem>
545 <para>Message printed using PrintGifError: "No screen descriptor detected"
546 Each GIF file should have screen descriptor in its header. This error will
547 be generated if no such descriptor was found.</para>
548 </listitem>
549 </varlistentry>
550
551 <varlistentry>
552 <term><errorname>D_GIF_ERR_NO_IMAG_DSCR</errorname></term>
553 <listitem>
554 <para>Message printed using PrintGifError: "No image descriptor detected"
555 Each image should have image descriptor in its header. This error will
556 be generated if no such descriptor was found.</para>
557 </listitem>
558 </varlistentry>
559
560 <varlistentry>
561 <term><errorname>D_GIF_ERR_NO_COLOR_MAP</errorname></term>
562 <listitem>
563 <para>Message printed using PrintGifError: "Neither global nor
564 local color map" An image must have either global (screen) or local
565 (image) color map. Neither were given in this case.</para>
566 </listitem>
567 </varlistentry>
568
569 <varlistentry>
570 <term><errorname>D_GIF_ERR_WRONG_RECORD</errorname></term>
571 <listitem>
572 <para>Message printed using PrintGifError: "Wrong record type detected"
573 Each record in a GIF file has a special identifier in its header. If the
574 record has an unrecognized identifier, this error is generated.</para>
575 </listitem>
576 </varlistentry>
577
578 <varlistentry>
579 <term><errorname>D_GIF_ERR_DATA_TOO_BIG</errorname></term>
580 <listitem>
581 <para>Message printed using PrintGifError: "Number of pixels bigger than
582 width * height" The number of pixels dumped for this image is
583 bigger than specified by image Height times image Width.</para>
584 </listitem>
585 </varlistentry>
586
587 <varlistentry>
588 <term><errorname>D_GIF_ERR_NOT_ENOUGH_MEM</errorname></term>
589 <listitem>
590 <para>Message printed using PrintGifError: "Failed to allocate
591 required memory" Once an attemp is made to open GIF file, special
592 structures are allocated to hold internal data for it. If
593 allocation fails this error is returned.</para>
594 </listitem>
595 </varlistentry>
596
597 <varlistentry>
598 <term><errorname>D_GIF_ERR_CLOSE_FAILED</errorname></term>
599 <listitem>
600 <para>Message printed using PrintGifError: "Failed to close given file"
601 Closing file failed.</para>
602 </listitem>
603 </varlistentry>
604
605 <varlistentry>
606 <term><errorname>D_GIF_ERR_NOT_READABLE</errorname></term>
607 <listitem>
608 <para>Message printed using PrintGifError: "Given file was not
609 opened for read" GIF files can be opened both for read (DGIF part
610 of library) and write (EGIF part of library). This error occurs
611 when a file is opened for write (using EGIF) is given to one of the
612 decoding (DGIF) routines.</para>
613 </listitem>
614 </varlistentry>
615
616 <varlistentry>
617 <term><errorname>D_GIF_ERR_IMAGE_DEFECT</errorname></term>
618 <listitem>
619 <para>Message printed using PrintGifError: "Image is defective,
620 decoding aborted" This error is generated, once the decoding failed
621 - probably image is defect.</para>
622 </listitem>
623 </varlistentry>
624
625 <varlistentry>
626 <term><errorname>D_GIF_ERR_EOF_TOO_SOON</errorname></term>
627 <listitem>
628 <para>Message printed using PrintGifError: "Image EOF detected,
629 before image complete" This error is generated once EOF errorname
630 is detected in encoded image before all the pixels (Width *
631 Height) has be decoded.</para>
632 </listitem>
633 </varlistentry>
634 </variablelist>
635
636 </sect2>
637 </sect1>
638 <sect1><title>Utility support library</title>
639
640 <para>These functions are not part of the core GIF library. They are part
641 of the getarg library that supports the utilities.</para>
642
643 <sect2><title>Error Handling</title>
644
645 <programlisting id="PrintGifError">
646 void PrintGifError(void)
647 </programlisting>
648
649 <para>Print a one-line diagnostic on the last giflib error to stderr.</para>
650
651 </sect2>
652 <sect2><title>Command Line Parsing</title>
653
654 <programlisting id="GAGetArgs">
655 bool GAGetArgs(int argc, char **argv, char *CtrlStr, ...)
656 </programlisting>
657
658 <para>Main routine of this module. Given argc &amp; argv as received by
659 the main procedure, the command line CtrlStr, and the addresses of
660 all parameters, parse the command line, and update the parameters.</para>
661
662 <para>The CtrlStr defines what types of variables should follow. Look at the
663 beginning of getarg.c for exact usage.</para>
664
665 <para>Returns false if successful, returns true on failure.</para>
666
667 <programlisting id="GAPrintErrMsg">
668 void GAPrintErrMsg(int Error)
669 </programlisting>
670
671 <para>If an error occurred in GAGetArgs, this routine may be used to print
672 one line diagnostic to stderr.</para>
673
674 <programlisting id="GAPrintHowTo">
675 void GAPrintHowTo(char *CtrlStr)
676 </programlisting>
677
678 <para>Given the same CtrlStr as for GAGetArgs, can be used to print a one line
679 'how to use'. </para>
680
681 </sect2>
682 </sect1>
683 <sect1 id="sequential"><title>Sequential access</title>
684
685 <para>If you are handling large images on an extremely memory-limited
686 machine, you may need to use the following functions for sequential
687 read and write. It's better to avoid them and use the simpler
688 DGifSlurp()/EGifSpew() interface.</para>
689
690 <sect2><title>Sequential reading</title>
691
692 <programlisting id="DGifGetScreenDesc">
693 int DGifGetScreenDesc(GifFileType *GifFile)
694 </programlisting>
695
696 <para>Reads the screen information into the GifFile structure. Note this
697 routine is automatically called once a file is opened, and therefore
698 usually need not be called explicitly.</para>
699
700 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
701
702 <programlisting id="DGifGetRecordType">
703 int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType)
704 </programlisting>
705
706 <para>As the GIF file can have different records in arbitrary order, this
707 routine should be called once the file was open to detect the next
708 record type, and act upon it. It can return these types in GifType:</para>
709
710 <variablelist>
711 <varlistentry>
712 <term>1. UndefinedRecordType </term>
713 <listitem>
714 <para>something is wrong!</para>
715 </listitem>
716 </varlistentry>
717
718 <varlistentry>
719 <term>2. ScreenDescRecordType </term>
720 <listitem>
721 <para>screen information. As the screen info is automatically read in when the file is open, this should not happen.</para>
722 </listitem>
723 </varlistentry>
724
725 <varlistentry>
726 <term>3. ImageDescRecordType </term>
727 <listitem>
728 <para> next record is an image descriptor.</para>
729 </listitem>
730 </varlistentry>
731
732 <varlistentry>
733 <term>4. ExtensionRecordType</term>
734 <listitem>
735 <para> next record is extension block.</para>
736 </listitem>
737 </varlistentry>
738
739 <varlistentry>
740 <term>5. TrailerRecordType</term>
741 <listitem>
742 <para>last record reached, can close the file.</para>
743 </listitem>
744 </varlistentry>
745 </variablelist>
746
747 <para>The first two types can usually be ignored. The function
748 returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
749
750 <programlisting id="DGifGetImageDesc">
751 int DGifGetImageDesc(GifFileType *GifFile)
752 </programlisting>
753
754 <para>Reads image information into the GifFile structure.
755 Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
756
757 <programlisting id="DGifGetLine">
758 int DGifGetLine(GifFileType *GifFile, PixelType *GifLine, int GifLineLen)
759 </programlisting>
760
761 <para>Load a block of pixels from the GIF file. The line can be
762 of any length. More than that, this routine may be interleaved with
763 DGifGetPixel until all pixels have been read.</para>
764
765 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
766
767 <programlisting>
768 int DGifGetPixel(GifFileType *GifFile, PixelType GifPixel)
769 </programlisting>
770
771 <para>Loads one pixel from the GIF file. This routine may be interleaved
772 with <link linkend="DGifGetLine">DGifGetLine()</link>, until all pixels are
773 read. Because of the overhead per each call, use of this routine is
774 not recommended.</para>
775
776 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
777
778 <programlisting>
779 int DGifGetExtension(
780 GifFileType *GifFile,
781 int *GifExtCode,
782 ByteType **GifExtension)
783 </programlisting>
784
785 <para>Loads an extension block from the GIF file. Extension blocks
786 are optional in GIF files. This routine should be followed by
787 <link linkend="DGifGetExtensionNext">DGifGetExtensionNext</link>.</para>
788
789 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
790
791 <para><programlisting id="DGifGetExtensionNext">
792 int DGifGetExtensionNext(GifFileType *GifFile, ByteType **GifExtension)
793 </programlisting>
794
795 As extensions may contain more than one block, use this routine to
796 continue after DGifGetExtension, until *GifExtension is NULL.</para>
797
798 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
799
800 <programlisting>
801 int DGifGetCode(
802 GifFileType *GifFile,
803 int *GifCodeSize, ByteType **GifCodeBlock)
804 </programlisting>
805
806 <para>It sometimes may be desired to read the compressed code as is
807 without decoding it. This routine does exactly that (with
808 DGifGetCodeNext), and can be used instead of DGifGetLine.</para>
809
810 <para>This compressed code information can be written out using the
811 EGifPutCode/EGifPutCodeNext sequence (see gifpos.c for example).
812 Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
813
814 <programlisting id="DGifGetCodeNext">
815 int DGifGetCodeNext(GifFileType *GifFile, ByteType **GifCodeBlock)
816 </programlisting>
817
818 <para>See DGifGetCode above.</para>
819
820 <programlisting id="DGifGetLZCodes">
821 int DGifGetLZCodes(GifFileType *GifFile, int *GifCode)
822 </programlisting>
823
824 <para>This routine can be called instead of DGifGetLine/DGifGetPixel or
825 DGifGetCode/DGifGetCodeNext to get the 12 bits LZ codes of the images.
826 It will be used mainly for debugging purposes (see GifText.c for
827 example).</para>
828
829 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
830
831 <programlisting id="DGifCloseFile">
832 int DGifCloseFile(GifFileType *GifFile, int *ErrorCode)
833 </programlisting>
834
835 <para>Write a termination block to the GIF, close the GIF file and
836 free all memory allocated for managing it. GifFile should not be used after
837 this routine has been called.</para>
838
839 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise. When
840 GIF_ERROR is returned, the diagnostic error code is left in ErrorCode.
841 The GifFile structure is unconditionally freed.</para>
842
843 <para>(Note: In versions before 5.1.0, the ErrorCode argument was
844 absent and the GifFile structure was not freed so that the
845 diagnostic error code will remain accessible in GifFile->Error.
846 This behavior was changed because it caused problems for the
847 implementation of library wrappers in dynamic languages.)</para>
848
849 <programlisting id="DGetGifVersion">
850 const char * DGifGetGifVersion(GifFileType *GifFile)
851 </programlisting>
852
853 <para>Get the GIF version collected during sequential read. This is
854 handy for sequential API users who want to set an encoder's version
855 from a decoder (e.g. for gif resizing). For the all-at-once users this
856 isn't necessary because gif encoder inspects all the extension blocks,
857 but sequential users do not have that luxury.</para>
858
859 </sect2>
860 <sect2><title>Sequential writing</title>
861
862 <para>If you are handling large images on a memory-limited machine, you may need
863 to use the following functions for sequential write.</para>
864
865 <programlisting id="EGifOpenFileName">
866 GifFileType *EGifOpenFileName(char *GifFileName, bool GifTestExistance, int *ErrorCode)
867 </programlisting>
868
869 <para>Open a new GIF file using the given GifFileName (in binary mode,
870 if under Windows). If GifTestExistance is TRUE, and file exists, the
871 file is not destroyed, and NULL returned.</para>
872
873 <para>If any error occurs, NULL is returned and the ErrorCode is set.</para>
874
875 <programlisting id="EGifOpenFileHandle">
876 GifFileType *EGifOpenFileHandle(int GifFileHandle, int *ErrorCode)
877 </programlisting>
878
879 <para>Open a new GIF file using the given GifFileHandle.</para>
880
881 <para>If any error occurs, NULL is returned and ErrorCode is set.</para>
882
883 <para>The file is opened in binary mode, and its buffer size is set to
884 FILE_BUFFER_SIZE bytes.</para>
885
886 <programlisting>
887 char *EGifGetGifVersion(GifFileType *GifFile)
888 </programlisting>
889
890 <para>That version computation is available through this function.</para>
891
892 <programlisting id="EGifSetGifVersion">
893 void EGifSetGifVersion(GifFileType *GifFile, bool gif89)
894 </programlisting>
895
896 <para>Set the GIF type, to GIF89 if the argument is true and GIF87 if
897 it is false. The default type is GIF87. This function may be called
898 after the GifFile record is allocated but before
899 EGifPutScreenDesc().</para>
900
901 <programlisting>
902 int EGifPutScreenDesc(GifFileType *GifFile,
903 const int GifWidth, const GifHeight,
904 const int GifColorRes, const int GifBackGround,
905 ColorMapObject *GifColorMap)
906 </programlisting>
907
908 <para>Update the GifFile Screen parameters, in GifFile structure and in
909 the real file. If error occurs, returns GIF_ERROR (see gif_lib.h),
910 otherwise GIF_OK.</para>
911
912 <para>This routine should be called immediately after the GIF file was
913 opened.</para>
914
915 <programlisting>
916 int EGifPutImageDesc(GifFileType *GifFile,
917 const int GifLeft, const int GifTop,
918 const int GifWidth, const GifHeight,
919 const bool GifInterlace,
920 ColorMapObject *GifColorMap)
921 </programlisting>
922
923 <para>Update GifFile Image parameters, in GifFile structure and in the real
924 file. if error occurs returns GIF_ERROR (see gif_lib.h), otherwise
925 GIF_OK.</para>
926
927 <para>This routine should be called each time a new image must be
928 dumped to the file.</para>
929
930 <programlisting id="EGifPutLine">
931 int EGifPutLine(GifFileType *GifFile, PixelType *GifLine, int GifLineLen)
932 </programlisting>
933
934 <para>Dumps a block of pixels out to the GIF file. The slab can be of
935 any length. More than that, this routine may be interleaved with
936 <link linkend="EGifPutPixel">EGifPutPixel()</link>, until all pixels
937 have been sent.</para>
938
939 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
940
941 <programlisting id="EGifPutPixel">
942 int EGifPutPixel(GifFileType *GifFile, const PixelType GifPixel)
943 </programlisting>
944
945 <para>Dumps one pixel to the GIF file. This routine may be interleaved with
946 <link linkend="EGifPutLine">EGifPutLine()</link>, until all pixels were sent.
947 Because of the overhead for each call, use of this routine is not
948 recommended.</para>
949
950 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
951
952 <programlisting id="EGifPutComment">
953 int EGifPutComment(GifFileType *GifFile, char *GifComment)
954 </programlisting>
955
956 <para>Uses extension GIF records to save a string as a comment is the file.
957 The extension code is 'C' (for Comment).</para>
958
959 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
960
961 <programlisting id="EGifPutExtension">
962 int EGifPutExtension(
963 GifFileType *GifFile,
964 const int GifExtCode,
965 const int GifExtLen,
966 void *GifExtension)
967 </programlisting>
968
969 <para>Dumps the given extension block into the GIF file. Extension blocks
970 are optional in GIF file. Extension blocks of more than 255 bytes or
971 more than one block are not supported in this function. Please use
972 EGifPutExtensionFirst, EGifPutExtensionBlock, and EGifPutExtensionTrailer
973 if your extension blocks may fall into this category.</para>
974
975 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
976
977 <programlisting id="EGifPutExtensionLeader">
978 int EGifPutExtensionLeader(
979 GifFileType * GifFile,
980 const int GifExtCode)
981 </programlisting>
982
983 <para>Dumps the beginning of a GIF extension block to a GIF file.
984 Extension blocks are optional in GIF files. This function outputs the
985 type code information necessary for a GIF extension block.</para>
986
987 <para>Further blocks of the GIF Extension should be dumped using
988 EGifPutExtensionBlock. When finished with this extension block,
989 EGifPutExtensionTrailer should be called to output the block termination.</para>
990
991 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
992
993 <programlisting id="EGifPutExtensionBlock">
994 int EGifPutExtensionBlock(
995 GifFileType * GifFile,
996 const int GifExtLen,
997 const VoidPtr GifExtension)
998 </programlisting>
999
1000 <para>Dumps a subblock of a GIF extension to a GIF File; should be
1001 used only following an initializing call to EGifPutExtensionLeader().
1002 Extension blocks are optional in GIF files. This function will write
1003 the Extension Data in GifExtension to the file as a subblock of the
1004 preceding Extension Block. Repeat calling of this function until all
1005 data subblocks have been output.</para>
1006
1007 <para>Note that EGifPutExtensionLeader needs to be called before any
1008 calls to this function. EGifPutExtensionTrailer should be called to
1009 finish the Extension block after all data subblocks have been
1010 output.</para>
1011
1012 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
1013
1014 <programlisting id="EGifPutExtensionTrailer">
1015 int EGifPutExtensionTrailer(
1016 GifFileType * GifFile,
1017 const VoidPtr GifExtension)
1018 </programlisting>
1019
1020 <para>Dumps the GIF extension block terminator to a GIF File to end
1021 the current Extension block.</para>
1022
1023 <para>Note that a call to EGifPutExtensionLeader is needed to open the GIF
1024 Extension Block prior to calling this function.</para>
1025
1026 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
1027
1028 <programlisting id="EGifPutCode">
1029 int EGifPutCode(
1030 GifFileType *GifFile,
1031 int *GifCodeSize,
1032 ByteType **GifCodeBlock)
1033 </programlisting>
1034
1035 <para>It sometimes may be desired to write the compressed code as is
1036 without decoding it. For example a filter for a GIF file that change
1037 only screen size (GifPos), does not need the exact pixel values.
1038 Piping out the compressed image as is makes this process much
1039 faster.</para>
1040
1041 <para>This routine does exactly that (with EGifPutCodeNext), and can be
1042 used instead of EGifPutLine. You'll usually use this with the
1043 DGifGetCode/DGifGetCodeNext routines, which reads the compressed
1044 code, while EGifPutCode/EGifPutCodeNext write it out. See gifpos.c
1045 for example.</para>
1046
1047 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</para>
1048
1049 <programlisting id="EGifPutCodeNext">
1050 int EGifPutCodeNext(GifFileType *GifFile, ByteType **GifCodeBlock)
1051 </programlisting>
1052
1053 <para>See EGifPutCode above.</para>
1054
1055 <programlisting id="EGifCloseFile">
1056 int EGifCloseFile(GifFileType *GifFile)
1057 </programlisting>
1058
1059 <para>Write a termination block to the GIF, close the GIF file, and
1060 free all memory allocated for managing it. GifFile should not be used
1061 after this routine has been called.</para>
1062
1063 <para>Returns GIF_ERROR if something went wrong, GIF_OK otherwise. When
1064 GIF_ERROR is returned, the diagnostic error code is left in ErrorCode.
1065 The GifFile structure is unconditionally freed.</para>
1066
1067 <para>(Note: In versions before 5.1.0, the ErrorCode argument was
1068 absent and the GifFile structure was not freed so that the
1069 diagnostic error code will remain accessible in GifFile->Error.
1070 This behavior was changed because it caused problems for the
1071 implementation of library wrappers in dynamic languages.)</para>
1072 </sect2>
1073
1074 </sect1>
1075 <sect1 id="compatibility"><title>Forward and Backward Compatibility</title>
1076
1077 <para>Except for some details of extension-block handling and the addition
1078 of read/write function hooks, the DGifSlurp()/EGifSpew() interface has
1079 been stable since 1990. It is expected to remain so.</para>
1080
1081 <para>However, the signatures of the file-opener functions were changed in 5.0
1082 in order to make the library fully reentrant and thread-safe - earlier library
1083 versions did not feature the final pointer-to-error-code argument in
1084 DGifOpen() and friends. For the same reason, the static storage queried by
1085 GifLastError() in older versions is gone, and that function abolished.</para>
1086
1087 <para>The library header contains some version #defines you can use if you
1088 need to condition your code so it can compile with different library
1089 versions</para>
1090
1091 <para>Versions up to 4.1.6 defined a GIF_LIB_VERSION macro that was
1092 string-valued with a tricky format to parse. This macro has been
1093 retired.</para>
1094
1095 <para>Versions after 4.1.6 define integer-valued GIFLIB_MAJOR, GIFLIB_MINOR,
1096 and GIFLIB_RELEASE macros for the three components of the version. See the
1097 NEWS file in the GIFLIB distribution to track API changes.</para>
1098
1099 <para>The following functions are entirely new:</para>
1100
1101 <itemizedlist>
1102 <listitem><para>New functions DGifSavedExtensionToGCB() and
1103 EGifGCBToSavedExtension() make it easy to read and edit GIF89 graphics
1104 control blocks in saved images.</para></listitem>
1105 <listitem><para>The new function DGifGetGifVersion() is convenient
1106 for people doing sequential reads.</para></listitem>
1107 </itemizedlist>
1108
1109 <para>A few changes in behavior were introduced in 5.0:</para>
1110
1111 <sect2><title>General behavior</title>
1112
1113 <itemizedlist>
1114 <listitem><para>The library is now fully re-entrant and
1115 thread-safe.</para></listitem>
1116 </itemizedlist>
1117 <itemizedlist>
1118 <listitem><para> All functions exported by this library now have DGif,
1119 EGif, or Gif as a name prefix.</para></listitem>
1120 <listitem><para>The default GIF version to write is now computed at
1121 write time from the types of an image's extension blocks. (Formerly
1122 EGifSpew() behaved this way, but the sequential-writing code didn't.)
1123 The result of this computation is available through the new function
1124 EGifGetGifVersion().</para></listitem>
1125 </itemizedlist>
1126
1127 </sect2>
1128 <sect2><title>In documented functions:</title>
1129
1130 <itemizedlist>
1131 <listitem><para>GIF file openers and closers - DGifOpenFileName(),
1132 DGifOpenFileHandle(), DGifOpen(), DGifClose(), EGifOpenFileName(),
1133 EGifOpenFileHandle(), EGifOpen(), and EGifClose() - all now take a
1134 final integer address argument. If non-null, this is used to pass
1135 back an error code when the function returns NULL.</para></listitem>
1136 <listitem><para>EGifSlurp() and EGifSpew() read and write
1137 extension blocks trailing after the last image, handle interlaced
1138 images properly.</para></listitem>
1139 <listitem><para>EGifPutExtensionFirst() has been replaced by
1140 EGifPutExtensionLeader(); the difference is the new function doesn't
1141 take an optional block, it just writes a block
1142 leader.</para></listitem>
1143 <listitem><para>EGifPutExtensionNext() has been replaced by
1144 EGifPutExtensionBlock(); the difference is that the new function does
1145 not take and then discard a function code argument.</para></listitem>
1146 <listitem><para>EGifPutExtensionLast() has been replaced by
1147 EGifPutExtensionTrailer(); all it does is write the terminator
1148 block. Split your old EGifPutExtensionLast() calls into
1149 EGifPutExtensionBlock() followed by
1150 EGifPutExtensionTrailer().</para></listitem>
1151 </itemizedlist>
1152
1153 </sect2>
1154 <sect2><title>In undocumented functions:</title>
1155
1156 <itemizedlist>
1157 <listitem><para>Some undocumented functions have been renamed.
1158 AddExtensionBlock() is now GifAddExtensionBlock(), and takes an additional
1159 function code argument. ApplyTranslation() is now GifApplyTranslation();
1160 FreeExtension() has become GifFreeExtensions() and takes a different argument
1161 type; MakeSavedImage() is now GifMakeSavedImage(), FreeSavedImages() is
1162 now GifFreeSavedImages(), and BitSize() is now GifBitSize().</para></listitem>
1163 <listitem><para>Three documented functions - MakeMapObject(),
1164 FreeMapObject(), and UnionColorMap() - have been renamed to
1165 GifMakeMapObject(), GifFreeMapObject(), and GifUnionColorMap()
1166 respectively.</para></listitem>
1167 </itemizedlist>
1168
1169 </sect2>
1170 <sect2><title>Error handling:</title>
1171
1172 <itemizedlist>
1173 <listitem><para>Library error handling no longer uses a static cell to
1174 store the last error code registered; that made the library
1175 thread-unsafe.</para></listitem>
1176 <listitem><para>For functions other than GIF file openers, the Error
1177 code is now put in an Error member of the GifFileType
1178 structure.</para></listitem>
1179 <listitem><para>The GifError() and
1180 GifLastError() functions that referenced that static cell are gone,
1181 and the GifErrorString() function introduced in the 4.2 release now
1182 takes an explicit error code argument.</para></listitem>
1183 </itemizedlist>
1184 </sect2>
1185 </sect1>
1186 <sect1><title>Skeletons of GIF filters</title>
1187
1188 <para>If you are developing on a virtual-memory OS such as most flavors of
1189 UNIX, or are otherwise sure of having enough memory to keep all of GIFs you
1190 need to operate in core, writing a filter is trivial. See the file
1191 gifsponge.c in util.</para>
1192
1193 <para>A sequential filter skeleton will usually look like the example file
1194 giffilter.c in util.</para>
1195
1196 <para>Please look at the utilities in the util directory for more ideas once
1197 you feel comfortable with these skeletons. Also try to follow the coding
1198 standards of this package if you want the maintainer to officially add your new
1199 utility to it.</para>
1200
1201 </sect1>
1202 <sect1><title>Unimplemented features</title>
1203
1204 <para>Some features of the original GIF specification have not stood the
1205 test of time. This library mostly ignores them, but they are described
1206 here for completeness.</para>
1207
1208 <para>The GIF standard fails to be explicit about a small but crucial detail:
1209 the unsigned two-byte integer fields in it are little-endian.</para>
1210
1211 <para>The GIF format seems to have been designed with the idea that viewers
1212 would render multiple images in a GIF on a common canvas, giving an effect like
1213 a picture wall. The 'logical screen descriptor block' (LSDB), 6 bytes right
1214 after the 6-byte GIF stamp and version header at the beginning of a
1215 GIF file, includes both two-byte canvas width and canvas height
1216 fields and a canvas background color. Each image, besides height and
1217 width, also has 'left' and 'top' coordinates specifying where it is to
1218 be placed on the canvas.</para>
1219
1220 <para>GIFLIB can read and set these fields; the gifpos and giftool
1221 utilities will enable you to script such changes. But browsers and
1222 modern image viewers ignore them. Nowadays multiple-image GIFs are
1223 generally used either as animations in which each sub-image is a frame
1224 or as image libraries, with the GIF client handling compositing into
1225 some canvas about which the GIF format holds no information.</para>
1226
1227 <para>Another feature of the LSDB that is generally ignored is the
1228 pixel aspect ratio byte. Until 5.0, GIFLIB ignored this flag on input
1229 and zeroed it on output; now it is read and preserved if present. The
1230 GIF standard doesn't give a rationale for it, but it seems likely that
1231 the designers intended it for representing image captures from the
1232 analog television of the day, which had rectangular pixel-equivalents.</para>
1233
1234 <para>Yet another ignored feature of both the LSDB and sub-images is
1235 the sort flag, which is supposed to signal whether the colors in the
1236 associated color map are sorted by decreasing importance in case the
1237 display device can only render a limited number of them. This feature
1238 reflected the high cost of dual-port memory at the time the GIF
1239 specification was written in the late 1980s. That kind of limit
1240 disappeared in the mid-1990s. Until 5.0, GIFLIB ignored this flag on
1241 input and zeroed it on output; now it is read and preserved if
1242 present.</para>
1243
1244 <para>Finally, the plaintext extension block. This is an extension block
1245 that contains instructions for overlaying text captions on a following image.
1246 GIFLIB treats these blocks as raw data, not attempting to parse out the
1247 location and text data.</para>
1248 </sect1>
1249 </article>