annotate src/gif_io.c @ 490:38fb9ae12edd

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