annotate src/dgif_lib.c @ 129:e292c9648bb9 xemacs-20-1p3

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