]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gifdecod.h
Applied patch [ 601957 ] wxGrid: Start editing with numberpad key
[wxWidgets.git] / include / wx / gifdecod.h
CommitLineData
661dc384
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: gifdecod.h
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
661dc384
JS
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
83413d6d
GRG
20#if wxUSE_STREAMS && wxUSE_GIF
21
661dc384
JS
22#include "wx/stream.h"
23#include "wx/image.h"
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,
34// the stream will not be correctly positioned. the
35//
36enum
37{
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 */
42};
43
44// Disposal method
45// Experimental; subject to change.
46//
e4b8154a
GRG
47enum
48{
49 wxGIF_D_UNSPECIFIED = -1, /* not specified */
50 wxGIF_D_DONOTDISPOSE = 0, /* do not dispose */
51 wxGIF_D_TOBACKGROUND = 1, /* restore to background colour */
52 wxGIF_D_TOPREVIOUS = 2 /* restore to previous image */
53};
54
e4b8154a
GRG
55
56#define MAX_BLOCK_SIZE 256 /* max. block size */
57
58
59// --------------------------------------------------------------------------
60// wxGIFDecoder class
61// --------------------------------------------------------------------------
62
63// internal class for storing GIF image data
64class GIFImage
661dc384 65{
e4b8154a 66public:
65c36a73
VZ
67 // def ctor
68 GIFImage();
69
661dc384
JS
70 unsigned int w; /* width */
71 unsigned int h; /* height */
72 unsigned int left; /* x coord (in logical screen) */
73 unsigned int top; /* y coord (in logical screen) */
74 int transparent; /* transparent color (-1 = none) */
3c87527e 75 int disposal; /* disposal method (-1 = unspecified) */
661dc384
JS
76 long delay; /* delay in ms (-1 = unused) */
77 unsigned char *p; /* bitmap */
78 unsigned char *pal; /* palette */
e4b8154a
GRG
79 GIFImage *next; /* next image */
80 GIFImage *prev; /* prev image */
81};
661dc384 82
76443e70 83
b31ba288 84class WXDLLEXPORT wxGIFDecoder
661dc384
JS
85{
86private:
e4b8154a 87 // logical screen
661dc384
JS
88 unsigned int m_screenw; /* logical screen width */
89 unsigned int m_screenh; /* logical screen height */
90 int m_background; /* background color (-1 = none) */
91
e4b8154a 92 // image data
661dc384
JS
93 bool m_anim; /* animated GIF */
94 int m_nimages; /* number of images */
95 int m_image; /* current image */
e4b8154a
GRG
96 GIFImage *m_pimage; /* pointer to current image */
97 GIFImage *m_pfirst; /* pointer to first image */
98 GIFImage *m_plast; /* pointer to last image */
661dc384 99
e4b8154a 100 // decoder state vars
661dc384
JS
101 int m_restbits; /* remaining valid bits */
102 unsigned int m_restbyte; /* remaining bytes in this block */
103 unsigned int m_lastbyte; /* last byte read */
76443e70
GRG
104 unsigned char m_buffer[MAX_BLOCK_SIZE]; /* buffer for reading */
105 unsigned char *m_bufp; /* pointer to next byte in buffer */
661dc384 106
e4b8154a
GRG
107 // input stream
108 wxInputStream *m_f; /* input stream */
661dc384
JS
109
110private:
111 int getcode(int bits, int abfin);
e4b8154a 112 int dgif(GIFImage *img, int interl, int bits);
661dc384 113
809e8e44 114public:
661dc384
JS
115 // get data of current frame
116 int GetFrameIndex() const;
117 unsigned char* GetData() const;
118 unsigned char* GetPalette() const;
119 unsigned int GetWidth() const;
120 unsigned int GetHeight() const;
121 unsigned int GetLeft() const;
122 unsigned int GetTop() const;
123 int GetDisposalMethod() const;
124 int GetTransparentColour() const;
125 long GetDelay() const;
126
127 // get global data
128 unsigned int GetLogicalScreenWidth() const;
129 unsigned int GetLogicalScreenHeight() const;
130 int GetBackgroundColour() const;
131 int GetNumberOfFrames() const;
132 bool IsAnimation() const;
133
134 // move through the animation
135 bool GoFirstFrame();
136 bool GoLastFrame();
137 bool GoNextFrame(bool cyclic = FALSE);
138 bool GoPrevFrame(bool cyclic = FALSE);
139 bool GoFrame(int which);
e4b8154a
GRG
140
141public:
142 // constructor, destructor, etc.
143 wxGIFDecoder(wxInputStream *s, bool anim = FALSE);
144 ~wxGIFDecoder();
145 bool CanRead();
146 int ReadGIF();
147 void Destroy();
148
149 // convert current frame to wxImage
150 bool ConvertToImage(wxImage *image) const;
661dc384
JS
151};
152
153
83413d6d 154#endif // wxUSE_STREAM && wxUSE_GIF
661dc384
JS
155#endif // _WX_GIFDECOD_H
156