33 if (
lblk == 0)
return -1;
70 unsigned char *
ptr1 = GIFarr;
74 if (strncmp((
const char *)GIFarr,
"GIF87a",6) && strncmp((
const char *)GIFarr,
"GIF89a",6))
76 fprintf(stderr,
"\nGIFinfo: not a GIF\n");
86 *Ncols = 1 << ((
b & 7) + 1);
87 if ((
b & 0x80) == 0) {
88 fprintf(stderr,
"\nGIFinfo: warning! no color map\n");
95 fprintf(stderr,
"\nGIFdecode: bad screen descriptor\n");
103 fprintf(stderr,
"\nGIFinfo: no image separator\n");
110 *Width =
b + 0x100*(*
ptr1++);
112 *Height =
b + 0x100*(*
ptr1++);
135int TGifDecode::GIFdecode(
unsigned char *GIFarr,
unsigned char *PIXarr,
int *Width,
int *Height,
int *Ncols,
unsigned char *
R,
unsigned char *
G,
unsigned char *B)
155 unsigned char Suffix[
TSIZE];
156 unsigned char OutCode[
TSIZE];
164 if (strncmp((
char *)GIFarr,
"GIF87a",6) && strncmp((
char *)GIFarr,
"GIF89a",6))
166 fprintf(stderr,
"\nGIFinfo: not a GIF\n");
176 BitsPixel = (
b & 7) + 1;
177 *Ncols = 1 << BitsPixel;
178 PixMask = (*Ncols) - 1;
179 if ((
b & 0x80) == 0) {
180 fprintf(stderr,
"\nGIFdecode: warning! no color map\n");
187 fprintf(stderr,
"\nGIFdecode: bad screen descriptor\n");
191 for (i=0; i<(*Ncols); i++) {
199 fprintf(stderr,
"\nGIFdecode: no image separator\n");
206 *Width =
b + 0x100*(*
ptr1++);
208 *Height =
b + 0x100*(*
ptr1++);
211 if ((
b & 0xc0) != 0) {
213 "\nGIFdecode: unexpected item (local colors or interlace)\n");
217 IniCodeSize = *
ptr1++;
220 ClearCode = (1 << (IniCodeSize - 1));
221 EOFCode = ClearCode + 1;
222 FreeCode = ClearCode + 2;
226 Npix =(long) (*Width) * (*Height);
233 fprintf(stderr,
"\nGIFdecode: corrupted GIF (zero block length)\n");
237 if (CurCode == EOFCode) {
238 fprintf(stderr,
"\nGIFdecode: corrupted GIF (unexpected EOF)\n");
242 if (CurCode == ClearCode) {
246 FreeCode = ClearCode + 2;
255 if (CurCode >= FreeCode) {
257 OutCode[OutCount++] = FinChar;
259 while (CurCode > PixMask) {
260 if (OutCount >=
TSIZE) {
261 fprintf(stderr,
"\nGIFdecode: corrupted GIF (big output count)\n");
264 OutCode[OutCount++] = Suffix[CurCode];
265 CurCode = Prefix[CurCode];
268 OutCode[OutCount++] = FinChar;
270 for (i=OutCount-1; i>=0; i--) {
276 Prefix[FreeCode] = OldCode;
277 Suffix[FreeCode] = FinChar;
#define R(a, b, c, d, e, f, g, h, i)
void OutPixel(unsigned char pix)
static int GIFinfo(unsigned char *GIFarr, int *Width, int *Height, int *Ncols)
int GIFdecode(unsigned char *GIFarr, unsigned char *PIXarr, int *Width, int *Height, int *Ncols, unsigned char *R, unsigned char *G, unsigned char *B)