]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/gifdecod.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation
4 // Author: Guillermo Rodriguez Garcia <guille@iies.es>
7 // Copyright: (c) 1999 Guillermo Rodriguez Garcia
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_GIFDECOD_H
12 #define _WX_GIFDECOD_H
16 #if wxUSE_STREAMS && wxUSE_GIF
18 #include "wx/stream.h"
22 // --------------------------------------------------------------------------
24 // --------------------------------------------------------------------------
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
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 */
41 // Experimental; subject to change.
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 */
52 #define MAX_BLOCK_SIZE 256 /* max. block size */
55 // --------------------------------------------------------------------------
57 // --------------------------------------------------------------------------
59 // internal class for storing GIF image data
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) */
71 int disposal
; /* disposal method (-1 = unspecified) */
72 long delay
; /* delay in ms (-1 = unused) */
73 unsigned char *p
; /* bitmap */
74 unsigned char *pal
; /* palette */
75 GIFImage
*next
; /* next image */
76 GIFImage
*prev
; /* prev image */
78 DECLARE_NO_COPY_CLASS(GIFImage
)
82 class WXDLLEXPORT wxGIFDecoder
86 unsigned int m_screenw
; /* logical screen width */
87 unsigned int m_screenh
; /* logical screen height */
88 int m_background
; /* background color (-1 = none) */
91 bool m_anim
; /* animated GIF */
92 int m_nimages
; /* number of images */
93 int m_image
; /* current image */
94 GIFImage
*m_pimage
; /* pointer to current image */
95 GIFImage
*m_pfirst
; /* pointer to first image */
96 GIFImage
*m_plast
; /* pointer to last image */
99 int m_restbits
; /* remaining valid bits */
100 unsigned int m_restbyte
; /* remaining bytes in this block */
101 unsigned int m_lastbyte
; /* last byte read */
102 unsigned char m_buffer
[MAX_BLOCK_SIZE
]; /* buffer for reading */
103 unsigned char *m_bufp
; /* pointer to next byte in buffer */
106 wxInputStream
*m_f
; /* input stream */
109 int getcode(int bits
, int abfin
);
110 int dgif(GIFImage
*img
, int interl
, int bits
);
113 // get data of current frame
114 int GetFrameIndex() const;
115 unsigned char* GetData() const;
116 unsigned char* GetPalette() const;
117 unsigned int GetWidth() const;
118 unsigned int GetHeight() const;
119 unsigned int GetLeft() const;
120 unsigned int GetTop() const;
121 int GetDisposalMethod() const;
122 int GetTransparentColour() const;
123 long GetDelay() const;
126 unsigned int GetLogicalScreenWidth() const;
127 unsigned int GetLogicalScreenHeight() const;
128 int GetBackgroundColour() const;
129 int GetNumberOfFrames() const;
130 bool IsAnimation() const;
132 // move through the animation
135 bool GoNextFrame(bool cyclic
= false);
136 bool GoPrevFrame(bool cyclic
= false);
137 bool GoFrame(int which
);
140 // constructor, destructor, etc.
141 wxGIFDecoder(wxInputStream
*s
, bool anim
= false);
147 // convert current frame to wxImage
148 bool ConvertToImage(wxImage
*image
) const;
150 DECLARE_NO_COPY_CLASS(wxGIFDecoder
)
154 #endif // wxUSE_STREAM && wxUSE_GIF
155 #endif // _WX_GIFDECOD_H