annotate src/gif_io.c @ 308:33bdb3d4b97f r21-0b52

Import from CVS: tag r21-0b52
author cvs
date Mon, 13 Aug 2007 10:42:44 +0200
parents
children 74fd4e045ea6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
308
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
1 #include <stdio.h>
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
2 #include <stdlib.h>
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
3 #include <string.h>
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
4 #include <unistd.h>
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
5 #include "gifrlib.h"
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
6
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
7 /******************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
8 * Set up the GifFileType structure for use. This must be called first in any *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
9 * client program. Then, if custom IO or Error functions are desired, call *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
10 * GifSetIOFunc/GifSetErrorFunc, then call EGifInitWrite. Else call *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
11 * EGifOpenFileName or EGifOpenFileHandle for standard IO functions. *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
12 * If setup fails, a NULL pointer is returned. *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
13 ******************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
14 GifFileType *GifSetup(void)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
15 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
16 GifIODataType *GifIO;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
17 GifFileType *GifFile;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
18
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
19 if ((GifFile = (GifFileType *) malloc(sizeof(GifFileType))) == NULL)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
20 return NULL;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
21 memset(GifFile, '\0', sizeof(GifFileType));
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
22 if ((GifIO = (GifIODataType *) malloc(sizeof(GifIODataType))) == NULL) {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
23 free((char *) GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
24 return NULL;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
25 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
26 memset(GifIO, '\0', sizeof(GifIODataType));
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
27 GifFile->GifIO = GifIO;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
28 return GifFile;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
29 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
30
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
31 void GifFree(GifFileType *GifFile)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
32 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
33 GifFilePrivateType *Private;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
34
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
35 if (GifFile == NULL) return;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
36
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
37 Private = (GifFilePrivateType *) GifFile->Private;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
38
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
39 if (GifFile->SavedImages)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
40 FreeSavedImages(GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
41 if (GifFile->Image.ColorMap)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
42 FreeMapObject(GifFile->Image.ColorMap);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
43 if (GifFile->SColorMap)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
44 FreeMapObject(GifFile->SColorMap);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
45 if (Private)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
46 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
47 free(Private);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
48 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
49 if (GifFile->GifIO)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
50 free(GifFile->GifIO);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
51 free(GifFile);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
52 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
53
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
54 /****************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
55 * Install the specified ReadFunction into the GifFile specified. *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
56 ****************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
57 void GifSetReadFunc(GifFileType *GifFile, Gif_rw_func ReadFunc, VoidPtr data)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
58 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
59 GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
60 GifIO->ReadFunc = ReadFunc;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
61 GifIO->ReadFunc_data = data;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
62 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
63
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
64 /****************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
65 * Install the specified WriteFunction into the GifFile specified. *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
66 ****************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
67 void GifSetWriteFunc(GifFileType *GifFile, Gif_rw_func WriteFunc, VoidPtr data)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
68 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
69 GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
70 GifIO->WriteFunc = WriteFunc;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
71 GifIO->WriteFunc_data = data;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
72 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
73
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
74 /****************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
75 * Install the specified CloseFunction into the GifFile specified. *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
76 ****************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
77 void GifSetCloseFunc(GifFileType *GifFile, Gif_close_func CloseFunc, VoidPtr data)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
78 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
79 GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
80 GifIO->CloseFunc = CloseFunc;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
81 GifIO->CloseFunc_data = data;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
82 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
83
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
84 /****************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
85 * Install the standard IO funcs into the GifFile, including the FILE info *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
86 ****************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
87 void GifStdIOInit(GifFileType *GifFile, FILE *file, int filehandle)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
88 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
89 GifStdIODataType *IOData;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
90
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
91 if ((IOData = (GifStdIODataType*)malloc(sizeof(GifStdIODataType))) == NULL)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
92 GifInternError(GifFile, GIF_ERR_NOT_ENOUGH_MEM);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
93 IOData->File = file;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
94 IOData->FileHandle = filehandle;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
95 GifSetReadFunc(GifFile, GifStdRead, IOData);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
96 GifSetWriteFunc(GifFile, GifStdWrite, IOData);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
97 GifSetCloseFunc(GifFile, GifStdFileClose, IOData);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
98 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
99
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
100 size_t GifStdRead(GifByteType *buf, size_t size, VoidPtr method_data)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
101 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
102 GifStdIODataType *IOtype = (GifStdIODataType*)method_data;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
103 return (fread(buf, 1, size, IOtype->File));
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
104 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
105
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
106 size_t GifStdWrite(GifByteType *buf, size_t size, VoidPtr method_data)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
107 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
108 GifStdIODataType *IOtype = (GifStdIODataType*)method_data;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
109 return (fwrite(buf, 1, size, IOtype->File));
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
110 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
111
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
112 int GifStdFileClose(VoidPtr method_data)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
113 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
114 int ret;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
115 GifStdIODataType *IOtype = (GifStdIODataType*)method_data;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
116 ret = fclose(IOtype->File);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
117 if (ret == 0 && IOtype->FileHandle != -1)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
118 ret = close(IOtype->FileHandle);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
119 return ret;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
120 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
121
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
122 void GifRead(GifByteType *buf, size_t size, GifFileType *GifFile)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
123 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
124 GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
125 if ((*(GifIO->ReadFunc))(buf, size, GifIO->ReadFunc_data) != size)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
126 GifError(GifFile, "Read error!");
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
127 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
128
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
129 void GifWrite(GifByteType *buf, size_t size, GifFileType *GifFile)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
130 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
131 GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
132 if ((*(GifIO->WriteFunc))(buf, size, GifIO->WriteFunc_data) != size)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
133 GifError(GifFile, "Write error!");
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
134 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
135
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
136 int GifClose(GifFileType *GifFile)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
137 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
138 GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
139 return ((*(GifIO->CloseFunc))(GifIO->CloseFunc_data));
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
140 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
141
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
142 static char *GifErrorString[14] = {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
143 "Failed to open given file", /* D_GIF_ERR_OPEN_FAILED */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
144 "Failed to read from given file", /* D_GIF_ERR_READ_FAILED */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
145 "Given file is NOT a GIF file", /* D_GIF_ERR_NOT_GIF_FILE */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
146 "No Screen Descriptor detected", /* D_GIF_ERR_NO_SCRN_DSCR */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
147 "No Image Descriptor detected", /* D_GIF_ERR_NO_IMAG_DSCR */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
148 "No global or local color map", /* D_GIF_ERR_NO_COLOR_MAP */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
149 "Wrong record type detected", /* D_GIF_ERR_WRONG_RECORD */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
150 "#Pixels bigger than Width * Height", /* D_GIF_ERR_DATA_TOO_BIG */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
151 "Fail to allocate required memory", /* D_GIF_ERR_NOT_ENOUGH_MEM */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
152 "Failed to close given file", /* D_GIF_ERR_CLOSE_FAILED */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
153 "Given file was not opened for read", /* D_GIF_ERR_CLOSE_FAILED */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
154 "Image is defective, decoding aborted", /* D_GIF_ERR_IMAGE_DEFECT */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
155 "Image EOF detected before image complete", /* D_GIF_ERR_EOF_TOO_SOON */
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
156 "Undefined error!",
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
157 };
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
158
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
159 const char *GetGifError(int error);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
160
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
161 /*****************************************************************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
162 * Get the last GIF error in human-readable form. *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
163 *****************************************************************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
164 const char *GetGifError(int error)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
165 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
166 char *Err;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
167
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
168 switch(error) {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
169 case D_GIF_ERR_OPEN_FAILED:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
170 Err = GifErrorString[0];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
171 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
172 case D_GIF_ERR_READ_FAILED:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
173 Err = GifErrorString[1];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
174 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
175 case D_GIF_ERR_NOT_GIF_FILE:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
176 Err = GifErrorString[2];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
177 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
178 case D_GIF_ERR_NO_SCRN_DSCR:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
179 Err = GifErrorString[3];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
180 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
181 case D_GIF_ERR_NO_IMAG_DSCR:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
182 Err = GifErrorString[4];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
183 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
184 case D_GIF_ERR_NO_COLOR_MAP:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
185 Err = GifErrorString[5];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
186 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
187 case D_GIF_ERR_WRONG_RECORD:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
188 Err = GifErrorString[6];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
189 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
190 case D_GIF_ERR_DATA_TOO_BIG:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
191 Err = GifErrorString[7];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
192 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
193 case D_GIF_ERR_NOT_ENOUGH_MEM:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
194 Err = GifErrorString[8];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
195 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
196 case D_GIF_ERR_CLOSE_FAILED:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
197 Err = GifErrorString[9];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
198 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
199 case D_GIF_ERR_NOT_READABLE:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
200 Err = GifErrorString[10];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
201 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
202 case D_GIF_ERR_IMAGE_DEFECT:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
203 Err = GifErrorString[11];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
204 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
205 case D_GIF_ERR_EOF_TOO_SOON:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
206 Err = GifErrorString[12];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
207 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
208 default:
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
209 Err = GifErrorString[13];
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
210 break;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
211 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
212 return Err;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
213 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
214
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
215 /******************************
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
216 * These are called internally *
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
217 ******************************/
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
218 void GifError(GifFileType *GifFile, const char *err_str)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
219 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
220 GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
221 if (GifIO->ErrorFunc)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
222 (*(GifIO->ErrorFunc))(err_str, GifIO->ErrorFunc_data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
223 else
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
224 fprintf(stderr, "GIF FATAL ERROR: %s", err_str);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
225 exit(-10);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
226 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
227
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
228 void GifWarning(GifFileType *GifFile, const char *err_str)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
229 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
230 GifIODataType *GifIO = (GifIODataType*)GifFile->GifIO;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
231 if (GifIO->WarningFunc)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
232 (*(GifIO->WarningFunc))(err_str, GifIO->WarningFunc_data);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
233 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
234
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
235 void GifInternError(GifFileType *GifFile, int error_num)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
236 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
237 const char *ErrStr = GetGifError(error_num);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
238 GifError(GifFile, ErrStr);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
239 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
240
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
241 void GifInternWarning(GifFileType *GifFile, int error_num)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
242 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
243 const char *ErrStr = GetGifError(error_num);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
244 GifWarning(GifFile, ErrStr);
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
245 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
246
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
247 void GifSetErrorFunc(GifFileType *GifFile, Gif_error_func ErrorFunc, VoidPtr data)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
248 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
249 GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
250 GifIO->ErrorFunc = ErrorFunc;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
251 GifIO->ErrorFunc_data = data;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
252 }
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
253
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
254 void GifSetWarningFunc(GifFileType *GifFile, Gif_error_func WarningFunc, VoidPtr data)
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
255 {
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
256 GifIODataType *GifIO = (GifIODataType *)GifFile->GifIO;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
257 GifIO->WarningFunc = WarningFunc;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
258 GifIO->WarningFunc_data = data;
33bdb3d4b97f Import from CVS: tag r21-0b52
cvs
parents:
diff changeset
259 }