From 99cc0158e2dd9ef4067fae9305b82321579a685e Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Mon, 12 Apr 1999 13:44:52 +0000 Subject: [PATCH] ... git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2100 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/imaggif.cpp | 51 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/src/common/imaggif.cpp b/src/common/imaggif.cpp index 887e94e924..0d83a397c9 100644 --- a/src/common/imaggif.cpp +++ b/src/common/imaggif.cpp @@ -40,13 +40,14 @@ FOLLOWING CODE IS BY G.R.G. : Guillermo Rodriguez Garcia - Version: 2.0 + Version: 2.1 *************************************************************************/ typedef struct { int w; /* width */ int h; /* height */ + int transparent; /* transparent color (-1 = none) */ unsigned char *p; /* bitmap */ unsigned char *pal; /* palette */ } IMAGEN; @@ -60,7 +61,7 @@ typedef struct Guillermo Rodriguez Garcia - Version: 2.0 + Version: 2.1 *************************************************************************/ @@ -94,12 +95,19 @@ class gifDecoder int readgif(IMAGEN *img); private: - int mygetc() {return (unsigned char)f -> GetC();} + unsigned char mygetc(); // This is NEEDED! GetC is char (signed) why we need unsigned value // from here }; +unsigned char gifDecoder::mygetc() +{ + unsigned char c; + f -> Read(&c, 1); + return c; +} + /* getcode: * Reads the next code from the file, with size 'bits' @@ -303,13 +311,26 @@ int gifDecoder::readgif(IMAGEN *img) f -> Read(pal, 3 * ncolors); } - /* skip extensions */ - while (mygetc() == 0x21) /* separator */ - { - mygetc(); /* function code */ + /* assume no transparent color */ + img->transparent = -1; - while ((i = mygetc()) != 0) /* byte count */ - f -> SeekI(i, wxFromCurrent); + /* skip most extensions */ + while (mygetc() == 0x21) /* separator */ + { + wxLogDebug("ugh"); + if (mygetc() == 0xF9) /* graphic control ext. */ + { + wxLogDebug("..."); + f->Read(buf, 6); + wxLogDebug("buf[1] is %i (%i)", buf[1], buf[1] & 0x01); + if (buf[1] & 0x01) { + wxLogDebug("setting transparen %i", buf[4]); + img->transparent = buf[4]; + } + } + else + while ((i = mygetc()) != 0) /* byte count */ + f->SeekI(i, wxFromCurrent); } /* read image descriptor block (IDB) */ @@ -392,6 +413,13 @@ bool wxGIFHandler::LoadFile( wxImage *image, wxInputStream& stream ) *(ptr++) = pal[3 * (*src) + 2]; } + if (igif.transparent != -1) { + wxLogDebug("oko"); + image->SetMaskColour(pal[3 * (igif.transparent) + 0], pal[3 * (igif.transparent) + 0], pal[3 * (igif.transparent) + 0]); + image->SetMask(TRUE); + } + + wxLogDebug("(unsigned int)%i", (unsigned int)-1); free(igif.pal); free(igif.p); return TRUE; @@ -404,3 +432,8 @@ bool wxGIFHandler::SaveFile( wxImage *image, wxOutputStream& stream ) } + + + + + -- 2.45.2