]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gifdecod.h
Added GAddress_INET_SetAnyAddress and dummy UNIX address handling.
[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 #ifdef __GNUG__
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 // disposal method
31 enum
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
40 enum
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
55 class GIFImage
56 {
57 public:
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) */
63 int disposal; /* disposal method (-1 = unspecified) */
64 long delay; /* delay in ms (-1 = unused) */
65 unsigned char *p; /* bitmap */
66 unsigned char *pal; /* palette */
67 GIFImage *next; /* next image */
68 GIFImage *prev; /* prev image */
69 };
70
71
72 class WXDLLEXPORT wxGIFDecoder
73 {
74 private:
75 // logical screen
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
80 // image data
81 bool m_anim; /* animated GIF */
82 int m_nimages; /* number of images */
83 int m_image; /* current image */
84 GIFImage *m_pimage; /* pointer to current image */
85 GIFImage *m_pfirst; /* pointer to first image */
86 GIFImage *m_plast; /* pointer to last image */
87
88 // decoder state vars
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 */
92 unsigned char m_buffer[MAX_BLOCK_SIZE]; /* buffer for reading */
93 unsigned char *m_bufp; /* pointer to next byte in buffer */
94
95 // input stream
96 wxInputStream *m_f; /* input stream */
97
98 private:
99 int getcode(int bits, int abfin);
100 int dgif(GIFImage *img, int interl, int bits);
101
102 protected:
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);
128
129 public:
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;
139 };
140
141
142 #endif // wxUSE_STREAM && wxUSE_GIF
143 #endif // _WX_GIFDECOD_H
144