]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gifdecod.h
added wxStreamBuffer::Truncate() (patch 1687081)
[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
GRG
6// CVS-ID: $Id$
7// Copyright: (c) 1999 Guillermo Rodriguez Garcia
65571936 8// Licence: wxWindows licence
661dc384
JS
9/////////////////////////////////////////////////////////////////////////////
10
870cf35c
VZ
11#ifndef _WX_GIFDECOD_H_
12#define _WX_GIFDECOD_H_
661dc384 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"
72045d57
VZ
20#include "wx/animdecod.h"
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
72045d57 48class WXDLLEXPORT 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 CanRead( wxInputStream& stream ) const;
79 virtual bool Load( wxInputStream& stream )
80 { return LoadGIF(stream) == wxGIF_OK; }
81
870cf35c 82 bool ConvertToImage(unsigned int frame, wxImage *image) const;
22f3361e 83
72045d57
VZ
84 wxAnimationDecoder *Clone() const
85 { return new wxGIFDecoder; }
86 wxAnimationType GetType() const
87 { return wxANIMATION_TYPE_GIF; }
88
89private:
870cf35c
VZ
90 // array of all frames
91 wxArrayPtrVoid m_frames;
92
93 // decoder state vars
94 int m_restbits; // remaining valid bits
95 unsigned int m_restbyte; // remaining bytes in this block
96 unsigned int m_lastbyte; // last byte read
97 unsigned char m_buffer[256]; // buffer for reading
98 unsigned char *m_bufp; // pointer to next byte in buffer
99
100 int getcode(wxInputStream& stream, int bits, int abfin);
101 wxGIFErrorCode dgif(wxInputStream& stream,
102 GIFImage *img, int interl, int bits);
103
22f3361e 104 DECLARE_NO_COPY_CLASS(wxGIFDecoder)
661dc384
JS
105};
106
870cf35c 107#endif // wxUSE_STREAM && wxUSE_GIF
661dc384 108
870cf35c 109#endif // _WX_GIFDECOD_H_