--- parser3/src/classes/gd/Attic/gifio.C 2001/04/23 09:38:45 1.7 +++ parser3/src/classes/gd/Attic/gifio.C 2003/03/24 15:08:02 1.21.2.2.2.7 @@ -1,10 +1,18 @@ /** @file Parser: image manipulations impl2. - Author: Alexander Petrosyan (http://design.ru/paf) + Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) + Author: Alexandr Petrosian (http://paf.design.ru) - $Id: gifio.C,v 1.7 2001/04/23 09:38:45 paf Exp $ + based on: gd + Written by Tom Boutell, 5/94. + Copyright 1994, Cold Spring Harbor Labs. + Permission granted to use this code in any fashion provided + that this notice is retained and any alterations are + labeled as such. It is requested, but not required, that + you share extensions to this module with us so that we + can incorporate them into new versions. based on: ** @@ -27,17 +35,19 @@ ** CompuServe Incorporated. */ +static const char* IDENT_GIFIO_C="$Date: 2003/03/24 15:08:02 $"; + #include "gif.h" static int colorstobpp(int colors); -void gdImage::Gif(String& out) +gdBuf gdImage::Gif() { int BitsPerPixel = colorstobpp(colorsTotal); /* Clear any old values in statics strewn through the GIF code */ - gdGifEncoder encoder(pool(), *this, out); + gdGifEncoder encoder(*this); /* All set, let's do it. */ - encoder.encode( + return encoder.encode( sx, sy, interlace, 0, transparent, BitsPerPixel, red, green, blue); } @@ -75,8 +85,12 @@ colorstobpp(int colors) * *****************************************************************************/ +#ifndef TRUE #define TRUE 1 +#endif +#ifndef FALSE #define FALSE 0 +#endif /* * Bump the 'curx' and 'cury' to point to the next pixel @@ -156,7 +170,7 @@ gdGifEncoder::GIFNextPixel() /* public */ -void +gdBuf gdGifEncoder::encode(int GWidth, int GHeight, int GInterlace, int Background, int Transparent, int BitsPerPixel, int *Red, int *Green, int *Blue) @@ -205,7 +219,8 @@ gdGifEncoder::encode(int GWidth, int GHe /* * Write the Magic header */ - fp << (Transparent < 0 ? "GIF87a" : "GIF89a"); + Putbyte('G');Putbyte('I');Putbyte('F'); + Putbyte('8');Putbyte(Transparent < 0?'7':'9');Putbyte('a'); /* * Write out the screen width and height @@ -307,16 +322,16 @@ gdGifEncoder::encode(int GWidth, int GHe * Write the GIF file terminator */ Putbyte( ';'); + + return buf; } /* * Write out a byte to the GIF file */ void -gdGifEncoder::Putbyte(int c) { - char *p=(char *)malloc(1); - *p=c; - fp.APPEND_AS_IS(p, 1, 0, 0); +gdGifEncoder::Putbyte(unsigned char c) { + buf.append(&c, 1); } /* * Write out a word to the GIF file @@ -324,16 +339,14 @@ gdGifEncoder::Putbyte(int c) { void gdGifEncoder::Putword(int w) { - char *p=(char *)malloc(2); - p[0]=w & 0xff; - p[1]=(w / 256) & 0xff; - fp.APPEND_AS_IS(p, 2, 0, 0); + unsigned char b0=w & 0xff; + unsigned char b1=w >> 8; + buf.append(&b0, 1); + buf.append(&b1, 1); } -void gdGifEncoder::Write(void *buf, size_t size) { - char *p=(char *)malloc(size); - memcpy(p, buf, size); - fp.APPEND_AS_IS(p, size, 0, 0); +void gdGifEncoder::Write(void *abuf, size_t size) { + buf.append((unsigned char*)abuf, size); } /*************************************************************************** @@ -353,9 +366,9 @@ void gdGifEncoder::Write(void *buf, size #ifdef NO_UCHAR typedef char char_type; -#else /*NO_UCHAR*/ +#else typedef unsigned char char_type; -#endif /*NO_UCHAR*/ +#endif /* * @@ -373,9 +386,9 @@ typedef unsigned char char_type */ #ifdef COMPATIBLE /* But wrong! */ # define MAXCODE(n_bits) ((code_int) 1 <<(n_bits) - 1) -#else /*COMPATIBLE*/ +#else # define MAXCODE(n_bits) (((code_int) 1 <<(n_bits)) - 1) -#endif /*COMPATIBLE*/ +#endif #define HashTabOf(i) htab[i] #define CodeTabOf(i) codetab[i] @@ -454,9 +467,9 @@ gdGifEncoder::compress(int init_bits) #ifdef SIGNED_COMPARE_SLOW while((c = GIFNextPixel( )) !=(unsigned) EOF ) { -#else /*SIGNED_COMPARE_SLOW*/ +#else while((c = GIFNextPixel( )) != EOF ) { /* } */ -#endif /*SIGNED_COMPARE_SLOW*/ +#endif ++in_count; @@ -487,9 +500,9 @@ nomatch: ent = c; #ifdef SIGNED_COMPARE_SLOW if((unsigned) free_ent <(unsigned) maxmaxcode) { -#else /*SIGNED_COMPARE_SLOW*/ +#else if( free_ent < maxmaxcode ) { /* } */ -#endif /*SIGNED_COMPARE_SLOW*/ +#endif CodeTabOf(i) = free_ent++; /* code -> hashtable */ HashTabOf(i) = fcode; } else @@ -593,7 +606,7 @@ void } void - gdGifEncoder::cl_hash(register count_int hsize) /* reset code table */ + gdGifEncoder::cl_hash(count_int hsize) /* reset code table */ { @@ -667,9 +680,8 @@ void } } -gdGifEncoder::gdGifEncoder(Pool& pool, gdImage& aim, String& afp) : Pooled(pool), - im(aim), - fp(afp) { +gdGifEncoder::gdGifEncoder(gdImage& aim): + im(aim) { /* Some of these are properly initialized later. What I'm doing here is making sure code that depends on C's initialization of statics doesn't break when the code gets called more @@ -713,8 +725,12 @@ gdGifEncoder::gdGifEncoder(Pool& pool, g #define MAXCOLORMAPSIZE 256 +#ifndef TRUE #define TRUE 1 +#endif +#ifndef FALSE #define FALSE 0 +#endif #define CM_RED 0 #define CM_GREEN 1 @@ -742,14 +758,16 @@ gdGifEncoder::gdGifEncoder(Pool& pool, g unsigned int AspectRatio; }; #endif - + +/// Graphic Control Extension struct +#ifndef DOXYGEN struct Gif89 { int transparent; int delayTime; int inputFlag; int disposal; }; - +#endif static int ReadColorMap(FILE *fd, int number, unsigned char(*buffer)[256]); static int GetCode(FILE *fd, int code_size, int flag);