| 1 |
<?xml version="1.0" encoding="UTF-8"?> |
| 2 |
<!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 Vsnapshot" /></head><body><div class="article"><div class="titlepage"><div><div><h2 class="title"><a id="id1337"></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"> |
| 3 |
Thyrsus Enterprises</a><br /></span><div class="address"><p><br /> |
| 4 |
<code class="email"><<a class="email" href="mailto:[email protected]">[email protected]</a>></code><br /> |
| 5 |
</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="#id1339">Introduction</a></span></dt><dt><span class="sect1"><a href="#id1340">Credit and Blame</a></span></dt><dt><span class="sect1"><a href="#id1341">The GIF descriptor</a></span></dt><dt><span class="sect1"><a href="#id1342">Decoding (dgif_lib.c)</a></span></dt><dt><span class="sect1"><a href="#id1343">Encoding (egif_lib.c)</a></span></dt><dt><span class="sect1"><a href="#id1344">Color map handling and allocation routines</a></span></dt><dt><span class="sect1"><a href="#id1345">Graphics control extension handling</a></span></dt><dt><span class="sect1"><a href="#id1346">Error Handling (gif_err.c)</a></span></dt><dt><span class="sect1"><a href="#id1347">The GIF Utility Font</a></span></dt><dt><span class="sect1"><a href="#id1350">Error codes</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id1348">Encoding errors</a></span></dt><dt><span class="sect2"><a href="#id1349">Decoding errors</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id1353">Utility support library</a></span></dt><dd><dl><dt><span class="sect2"><a href="#id1351">Error Handling</a></span></dt><dt><span class="sect2"><a href="#id1352">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="#id1354">Sequential reading</a></span></dt><dt><span class="sect2"><a href="#id1355">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="#id1356">General behavior</a></span></dt><dt><span class="sect2"><a href="#id1357">In documented functions:</a></span></dt><dt><span class="sect2"><a href="#id1358">In undocumented functions:</a></span></dt><dt><span class="sect2"><a href="#id1359">Error handling:</a></span></dt></dl></dd><dt><span class="sect1"><a href="#id1360">Skeletons of GIF filters</a></span></dt><dt><span class="sect1"><a href="#id1361">Unimplemented features</a></span></dt></dl></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id1339"></a>Introduction</h2></div></div></div><p>The Graphics Interchange Format(c) is the Copyright property of |
| 6 |
CompuServe Incorporated. GIF(sm) is a Service Mark property of CompuServe |
| 7 |
Incorporated.</p><p>This document explains the GIF library code in directory `lib'. The |
| 8 |
code is collected into a service library which is used in all the utilities in |
| 9 |
`util'. It can be used in any application needs to read/write the GIF |
| 10 |
file format. This document does <span class="emphasis"><em>not</em></span> explain the GIF file |
| 11 |
format and assumes you know it, at least to the level of the GIF file |
| 12 |
structure.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id1340"></a>Credit and Blame</h2></div></div></div><p>Gershon wrote: "This library was written because I couldn't find |
| 13 |
anything similar and I wanted one. I was inspired by the RLE Utah tool kit, |
| 14 |
which I hoped to port to an IBM PC, but found it to be too machine specific, |
| 15 |
and its compression ratio too low. I compromised on the GIF format, but I am |
| 16 |
not sure how long 8 bits per pixel will be enough."</p><p>During his first spell of maintainership between 1989 and 1994, Eric |
| 17 |
S. Raymond (aka "ESR") ported the code to Unix, wrote the high-level |
| 18 |
DGifSlurp()/EGifSpew() interface, rationalized the internal data |
| 19 |
structures, and did a lot of general cleanup and refactoring to |
| 20 |
improve the code quality.</p><p>Between 1994 and 2012 Toshio Kuratomi fixed various tool bugs, |
| 21 |
build-recipe problems and rare segfaults. He partially untangled the |
| 22 |
somewhat misdesigned extension-block handling in earlier versions. |
| 23 |
The core code was very stable during this period.</p><p>During his second spell of maintainership, ESR fixed the |
| 24 |
extension API, made the library re-entrant and thread-safe, wrote a |
| 25 |
regression-test suite, greatly improved the documentation, and |
| 26 |
discarded a lot of obsolete code.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id1341"></a>The GIF descriptor</h2></div></div></div><p>When a GIF file is opened, a GIF file descriptor is created which |
| 27 |
is a pointer to GifFileType structure as follows:</p><pre class="programlisting"> |
| 28 |
typedef struct GifFileType { |
| 29 |
GifWord SWidth, SHeight; /* Size of virtual canvas */ |
| 30 |
GifWord SColorResolution; /* How many colors can we generate? */ |
| 31 |
GifWord SBackGroundColor; /* Background color for virtual canvas */ |
| 32 |
GifByteType AspectByte; /* Used to compute pixel aspect ratio */ |
| 33 |
ColorMapObject *SColorMap; /* Global colormap, NULL if nonexistent. */ |
| 34 |
int ImageCount; /* Number of current image (both APIs) */ |
| 35 |
GifImageDesc Image; /* Current image (low-level API) */ |
| 36 |
SavedImage *SavedImages; /* Image sequence (high-level API) */ |
| 37 |
int ExtensionBlockCount; /* Count extensions past last image */ |
| 38 |
ExtensionBlock *ExtensionBlocks; /* Extensions past last image */ |
| 39 |
int Error; /* Last error condition reported */ |
| 40 |
void *UserData; /* hook to attach user data (TVT) */ |
| 41 |
void *Private; /* Don't mess with this! */ |
| 42 |
} GifFileType; |
| 43 |
</pre><p>This structure was copied from gif_lib.h - the header file for the GIF |
| 44 |
library. Any application program that uses the libgif.a library should |
| 45 |
include it. Members beginning with S refer to the GIF screen; others hold |
| 46 |
properties of the current image (a GIF file may have more than one image) |
| 47 |
or point to allocated store used by various routines.</p><p>The user almost never writes into this structure (exception: it |
| 48 |
may occasionally be useful to alter things in the SavedImages array and |
| 49 |
Trailing member), but can read any of these items at any time it is |
| 50 |
valid (Image information is invalid until the first image has been read; |
| 51 |
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 |
| 52 |
to hidden data is included. Applications should ignore this.</p><p>The library allocates its own memory dynamically, on opening of files, |
| 53 |
and releases that once closed. The user is never required to allocate |
| 54 |
any memory for any of the functions of this library, and is almost never |
| 55 |
required to free them directly. The "almost" in the latter clause is because |
| 56 |
one manual free() call may be required on a failed file close; see the |
| 57 |
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 |
| 58 |
internally only.</p><p>Most of the routines return GIF_ERROR (see gif_lib.h) if something |
| 59 |
went wrong, GIF_OK otherwise. After an error return, all routines that |
| 60 |
take a pointer-to-GifFileType argument set the Error member with a code that |
| 61 |
can be interpreted into an explanatory string with the function |
| 62 |
GifErrorString() in gif_err.c. (The exception to this is the |
| 63 |
DGifClose() and EGifClose() routines, which deallocate that structure |
| 64 |
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="id1342"></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"> |
| 65 |
GifFileType *DGifOpenFileName(char *GifFileName, int *ErrorCode) |
| 66 |
</pre><p>Open a new GIF file (in binary mode, if under Windows) using the |
| 67 |
given GifFileName, and read its Screen information.</p><p>If any error occurs, NULL is returned and ErrorCode is set (if |
| 68 |
non-NULL).</p><a id="DGifOpenFileHandle"></a><pre class="programlisting"> |
| 69 |
GifFileType *DGifOpenFileHandle(int FileHandle, int *ErrorCode) |
| 70 |
</pre><p>Open a new GIF file using the given FileHandle, and read its Screen |
| 71 |
information.</p><p>If any error occurs, NULL is returned and ErrorCode is set (if |
| 72 |
non-NULL).</p><p>Once you have acquired a handle on a GIF, the high-level |
| 73 |
function</p><a id="DGifSlurp"></a><pre class="programlisting"> |
| 74 |
int DGifSlurp(GifFileType) |
| 75 |
</pre><p>reads the rest of a complete (possibly multi-image) GIF file from the |
| 76 |
indicated file handle into in-core allocated structures. It returns |
| 77 |
GIF_OK on success, GIF_ERROR on failure; on failure, the Error member |
| 78 |
will be set.</p><p>Once you have done this, all image, raster, and extension-block |
| 79 |
data in the GIF is accessible in the SavedImages member (see the |
| 80 |
structures in gif_lib.h). When you have modified the image to taste, |
| 81 |
write it out with EGifSpew().</p><p>One detail that may not be clear from just looking at the |
| 82 |
structures is how extension blocks and sub-blocks are stored. Each |
| 83 |
ExtensionBlock structure represents an extension data block. Those |
| 84 |
with a zero function code represent continuation data blocks attached |
| 85 |
to previous blocks with nonzero function codes.</p><p>You can read from a GIF file through a function hook. Initialize |
| 86 |
with </p><a id="DGifOpen"></a><pre class="programlisting"> |
| 87 |
GifFileType *DGifOpen(void *userPtr, InputFunc readFunc, int *ErrorCode) |
| 88 |
</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, |
| 89 |
described in a later section.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id1343"></a>Encoding (egif_lib.c)</h2></div></div></div><p>The high-level function</p><a id="EGifSpew"></a><pre class="programlisting"> |
| 90 |
int EGifSpew(GifFileType *GifFile, int *ErrorCode) |
| 91 |
</pre><p>writes a complete (possibly multi-image) GIF file to the indicated file |
| 92 |
handle from in-core allocated structures created by a previous DGifSlurp() |
| 93 |
or equivalent operations. Its argument is a GIF file descriptor, which |
| 94 |
implicitly points to storage previously allocated by DGifSlurp().</p><p>If ErrorCode is non-NULL, it returns a GIFLIB error code on failure; |
| 95 |
otherwise it may be NULL. The function returns GIF_OK or GIF_ERROR.</p><p>The file is written with a GIF87 stamp unless it contains one of the four |
| 96 |
special extension blocks defined in GIF89, in which case it is written |
| 97 |
with a GIF89 stamp.</p><p>EGifSpew() finishes by closing the GIF (writing a termination |
| 98 |
record to it) and deallocating the associated storage.</p><p>You can write to a GIF file through a function hook. Initialize |
| 99 |
with </p><a id="EGifOpen"></a><pre class="programlisting"> |
| 100 |
GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc, int *ErrorCode) |
| 101 |
</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, |
| 102 |
described in a later section.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id1344"></a>Color map handling and allocation routines</h2></div></div></div><a id="GifMakeMapObject"></a><pre class="programlisting"> |
| 103 |
ColorMapObject *GifMakeMapObject(int ColorCount, GifColorType *ColorMap) |
| 104 |
</pre><p>Allocate storage for a color map object with the given number of |
| 105 |
RGB triplet slots. If the second argument is non-NULL, initialize |
| 106 |
the color table portion of the new map from it. Returns NULL if |
| 107 |
memory is exhausted or if the size is not a power of 2 <= 256.</p><a id="GifFreeMapObject"></a><pre class="programlisting"> |
| 108 |
void GifFreeMapObject(ColorMapObject *Object) |
| 109 |
</pre><p>Free the storage occupied by a ColorMapObject that is no longer |
| 110 |
needed.</p><a id="GifUnionColorMap"></a><pre class="programlisting"> |
| 111 |
ColorMapObject *GifUnionColorMap( |
| 112 |
ColorMapObject *ColorIn1, ColorMapObject *ColorIn2, |
| 113 |
GifPixelType ColorTransIn2[]) |
| 114 |
</pre><p>Create the union of two given color maps and return it. If the |
| 115 |
result won't fit into 256 colors, NULL is returned, the allocated |
| 116 |
union otherwise. ColorIn1 is copied as it to ColorUnion, while colors |
| 117 |
from ColorIn2 are copied if and only if they didn't exist before. |
| 118 |
ColorTransIn2 maps the old ColorIn2 into ColorUnion color map |
| 119 |
table.</p><a id="GifAttachImage"></a><pre class="programlisting"> |
| 120 |
SavedImage *GifAttachImage(GifFileType *GifFile) |
| 121 |
</pre><p>Add an image block to the SavedImages array. The image block is |
| 122 |
initially zeroed out. This image block will be seen by any following |
| 123 |
EGifSpew() calls.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id1345"></a>Graphics control extension handling</h2></div></div></div><p>GIF89 added a graphics control extension block, but versions |
| 124 |
of GIFLIB before 5.0 weren't much help in reading or modifying them. |
| 125 |
This lack has been remedied with the following structure and functions:</p><pre class="programlisting"> |
| 126 |
typedef struct GraphicsControlBlock { |
| 127 |
int DisposalMode; |
| 128 |
#define DISPOSAL_UNSPECIFIED 0 /* No disposal specified. */ |
| 129 |
#define DISPOSE_DO_NOT 1 /* Leave image in place */ |
| 130 |
#define DISPOSE_BACKGROUND 2 /* Set area too background color */ |
| 131 |
#define DISPOSE_PREVIOUS 3 /* Restore to previous content */ |
| 132 |
bool UserInputFlag; /* User confirmation required before disposal */ |
| 133 |
int DelayTime; /* pre-display delay in 0.01sec units */ |
| 134 |
int TransparentColor; /* Palette index for transparency, -1 if none */ |
| 135 |
#define NO_TRANSPARENT_COLOR -1 |
| 136 |
} GraphicsControlBlock; |
| 137 |
|
| 138 |
int DGifSavedExtensionToGCB(GifFileType *GifFile, |
| 139 |
int ImageIndex, |
| 140 |
GraphicsControlBlock *GCB); |
| 141 |
int EGifGCBToSavedExtension(const GraphicsControlBlock *GCB, |
| 142 |
GifFileType *GifFile, |
| 143 |
int ImageIndex); |
| 144 |
</pre><p>With these functions you can extract the data from a graphics |
| 145 |
control extension associated with a saved image into a |
| 146 |
GraphicsControlBlock, modify it, and write it back out. Note that if |
| 147 |
the specified saved image doesn't have a graphics control extension, |
| 148 |
DGifSavedExtensionToGCB() will fill the GCB with default values and |
| 149 |
return GIF_ERROR (which can be ignored); EGifGCBToSavedExtension() |
| 150 |
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="id1346"></a>Error Handling (gif_err.c)</h2></div></div></div><pre class="programlisting"> |
| 151 |
int GifErrorString(int ErrorCode) |
| 152 |
</pre><p>Returns a string describing the specified GIFLIB error code. |
| 153 |
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="id1347"></a>The GIF Utility Font</h2></div></div></div><p>The 8x8 utility font used in the (obsolete, no longer installed) |
| 154 |
gifecho and gifcolor lives in the library module gif_font.c, in a |
| 155 |
table called GifAsciiTable. The library header file includes suitable |
| 156 |
externs and defines.</p><p>The GIF utility font support includes entry points for drawing legends |
| 157 |
on in-core images, drawing boxes and rectangles, and boxing text. |
| 158 |
These entry points are as follows:</p><a id="GifDrawText"></a><pre class="programlisting"> |
| 159 |
void GifDrawText8x8( |
| 160 |
SavedImage *Image, |
| 161 |
const int x, const int y, |
| 162 |
const char *legend, |
| 163 |
const int color) |
| 164 |
</pre><p>Draw text using the 8x8 utility font on the saved image. Upper |
| 165 |
left corner of the text is at image pixel (x, y). Use the specified |
| 166 |
color index.</p><a id="GifDrawBox"></a><pre class="programlisting"> |
| 167 |
void GifDrawBox(SavedImage *Image, |
| 168 |
const int x, const int y, |
| 169 |
const int w, const int h, |
| 170 |
const int color) |
| 171 |
</pre><p>Draw a box on the saved image. Upper left corner of the box is at |
| 172 |
image pixels (x, y), width is w, height is h. Use the specified color |
| 173 |
index.</p><a id="GifDrawRectangle"></a><pre class="programlisting"> |
| 174 |
void GifDrawRectangle(SavedImage *Image, |
| 175 |
const int x, const int y, |
| 176 |
const int w, const int h, |
| 177 |
const int color) |
| 178 |
</pre><p>Draw a (filled) rectangle on the saved image. Upper left corner of |
| 179 |
the box is at image pixels (x, y), width is w, height is h. Use the |
| 180 |
specified color index.</p><a id="GifDrawBoxedText"></a><pre class="programlisting"> |
| 181 |
void GifDrawBoxedText8x8(SavedImage *Image, |
| 182 |
const int x, const int y, |
| 183 |
const char *legend, |
| 184 |
const int border, |
| 185 |
const int bg, const int fg) |
| 186 |
</pre><p>Draw text on a filled rectangle. The rectangle will be sized to fit |
| 187 |
the text, with upper left hand corner at (x, y) on the saved image. |
| 188 |
The `border' argument specifies a pixel margin around the text. The |
| 189 |
`bg' argument is the color table index to fill the rectangle with; |
| 190 |
`fg' is the color table index to draw the text with.</p><p>This function interprets some characters in the legend string |
| 191 |
specially. A tab (\t) is interpreted as a command to center the |
| 192 |
following text in the box. A carriage return (\r) is interpreted |
| 193 |
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="id1350"></a>Error codes</h2></div></div></div><p>Errors as reported from the GIFLIB library are divided to two major |
| 194 |
categories: the encoder (errors prefixed by E_GIF_ERR), and the |
| 195 |
decoder (errors prefixed by D_GIF_ERR). This document explains them |
| 196 |
briefly.</p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="id1348"></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" |
| 197 |
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" |
| 198 |
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 |
| 199 |
already been set" Attempt to write second screen descriptor to same |
| 200 |
GIF file. GIF file should have exactly one screen descriptor which |
| 201 |
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" |
| 202 |
Image descriptor should be sent before and image dump, and no second |
| 203 |
image descriptor should be sent before current image dump ended. This error |
| 204 |
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 |
| 205 |
Local color map" An image must have either global (screen) or local |
| 206 |
(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 |
| 207 |
Width * Height" The number of pixels dumped for this image is |
| 208 |
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 |
| 209 |
required memory" Once an attempt is made to open GIF file, special |
| 210 |
structures are allocated to hold internal data for it. If |
| 211 |
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?)" |
| 212 |
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" |
| 213 |
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 |
| 214 |
opened for write" GIF files can be opened both for read (DGIF part |
| 215 |
of library) and write (EGIF part of library). This error occurs |
| 216 |
when a file is opened for read (using DGIF) is given to one of the |
| 217 |
encoding (EGIF) routines.</p></dd></dl></div></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="id1349"></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" |
| 218 |
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" |
| 219 |
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" |
| 220 |
GIF files should have special stamp identifies them as such, If that stamp |
| 221 |
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" |
| 222 |
Each GIF file should have screen descriptor in its header. This error will |
| 223 |
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" |
| 224 |
Each image should have image descriptor in its header. This error will |
| 225 |
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 |
| 226 |
local color map" An image must have either global (screen) or local |
| 227 |
(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" |
| 228 |
Each record in a GIF file has a special identifier in its header. If the |
| 229 |
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 |
| 230 |
width * height" The number of pixels dumped for this image is |
| 231 |
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 |
| 232 |
required memory" Once an attemp is made to open GIF file, special |
| 233 |
structures are allocated to hold internal data for it. If |
| 234 |
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" |
| 235 |
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 |
| 236 |
opened for read" GIF files can be opened both for read (DGIF part |
| 237 |
of library) and write (EGIF part of library). This error occurs |
| 238 |
when a file is opened for write (using EGIF) is given to one of the |
| 239 |
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, |
| 240 |
decoding aborted" This error is generated, once the decoding failed |
| 241 |
- 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, |
| 242 |
before image complete" This error is generated once EOF errorname |
| 243 |
is detected in encoded image before all the pixels (Width * |
| 244 |
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="id1353"></a>Utility support library</h2></div></div></div><p>These functions are not part of the core GIF library. They are part |
| 245 |
of the getarg library that supports the utilities.</p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="id1351"></a>Error Handling</h3></div></div></div><a id="PrintGifError"></a><pre class="programlisting"> |
| 246 |
void PrintGifError(void) |
| 247 |
</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="id1352"></a>Command Line Parsing</h3></div></div></div><a id="GAGetArgs"></a><pre class="programlisting"> |
| 248 |
bool GAGetArgs(int argc, char **argv, char *CtrlStr, ...) |
| 249 |
</pre><p>Main routine of this module. Given argc & argv as received by |
| 250 |
the main procedure, the command line CtrlStr, and the addresses of |
| 251 |
all parameters, parse the command line, and update the parameters.</p><p>The CtrlStr defines what types of variables should follow. Look at the |
| 252 |
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"> |
| 253 |
void GAPrintErrMsg(int Error) |
| 254 |
</pre><p>If an error occurred in GAGetArgs, this routine may be used to print |
| 255 |
one line diagnostic to stderr.</p><a id="GAPrintHowTo"></a><pre class="programlisting"> |
| 256 |
void GAPrintHowTo(char *CtrlStr) |
| 257 |
</pre><p>Given the same CtrlStr as for GAGetArgs, can be used to print a one line |
| 258 |
'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 |
| 259 |
machine, you may need to use the following functions for sequential |
| 260 |
read and write. It's better to avoid them and use the simpler |
| 261 |
DGifSlurp()/EGifSpew() interface.</p><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="id1354"></a>Sequential reading</h3></div></div></div><a id="DGifGetScreenDesc"></a><pre class="programlisting"> |
| 262 |
int DGifGetScreenDesc(GifFileType *GifFile) |
| 263 |
</pre><p>Reads the screen information into the GifFile structure. Note this |
| 264 |
routine is automatically called once a file is opened, and therefore |
| 265 |
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"> |
| 266 |
int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType) |
| 267 |
</pre><p>As the GIF file can have different records in arbitrary order, this |
| 268 |
routine should be called once the file was open to detect the next |
| 269 |
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 |
| 270 |
returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="DGifGetImageDesc"></a><pre class="programlisting"> |
| 271 |
int DGifGetImageDesc(GifFileType *GifFile) |
| 272 |
</pre><p>Reads image information into the GifFile structure. |
| 273 |
Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="DGifGetLine"></a><pre class="programlisting"> |
| 274 |
int DGifGetLine(GifFileType *GifFile, PixelType *GifLine, int GifLineLen) |
| 275 |
</pre><p>Load a block of pixels from the GIF file. The line can be |
| 276 |
of any length. More than that, this routine may be interleaved with |
| 277 |
DGifGetPixel until all pixels have been read.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><pre class="programlisting"> |
| 278 |
int DGifGetPixel(GifFileType *GifFile, PixelType GifPixel) |
| 279 |
</pre><p>Loads one pixel from the GIF file. This routine may be interleaved |
| 280 |
with <a class="link" href="#DGifGetLine">DGifGetLine()</a>, until all pixels are |
| 281 |
read. Because of the overhead per each call, use of this routine is |
| 282 |
not recommended.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><pre class="programlisting"> |
| 283 |
int DGifGetExtension( |
| 284 |
GifFileType *GifFile, |
| 285 |
int *GifExtCode, |
| 286 |
ByteType **GifExtension) |
| 287 |
</pre><p>Loads an extension block from the GIF file. Extension blocks |
| 288 |
are optional in GIF files. This routine should be followed by |
| 289 |
<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"> |
| 290 |
int DGifGetExtensionNext(GifFileType *GifFile, ByteType **GifExtension) |
| 291 |
</pre><p> |
| 292 |
|
| 293 |
As extensions may contain more than one block, use this routine to |
| 294 |
continue after DGifGetExtension, until *GifExtension is NULL.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><pre class="programlisting"> |
| 295 |
int DGifGetCode( |
| 296 |
GifFileType *GifFile, |
| 297 |
int *GifCodeSize, ByteType **GifCodeBlock) |
| 298 |
</pre><p>It sometimes may be desired to read the compressed code as is |
| 299 |
without decoding it. This routine does exactly that (with |
| 300 |
DGifGetCodeNext), and can be used instead of DGifGetLine.</p><p>This compressed code information can be written out using the |
| 301 |
EGifPutCode/EGifPutCodeNext sequence (see gifpos.c for example). |
| 302 |
Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="DGifGetCodeNext"></a><pre class="programlisting"> |
| 303 |
int DGifGetCodeNext(GifFileType *GifFile, ByteType **GifCodeBlock) |
| 304 |
</pre><p>See DGifGetCode above.</p><a id="DGifGetLZCodes"></a><pre class="programlisting"> |
| 305 |
int DGifGetLZCodes(GifFileType *GifFile, int *GifCode) |
| 306 |
</pre><p>This routine can be called instead of DGifGetLine/DGifGetPixel or |
| 307 |
DGifGetCode/DGifGetCodeNext to get the 12 bits LZ codes of the images. |
| 308 |
It will be used mainly for debugging purposes (see GifText.c for |
| 309 |
example).</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="DGifCloseFile"></a><pre class="programlisting"> |
| 310 |
int DGifCloseFile(GifFileType *GifFile, int *ErrorCode) |
| 311 |
</pre><p>Write a termination block to the GIF, close the GIF file and |
| 312 |
free all memory allocated for managing it. GifFile should not be used after |
| 313 |
this routine has been called.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise. When |
| 314 |
GIF_ERROR is returned, the diagnostic error code is left in ErrorCode. |
| 315 |
The GifFile structure is unconditionally freed.</p><p>(Note: In versions before 5.1.0, the ErrorCode argument was |
| 316 |
absent and the GifFile structure was not freed so that the |
| 317 |
diagnostic error code will remain accessible in GifFile->Error. |
| 318 |
This behavior was changed because it caused problems for the |
| 319 |
implementation of library wrappers in dynamic languages.)</p><a id="DGetGifVersion"></a><pre class="programlisting"> |
| 320 |
const char * DGifGetGifVersion(GifFileType *GifFile) |
| 321 |
</pre><p>Get the GIF version collected during sequential read. This is |
| 322 |
handy for sequential API users who want to set an encoder's version |
| 323 |
from a decoder (e.g. for gif resizing). For the all-at-once users this |
| 324 |
isn't necessary because gif encoder inspects all the extension blocks, |
| 325 |
but sequential users do not have that luxury.</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="id1355"></a>Sequential writing</h3></div></div></div><p>If you are handling large images on a memory-limited machine, you may need |
| 326 |
to use the following functions for sequential write.</p><a id="EGifOpenFileName"></a><pre class="programlisting"> |
| 327 |
GifFileType *EGifOpenFileName(char *GifFileName, bool GifTestExistance, int *ErrorCode) |
| 328 |
</pre><p>Open a new GIF file using the given GifFileName (in binary mode, |
| 329 |
if under Windows). If GifTestExistance is TRUE, and file exists, the |
| 330 |
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"> |
| 331 |
GifFileType *EGifOpenFileHandle(int GifFileHandle, int *ErrorCode) |
| 332 |
</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 |
| 333 |
FILE_BUFFER_SIZE bytes.</p><pre class="programlisting"> |
| 334 |
char *EGifGetGifVersion(GifFileType *GifFile) |
| 335 |
</pre><p>That version computation is available through this function.</p><a id="EGifSetGifVersion"></a><pre class="programlisting"> |
| 336 |
void EGifSetGifVersion(GifFileType *GifFile, bool gif89) |
| 337 |
</pre><p>Set the GIF type, to GIF89 if the argument is true and GIF87 if |
| 338 |
it is false. The default type is GIF87. This function may be called |
| 339 |
after the GifFile record is allocated but before |
| 340 |
EGifPutScreenDesc().</p><pre class="programlisting"> |
| 341 |
int EGifPutScreenDesc(GifFileType *GifFile, |
| 342 |
const int GifWidth, const GifHeight, |
| 343 |
const int GifColorRes, const int GifBackGround, |
| 344 |
ColorMapObject *GifColorMap) |
| 345 |
</pre><p>Update the GifFile Screen parameters, in GifFile structure and in |
| 346 |
the real file. If error occurs, returns GIF_ERROR (see gif_lib.h), |
| 347 |
otherwise GIF_OK.</p><p>This routine should be called immediately after the GIF file was |
| 348 |
opened.</p><pre class="programlisting"> |
| 349 |
int EGifPutImageDesc(GifFileType *GifFile, |
| 350 |
const int GifLeft, const int GifTop, |
| 351 |
const int GifWidth, const GifHeight, |
| 352 |
const bool GifInterlace, |
| 353 |
ColorMapObject *GifColorMap) |
| 354 |
</pre><p>Update GifFile Image parameters, in GifFile structure and in the real |
| 355 |
file. if error occurs returns GIF_ERROR (see gif_lib.h), otherwise |
| 356 |
GIF_OK.</p><p>This routine should be called each time a new image must be |
| 357 |
dumped to the file.</p><a id="EGifPutLine"></a><pre class="programlisting"> |
| 358 |
int EGifPutLine(GifFileType *GifFile, PixelType *GifLine, int GifLineLen) |
| 359 |
</pre><p>Dumps a block of pixels out to the GIF file. The slab can be of |
| 360 |
any length. More than that, this routine may be interleaved with |
| 361 |
<a class="link" href="#EGifPutPixel">EGifPutPixel()</a>, until all pixels |
| 362 |
have been sent.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="EGifPutPixel"></a><pre class="programlisting"> |
| 363 |
int EGifPutPixel(GifFileType *GifFile, const PixelType GifPixel) |
| 364 |
</pre><p>Dumps one pixel to the GIF file. This routine may be interleaved with |
| 365 |
<a class="link" href="#EGifPutLine">EGifPutLine()</a>, until all pixels were sent. |
| 366 |
Because of the overhead for each call, use of this routine is not |
| 367 |
recommended.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="EGifPutComment"></a><pre class="programlisting"> |
| 368 |
int EGifPutComment(GifFileType *GifFile, char *GifComment) |
| 369 |
</pre><p>Uses extension GIF records to save a string as a comment is the file. |
| 370 |
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"> |
| 371 |
int EGifPutExtension( |
| 372 |
GifFileType *GifFile, |
| 373 |
const int GifExtCode, |
| 374 |
const int GifExtLen, |
| 375 |
void *GifExtension) |
| 376 |
</pre><p>Dumps the given extension block into the GIF file. Extension blocks |
| 377 |
are optional in GIF file. Extension blocks of more than 255 bytes or |
| 378 |
more than one block are not supported in this function. Please use |
| 379 |
EGifPutExtensionFirst, EGifPutExtensionBlock, and EGifPutExtensionTrailer |
| 380 |
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"> |
| 381 |
int EGifPutExtensionLeader( |
| 382 |
GifFileType * GifFile, |
| 383 |
const int GifExtCode) |
| 384 |
</pre><p>Dumps the beginning of a GIF extension block to a GIF file. |
| 385 |
Extension blocks are optional in GIF files. This function outputs the |
| 386 |
type code information necessary for a GIF extension block.</p><p>Further blocks of the GIF Extension should be dumped using |
| 387 |
EGifPutExtensionBlock. When finished with this extension block, |
| 388 |
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"> |
| 389 |
int EGifPutExtensionBlock( |
| 390 |
GifFileType * GifFile, |
| 391 |
const int GifExtLen, |
| 392 |
const VoidPtr GifExtension) |
| 393 |
</pre><p>Dumps a subblock of a GIF extension to a GIF File; should be |
| 394 |
used only following an initializing call to EGifPutExtensionLeader(). |
| 395 |
Extension blocks are optional in GIF files. This function will write |
| 396 |
the Extension Data in GifExtension to the file as a subblock of the |
| 397 |
preceding Extension Block. Repeat calling of this function until all |
| 398 |
data subblocks have been output.</p><p>Note that EGifPutExtensionLeader needs to be called before any |
| 399 |
calls to this function. EGifPutExtensionTrailer should be called to |
| 400 |
finish the Extension block after all data subblocks have been |
| 401 |
output.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="EGifPutExtensionTrailer"></a><pre class="programlisting"> |
| 402 |
int EGifPutExtensionTrailer( |
| 403 |
GifFileType * GifFile, |
| 404 |
const VoidPtr GifExtension) |
| 405 |
</pre><p>Dumps the GIF extension block terminator to a GIF File to end |
| 406 |
the current Extension block.</p><p>Note that a call to EGifPutExtensionLeader is needed to open the GIF |
| 407 |
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"> |
| 408 |
int EGifPutCode( |
| 409 |
GifFileType *GifFile, |
| 410 |
int *GifCodeSize, |
| 411 |
ByteType **GifCodeBlock) |
| 412 |
</pre><p>It sometimes may be desired to write the compressed code as is |
| 413 |
without decoding it. For example a filter for a GIF file that change |
| 414 |
only screen size (GifPos), does not need the exact pixel values. |
| 415 |
Piping out the compressed image as is makes this process much |
| 416 |
faster.</p><p>This routine does exactly that (with EGifPutCodeNext), and can be |
| 417 |
used instead of EGifPutLine. You'll usually use this with the |
| 418 |
DGifGetCode/DGifGetCodeNext routines, which reads the compressed |
| 419 |
code, while EGifPutCode/EGifPutCodeNext write it out. See gifpos.c |
| 420 |
for example.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise.</p><a id="EGifPutCodeNext"></a><pre class="programlisting"> |
| 421 |
int EGifPutCodeNext(GifFileType *GifFile, ByteType **GifCodeBlock) |
| 422 |
</pre><p>See EGifPutCode above.</p><a id="EGifCloseFile"></a><pre class="programlisting"> |
| 423 |
int EGifCloseFile(GifFileType *GifFile) |
| 424 |
</pre><p>Write a termination block to the GIF, close the GIF file, and |
| 425 |
free all memory allocated for managing it. GifFile should not be used |
| 426 |
after this routine has been called.</p><p>Returns GIF_ERROR if something went wrong, GIF_OK otherwise. When |
| 427 |
GIF_ERROR is returned, the diagnostic error code is left in ErrorCode. |
| 428 |
The GifFile structure is unconditionally freed.</p><p>(Note: In versions before 5.1.0, the ErrorCode argument was |
| 429 |
absent and the GifFile structure was not freed so that the |
| 430 |
diagnostic error code will remain accessible in GifFile->Error. |
| 431 |
This behavior was changed because it caused problems for the |
| 432 |
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 |
| 433 |
of read/write function hooks, the DGifSlurp()/EGifSpew() interface has |
| 434 |
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 |
| 435 |
in order to make the library fully reentrant and thread-safe - earlier library |
| 436 |
versions did not feature the final pointer-to-error-code argument in |
| 437 |
DGifOpen() and friends. For the same reason, the static storage queried by |
| 438 |
GifLastError() in older versions is gone, and that function abolished.</p><p>The library header contains some version #defines you can use if you |
| 439 |
need to condition your code so it can compile with different library |
| 440 |
versions</p><p>Versions up to 4.1.6 defined a GIF_LIB_VERSION macro that was |
| 441 |
string-valued with a tricky format to parse. This macro has been |
| 442 |
retired.</p><p>Versions after 4.1.6 define integer-valued GIFLIB_MAJOR, GIFLIB_MINOR, |
| 443 |
and GIFLIB_RELEASE macros for the three components of the version. See the |
| 444 |
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 |
| 445 |
EGifGCBToSavedExtension() make it easy to read and edit GIF89 graphics |
| 446 |
control blocks in saved images.</p></li><li class="listitem"><p>The new function DGifGetGifVersion() is convenient |
| 447 |
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="id1356"></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 |
| 448 |
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, |
| 449 |
EGif, or Gif as a name prefix.</p></li><li class="listitem"><p>The default GIF version to write is now computed at |
| 450 |
write time from the types of an image's extension blocks. (Formerly |
| 451 |
EGifSpew() behaved this way, but the sequential-writing code didn't.) |
| 452 |
The result of this computation is available through the new function |
| 453 |
EGifGetGifVersion().</p></li></ul></div></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="id1357"></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(), |
| 454 |
DGifOpenFileHandle(), DGifOpen(), DGifClose(), EGifOpenFileName(), |
| 455 |
EGifOpenFileHandle(), EGifOpen(), and EGifClose() - all now take a |
| 456 |
final integer address argument. If non-null, this is used to pass |
| 457 |
back an error code when the function returns NULL.</p></li><li class="listitem"><p>EGifSlurp() and EGifSpew() read and write |
| 458 |
extension blocks trailing after the last image, handle interlaced |
| 459 |
images properly.</p></li><li class="listitem"><p>EGifPutExtensionFirst() has been replaced by |
| 460 |
EGifPutExtensionLeader(); the difference is the new function doesn't |
| 461 |
take an optional block, it just writes a block |
| 462 |
leader.</p></li><li class="listitem"><p>EGifPutExtensionNext() has been replaced by |
| 463 |
EGifPutExtensionBlock(); the difference is that the new function does |
| 464 |
not take and then discard a function code argument.</p></li><li class="listitem"><p>EGifPutExtensionLast() has been replaced by |
| 465 |
EGifPutExtensionTrailer(); all it does is write the terminator |
| 466 |
block. Split your old EGifPutExtensionLast() calls into |
| 467 |
EGifPutExtensionBlock() followed by |
| 468 |
EGifPutExtensionTrailer().</p></li></ul></div></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="id1358"></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. |
| 469 |
AddExtensionBlock() is now GifAddExtensionBlock(), and takes an additional |
| 470 |
function code argument. ApplyTranslation() is now GifApplyTranslation(); |
| 471 |
FreeExtension() has become GifFreeExtensions() and takes a different argument |
| 472 |
type; MakeSavedImage() is now GifMakeSavedImage(), FreeSavedImages() is |
| 473 |
now GifFreeSavedImages(), and BitSize() is now GifBitSize().</p></li><li class="listitem"><p>Three documented functions - MakeMapObject(), |
| 474 |
FreeMapObject(), and UnionColorMap() - have been renamed to |
| 475 |
GifMakeMapObject(), GifFreeMapObject(), and GifUnionColorMap() |
| 476 |
respectively.</p></li></ul></div></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a id="id1359"></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 |
| 477 |
store the last error code registered; that made the library |
| 478 |
thread-unsafe.</p></li><li class="listitem"><p>For functions other than GIF file openers, the Error |
| 479 |
code is now put in an Error member of the GifFileType |
| 480 |
structure.</p></li><li class="listitem"><p>The GifError() and |
| 481 |
GifLastError() functions that referenced that static cell are gone, |
| 482 |
and the GifErrorString() function introduced in the 4.2 release now |
| 483 |
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="id1360"></a>Skeletons of GIF filters</h2></div></div></div><p>If you are developing on a virtual-memory OS such as most flavors of |
| 484 |
UNIX, or are otherwise sure of having enough memory to keep all of GIFs you |
| 485 |
need to operate in core, writing a filter is trivial. See the file |
| 486 |
gifsponge.c in util.</p><p>A sequential filter skeleton will usually look like the example file |
| 487 |
giffilter.c in util.</p><p>Please look at the utilities in the util directory for more ideas once |
| 488 |
you feel comfortable with these skeletons. Also try to follow the coding |
| 489 |
standards of this package if you want the maintainer to officially add your new |
| 490 |
utility to it.</p></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id1361"></a>Unimplemented features</h2></div></div></div><p>Some features of the original GIF specification have not stood the |
| 491 |
test of time. This library mostly ignores them, but they are described |
| 492 |
here for completeness.</p><p>The GIF standard fails to be explicit about a small but crucial detail: |
| 493 |
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 |
| 494 |
would render multiple images in a GIF on a common canvas, giving an effect like |
| 495 |
a picture wall. The 'logical screen descriptor block' (LSDB), 6 bytes right |
| 496 |
after the 6-byte GIF stamp and version header at the beginning of a |
| 497 |
GIF file, includes both two-byte canvas width and canvas height |
| 498 |
fields and a canvas background color. Each image, besides height and |
| 499 |
width, also has 'left' and 'top' coordinates specifying where it is to |
| 500 |
be placed on the canvas.</p><p>GIFLIB can read and set these fields; the gifpos and giftool |
| 501 |
utilities will enable you to script such changes. But browsers and |
| 502 |
modern image viewers ignore them. Nowadays multiple-image GIFs are |
| 503 |
generally used either as animations in which each sub-image is a frame |
| 504 |
or as image libraries, with the GIF client handling compositing into |
| 505 |
some canvas about which the GIF format holds no information.</p><p>Another feature of the LSDB that is generally ignored is the |
| 506 |
pixel aspect ratio byte. Until 5.0, GIFLIB ignored this flag on input |
| 507 |
and zeroed it on output; now it is read and preserved if present. The |
| 508 |
GIF standard doesn't give a rationale for it, but it seems likely that |
| 509 |
the designers intended it for representing image captures from the |
| 510 |
analog television of the day, which had rectangular pixel-equivalents.</p><p>Yet another ignored feature of both the LSDB and sub-images is |
| 511 |
the sort flag, which is supposed to signal whether the colors in the |
| 512 |
associated color map are sorted by decreasing importance in case the |
| 513 |
display device can only render a limited number of them. This feature |
| 514 |
reflected the high cost of dual-port memory at the time the GIF |
| 515 |
specification was written in the late 1980s. That kind of limit |
| 516 |
disappeared in the mid-1990s. Until 5.0, GIFLIB ignored this flag on |
| 517 |
input and zeroed it on output; now it is read and preserved if |
| 518 |
present.</p><p>Finally, the plaintext extension block. This is an extension block |
| 519 |
that contains instructions for overlaying text captions on a following image. |
| 520 |
GIFLIB treats these blocks as raw data, not attempting to parse out the |
| 521 |
location and text data.</p></div></div></body></html> |