33#ifdef SIGNED_COMPARE_SLOW
35typedef unsigned short int count_short;
42#define maxbits GIFBITS
45#define maxmaxcode ((code_int)1 << GIFBITS)
89static int colorstobpp(
int colors);
90static void BumpPixel (
GifCtx *ctx);
92static void GIFEncode (
gdIOCtxPtr fp,
int GWidth,
int GHeight,
int GInterlace,
int Background,
int Transparent,
int BitsPerPixel,
int *Red,
int *Green,
int *Blue,
gdImagePtr im);
95static void cl_block (
GifCtx *ctx);
97static void char_init (
GifCtx *ctx);
98static void char_out (
int c,
GifCtx *ctx);
99static void flush_char (
GifCtx *ctx);
107 if (!_gdImageGifCtx(im,
out)) {
125 _gdImageGifCtx(im,
out);
132 int interlace, BitsPerPixel;
144 BitsPerPixel = colorstobpp(tim->colorsTotal);
147 out, tim->sx, tim->sy, interlace, 0, tim->transparent, BitsPerPixel,
148 tim->red, tim->green, tim->blue, tim);
214 switch( ctx->
Pass ) {
271GIFEncode(
gdIOCtxPtr fp,
int GWidth,
int GHeight,
int GInterlace,
int Background,
int Transparent,
int BitsPerPixel,
int *Red,
int *Green,
int *Blue,
gdImagePtr im)
282 memset(&ctx, 0,
sizeof(ctx));
286 ColorMapSize = 1 << BitsPerPixel;
288 RWidth = ctx.
Width = GWidth;
289 RHeight = ctx.
Height = GHeight;
290 LeftOfs = TopOfs = 0;
292 Resolution = BitsPerPixel;
307 if( BitsPerPixel <= 1 )
310 InitCodeSize = BitsPerPixel;
320 gdPutBuf(Transparent < 0 ?
"GIF87a" :
"GIF89a", 6, fp );
325 gifPutWord( RWidth, fp );
326 gifPutWord( RHeight, fp );
336 B |= (Resolution - 1) << 4;
341 B |= (BitsPerPixel - 1);
361 for( i=0; i<ColorMapSize; ++i ) {
370 if ( Transparent >= 0 ) {
377 gdPutC( (
unsigned char) Transparent, fp );
390 gifPutWord( LeftOfs, fp );
391 gifPutWord( TopOfs, fp );
392 gifPutWord( ctx.
Width, fp );
393 gifPutWord( ctx.
Height, fp );
406 gdPutC( InitCodeSize, fp );
411 compress( InitCodeSize+1, fp, im, &ctx );
461#define ARGVAL() (*++(*argv) || (--argc && *++argv))
464# define MAXCODE(n_bits) ((code_int) 1 << (n_bits) - 1)
466# define MAXCODE(n_bits) (((code_int) 1 << (n_bits)) - 1)
469#define HashTabOf(i) ctx->htab[i]
470#define CodeTabOf(i) ctx->codetab[i]
482#define tab_prefixof(i) CodeTabOf(i)
483#define tab_suffixof(i) ((char_type*)(htab))[i]
484#define de_stack ((char_type*)&tab_suffixof((code_int)1<<GIFBITS))
538 ent = GIFNextPixel( im, ctx );
541 for ( fcode = (
long)
hsize; fcode < 65536L; fcode *= 2L )
550#ifdef SIGNED_COMPARE_SLOW
551 while ( (c = GIFNextPixel( im, ctx )) != (
unsigned) EOF ) {
553 while ( (c = GIFNextPixel( im, ctx )) != EOF ) {
558 fcode = (long) (((
long) c <<
maxbits) + ent);
559 i = (((
code_int)c << hshift) ^ ent);
566 disp = hsize_reg - i;
570 if ( (i -= disp) < 0 )
583#ifdef SIGNED_COMPARE_SLOW
618static const unsigned long masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F,
619 0x001F, 0x003F, 0x007F, 0x00FF,
620 0x01FF, 0x03FF, 0x07FF, 0x0FFF,
621 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
628#define CUR_BITS_FINISHED -1000
648 char_out( (
unsigned int)(ctx->
cur_accum & 0xff), ctx );
679 char_out( (
unsigned int)(ctx->
cur_accum & 0xff), ctx);
713 register long m1 = -1;
734 }
while ((i -= 16) >= 0);
736 for ( i += 16; i > 0; --i )
760char_out(
int c,
GifCtx *ctx)
memset(ptr, 0, type->size)
void * gdDPExtractData(struct gdIOCtx *ctx, int *size)
gdImagePtr gdImageCreatePaletteFromTrueColor(gdImagePtr im, int ditherFlag, int colorsWanted)
gdIOCtx * gdNewFileCtx(FILE *)
gdIOCtx * gdNewDynamicCtx(int, void *)
void * gdImageGifPtr(gdImagePtr im, int *size)
void gdImageGifCtx(gdImagePtr im, gdIOCtxPtr out)
#define CUR_BITS_FINISHED
void gdImageGif(gdImagePtr im, FILE *outFile)
int gdPutBuf(const void *buf, int size, gdIOCtx *ctx)
void gdPutC(const unsigned char c, gdIOCtx *ctx)
struct gdIOCtx * gdIOCtxPtr
int gdImageGetPixel(gdImagePtr im, int x, int y)
void gdImageDestroy(gdImagePtr im)
const phpdbg_color_t * colors[PHPDBG_COLORS]
unsigned short codetab[HSIZE]