1999-08-18 06:28:59 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: gifdecod.h
|
|
|
|
// Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation
|
|
|
|
// Author: Guillermo Rodriguez Garcia <guille@iies.es>
|
1999-08-24 22:13:26 +00:00
|
|
|
// Version: 3.02
|
1999-09-09 22:12:08 +00:00
|
|
|
// CVS-ID: $Id$
|
|
|
|
// Copyright: (c) 1999 Guillermo Rodriguez Garcia
|
1999-08-18 06:28:59 +00:00
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#ifndef _WX_GIFDECOD_H
|
|
|
|
#define _WX_GIFDECOD_H
|
|
|
|
|
2002-08-31 11:29:13 +00:00
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
1999-08-18 06:28:59 +00:00
|
|
|
#pragma interface "gifdecod.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/setup.h"
|
|
|
|
|
1999-09-09 22:12:08 +00:00
|
|
|
#if wxUSE_STREAMS && wxUSE_GIF
|
|
|
|
|
1999-08-18 06:28:59 +00:00
|
|
|
#include "wx/stream.h"
|
|
|
|
#include "wx/image.h"
|
|
|
|
|
|
|
|
|
1999-12-10 20:16:01 +00:00
|
|
|
// --------------------------------------------------------------------------
|
2000-02-17 23:39:35 +00:00
|
|
|
// Constants
|
1999-12-10 20:16:01 +00:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2000-02-17 23:39:35 +00:00
|
|
|
// Error codes:
|
|
|
|
// Note that the error code wxGIF_TRUNCATED means that the image itself
|
|
|
|
// is most probably OK, but the decoder didn't reach the end of the data
|
|
|
|
// stream; this means that if it was not reading directly from file,
|
|
|
|
// the stream will not be correctly positioned. the
|
|
|
|
//
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
wxGIF_OK = 0, /* everything was OK */
|
|
|
|
wxGIF_INVFORMAT, /* error in gif header */
|
|
|
|
wxGIF_MEMERR, /* error allocating memory */
|
|
|
|
wxGIF_TRUNCATED /* file appears to be truncated */
|
|
|
|
};
|
|
|
|
|
|
|
|
// Disposal method
|
|
|
|
// Experimental; subject to change.
|
|
|
|
//
|
1999-12-10 20:16:01 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
wxGIF_D_UNSPECIFIED = -1, /* not specified */
|
|
|
|
wxGIF_D_DONOTDISPOSE = 0, /* do not dispose */
|
|
|
|
wxGIF_D_TOBACKGROUND = 1, /* restore to background colour */
|
|
|
|
wxGIF_D_TOPREVIOUS = 2 /* restore to previous image */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX_BLOCK_SIZE 256 /* max. block size */
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
// wxGIFDecoder class
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// internal class for storing GIF image data
|
|
|
|
class GIFImage
|
1999-08-18 06:28:59 +00:00
|
|
|
{
|
1999-12-10 20:16:01 +00:00
|
|
|
public:
|
2002-01-13 01:26:57 +00:00
|
|
|
// def ctor
|
|
|
|
GIFImage();
|
|
|
|
|
1999-08-18 06:28:59 +00:00
|
|
|
unsigned int w; /* width */
|
|
|
|
unsigned int h; /* height */
|
|
|
|
unsigned int left; /* x coord (in logical screen) */
|
|
|
|
unsigned int top; /* y coord (in logical screen) */
|
|
|
|
int transparent; /* transparent color (-1 = none) */
|
1999-08-24 22:13:26 +00:00
|
|
|
int disposal; /* disposal method (-1 = unspecified) */
|
1999-08-18 06:28:59 +00:00
|
|
|
long delay; /* delay in ms (-1 = unused) */
|
|
|
|
unsigned char *p; /* bitmap */
|
|
|
|
unsigned char *pal; /* palette */
|
1999-12-10 20:16:01 +00:00
|
|
|
GIFImage *next; /* next image */
|
|
|
|
GIFImage *prev; /* prev image */
|
2003-01-02 23:38:11 +00:00
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(GIFImage)
|
1999-12-10 20:16:01 +00:00
|
|
|
};
|
1999-08-18 06:28:59 +00:00
|
|
|
|
1999-12-08 14:39:28 +00:00
|
|
|
|
1999-09-13 13:16:28 +00:00
|
|
|
class WXDLLEXPORT wxGIFDecoder
|
1999-08-18 06:28:59 +00:00
|
|
|
{
|
|
|
|
private:
|
1999-12-10 20:16:01 +00:00
|
|
|
// logical screen
|
1999-08-18 06:28:59 +00:00
|
|
|
unsigned int m_screenw; /* logical screen width */
|
|
|
|
unsigned int m_screenh; /* logical screen height */
|
|
|
|
int m_background; /* background color (-1 = none) */
|
|
|
|
|
1999-12-10 20:16:01 +00:00
|
|
|
// image data
|
1999-08-18 06:28:59 +00:00
|
|
|
bool m_anim; /* animated GIF */
|
|
|
|
int m_nimages; /* number of images */
|
|
|
|
int m_image; /* current image */
|
1999-12-10 20:16:01 +00:00
|
|
|
GIFImage *m_pimage; /* pointer to current image */
|
|
|
|
GIFImage *m_pfirst; /* pointer to first image */
|
|
|
|
GIFImage *m_plast; /* pointer to last image */
|
1999-08-18 06:28:59 +00:00
|
|
|
|
1999-12-10 20:16:01 +00:00
|
|
|
// decoder state vars
|
1999-08-18 06:28:59 +00:00
|
|
|
int m_restbits; /* remaining valid bits */
|
|
|
|
unsigned int m_restbyte; /* remaining bytes in this block */
|
|
|
|
unsigned int m_lastbyte; /* last byte read */
|
1999-12-08 14:39:28 +00:00
|
|
|
unsigned char m_buffer[MAX_BLOCK_SIZE]; /* buffer for reading */
|
|
|
|
unsigned char *m_bufp; /* pointer to next byte in buffer */
|
1999-08-18 06:28:59 +00:00
|
|
|
|
1999-12-10 20:16:01 +00:00
|
|
|
// input stream
|
|
|
|
wxInputStream *m_f; /* input stream */
|
1999-08-18 06:28:59 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int getcode(int bits, int abfin);
|
1999-12-10 20:16:01 +00:00
|
|
|
int dgif(GIFImage *img, int interl, int bits);
|
1999-08-18 06:28:59 +00:00
|
|
|
|
2001-07-02 10:06:51 +00:00
|
|
|
public:
|
1999-08-18 06:28:59 +00:00
|
|
|
// get data of current frame
|
|
|
|
int GetFrameIndex() const;
|
|
|
|
unsigned char* GetData() const;
|
|
|
|
unsigned char* GetPalette() const;
|
|
|
|
unsigned int GetWidth() const;
|
|
|
|
unsigned int GetHeight() const;
|
|
|
|
unsigned int GetLeft() const;
|
|
|
|
unsigned int GetTop() const;
|
|
|
|
int GetDisposalMethod() const;
|
|
|
|
int GetTransparentColour() const;
|
|
|
|
long GetDelay() const;
|
|
|
|
|
|
|
|
// get global data
|
|
|
|
unsigned int GetLogicalScreenWidth() const;
|
|
|
|
unsigned int GetLogicalScreenHeight() const;
|
|
|
|
int GetBackgroundColour() const;
|
|
|
|
int GetNumberOfFrames() const;
|
|
|
|
bool IsAnimation() const;
|
|
|
|
|
|
|
|
// move through the animation
|
|
|
|
bool GoFirstFrame();
|
|
|
|
bool GoLastFrame();
|
|
|
|
bool GoNextFrame(bool cyclic = FALSE);
|
|
|
|
bool GoPrevFrame(bool cyclic = FALSE);
|
|
|
|
bool GoFrame(int which);
|
1999-12-10 20:16:01 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// constructor, destructor, etc.
|
|
|
|
wxGIFDecoder(wxInputStream *s, bool anim = FALSE);
|
|
|
|
~wxGIFDecoder();
|
|
|
|
bool CanRead();
|
|
|
|
int ReadGIF();
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
// convert current frame to wxImage
|
|
|
|
bool ConvertToImage(wxImage *image) const;
|
2003-01-02 23:38:11 +00:00
|
|
|
|
|
|
|
DECLARE_NO_COPY_CLASS(wxGIFDecoder)
|
1999-08-18 06:28:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-09-09 22:12:08 +00:00
|
|
|
#endif // wxUSE_STREAM && wxUSE_GIF
|
1999-08-18 06:28:59 +00:00
|
|
|
#endif // _WX_GIFDECOD_H
|
|
|
|
|