10
/* Code drawn from ppmtogif.c, from the pbmplus package
12
** Based on GIFENCOD by David Rowley <mgardi@watdscu.waterloo.edu>. A
13
** Lempel-Zim compression based on "compress".
15
** Modified by Marcel Wijkstra <wijkstra@fwi.uva.nl>
17
** Copyright (C) 1989 by Jef Poskanzer.
19
** Permission to use, copy, modify, and distribute this software and its
20
** documentation for any purpose and without fee is hereby granted, provided
21
** that the above copyright notice appear in all copies and that both that
22
** copyright notice and this permission notice appear in supporting
23
** documentation. This software is provided "as is" without express or
26
** The Graphics Interchange Format(c) is the Copyright property of
27
** CompuServe Incorporated. GIF(sm) is a Service Mark property of
28
** CompuServe Incorporated.
30
* Heavily modified by Mouse, 1998-02-12.
31
* Remove LZW compression.
32
* Added miGIF run length compression.
37
* a code_int must be able to hold 2**GIFBITS values of type int, and also -1
41
static int colorstobpp(int colors);
42
static void BumpPixel (void);
43
static int GIFNextPixel (gdImagePtr im);
44
static void GIFEncode (gdIOCtx *ctx, int GWidth, int GHeight, int GInterlace, int Background, int Transparent, int BitsPerPixel, int *Red, int *Green, int *Blue, gdImagePtr im);
45
static void compress (int, gdIOCtx *, gdImagePtr, int);
46
static void output (code_int code);
47
/* Allows for reuse */
48
static void init_statics(void);
50
void gdImageGif(gdImagePtr im, FILE *outFile)
52
gdIOCtx *out = gdNewFileCtx(outFile);
53
gdImageGifCtx(im, out);
57
void* gdImageGifPtr(gdImagePtr im, int *size)
60
gdIOCtx *out = gdNewDynamicCtx(2048, NULL);
61
gdImageGifCtx(im, out);
62
rv = gdDPExtractData(out, size);
67
void gdImageGifCtx(gdImagePtr im, gdIOCtx *out)
69
int interlace, transparent, BitsPerPixel;
70
interlace = im->interlace;
71
transparent = im->transparent;
73
BitsPerPixel = colorstobpp(im->colorsTotal);
74
/* Clear any old values in statics strewn through the GIF code */
76
/* All set, let's do it. */
78
out, im->sx, im->sy, interlace, 0, transparent, BitsPerPixel,
79
im->red, im->green, im->blue, im);
83
colorstobpp(int colors)
89
else if ( colors <= 4 )
91
else if ( colors <= 8 )
93
else if ( colors <= 16 )
95
else if ( colors <= 32 )
97
else if ( colors <= 64 )
99
else if ( colors <= 128 )
101
else if ( colors <= 256 )
106
/*****************************************************************************
108
* GIFENCODE.C - GIF Image compression interface
110
* GIFEncode( FName, GHeight, GWidth, GInterlace, Background, Transparent,
111
* BitsPerPixel, Red, Green, Blue, gdImagePtr )
113
*****************************************************************************/
118
static int Width, Height;
119
static int curx, cury;
120
static long CountDown;
122
static int Interlace;
125
* Bump the 'curx' and 'cury' to point to the next pixel
131
* Bump the current X position
136
* If we are at the end of a scan line, set curx back to the beginning
137
* If we are interlaced, bump the cury to the appropriate spot,
138
* otherwise, just increment it.
140
if( curx == Width ) {
150
if( cury >= Height ) {
158
if( cury >= Height ) {
166
if( cury >= Height ) {
181
* Return the next pixel from the image
184
GIFNextPixel(gdImagePtr im)
193
r = gdImageGetPixel(im, curx, cury);
203
GIFEncode(gdIOCtx *ctx, int GWidth, int GHeight, int GInterlace, int Background, int Transparent, int BitsPerPixel, int *Red, int *Green, int *Blue, gdImagePtr im)
213
Interlace = GInterlace;
215
ColorMapSize = 1 << BitsPerPixel;
217
RWidth = Width = GWidth;
218
RHeight = Height = GHeight;
219
LeftOfs = TopOfs = 0;
221
Resolution = BitsPerPixel;
224
* Calculate number of bits we are expecting
226
CountDown = (long)Width * (long)Height;
229
* Indicate which pass we are on (if interlace)
234
* The initial code size
236
if( BitsPerPixel <= 1 )
239
InitCodeSize = BitsPerPixel;
242
* Set up the current x and y position
247
* Write the Magic header
249
gdPutBuf( Transparent < 0 ? "GIF87a" : "GIF89a", 6, ctx );
252
* Write out the screen width and height
254
Putword( RWidth, ctx );
255
Putword( RHeight, ctx );
258
* Indicate that there is a global colour map
260
B = 0x80; /* Yes, there is a color map */
263
* OR in the resolution
265
B |= (Resolution - 1) << 4;
268
* OR in the Bits per Pixel
270
B |= (BitsPerPixel - 1);
278
* Write out the Background colour
280
Putchar( Background, ctx );
283
* Byte of 0's (future expansion)
288
* Write out the Global Colour Map
290
for( i=0; i<ColorMapSize; ++i ) {
291
Putchar( Red[i], ctx );
292
Putchar( Green[i], ctx );
293
Putchar( Blue[i], ctx );
297
* Write out extension for transparent colour index, if necessary.
299
if ( Transparent >= 0 ) {
301
Putchar( 0xf9, ctx );
306
Putchar( (unsigned char) Transparent, ctx );
311
* Write an Image separator
316
* Write the Image header
319
Putword( LeftOfs, ctx );
320
Putword( TopOfs, ctx );
321
Putword( Width, ctx );
322
Putword( Height, ctx );
325
* Write out whether or not the image is interlaced
328
Putchar( 0x40, ctx );
330
Putchar( 0x00, ctx );
333
* Write out the initial code size
335
Putchar( InitCodeSize, ctx );
338
* Go and actually compress the data
340
compress( InitCodeSize+1, ctx, im, Background );
343
* Write out a Zero-length packet (to end the series)
348
* Write the GIF file terminator
355
/*-----------------------------------------------------------------------
357
* miGIF Compression - mouse and ivo's GIF-compatible compression
359
* -run length encoding compression routines-
361
* Copyright (C) 1998 Hutchison Avenue Software Corporation
362
* http://www.hasc.com
365
* Permission to use, copy, modify, and distribute this software and its
366
* documentation for any purpose and without fee is hereby granted, provided
367
* that the above copyright notice appear in all copies and that both that
368
* copyright notice and this permission notice appear in supporting
369
* documentation. This software is provided "AS IS." The Hutchison Avenue
370
* Software Corporation disclaims all warranties, either express or implied,
371
* including but not limited to implied warranties of merchantability and
372
* fitness for a particular purpose, with respect to this code and accompanying
375
* The miGIF compression routines do not, strictly speaking, generate files
376
* conforming to the GIF spec, since the image data is not LZW-compressed
377
* (this is the point: in order to avoid transgression of the Unisys patent
378
* on the LZW algorithm.) However, miGIF generates data streams that any
379
* reasonably sane LZW decompresser will decompress to what we want.
381
* miGIF compression uses run length encoding. It compresses horizontal runs
382
* of pixels of the same color. This type of compression gives good results
383
* on images with many runs, for example images with lines, text and solid
384
* shapes on a solid-colored background. It gives little or no compression
385
* on images with few runs, for example digital or scanned photos.
388
* mouse@rodents.montreal.qc.ca
389
* 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B
393
* The Graphics Interchange Format(c) is the Copyright property of
394
* CompuServe Incorporated. GIF(sm) is a Service Mark property of
395
* CompuServe Incorporated.
400
static int rl_basecode;
402
static int rl_table_pixel;
403
static int rl_table_max;
404
static int just_cleared;
406
static int out_bits_init;
407
static int out_count;
409
static int out_bump_init;
410
static int out_clear;
411
static int out_clear_init;
412
static int max_ocodes;
413
static int code_clear;
415
static unsigned int obuf;
417
static gdIOCtx *octx;
418
static unsigned char oblock[256];
421
/* Used only when debugging GIF compression code */
422
/* #define DEBUGGING_ENVARS */
424
#ifdef DEBUGGING_ENVARS
426
static int verbose_set = 0;
428
#define VERBOSE (verbose_set?verbose:set_verbose())
430
static int set_verbose(void)
432
verbose = !!getenv("GIF_VERBOSE");
444
static const char *binformat(unsigned int v, int nbits)
446
static char bufs[8][64];
447
static int bhand = 0;
453
if (bhand < 0) bhand = (sizeof(bufs)/sizeof(bufs[0]))-1;
454
bp = &bufs[bhand][0];
455
for (bno=nbits-1,bit=1U<<bno;bno>=0;bno--,bit>>=1)
456
{ *bp++ = (v & bit) ? '1' : '0';
457
if (((bno&3) == 0) && (bno != 0)) *bp++ = '.';
460
return(&bufs[bhand][0]);
463
static void write_block(void)
468
{ printf("write_block %d:",oblen);
469
for (i=0;i<oblen;i++) printf(" %02x",oblock[i]);
473
gdPutBuf(&oblock[0],oblen,octx);
477
static void block_out(unsigned char c)
479
if (VERBOSE) printf("block_out %s\n",binformat(c,8));
481
if (oblen >= 255) write_block();
484
static void block_flush(void)
486
if (VERBOSE) printf("block_flush\n");
487
if (oblen > 0) write_block();
490
static void output(int val)
492
if (VERBOSE) printf("output %s [%s %d %d]\n",binformat(val,out_bits),binformat(obuf,obits),obits,out_bits);
493
obuf |= val << obits;
496
{ block_out(obuf&0xff);
500
if (VERBOSE) printf("output leaving [%s %d]\n",binformat(obuf,obits),obits);
503
static void output_flush(void)
505
if (VERBOSE) printf("output_flush\n");
506
if (obits > 0) block_out(obuf);
510
static void did_clear(void)
512
if (VERBOSE) printf("did_clear\n");
513
out_bits = out_bits_init;
514
out_bump = out_bump_init;
515
out_clear = out_clear_init;
521
static void output_plain(int c)
523
if (VERBOSE) printf("output_plain %s\n",binformat(c,out_bits));
527
if (out_count >= out_bump)
529
out_bump += 1 << (out_bits - 1);
531
if (out_count >= out_clear)
532
{ output(code_clear);
537
static unsigned int isqrt(unsigned int x)
542
if (x < 2) return(x);
543
for (v=x,r=1;v;v>>=2,r<<=1) ;
545
{ v = ((x / r) + r) / 2;
546
if ((v == r) || (v == r+1)) return(r);
551
static unsigned int compute_triangle_count(unsigned int count, unsigned int nrepcodes)
557
perrep = (nrepcodes * (nrepcodes+1)) / 2;
558
while (count >= perrep)
565
while ((n*(n+1)) >= 2*count) n --;
566
while ((n*(n+1)) < 2*count) n ++;
572
static void max_out_clear(void)
574
out_clear = max_ocodes;
577
static void reset_out_clear(void)
579
out_clear = out_clear_init;
580
if (out_count >= out_clear)
581
{ output(code_clear);
586
static void rl_flush_fromclear(int count)
590
if (VERBOSE) printf("rl_flush_fromclear %d\n",count);
592
rl_table_pixel = rl_pixel;
597
output_plain(rl_pixel);
602
output_plain(rl_basecode+n-2);
607
output_plain(rl_pixel);
612
output_plain(rl_basecode+count-2);
615
if (out_count == 0) n = 1; else n ++;
618
if (VERBOSE) printf("rl_flush_fromclear leaving table_max=%d\n",rl_table_max);
621
static void rl_flush_clearorrep(int count)
625
if (VERBOSE) printf("rl_flush_clearorrep %d\n",count);
626
withclr = 1 + compute_triangle_count(count,max_ocodes);
628
{ output(code_clear);
630
rl_flush_fromclear(count);
633
{ for (;count>0;count--) output_plain(rl_pixel);
637
static void rl_flush_withtable(int count)
643
if (VERBOSE) printf("rl_flush_withtable %d\n",count);
644
repmax = count / rl_table_max;
645
leftover = count % rl_table_max;
646
repleft = (leftover ? 1 : 0);
647
if (out_count+repmax+repleft > max_ocodes)
648
{ repmax = max_ocodes - out_count;
649
leftover = count - (repmax * rl_table_max);
650
repleft = 1 + compute_triangle_count(leftover,max_ocodes);
652
if (VERBOSE) printf("rl_flush_withtable repmax=%d leftover=%d repleft=%d\n",repmax,leftover,repleft);
653
if (1+compute_triangle_count(count,max_ocodes) < repmax+repleft)
654
{ output(code_clear);
656
rl_flush_fromclear(count);
660
for (;repmax>0;repmax--) output_plain(rl_basecode+rl_table_max-2);
663
{ rl_flush_fromclear(leftover);
665
else if (leftover == 1)
666
{ output_plain(rl_pixel);
669
{ output_plain(rl_basecode+leftover-2);
675
static void rl_flush(void)
677
if (VERBOSE) printf("rl_flush [ %d %d\n",rl_count,rl_pixel);
679
{ output_plain(rl_pixel);
681
if (VERBOSE) printf("rl_flush ]\n");
685
{ rl_flush_fromclear(rl_count);
687
else if ((rl_table_max < 2) || (rl_table_pixel != rl_pixel))
688
{ rl_flush_clearorrep(rl_count);
691
{ rl_flush_withtable(rl_count);
693
if (VERBOSE) printf("rl_flush ]\n");
697
static void compress(int init_bits, gdIOCtx *ctx, gdImagePtr im, int background)
705
code_clear = 1 << (init_bits - 1);
706
code_eof = code_clear + 1;
707
rl_basecode = code_eof + 1;
708
out_bump_init = (1 << (init_bits - 1)) - 1;
709
/* for images with a lot of runs, making out_clear_init larger will
710
give better compression. */
711
out_clear_init = (init_bits <= 3) ? 9 : (out_bump_init-1);
712
#ifdef DEBUGGING_ENVARS
713
{ const char *ocienv;
714
ocienv = getenv("GIF_OUT_CLEAR_INIT");
716
{ out_clear_init = atoi(ocienv);
717
if (VERBOSE) printf("[overriding out_clear_init to %d]\n",out_clear_init);
721
out_bits_init = init_bits;
722
max_ocodes = (1 << GIFBITS) - ((1 << (out_bits_init - 1)) + 3);
727
{ c = GIFNextPixel(im);
728
if ((rl_count > 0) && (c != rl_pixel)) rl_flush();
742
/*-----------------------------------------------------------------------
744
* End of miGIF section - See copyright notice at start of section.
746
*-----------------------------------------------------------------------*/
749
/******************************************************************************
751
* GIF Specific routines
753
******************************************************************************/
755
static void init_statics(void) {
756
/* Some of these are properly initialized later. What I'm doing
757
here is making sure code that depends on C's initialization
758
of statics doesn't break when the code gets called more
770
/* +-------------------------------------------------------------------+ */
771
/* | Copyright 1990, 1991, 1993, David Koblas. (koblas@netcom.com) | */
772
/* | Permission to use, copy, modify, and distribute this software | */
773
/* | and its documentation for any purpose and without fee is hereby | */
774
/* | granted, provided that the above copyright notice appear in all | */
775
/* | copies and that both that copyright notice and this permission | */
776
/* | notice appear in supporting documentation. This software is | */
777
/* | provided "as is" without express or implied warranty. | */
778
/* +-------------------------------------------------------------------+ */
781
#define MAXCOLORMAPSIZE 256
790
#define MAX_LWZ_BITS 12
792
#define INTERLACE 0x40
793
#define LOCALCOLORMAP 0x80
794
#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
796
#define ReadOK(file,buffer,len) (fread(buffer, len, 1, file) != 0)
798
#define LM_to_uint(a,b) (((b)<<8)|(a))
800
/* We may eventually want to use this information, but def it out for now */
805
unsigned char ColorMap[3][MAXCOLORMAPSIZE];
806
unsigned int BitPixel;
807
unsigned int ColorResolution;
808
unsigned int Background;
809
unsigned int AspectRatio;
820
} Gif89 = { -1, -1, -1, 0 };
823
static int ReadColorMap (FILE *fd, int number, unsigned char (*buffer)[256]);
824
static int DoExtension (FILE *fd, int label, int *Transparent);
825
static int GetDataBlock (FILE *fd, unsigned char *buf);
826
static int GetCode (FILE *fd, int code_size, int flag);
827
static int LWZReadByte (FILE *fd, int flag, int input_code_size);
828
static void ReadImage (gdImagePtr im, FILE *fd, int len, int height, unsigned char (*cmap)[256], int interlace, int ignore);
833
gdImageCreateFromGif(FILE *fd)
843
int Transparent = (-1);
844
unsigned char buf[16];
846
unsigned char ColorMap[3][MAXCOLORMAPSIZE];
847
unsigned char localColorMap[3][MAXCOLORMAPSIZE];
849
int useGlobalColormap;
854
ZeroDataBlock = FALSE;
857
if (! ReadOK(fd,buf,6)) {
860
if (strncmp((char *)buf,"GIF",3) != 0) {
863
strncpy(version, (char *)buf + 3, 3);
866
if ((strcmp(version, "87a") != 0) && (strcmp(version, "89a") != 0)) {
869
if (! ReadOK(fd,buf,7)) {
872
BitPixel = 2<<(buf[4]&0x07);
875
ColorResolution = (int) (((buf[4]&0x70)>>3)+1);
877
AspectRatio = buf[6];
880
if (BitSet(buf[4], LOCALCOLORMAP)) { /* Global Colormap */
881
if (ReadColorMap(fd, BitPixel, ColorMap)) {
886
if (! ReadOK(fd,&c,1)) {
889
if (c == ';') { /* GIF terminator */
891
if (imageCount < imageNumber) {
894
/* Terminator before any image was declared! */
898
/* Check for open colors at the end, so
899
we can reduce colorsTotal and ultimately
901
for (i=((im->colorsTotal-1)); (i>=0); i--) {
911
if (c == '!') { /* Extension */
912
if (! ReadOK(fd,&c,1)) {
915
DoExtension(fd, c, &Transparent);
919
if (c != ',') { /* Not a valid start character */
925
if (! ReadOK(fd,buf,9)) {
929
useGlobalColormap = ! BitSet(buf[8], LOCALCOLORMAP);
931
bitPixel = 1<<((buf[8]&0x07)+1);
933
imw = LM_to_uint(buf[4],buf[5]);
934
imh = LM_to_uint(buf[6],buf[7]);
935
if (!(im = gdImageCreate(imw, imh))) {
938
im->interlace = BitSet(buf[8], INTERLACE);
939
if (! useGlobalColormap) {
940
if (ReadColorMap(fd, bitPixel, localColorMap)) {
943
ReadImage(im, fd, imw, imh, localColorMap,
944
BitSet(buf[8], INTERLACE),
945
imageCount != imageNumber);
947
ReadImage(im, fd, imw, imh,
949
BitSet(buf[8], INTERLACE),
950
imageCount != imageNumber);
952
if (Transparent != (-1)) {
953
gdImageColorTransparent(im, Transparent);
959
ReadColorMap(FILE *fd, int number, unsigned char (*buffer)[256])
962
unsigned char rgb[3];
965
for (i = 0; i < number; ++i) {
966
if (! ReadOK(fd, rgb, sizeof(rgb))) {
969
buffer[CM_RED][i] = rgb[0] ;
970
buffer[CM_GREEN][i] = rgb[1] ;
971
buffer[CM_BLUE][i] = rgb[2] ;
979
DoExtension(FILE *fd, int label, int *Transparent)
981
static unsigned char buf[256];
984
case 0xf9: /* Graphic Control Extension */
985
(void) GetDataBlock(fd, (unsigned char*) buf);
988
Gif89.disposal = (buf[0] >> 2) & 0x7;
989
Gif89.inputFlag = (buf[0] >> 1) & 0x1;
990
Gif89.delayTime = LM_to_uint(buf[1],buf[2]);
992
if ((buf[0] & 0x1) != 0)
993
*Transparent = buf[3];
995
while (GetDataBlock(fd, (unsigned char*) buf) != 0)
1001
while (GetDataBlock(fd, (unsigned char*) buf) != 0)
1008
GetDataBlock_(FILE *fd, unsigned char *buf)
1010
unsigned char count;
1012
if (! ReadOK(fd,&count,1)) {
1016
ZeroDataBlock = count == 0;
1018
if ((count != 0) && (! ReadOK(fd, buf, count))) {
1026
GetDataBlock(FILE *fd, unsigned char *buf)
1031
rv = GetDataBlock_(fd,buf);
1033
{ printf("[GetDataBlock returning %d",rv);
1036
for (i=0;i<rv;i++) printf(" %02x",buf[i]);
1044
GetCode_(FILE *fd, int code_size, int flag)
1046
static unsigned char buf[280];
1047
static int curbit, lastbit, done, last_byte;
1049
unsigned char count;
1058
if ( (curbit+code_size) >= lastbit) {
1060
if (curbit >= lastbit) {
1065
buf[0] = buf[last_byte-2];
1066
buf[1] = buf[last_byte-1];
1068
if ((count = GetDataBlock(fd, &buf[2])) == 0)
1071
last_byte = 2 + count;
1072
curbit = (curbit - lastbit) + 16;
1073
lastbit = (2+count)*8 ;
1077
for (i = curbit, j = 0; j < code_size; ++i, ++j)
1078
ret |= ((buf[ i / 8 ] & (1 << (i % 8))) != 0) << j;
1080
curbit += code_size;
1085
GetCode(FILE *fd, int code_size, int flag)
1089
rv = GetCode_(fd,code_size,flag);
1090
if (VERBOSE) printf("[GetCode(,%d,%d) returning %d]\n",code_size,flag,rv);
1095
LWZReadByte_(FILE *fd, int flag, int input_code_size)
1097
static int fresh = FALSE;
1099
static int code_size, set_code_size;
1100
static int max_code, max_code_size;
1101
static int firstcode, oldcode;
1102
static int clear_code, end_code;
1103
static int table[2][(1<< MAX_LWZ_BITS)];
1104
static int stack[(1<<(MAX_LWZ_BITS))*2], *sp;
1108
set_code_size = input_code_size;
1109
code_size = set_code_size+1;
1110
clear_code = 1 << set_code_size ;
1111
end_code = clear_code + 1;
1112
max_code_size = 2*clear_code;
1113
max_code = clear_code+2;
1115
GetCode(fd, 0, TRUE);
1119
for (i = 0; i < clear_code; ++i) {
1123
for (; i < (1<<MAX_LWZ_BITS); ++i)
1124
table[0][i] = table[1][0] = 0;
1132
firstcode = oldcode =
1133
GetCode(fd, code_size, FALSE);
1134
} while (firstcode == clear_code);
1141
while ((code = GetCode(fd, code_size, FALSE)) >= 0) {
1142
if (code == clear_code) {
1143
for (i = 0; i < clear_code; ++i) {
1147
for (; i < (1<<MAX_LWZ_BITS); ++i)
1148
table[0][i] = table[1][i] = 0;
1149
code_size = set_code_size+1;
1150
max_code_size = 2*clear_code;
1151
max_code = clear_code+2;
1153
firstcode = oldcode =
1154
GetCode(fd, code_size, FALSE);
1156
} else if (code == end_code) {
1158
unsigned char buf[260];
1163
while ((count = GetDataBlock(fd, buf)) > 0)
1172
if (code >= max_code) {
1177
while (code >= clear_code) {
1178
*sp++ = table[1][code];
1179
if (code == table[0][code]) {
1182
code = table[0][code];
1185
*sp++ = firstcode = table[1][code];
1187
if ((code = max_code) <(1<<MAX_LWZ_BITS)) {
1188
table[0][code] = oldcode;
1189
table[1][code] = firstcode;
1191
if ((max_code >= max_code_size) &&
1192
(max_code_size < (1<<MAX_LWZ_BITS))) {
1207
LWZReadByte(FILE *fd, int flag, int input_code_size)
1211
rv = LWZReadByte_(fd,flag,input_code_size);
1212
if (VERBOSE) printf("[LWZReadByte(,%d,%d) returning %d]\n",flag,input_code_size,rv);
1217
ReadImage(gdImagePtr im, FILE *fd, int len, int height, unsigned char (*cmap)[256], int interlace, int ignore)
1221
int xpos = 0, ypos = 0, pass = 0;
1223
/* Stash the color map into the image */
1224
for (i=0; (i<gdMaxColors); i++) {
1225
im->red[i] = cmap[CM_RED][i];
1226
im->green[i] = cmap[CM_GREEN][i];
1227
im->blue[i] = cmap[CM_BLUE][i];
1230
/* Many (perhaps most) of these colors will remain marked open. */
1231
im->colorsTotal = gdMaxColors;
1233
** Initialize the Compression routines
1235
if (! ReadOK(fd,&c,1)) {
1238
if (LWZReadByte(fd, TRUE, c) < 0) {
1243
** If this is an "uninteresting picture" ignore it.
1246
while (LWZReadByte(fd, FALSE, c) >= 0)
1251
while ((v = LWZReadByte(fd,FALSE,c)) >= 0 ) {
1252
/* This how we recognize which colors are actually used. */
1256
gdImageSetPixel(im, xpos, ypos, v);
1271
if (ypos >= height) {
1293
if (LWZReadByte(fd,FALSE,c)>=0) {