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