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