]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gifdecod.h
Don't define __STRICT_ANSI__, we should build both with and without it.
[wxWidgets.git] / include / wx / gifdecod.h
CommitLineData
661dc384 1/////////////////////////////////////////////////////////////////////////////
ce7208d4 2// Name: wx/gifdecod.h
661dc384
JS
3// Purpose: wxGIFDecoder, GIF reader for wxImage and wxAnimation
4// Author: Guillermo Rodriguez Garcia <guille@iies.es>
3c87527e 5// Version: 3.02
83413d6d 6// Copyright: (c) 1999 Guillermo Rodriguez Garcia
65571936 7// Licence: wxWindows licence
661dc384
JS
8/////////////////////////////////////////////////////////////////////////////
9
870cf35c
VZ
10#ifndef _WX_GIFDECOD_H_
11#define _WX_GIFDECOD_H_
661dc384 12
2ecf902b 13#include "wx/defs.h"
661dc384 14
83413d6d
GRG
15#if wxUSE_STREAMS && wxUSE_GIF
16
661dc384
JS
17#include "wx/stream.h"
18#include "wx/image.h"
72045d57 19#include "wx/animdecod.h"
7e0bac9d 20#include "wx/dynarray.h"
72045d57
VZ
21
22// internal utility used to store a frame in 8bit-per-pixel format
870cf35c 23class GIFImage;
661dc384
JS
24
25
e4b8154a 26// --------------------------------------------------------------------------
8141573c 27// Constants
e4b8154a
GRG
28// --------------------------------------------------------------------------
29
8141573c
GRG
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,
870cf35c 34// the stream will not be correctly positioned.
8141573c 35//
72045d57 36enum wxGIFErrorCode
8141573c 37{
870cf35c
VZ
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
8141573c
GRG
42};
43
e4b8154a
GRG
44// --------------------------------------------------------------------------
45// wxGIFDecoder class
46// --------------------------------------------------------------------------
47
53a2db12 48class WXDLLIMPEXP_CORE wxGIFDecoder : public wxAnimationDecoder
661dc384 49{
809e8e44 50public:
870cf35c
VZ
51 // constructor, destructor, etc.
52 wxGIFDecoder();
53 ~wxGIFDecoder();
54
661dc384 55 // get data of current frame
870cf35c
VZ
56 unsigned char* GetData(unsigned int frame) const;
57 unsigned char* GetPalette(unsigned int frame) const;
58 unsigned int GetNcolours(unsigned int frame) const;
59 int GetTransparentColourIndex(unsigned int frame) const;
60 wxColour GetTransparentColour(unsigned int frame) const;
72045d57 61
870cf35c
VZ
62 virtual wxSize GetFrameSize(unsigned int frame) const;
63 virtual wxPoint GetFramePosition(unsigned int frame) const;
64 virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const;
65 virtual long GetDelay(unsigned int frame) const;
72045d57
VZ
66
67 // GIFs can contain both static images and animations
68 bool IsAnimation() const
69 { return m_nFrames > 1; }
e4b8154a 70
72045d57
VZ
71 // load function which returns more info than just Load():
72 wxGIFErrorCode LoadGIF( wxInputStream& stream );
73
74 // free all internal frames
e4b8154a
GRG
75 void Destroy();
76
870cf35c 77 // implementation of wxAnimationDecoder's pure virtuals
72045d57
VZ
78 virtual bool Load( wxInputStream& stream )
79 { return LoadGIF(stream) == wxGIF_OK; }
80
870cf35c 81 bool ConvertToImage(unsigned int frame, wxImage *image) const;
22f3361e 82
72045d57
VZ
83 wxAnimationDecoder *Clone() const
84 { return new wxGIFDecoder; }
85 wxAnimationType GetType() const
86 { return wxANIMATION_TYPE_GIF; }
87
88private:
8faef7cc
FM
89 // wxAnimationDecoder pure virtual
90 virtual bool DoCanRead( wxInputStream& stream ) const;
91 // modifies current stream position (see wxAnimationDecoder::CanRead)
92
93 int getcode(wxInputStream& stream, int bits, int abfin);
94 wxGIFErrorCode dgif(wxInputStream& stream,
95 GIFImage *img, int interl, int bits);
96
03647350 97
870cf35c
VZ
98 // array of all frames
99 wxArrayPtrVoid m_frames;
100
101 // decoder state vars
102 int m_restbits; // remaining valid bits
103 unsigned int m_restbyte; // remaining bytes in this block
104 unsigned int m_lastbyte; // last byte read
105 unsigned char m_buffer[256]; // buffer for reading
106 unsigned char *m_bufp; // pointer to next byte in buffer
107
c0c133e1 108 wxDECLARE_NO_COPY_CLASS(wxGIFDecoder);
661dc384
JS
109};
110
b0f76951 111#endif // wxUSE_STREAMS && wxUSE_GIF
661dc384 112
870cf35c 113#endif // _WX_GIFDECOD_H_