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