|
|
| version 1.5.2.1, 2001/04/16 11:26:38 | version 1.21.2.2.2.5, 2003/03/24 13:43:40 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: image manipulations impl2. | Parser: image manipulations impl2. |
| Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf) | Copyright (c) 2001-2003 ArtLebedev Group (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | |
| $Id$ | 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: | based on: |
| ** | ** |
| Line 27 | Line 35 |
| ** CompuServe Incorporated. | ** CompuServe Incorporated. |
| */ | */ |
| static const char* IDENT_GIFIO_C="$Date$"; | |
| #include "gif.h" | #include "gif.h" |
| static int colorstobpp(int colors); | static int colorstobpp(int colors); |
| Line 35 void gdImage::Gif(String& out) | Line 45 void gdImage::Gif(String& out) |
| { | { |
| int BitsPerPixel = colorstobpp(colorsTotal); | int BitsPerPixel = colorstobpp(colorsTotal); |
| /* Clear any old values in statics strewn through the GIF code */ | /* Clear any old values in statics strewn through the GIF code */ |
| gdGifEncoder encoder(pool(), *this, out); | gdGifEncoder encoder(*this, out); |
| /* All set, let's do it. */ | /* All set, let's do it. */ |
| encoder.encode( | encoder.encode( |
| sx, sy, interlace, 0, transparent, BitsPerPixel, | sx, sy, interlace, 0, transparent, BitsPerPixel, |
| Line 75 colorstobpp(int colors) | Line 85 colorstobpp(int colors) |
| * | * |
| *****************************************************************************/ | *****************************************************************************/ |
| #ifndef TRUE | |
| #define TRUE 1 | #define TRUE 1 |
| #endif | |
| #ifndef FALSE | |
| #define FALSE 0 | #define FALSE 0 |
| #endif | |
| /* | /* |
| * Bump the 'curx' and 'cury' to point to the next pixel | * Bump the 'curx' and 'cury' to point to the next pixel |
| Line 314 gdGifEncoder::encode(int GWidth, int GHe | Line 328 gdGifEncoder::encode(int GWidth, int GHe |
| */ | */ |
| void | void |
| gdGifEncoder::Putbyte(int c) { | gdGifEncoder::Putbyte(int c) { |
| char *p=(char *)malloc(1); | char *p=new(PointerFreeGC) char[1]; |
| *p=c; | *p=c; |
| fp.APPEND_CLEAN(p, 1, 0, 0); | fp.append(p, 1, String::L_AS_IS); |
| } | } |
| /* | /* |
| * Write out a word to the GIF file | * Write out a word to the GIF file |
| Line 324 gdGifEncoder::Putbyte(int c) { | Line 338 gdGifEncoder::Putbyte(int c) { |
| void | void |
| gdGifEncoder::Putword(int w) | gdGifEncoder::Putword(int w) |
| { | { |
| char *p=(char *)malloc(2); | char *p=new(PointerFreeGC) char[2]; |
| p[0]=w & 0xff; | p[0]=w & 0xff; |
| p[1]=(w / 256) & 0xff; | p[1]=(w / 256) & 0xff; |
| fp.APPEND_CLEAN(p, 2, 0, 0); | fp.append(p, 2, String::L_AS_IS); |
| } | } |
| void gdGifEncoder::Write(void *buf, size_t size) { | void gdGifEncoder::Write(void *buf, size_t size) { |
| char *p=(char *)malloc(size); | char *p=new(PointerFreeGC) char[size]; |
| memcpy(p, buf, size); | memcpy(p, buf, size); |
| fp.APPEND_CLEAN(p, size, 0, 0); | fp.append(p, size, String::L_AS_IS); |
| } | } |
| /*************************************************************************** | /*************************************************************************** |
| Line 353 void gdGifEncoder::Write(void *buf, size | Line 367 void gdGifEncoder::Write(void *buf, size |
| #ifdef NO_UCHAR | #ifdef NO_UCHAR |
| typedef char char_type; | typedef char char_type; |
| #else /*NO_UCHAR*/ | #else |
| typedef unsigned char char_type; | typedef unsigned char char_type; |
| #endif /*NO_UCHAR*/ | #endif |
| /* | /* |
| * | * |
| Line 373 typedef unsigned char char_type | Line 387 typedef unsigned char char_type |
| */ | */ |
| #ifdef COMPATIBLE /* But wrong! */ | #ifdef COMPATIBLE /* But wrong! */ |
| # define MAXCODE(n_bits) ((code_int) 1 <<(n_bits) - 1) | # define MAXCODE(n_bits) ((code_int) 1 <<(n_bits) - 1) |
| #else /*COMPATIBLE*/ | #else |
| # define MAXCODE(n_bits) (((code_int) 1 <<(n_bits)) - 1) | # define MAXCODE(n_bits) (((code_int) 1 <<(n_bits)) - 1) |
| #endif /*COMPATIBLE*/ | #endif |
| #define HashTabOf(i) htab[i] | #define HashTabOf(i) htab[i] |
| #define CodeTabOf(i) codetab[i] | #define CodeTabOf(i) codetab[i] |
| Line 454 gdGifEncoder::compress(int init_bits) | Line 468 gdGifEncoder::compress(int init_bits) |
| #ifdef SIGNED_COMPARE_SLOW | #ifdef SIGNED_COMPARE_SLOW |
| while((c = GIFNextPixel( )) !=(unsigned) EOF ) { | while((c = GIFNextPixel( )) !=(unsigned) EOF ) { |
| #else /*SIGNED_COMPARE_SLOW*/ | #else |
| while((c = GIFNextPixel( )) != EOF ) { /* } */ | while((c = GIFNextPixel( )) != EOF ) { /* } */ |
| #endif /*SIGNED_COMPARE_SLOW*/ | #endif |
| ++in_count; | ++in_count; |
| Line 487 nomatch: | Line 501 nomatch: |
| ent = c; | ent = c; |
| #ifdef SIGNED_COMPARE_SLOW | #ifdef SIGNED_COMPARE_SLOW |
| if((unsigned) free_ent <(unsigned) maxmaxcode) { | if((unsigned) free_ent <(unsigned) maxmaxcode) { |
| #else /*SIGNED_COMPARE_SLOW*/ | #else |
| if( free_ent < maxmaxcode ) { /* } */ | if( free_ent < maxmaxcode ) { /* } */ |
| #endif /*SIGNED_COMPARE_SLOW*/ | #endif |
| CodeTabOf(i) = free_ent++; /* code -> hashtable */ | CodeTabOf(i) = free_ent++; /* code -> hashtable */ |
| HashTabOf(i) = fcode; | HashTabOf(i) = fcode; |
| } else | } else |
| Line 593 void | Line 607 void |
| } | } |
| void | void |
| gdGifEncoder::cl_hash(register count_int hsize) /* reset code table */ | gdGifEncoder::cl_hash(count_int hsize) /* reset code table */ |
| { | { |
| Line 667 void | Line 681 void |
| } | } |
| } | } |
| gdGifEncoder::gdGifEncoder(Pool& pool, gdImage& aim, String& afp) : Pooled(pool), | gdGifEncoder::gdGifEncoder(gdImage& aim, String& afp): |
| im(aim), | im(aim), |
| fp(afp) { | fp(afp) { |
| /* Some of these are properly initialized later. What I'm doing | /* Some of these are properly initialized later. What I'm doing |
| Line 713 gdGifEncoder::gdGifEncoder(Pool& pool, g | Line 727 gdGifEncoder::gdGifEncoder(Pool& pool, g |
| #define MAXCOLORMAPSIZE 256 | #define MAXCOLORMAPSIZE 256 |
| #ifndef TRUE | |
| #define TRUE 1 | #define TRUE 1 |
| #endif | |
| #ifndef FALSE | |
| #define FALSE 0 | #define FALSE 0 |
| #endif | |
| #define CM_RED 0 | #define CM_RED 0 |
| #define CM_GREEN 1 | #define CM_GREEN 1 |
| Line 742 gdGifEncoder::gdGifEncoder(Pool& pool, g | Line 760 gdGifEncoder::gdGifEncoder(Pool& pool, g |
| unsigned int AspectRatio; | unsigned int AspectRatio; |
| }; | }; |
| #endif | #endif |
| /// Graphic Control Extension struct | |
| #ifndef DOXYGEN | |
| struct Gif89 { | struct Gif89 { |
| int transparent; | int transparent; |
| int delayTime; | int delayTime; |
| int inputFlag; | int inputFlag; |
| int disposal; | int disposal; |
| }; | }; |
| #endif | |
| static int ReadColorMap(FILE *fd, int number, unsigned char(*buffer)[256]); | static int ReadColorMap(FILE *fd, int number, unsigned char(*buffer)[256]); |
| static int GetCode(FILE *fd, int code_size, int flag); | static int GetCode(FILE *fd, int code_size, int flag); |