]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gifdecod.h
last line missing
[wxWidgets.git] / include / wx / gifdecod.h
CommitLineData
661dc384
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: gifdecod.h
3// Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation
4// Author: Guillermo Rodriguez Garcia <guille@iies.es>
3c87527e 5// Version: 3.02
83413d6d
GRG
6// CVS-ID: $Id$
7// Copyright: (c) 1999 Guillermo Rodriguez Garcia
661dc384
JS
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_GIFDECOD_H
12#define _WX_GIFDECOD_H
13
14#ifdef __GNUG__
15#pragma interface "gifdecod.h"
16#endif
17
18#include "wx/setup.h"
19
83413d6d
GRG
20#if wxUSE_STREAMS && wxUSE_GIF
21
661dc384
JS
22#include "wx/stream.h"
23#include "wx/image.h"
24
25
e4b8154a
GRG
26// --------------------------------------------------------------------------
27// constants
28// --------------------------------------------------------------------------
29
30// disposal method
31enum
32{
33 wxGIF_D_UNSPECIFIED = -1, /* not specified */
34 wxGIF_D_DONOTDISPOSE = 0, /* do not dispose */
35 wxGIF_D_TOBACKGROUND = 1, /* restore to background colour */
36 wxGIF_D_TOPREVIOUS = 2 /* restore to previous image */
37};
38
39// error codes
40enum
41{
42 wxGIF_OK = 0, /* everything was OK */
43 wxGIF_INVFORMAT = 1, /* error in gif header */
44 wxGIF_MEMERR = 2 /* error allocating memory */
45};
46
47#define MAX_BLOCK_SIZE 256 /* max. block size */
48
49
50// --------------------------------------------------------------------------
51// wxGIFDecoder class
52// --------------------------------------------------------------------------
53
54// internal class for storing GIF image data
55class GIFImage
661dc384 56{
e4b8154a 57public:
661dc384
JS
58 unsigned int w; /* width */
59 unsigned int h; /* height */
60 unsigned int left; /* x coord (in logical screen) */
61 unsigned int top; /* y coord (in logical screen) */
62 int transparent; /* transparent color (-1 = none) */
3c87527e 63 int disposal; /* disposal method (-1 = unspecified) */
661dc384
JS
64 long delay; /* delay in ms (-1 = unused) */
65 unsigned char *p; /* bitmap */
66 unsigned char *pal; /* palette */
e4b8154a
GRG
67 GIFImage *next; /* next image */
68 GIFImage *prev; /* prev image */
69};
661dc384 70
76443e70 71
b31ba288 72class WXDLLEXPORT wxGIFDecoder
661dc384
JS
73{
74private:
e4b8154a 75 // logical screen
661dc384
JS
76 unsigned int m_screenw; /* logical screen width */
77 unsigned int m_screenh; /* logical screen height */
78 int m_background; /* background color (-1 = none) */
79
e4b8154a 80 // image data
661dc384
JS
81 bool m_anim; /* animated GIF */
82 int m_nimages; /* number of images */
83 int m_image; /* current image */
e4b8154a
GRG
84 GIFImage *m_pimage; /* pointer to current image */
85 GIFImage *m_pfirst; /* pointer to first image */
86 GIFImage *m_plast; /* pointer to last image */
661dc384 87
e4b8154a 88 // decoder state vars
661dc384
JS
89 int m_restbits; /* remaining valid bits */
90 unsigned int m_restbyte; /* remaining bytes in this block */
91 unsigned int m_lastbyte; /* last byte read */
76443e70
GRG
92 unsigned char m_buffer[MAX_BLOCK_SIZE]; /* buffer for reading */
93 unsigned char *m_bufp; /* pointer to next byte in buffer */
661dc384 94
e4b8154a
GRG
95 // input stream
96 wxInputStream *m_f; /* input stream */
661dc384
JS
97
98private:
99 int getcode(int bits, int abfin);
e4b8154a 100 int dgif(GIFImage *img, int interl, int bits);
661dc384 101
e4b8154a 102protected:
661dc384
JS
103 // get data of current frame
104 int GetFrameIndex() const;
105 unsigned char* GetData() const;
106 unsigned char* GetPalette() const;
107 unsigned int GetWidth() const;
108 unsigned int GetHeight() const;
109 unsigned int GetLeft() const;
110 unsigned int GetTop() const;
111 int GetDisposalMethod() const;
112 int GetTransparentColour() const;
113 long GetDelay() const;
114
115 // get global data
116 unsigned int GetLogicalScreenWidth() const;
117 unsigned int GetLogicalScreenHeight() const;
118 int GetBackgroundColour() const;
119 int GetNumberOfFrames() const;
120 bool IsAnimation() const;
121
122 // move through the animation
123 bool GoFirstFrame();
124 bool GoLastFrame();
125 bool GoNextFrame(bool cyclic = FALSE);
126 bool GoPrevFrame(bool cyclic = FALSE);
127 bool GoFrame(int which);
e4b8154a
GRG
128
129public:
130 // constructor, destructor, etc.
131 wxGIFDecoder(wxInputStream *s, bool anim = FALSE);
132 ~wxGIFDecoder();
133 bool CanRead();
134 int ReadGIF();
135 void Destroy();
136
137 // convert current frame to wxImage
138 bool ConvertToImage(wxImage *image) const;
661dc384
JS
139};
140
141
83413d6d 142#endif // wxUSE_STREAM && wxUSE_GIF
661dc384
JS
143#endif // _WX_GIFDECOD_H
144