|
|
| version 1.12, 2001/09/21 14:46:09 | version 1.21.2.2.2.6, 2003/03/24 14:53:56 |
|---|---|
| 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) | |
| 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 23 | Line 34 |
| ** CompuServe Incorporated. GIF(sm) is a Service Mark property of | ** CompuServe Incorporated. GIF(sm) is a Service Mark property of |
| ** CompuServe Incorporated. | ** CompuServe Incorporated. |
| */ | */ |
| static const char *RCSId="$Id$"; | |
| static const char* IDENT_GIFIO_C="$Date$"; | |
| #include "gif.h" | #include "gif.h" |
| static int colorstobpp(int colors); | static int colorstobpp(int colors); |
| void gdImage::Gif(String& out) | gdBuf gdImage::Gif() |
| { | { |
| 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); | CORD_ec x; CORD_ec_init(x); |
| gdGifEncoder encoder(*this, x); | |
| /* 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, |
| red, green, blue); | red, green, blue); |
| CORD result=CORD_ec_to_cord(x); | |
| return gdBuf(CORD_to_char_star(result), CORD_len(result)); | |
| } | } |
| static int | static int |
| Line 73 colorstobpp(int colors) | Line 89 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 203 gdGifEncoder::encode(int GWidth, int GHe | Line 223 gdGifEncoder::encode(int GWidth, int GHe |
| /* | /* |
| * Write the Magic header | * 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 | * Write out the screen width and height |
| Line 312 gdGifEncoder::encode(int GWidth, int GHe | Line 333 gdGifEncoder::encode(int GWidth, int GHe |
| */ | */ |
| void | void |
| gdGifEncoder::Putbyte(int c) { | gdGifEncoder::Putbyte(int c) { |
| char *p=(char *)malloc(1); | CORD_ec_append(fp, c); |
| *p=c; | |
| fp.APPEND_AS_IS(p, 1, 0, 0); | |
| } | } |
| /* | /* |
| * Write out a word to the GIF file | * Write out a word to the GIF file |
| Line 322 gdGifEncoder::Putbyte(int c) { | Line 341 gdGifEncoder::Putbyte(int c) { |
| void | void |
| gdGifEncoder::Putword(int w) | gdGifEncoder::Putword(int w) |
| { | { |
| char *p=(char *)malloc(2); | CORD_ec_append(fp, w & 0xff); |
| p[0]=w & 0xff; | CORD_ec_append(fp, w >> 8); |
| p[1]=(w / 256) & 0xff; | |
| fp.APPEND_AS_IS(p, 2, 0, 0); | |
| } | } |
| inline void ec_append(CORD_ec& result, char *buf, size_t size) { | |
| while(size--) | |
| CORD_ec_append(result, *buf++); | |
| } | |
| void gdGifEncoder::Write(void *buf, size_t size) { | void gdGifEncoder::Write(void *buf, size_t size) { |
| char *p=(char *)malloc(size); | ec_append(fp, (char*)buf, size); |
| memcpy(p, buf, size); | |
| fp.APPEND_AS_IS(p, size, 0, 0); | |
| } | } |
| /*************************************************************************** | /*************************************************************************** |
| Line 665 void | Line 684 void |
| } | } |
| } | } |
| gdGifEncoder::gdGifEncoder(Pool& pool, gdImage& aim, String& afp) : Pooled(pool), | gdGifEncoder::gdGifEncoder(gdImage& aim, CORD_ec& 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 711 gdGifEncoder::gdGifEncoder(Pool& pool, g | Line 730 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 |