File: gifdecod.h

package info (click to toggle)
wxwidgets3.0 3.0.5.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 120,464 kB
  • sloc: cpp: 896,633; makefile: 52,303; ansic: 21,971; sh: 5,713; python: 2,940; xml: 1,534; perl: 264; javascript: 33
file content (113 lines) | stat: -rw-r--r-- 3,878 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/////////////////////////////////////////////////////////////////////////////
// Name:        wx/gifdecod.h
// Purpose:     wxGIFDecoder, GIF reader for wxImage and wxAnimation
// Author:      Guillermo Rodriguez Garcia <guille@iies.es>
// Version:     3.02
// Copyright:   (c) 1999 Guillermo Rodriguez Garcia
// Licence:     wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef _WX_GIFDECOD_H_
#define _WX_GIFDECOD_H_

#include "wx/defs.h"

#if wxUSE_STREAMS && wxUSE_GIF

#include "wx/stream.h"
#include "wx/image.h"
#include "wx/animdecod.h"
#include "wx/dynarray.h"

// internal utility used to store a frame in 8bit-per-pixel format
class GIFImage;


// --------------------------------------------------------------------------
// Constants
// --------------------------------------------------------------------------

// Error codes:
//  Note that the error code wxGIF_TRUNCATED means that the image itself
//  is most probably OK, but the decoder didn't reach the end of the data
//  stream; this means that if it was not reading directly from file,
//  the stream will not be correctly positioned.
//
enum wxGIFErrorCode
{
    wxGIF_OK = 0,                   // everything was OK
    wxGIF_INVFORMAT,                // error in GIF header
    wxGIF_MEMERR,                   // error allocating memory
    wxGIF_TRUNCATED                 // file appears to be truncated
};

// --------------------------------------------------------------------------
// wxGIFDecoder class
// --------------------------------------------------------------------------

class WXDLLIMPEXP_CORE wxGIFDecoder : public wxAnimationDecoder
{
public:
    // constructor, destructor, etc.
    wxGIFDecoder();
    ~wxGIFDecoder();

    // get data of current frame
    unsigned char* GetData(unsigned int frame) const;
    unsigned char* GetPalette(unsigned int frame) const;
    unsigned int GetNcolours(unsigned int frame) const;
    int GetTransparentColourIndex(unsigned int frame) const;
    wxColour GetTransparentColour(unsigned int frame) const;

    virtual wxSize GetFrameSize(unsigned int frame) const;
    virtual wxPoint GetFramePosition(unsigned int frame) const;
    virtual wxAnimationDisposal GetDisposalMethod(unsigned int frame) const;
    virtual long GetDelay(unsigned int frame) const;

    // GIFs can contain both static images and animations
    bool IsAnimation() const
        { return m_nFrames > 1; }

    // load function which returns more info than just Load():
    wxGIFErrorCode LoadGIF( wxInputStream& stream );

    // free all internal frames
    void Destroy();

    // implementation of wxAnimationDecoder's pure virtuals
    virtual bool Load( wxInputStream& stream )
        { return LoadGIF(stream) == wxGIF_OK; }

    bool ConvertToImage(unsigned int frame, wxImage *image) const;

    wxAnimationDecoder *Clone() const
        { return new wxGIFDecoder; }
    wxAnimationType GetType() const
        { return wxANIMATION_TYPE_GIF; }

private:
    // wxAnimationDecoder pure virtual
    virtual bool DoCanRead( wxInputStream& stream ) const;
        // modifies current stream position (see wxAnimationDecoder::CanRead)

    int getcode(wxInputStream& stream, int bits, int abfin);
    wxGIFErrorCode dgif(wxInputStream& stream,
                        GIFImage *img, int interl, int bits);


    // array of all frames
    wxArrayPtrVoid m_frames;

    // decoder state vars
    int           m_restbits;       // remaining valid bits
    unsigned int  m_restbyte;       // remaining bytes in this block
    unsigned int  m_lastbyte;       // last byte read
    unsigned char m_buffer[256];    // buffer for reading
    unsigned char *m_bufp;          // pointer to next byte in buffer

    wxDECLARE_NO_COPY_CLASS(wxGIFDecoder);
};

#endif // wxUSE_STREAMS && wxUSE_GIF

#endif // _WX_GIFDECOD_H_