]> git.saurik.com Git - wxWidgets.git/blob - include/wx/gifdecod.h
Added GSocket/wxSocket alias to socket.h to prevent us from using GSocket
[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 // Last rev: 1999/08/18
7 // Copyright: (c) 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
21 #include "wx/stream.h"
22 #include "wx/image.h"
23
24
25 typedef struct _IMAGEN
26 {
27 unsigned int w; /* width */
28 unsigned int h; /* height */
29 unsigned int left; /* x coord (in logical screen) */
30 unsigned int top; /* y coord (in logical screen) */
31 int transparent; /* transparent color (-1 = none) */
32 int disposal; /* disposal method (-1 = unspecified) */
33 long delay; /* delay in ms (-1 = unused) */
34 unsigned char *p; /* bitmap */
35 unsigned char *pal; /* palette */
36 struct _IMAGEN *next; /* next image */
37 struct _IMAGEN *prev; /* prev image */
38 } IMAGEN;
39
40
41 /* disposal method */
42 #define D_UNSPECIFIED -1 /* not specified */
43 #define D_DONOTDISPOSE 0 /* do not dispose */
44 #define D_TOBACKGROUND 1 /* restore to background colour */
45 #define D_TOPREVIOUS 2 /* restore to previous image */
46
47 /* error codes */
48 #define E_OK 0 /* everything was OK */
49 #define E_ARCHIVO -1 /* error opening file */
50 #define E_FORMATO -2 /* error in gif header */
51 #define E_MEMORIA -3 /* error allocating memory */
52
53
54 class wxGIFDecoder
55 {
56 private:
57 /* logical screen */
58 unsigned int m_screenw; /* logical screen width */
59 unsigned int m_screenh; /* logical screen height */
60 int m_background; /* background color (-1 = none) */
61
62 /* image data */
63 bool m_anim; /* animated GIF */
64 int m_nimages; /* number of images */
65 int m_image; /* current image */
66 IMAGEN *m_pimage; /* pointer to current image */
67 IMAGEN *m_pfirst; /* pointer to first image */
68 IMAGEN *m_plast; /* pointer to last image */
69
70 /* decoder state vars */
71 int m_restbits; /* remaining valid bits */
72 unsigned int m_restbyte; /* remaining bytes in this block */
73 unsigned int m_lastbyte; /* last byte read */
74
75 wxInputStream *m_f; /* input file */
76
77 private:
78 int getcode(int bits, int abfin);
79 int dgif(IMAGEN *img, int interl, int bits);
80
81 public:
82 // constructor, destructor, etc.
83 wxGIFDecoder(wxInputStream *s, bool anim = FALSE);
84 ~wxGIFDecoder();
85 bool CanRead();
86 int ReadGIF();
87 void Destroy();
88
89 // convert current frame to wxImage
90 bool ConvertToImage(wxImage *image) const;
91
92 // get data of current frame
93 int GetFrameIndex() const;
94 unsigned char* GetData() const;
95 unsigned char* GetPalette() const;
96 unsigned int GetWidth() const;
97 unsigned int GetHeight() const;
98 unsigned int GetLeft() const;
99 unsigned int GetTop() const;
100 int GetDisposalMethod() const;
101 int GetTransparentColour() const;
102 long GetDelay() const;
103
104 // get global data
105 unsigned int GetLogicalScreenWidth() const;
106 unsigned int GetLogicalScreenHeight() const;
107 int GetBackgroundColour() const;
108 int GetNumberOfFrames() const;
109 bool IsAnimation() const;
110
111 // move through the animation
112 bool GoFirstFrame();
113 bool GoLastFrame();
114 bool GoNextFrame(bool cyclic = FALSE);
115 bool GoPrevFrame(bool cyclic = FALSE);
116 bool GoFrame(int which);
117 };
118
119
120 #endif // wxUSE_STREAM
121 #endif // _WX_GIFDECOD_H
122