annotate src/dgif_lib.c @ 247:e70b3a057e12 r20-5b22

Import from CVS: tag r20-5b22
author cvs
date Mon, 13 Aug 2007 10:18:21 +0200
parents 850242ba4a81
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 * "Gif-Lib" - Yet another gif library. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 * *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 * Written by: Gershon Elber IBM PC Ver 1.1, Aug. 1990 *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 *******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 * The kernel of the GIF Decoding process can be found here. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 *******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 * History: *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 * 16 Jun 89 - Version 1.0 by Gershon Elber. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 * 3 Sep 90 - Version 1.1 by Gershon Elber (Support for Gif89, Unique names). *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
15 #ifdef emacs
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
16 #include <config.h>
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
17 #endif /* emacs */
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
18
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 #ifdef __MSDOS__
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 #include <io.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 #include <alloc.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 #include <stdlib.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 #include <sys\stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include <sys/types.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include <sys/stat.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #endif /* __MSDOS__ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include <fcntl.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include <stdio.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #include <string.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include "gif_lib.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 #ifndef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include "gif_hash.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
187
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
38 #ifdef emacs
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
39 void *xmalloc (size_t size);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
40 void *xrealloc (void *ptr, size_t size);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
41 #ifdef ERROR_CHECK_MALLOC
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
42 void *xfree_1 (void *);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
43 #define xfree xfree_1
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
44 #else
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
45 void *xfree (void *);
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
46 #endif
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
47 #endif /* emacs */
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
48
b405438285a2 Import from CVS: tag r20-3b20
cvs
parents: 185
diff changeset
49
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #define PROGRAM_NAME "GIF_LIBRARY"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #define COMMENT_EXT_FUNC_CODE 0xfe /* Extension function code for comment. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #define GIF_STAMP "GIFVER" /* First chars in file - GIF stamp. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #define GIF_VERSION_POS 3 /* Version first character in stamp. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #define LZ_MAX_CODE 4095 /* Biggest code possible in 12 bits. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 #define LZ_BITS 12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 #define FILE_STATE_READ 0x01/* 1 write, 0 read - EGIF_LIB compatible.*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 #define FLUSH_OUTPUT 4096 /* Impossible code, to signal flush. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #define FIRST_CODE 4097 /* Impossible code, to signal first. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 #define NO_SUCH_CODE 4098 /* Impossible code, to signal empty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 #define IS_READABLE(Private) (!(Private->FileState & FILE_STATE_READ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 typedef struct GifFilePrivateType {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 int FileState,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 FileHandle, /* Where all this data goes to! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 BitsPerPixel, /* Bits per pixel (Codes uses at list this + 1). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ClearCode, /* The CLEAR LZ code. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 EOFCode, /* The EOF LZ code. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 RunningCode, /* The next code algorithm can generate. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 RunningBits,/* The number of bits required to represent RunningCode. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 MaxCode1, /* 1 bigger than max. possible code, in RunningBits bits. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 LastCode, /* The code before the current code. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 CrntCode, /* Current algorithm code. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 StackPtr, /* For character stack (see below). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 CrntShiftState; /* Number of bits in CrntShiftDWord. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 unsigned long CrntShiftDWord; /* For bytes decomposition into codes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 long PixelCount; /* Number of pixels in image. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 FILE *File; /* File as stream. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 GifByteType Buf[256]; /* Compressed input is buffered here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 GifByteType Stack[LZ_MAX_CODE]; /* Decoded pixels are stacked here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 GifByteType Suffix[LZ_MAX_CODE+1]; /* So we can trace the codes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 unsigned int Prefix[LZ_MAX_CODE+1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 } GifFilePrivateType;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 #ifndef emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 #ifdef SYSV
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 static char *VersionStr =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 "Gif library module,\t\tGershon Elber\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (C) Copyright 1989 Gershon Elber, Non commercial use only.\n";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 static char *VersionStr =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 PROGRAM_NAME
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 " IBMPC "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 GIF_LIB_VERSION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 " Gershon Elber, "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 __DATE__ ", " __TIME__ "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "(C) Copyright 1989 Gershon Elber, Non commercial use only.\n";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 #endif /* SYSV */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 #endif /* !emacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 extern int _GifError;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 static int DGifGetWord(FILE *File, int *Word);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 static int DGifSetupDecompress(GifFileType *GifFile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 static int DGifDecompressLine(GifFileType *GifFile, GifPixelType *Line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 int LineLen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 static int DGifGetPrefixChar(unsigned int *Prefix, int Code, int ClearCode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 static int DGifDecompressInput(GifFilePrivateType *Private, int *Code);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 static int DGifBufferedInput(FILE *File, GifByteType *Buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 GifByteType *NextByte);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 * Open a new gif file for read, given by its name. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 * Returns GifFileType pointer dynamically allocated which serves as the gif *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 * info record. _GifError is cleared if succesfull. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ******************************************************************************/
203
850242ba4a81 Import from CVS: tag r20-3b28
cvs
parents: 187
diff changeset
122 GifFileType *DGifOpenFileName(CONST char *FileName)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 int FileHandle;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 if ((FileHandle = open(FileName, O_RDONLY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 #ifdef __MSDOS__
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 | O_BINARY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 #endif /* __MSDOS__ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 )) == -1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 _GifError = D_GIF_ERR_OPEN_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 return DGifOpenFileHandle(FileHandle);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 * Update a new gif file, given its file handle. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 * Returns GifFileType pointer dynamically allocated which serves as the gif *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 * info record. _GifError is cleared if succesfull. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 GifFileType *DGifOpenFileHandle(int FileHandle)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 char Buf[GIF_STAMP_LEN+1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 GifFileType *GifFile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 GifFilePrivateType *Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 FILE *f;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 #ifdef __MSDOS__
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 setmode(FileHandle, O_BINARY); /* Make sure it is in binary mode. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 f = fdopen(FileHandle, "rb"); /* Make it into a stream: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 setvbuf(f, NULL, _IOFBF, GIF_FILE_BUFFER_SIZE);/* And inc. stream buffer.*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 f = fdopen(FileHandle, "r"); /* Make it into a stream: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 #endif /* __MSDOS__ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 if ((GifFile = (GifFileType *) xmalloc(sizeof(GifFileType))) == NULL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 _GifError = D_GIF_ERR_NOT_ENOUGH_MEM;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 memset(GifFile, '\0', sizeof(GifFileType));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 if ((Private = (GifFilePrivateType *) xmalloc(sizeof(GifFilePrivateType)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 == NULL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 _GifError = D_GIF_ERR_NOT_ENOUGH_MEM;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 xfree((char *) GifFile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 GifFile->Private = (VoidPtr) Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 Private->FileHandle = FileHandle;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 Private->File = f;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 Private->FileState = 0; /* Make sure bit 0 = 0 (File open for read). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 /* Lets see if this is a GIF file: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 if (fread(Buf, 1, GIF_STAMP_LEN, Private->File) != GIF_STAMP_LEN) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 xfree((char *) Private);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 xfree((char *) GifFile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 /* The GIF Version number is ignored at this time. Maybe we should do */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 /* something more useful with it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 Buf[GIF_STAMP_LEN] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 if (strncmp(GIF_STAMP, Buf, GIF_VERSION_POS) != 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 _GifError = D_GIF_ERR_NOT_GIF_FILE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 xfree((char *) Private);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 xfree((char *) GifFile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 if (DGifGetScreenDesc(GifFile) == GIF_ERROR) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 xfree((char *) Private);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 xfree((char *) GifFile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 return NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 _GifError = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 return GifFile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 * This routine should be called before any other DGif calls. Note that *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 * this routine is called automatically from DGif file open routines. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 int DGifGetScreenDesc(GifFileType *GifFile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 int i, BitsPerPixel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 GifByteType Buf[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 if (!IS_READABLE(Private)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 /* This file was NOT open for reading: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 _GifError = D_GIF_ERR_NOT_READABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 /* Put the screen descriptor into the file: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 if (DGifGetWord(Private->File, &GifFile->SWidth) == GIF_ERROR ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 DGifGetWord(Private->File, &GifFile->SHeight) == GIF_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 if (fread(Buf, 1, 3, Private->File) != 3) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 GifFile->SColorResolution = ((int) ((Buf[0] & 0x70) + 1) >> 4) + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 BitsPerPixel = (Buf[0] & 0x07) + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 GifFile->SBackGroundColor = Buf[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 if (Buf[0] & 0x80) { /* Do we have global color map? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 GifFile->SColorMap = MakeMapObject(1 << BitsPerPixel, NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 /* Get the global color map: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 for (i = 0; i < GifFile->SColorMap->ColorCount; i++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 if (fread(Buf, 1, 3, Private->File) != 3) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 GifFile->SColorMap->Colors[i].Red = Buf[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 GifFile->SColorMap->Colors[i].Green = Buf[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 GifFile->SColorMap->Colors[i].Blue = Buf[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 }
129
e292c9648bb9 Import from CVS: tag xemacs-20-1p3
cvs
parents: 114
diff changeset
247 } else {
e292c9648bb9 Import from CVS: tag xemacs-20-1p3
cvs
parents: 114
diff changeset
248 /* XEmacs assumes we always have a colormap */
e292c9648bb9 Import from CVS: tag xemacs-20-1p3
cvs
parents: 114
diff changeset
249 GifFile->SColorMap = MakeMapObject(2, NULL);
e292c9648bb9 Import from CVS: tag xemacs-20-1p3
cvs
parents: 114
diff changeset
250 GifFile->SColorMap->Colors[0].Red = 0;
e292c9648bb9 Import from CVS: tag xemacs-20-1p3
cvs
parents: 114
diff changeset
251 GifFile->SColorMap->Colors[0].Green = 0;
e292c9648bb9 Import from CVS: tag xemacs-20-1p3
cvs
parents: 114
diff changeset
252 GifFile->SColorMap->Colors[0].Blue = 0;
e292c9648bb9 Import from CVS: tag xemacs-20-1p3
cvs
parents: 114
diff changeset
253 GifFile->SColorMap->Colors[1].Red = 0xff;
e292c9648bb9 Import from CVS: tag xemacs-20-1p3
cvs
parents: 114
diff changeset
254 GifFile->SColorMap->Colors[1].Green = 0xff;
e292c9648bb9 Import from CVS: tag xemacs-20-1p3
cvs
parents: 114
diff changeset
255 GifFile->SColorMap->Colors[1].Blue = 0xff;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 * This routine should be called before any attemp to read an image. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 int DGifGetRecordType(GifFileType *GifFile, GifRecordType *Type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 GifByteType Buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 if (!IS_READABLE(Private)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 /* This file was NOT open for reading: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 _GifError = D_GIF_ERR_NOT_READABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 if (fread(&Buf, 1, 1, Private->File) != 1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 switch (Buf) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 case ',':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 *Type = IMAGE_DESC_RECORD_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 case '!':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 *Type = EXTENSION_RECORD_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 case ';':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 *Type = TERMINATE_RECORD_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 *Type = UNDEFINED_RECORD_TYPE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 _GifError = D_GIF_ERR_WRONG_RECORD;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 * This routine should be called before any attemp to read an image. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 * Note it is assumed the Image desc. header (',') has been read. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 int DGifGetImageDesc(GifFileType *GifFile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 int i, BitsPerPixel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 GifByteType Buf[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 if (!IS_READABLE(Private)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 /* This file was NOT open for reading: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 _GifError = D_GIF_ERR_NOT_READABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 if (DGifGetWord(Private->File, &GifFile->Image.Left) == GIF_ERROR ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 DGifGetWord(Private->File, &GifFile->Image.Top) == GIF_ERROR ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 DGifGetWord(Private->File, &GifFile->Image.Width) == GIF_ERROR ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 DGifGetWord(Private->File, &GifFile->Image.Height) == GIF_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 if (fread(Buf, 1, 1, Private->File) != 1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 BitsPerPixel = (Buf[0] & 0x07) + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 GifFile->Image.Interlace = (Buf[0] & 0x40);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 if (Buf[0] & 0x80) { /* Does this image have local color map? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 if (GifFile->Image.ColorMap && GifFile->SavedImages == NULL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 FreeMapObject(GifFile->Image.ColorMap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 GifFile->Image.ColorMap = MakeMapObject(1 << BitsPerPixel, NULL);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
332
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 /* Get the image local color map: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 for (i = 0; i < GifFile->Image.ColorMap->ColorCount; i++) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 if (fread(Buf, 1, 3, Private->File) != 3) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 GifFile->Image.ColorMap->Colors[i].Red = Buf[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 GifFile->Image.ColorMap->Colors[i].Green = Buf[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 GifFile->Image.ColorMap->Colors[i].Blue = Buf[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 if (GifFile->SavedImages) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 SavedImage *sp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 if ((GifFile->SavedImages = (SavedImage *)xrealloc(GifFile->SavedImages,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 sizeof(SavedImage) * (GifFile->ImageCount + 1))) == NULL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 _GifError = D_GIF_ERR_NOT_ENOUGH_MEM;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 sp = &GifFile->SavedImages[GifFile->ImageCount];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 memcpy(&sp->ImageDesc, &GifFile->Image, sizeof(GifImageDesc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 if (GifFile->Image.ColorMap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 sp->ImageDesc.ColorMap =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 MakeMapObject (GifFile->Image.ColorMap->ColorCount,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 GifFile->Image.ColorMap->Colors);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 sp->RasterBits = (GifPixelType *)NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 sp->ExtensionBlockCount = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 sp->ExtensionBlocks = (ExtensionBlock *)NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 GifFile->ImageCount++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 Private->PixelCount = (long) GifFile->Image.Width *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (long) GifFile->Image.Height;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 DGifSetupDecompress(GifFile); /* Reset decompress algorithm parameters. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 * Get one full scanned line (Line) of length LineLen from GIF file. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 int DGifGetLine(GifFileType *GifFile, GifPixelType *Line, int LineLen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 GifByteType *Dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 if (!IS_READABLE(Private)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 /* This file was NOT open for reading: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 _GifError = D_GIF_ERR_NOT_READABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 if (!LineLen) LineLen = GifFile->Image.Width;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 #ifdef __MSDOS__
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 if ((Private->PixelCount -= LineLen) > 0xffff0000UL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 if ((unsigned) (Private->PixelCount -= LineLen) > 0xffff0000) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 #endif /* __MSDOS__ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 _GifError = D_GIF_ERR_DATA_TOO_BIG;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 if (DGifDecompressLine(GifFile, Line, LineLen) == GIF_OK) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 if (Private->PixelCount == 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 /* We probably would not be called any more, so lets clean */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 /* everything before we return: need to flush out all rest of */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 /* image until empty block (size 0) detected. We use GetCodeNext.*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 do if (DGifGetCodeNext(GifFile, &Dummy) == GIF_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 while (Dummy != NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 * Put one pixel (Pixel) into GIF file. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 int DGifGetPixel(GifFileType *GifFile, GifPixelType Pixel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 GifByteType *Dummy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 if (!IS_READABLE(Private)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 /* This file was NOT open for reading: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 _GifError = D_GIF_ERR_NOT_READABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 #ifdef __MSDOS__
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 if (--Private->PixelCount > 0xffff0000UL)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 if ((unsigned) --Private->PixelCount > 0xffff0000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 #endif /* __MSDOS__ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 _GifError = D_GIF_ERR_DATA_TOO_BIG;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 if (DGifDecompressLine(GifFile, &Pixel, 1) == GIF_OK) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 if (Private->PixelCount == 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 /* We probably would not be called any more, so lets clean */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 /* everything before we return: need to flush out all rest of */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 /* image until empty block (size 0) detected. We use GetCodeNext.*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 do if (DGifGetCodeNext(GifFile, &Dummy) == GIF_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 while (Dummy != NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 * Get an extension block (see GIF manual) from gif file. This routine only *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 * returns the first data block, and DGifGetExtensionNext shouldbe called *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 * after this one until NULL extension is returned. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 * The Extension should NOT be freed by the user (not dynamically allocated).*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 * Note it is assumed the Extension desc. header ('!') has been read. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 int DGifGetExtension(GifFileType *GifFile, int *ExtCode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 GifByteType **Extension)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 GifByteType Buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 if (!IS_READABLE(Private)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 /* This file was NOT open for reading: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 _GifError = D_GIF_ERR_NOT_READABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 if (fread(&Buf, 1, 1, Private->File) != 1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 *ExtCode = Buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 return DGifGetExtensionNext(GifFile, Extension);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 * Get a following extension block (see GIF manual) from gif file. This *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 * routine sould be called until NULL Extension is returned. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 * The Extension should NOT be freed by the user (not dynamically allocated).*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **Extension)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 GifByteType Buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 if (fread(&Buf, 1, 1, Private->File) != 1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 if (Buf > 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 *Extension = Private->Buf; /* Use private unused buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (*Extension)[0] = Buf; /* Pascal strings notation (pos. 0 is len.). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 if (fread(&((*Extension)[1]), 1, Buf, Private->File) != Buf) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 *Extension = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 * This routine should be called last, to close the GIF file. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 int DGifCloseFile(GifFileType *GifFile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 GifFilePrivateType *Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 FILE *File;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 if (GifFile == NULL) return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 if (!IS_READABLE(Private)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 /* This file was NOT open for reading: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 _GifError = D_GIF_ERR_NOT_READABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 File = Private->File;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 if (GifFile->Image.ColorMap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 FreeMapObject(GifFile->Image.ColorMap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 GifFile->Image.ColorMap = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 if (GifFile->SColorMap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 FreeMapObject(GifFile->SColorMap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 GifFile->SColorMap = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 if (Private)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 xfree((char *) Private);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 GifFile->Private = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 if (GifFile->SavedImages)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 FreeSavedImages(GifFile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 GifFile->SavedImages = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 xfree(GifFile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 if (fclose(File) != 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 _GifError = D_GIF_ERR_CLOSE_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 * Get 2 bytes (word) from the given file: *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 static int DGifGetWord(FILE *File, int *Word)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 unsigned char c[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 if (fread(c, 1, 2, File) != 2) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 *Word = (((unsigned int) c[1]) << 8) + c[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 * Get the image code in compressed form. his routine can be called if the *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 * information needed to be piped out as is. Obviously this is much faster *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 * than decoding and encoding again. This routine should be followed by calls *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 * to DGifGetCodeNext, until NULL block is returned. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 * The block should NOT be freed by the user (not dynamically allocated). *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 int DGifGetCode(GifFileType *GifFile, int *CodeSize, GifByteType **CodeBlock)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 if (!IS_READABLE(Private)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 /* This file was NOT open for reading: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 _GifError = D_GIF_ERR_NOT_READABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 *CodeSize = Private->BitsPerPixel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 return DGifGetCodeNext(GifFile, CodeBlock);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 * Continue to get the image code in compressed form. This routine should be *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 * called until NULL block is returned. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 * The block should NOT be freed by the user (not dynamically allocated). *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 int DGifGetCodeNext(GifFileType *GifFile, GifByteType **CodeBlock)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 GifByteType Buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 if (fread(&Buf, 1, 1, Private->File) != 1) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 if (Buf > 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 *CodeBlock = Private->Buf; /* Use private unused buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (*CodeBlock)[0] = Buf; /* Pascal strings notation (pos. 0 is len.). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 if (fread(&((*CodeBlock)[1]), 1, Buf, Private->File) != Buf) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 *CodeBlock = NULL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 Private->Buf[0] = 0; /* Make sure the buffer is empty! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 Private->PixelCount = 0; /* And local info. indicate image read. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 * Setup the LZ decompression for this image: *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 static int DGifSetupDecompress(GifFileType *GifFile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 int i, BitsPerPixel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 GifByteType CodeSize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 unsigned int *Prefix;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 fread(&CodeSize, 1, 1, Private->File); /* Read Code size from file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 BitsPerPixel = CodeSize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 Private->Buf[0] = 0; /* Input Buffer empty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 Private->BitsPerPixel = BitsPerPixel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 Private->ClearCode = (1 << BitsPerPixel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 Private->EOFCode = Private->ClearCode + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 Private->RunningCode = Private->EOFCode + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 Private->RunningBits = BitsPerPixel + 1; /* Number of bits per code. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 Private->MaxCode1 = 1 << Private->RunningBits; /* Max. code + 1. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 Private->StackPtr = 0; /* No pixels on the pixel stack. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 Private->LastCode = NO_SUCH_CODE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 Private->CrntShiftState = 0; /* No information in CrntShiftDWord. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 Private->CrntShiftDWord = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 Prefix = Private->Prefix;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 for (i = 0; i <= LZ_MAX_CODE; i++) Prefix[i] = NO_SUCH_CODE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 * The LZ decompression routine: *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 * This version decompress the given gif file into Line of length LineLen. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 * This routine can be called few times (one per scan line, for example), in *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 * order the complete the whole image. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 static int DGifDecompressLine(GifFileType *GifFile, GifPixelType *Line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 int LineLen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 int i = 0, j, CrntCode, EOFCode, ClearCode, CrntPrefix, LastCode, StackPtr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 GifByteType *Stack, *Suffix;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 unsigned int *Prefix;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 StackPtr = Private->StackPtr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 Prefix = Private->Prefix;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 Suffix = Private->Suffix;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 Stack = Private->Stack;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 EOFCode = Private->EOFCode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 ClearCode = Private->ClearCode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 LastCode = Private->LastCode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 if (StackPtr != 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 /* Let pop the stack off before continueing to read the gif file: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 while (StackPtr != 0 && i < LineLen) Line[i++] = Stack[--StackPtr];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 while (i < LineLen) { /* Decode LineLen items. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 if (DGifDecompressInput(Private, &CrntCode) == GIF_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 if (CrntCode == EOFCode) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 /* Note however that usually we will not be here as we will stop */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 /* decoding as soon as we got all the pixel, or EOF code will */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 /* not be read at all, and DGifGetLine/Pixel clean everything. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 if (i != LineLen - 1 || Private->PixelCount != 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 _GifError = D_GIF_ERR_EOF_TOO_SOON;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 i++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 else if (CrntCode == ClearCode) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 /* We need to start over again: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 for (j = 0; j <= LZ_MAX_CODE; j++) Prefix[j] = NO_SUCH_CODE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 Private->RunningCode = Private->EOFCode + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 Private->RunningBits = Private->BitsPerPixel + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 Private->MaxCode1 = 1 << Private->RunningBits;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 LastCode = Private->LastCode = NO_SUCH_CODE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 /* Its regular code - if in pixel range simply add it to output */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 /* stream, otherwise trace to codes linked list until the prefix */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 /* is in pixel range: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 if (CrntCode < ClearCode) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 /* This is simple - its pixel scalar, so add it to output: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 Line[i++] = CrntCode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 /* Its a code to needed to be traced: trace the linked list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 /* until the prefix is a pixel, while pushing the suffix */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 /* pixels on our stack. If we done, pop the stack in reverse */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 /* (thats what stack is good for!) order to output. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 if (Prefix[CrntCode] == NO_SUCH_CODE) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 /* Only allowed if CrntCode is exactly the running code: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 /* In that case CrntCode = XXXCode, CrntCode or the */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 /* prefix code is last code and the suffix char is */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 /* exactly the prefix of last code! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 if (CrntCode == Private->RunningCode - 2) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 CrntPrefix = LastCode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 Suffix[Private->RunningCode - 2] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 Stack[StackPtr++] = DGifGetPrefixChar(Prefix,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 LastCode, ClearCode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 _GifError = D_GIF_ERR_IMAGE_DEFECT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 CrntPrefix = CrntCode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 /* Now (if image is O.K.) we should not get an NO_SUCH_CODE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 /* During the trace. As we might loop forever, in case of */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 /* defective image, we count the number of loops we trace */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 /* and stop if we got LZ_MAX_CODE. obviously we can not */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 /* loop more than that. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 j = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 while (j++ <= LZ_MAX_CODE &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 CrntPrefix > ClearCode &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 CrntPrefix <= LZ_MAX_CODE) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 Stack[StackPtr++] = Suffix[CrntPrefix];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 CrntPrefix = Prefix[CrntPrefix];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 if (j >= LZ_MAX_CODE || CrntPrefix > LZ_MAX_CODE) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 _GifError = D_GIF_ERR_IMAGE_DEFECT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 /* Push the last character on stack: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 Stack[StackPtr++] = CrntPrefix;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 /* Now lets pop all the stack into output: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 while (StackPtr != 0 && i < LineLen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 Line[i++] = Stack[--StackPtr];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 if (LastCode != NO_SUCH_CODE) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 Prefix[Private->RunningCode - 2] = LastCode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 if (CrntCode == Private->RunningCode - 2) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 /* Only allowed if CrntCode is exactly the running code: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 /* In that case CrntCode = XXXCode, CrntCode or the */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 /* prefix code is last code and the suffix char is */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 /* exactly the prefix of last code! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 Suffix[Private->RunningCode - 2] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 DGifGetPrefixChar(Prefix, LastCode, ClearCode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 Suffix[Private->RunningCode - 2] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 DGifGetPrefixChar(Prefix, CrntCode, ClearCode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 LastCode = CrntCode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 Private->LastCode = LastCode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 Private->StackPtr = StackPtr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 * Routine to trace the Prefixes linked list until we get a prefix which is *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 * not code, but a pixel value (less than ClearCode). Returns that pixel value.*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 * If image is defective, we might loop here forever, so we limit the loops to *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 * the maximum possible if image O.k. - LZ_MAX_CODE times. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 static int DGifGetPrefixChar(unsigned int *Prefix, int Code, int ClearCode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 int i = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 while (Code > ClearCode && i++ <= LZ_MAX_CODE) Code = Prefix[Code];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 return Code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 * Interface for accessing the LZ codes directly. Set Code to the real code *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 * (12bits), or to -1 if EOF code is returned. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 int DGifGetLZCodes(GifFileType *GifFile, int *Code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 GifByteType *CodeBlock;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 GifFilePrivateType *Private = (GifFilePrivateType *) GifFile->Private;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 if (!IS_READABLE(Private)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 /* This file was NOT open for reading: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 _GifError = D_GIF_ERR_NOT_READABLE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 if (DGifDecompressInput(Private, Code) == GIF_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 if (*Code == Private->EOFCode) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 /* Skip rest of codes (hopefully only NULL terminating block): */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 do if (DGifGetCodeNext(GifFile, &CodeBlock) == GIF_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 while (CodeBlock != NULL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 *Code = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 else if (*Code == Private->ClearCode) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 /* We need to start over again: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 Private->RunningCode = Private->EOFCode + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 Private->RunningBits = Private->BitsPerPixel + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 Private->MaxCode1 = 1 << Private->RunningBits;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 * The LZ decompression input routine: *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 * This routine is responsable for the decompression of the bit stream from *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 * 8 bits (bytes) packets, into the real codes. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 * Returns GIF_OK if read succesfully. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 static int DGifDecompressInput(GifFilePrivateType *Private, int *Code)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 GifByteType NextByte;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 static unsigned int CodeMasks[] = {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 0x0000, 0x0001, 0x0003, 0x0007,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 0x000f, 0x001f, 0x003f, 0x007f,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 0x00ff, 0x01ff, 0x03ff, 0x07ff,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 0x0fff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 while (Private->CrntShiftState < Private->RunningBits) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 /* Needs to get more bytes from input stream for next code: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 if (DGifBufferedInput(Private->File, Private->Buf, &NextByte)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 == GIF_ERROR) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 Private->CrntShiftDWord |=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 ((unsigned long) NextByte) << Private->CrntShiftState;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 Private->CrntShiftState += 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 *Code = Private->CrntShiftDWord & CodeMasks[Private->RunningBits];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 Private->CrntShiftDWord >>= Private->RunningBits;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 Private->CrntShiftState -= Private->RunningBits;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 /* If code cannt fit into RunningBits bits, must raise its size. Note */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 /* however that codes above 4095 are used for special signaling. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 if (++Private->RunningCode > Private->MaxCode1 &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 Private->RunningBits < LZ_BITS) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 Private->MaxCode1 <<= 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 Private->RunningBits++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 * This routines read one gif data block at a time and buffers it internally *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 * so that the decompression routine could access it. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 * The routine returns the next byte from its internal buffer (or read next *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 * block in if buffer empty) and returns GIF_OK if succesful. *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 static int DGifBufferedInput(FILE *File, GifByteType *Buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 GifByteType *NextByte)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 if (Buf[0] == 0) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 /* Needs to read the next buffer - this one is empty: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 if (fread(Buf, 1, 1, File) != 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 if (fread(&Buf[1], 1, Buf[0], File) != Buf[0])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 _GifError = D_GIF_ERR_READ_FAILED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 return GIF_ERROR;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 *NextByte = Buf[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 Buf[1] = 2; /* We use now the second place as last char read! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 Buf[0]--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 else {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 *NextByte = Buf[Buf[1]++];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 Buf[0]--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 return GIF_OK;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 /******************************************************************************
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 * This routine reads an entire GIF into core, hanging all its state info off *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 * the GifFileType pointer. Call DGifOpenFileName() or DGifOpenFileHandle() *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 * first to initialize I/O. Its inverse is EGifSpew(). *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 ******************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 int DGifSlurp(GifFileType *GifFile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 int i, j, Error;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 int ImageSize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 GifRecordType RecordType;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 SavedImage *sp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 GifByteType *ExtData;
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
930 int ExtCode;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 /* Some versions of malloc dislike 0-length requests */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 GifFile->SavedImages = (SavedImage *)xmalloc(sizeof(SavedImage));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 do {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 if (DGifGetRecordType(GifFile, &RecordType) == GIF_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 return(GIF_ERROR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 switch (RecordType) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 case IMAGE_DESC_RECORD_TYPE:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 if (DGifGetImageDesc(GifFile) == GIF_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 return(GIF_ERROR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 sp = &GifFile->SavedImages[GifFile->ImageCount-1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 ImageSize = sp->ImageDesc.Width * sp->ImageDesc.Height;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 sp->RasterBits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 = (GifPixelType*) xmalloc(ImageSize * sizeof(GifPixelType));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 if (DGifGetLine(GifFile, sp->RasterBits, ImageSize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 == GIF_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 return(GIF_ERROR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 case EXTENSION_RECORD_TYPE:
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
957 /* This code fails if no image_desc record has been read
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
958 yet. I don't know if that's legal, but I've seen GIFs
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
959 that start with an extension record. XEmacs doesn't use
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
960 the extension records anyway, so we'll just ignore them.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
961 - dkindred@cs.cmu.edu */
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
962 #if 0
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 if (DGifGetExtension(GifFile,&sp->Function,&ExtData)==GIF_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 return(GIF_ERROR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 {
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 129
diff changeset
967 ExtensionBlock *ep =
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 129
diff changeset
968 &sp->ExtensionBlocks[sp->ExtensionBlockCount++];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 ep->ByteCount = ExtData[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 ep->Bytes = (GifByteType *)xmalloc(ep->ByteCount * sizeof(GifByteType));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 memcpy(ep->Bytes, ExtData, ep->ByteCount * sizeof(char));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 while (ExtData != NULL) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 if (DGifGetExtensionNext(GifFile, &ExtData) == GIF_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 return(GIF_ERROR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 {
175
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 129
diff changeset
980 ExtensionBlock *ep =
2d532a89d707 Import from CVS: tag r20-3b14
cvs
parents: 129
diff changeset
981 &sp->ExtensionBlocks[sp->ExtensionBlockCount++];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 ep->ByteCount = ExtData[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 ep->Bytes = (GifByteType *)xmalloc(ep->ByteCount * sizeof(GifByteType));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 memcpy(ep->Bytes,ExtData,ep->ByteCount * sizeof(char));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 }
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
988 #else
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
989 /* Skip any extension blocks in the file. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 175
diff changeset
990 if (DGifGetExtension (GifFile, &ExtCode, &ExtData)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
991 == GIF_ERROR)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
992 return GIF_ERROR;
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
993
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
994 while (ExtData != NULL) {
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
995 if (DGifGetExtensionNext (GifFile, &ExtData) == GIF_ERROR)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
996 return GIF_ERROR;
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
997 }
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 74
diff changeset
998 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 case TERMINATE_RECORD_TYPE:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 default: /* Should be trapped by DGifGetRecordType */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (RecordType != TERMINATE_RECORD_TYPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 return(GIF_OK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013