]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: image.h | |
3 | // Purpose: wxImage class | |
4 | // Author: Robert Roebling | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) Robert Roebling | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #ifndef _WX_IMAGE_H_ | |
11 | #define _WX_IMAGE_H_ | |
12 | ||
13 | #ifdef __GNUG__ | |
14 | #pragma interface "image.h" | |
15 | #endif | |
16 | ||
17 | #include "wx/setup.h" | |
18 | #include "wx/object.h" | |
19 | #include "wx/string.h" | |
20 | #include "wx/gdicmn.h" | |
21 | ||
22 | #if wxUSE_STREAMS | |
23 | #include "wx/stream.h" | |
24 | #endif | |
25 | ||
26 | //----------------------------------------------------------------------------- | |
27 | // classes | |
28 | //----------------------------------------------------------------------------- | |
29 | ||
30 | class WXDLLEXPORT wxImageHandler; | |
31 | #if wxUSE_LIBPNG | |
32 | class WXDLLEXPORT wxPNGHandler; | |
33 | #endif | |
34 | #if wxUSE_LIBJPEG | |
35 | class WXDLLEXPORT wxJPEGHandler; | |
36 | #endif | |
37 | class WXDLLEXPORT wxBMPHandler; | |
38 | class WXDLLEXPORT wxImage; | |
39 | ||
40 | class WXDLLEXPORT wxBitmap; | |
41 | ||
42 | //----------------------------------------------------------------------------- | |
43 | // wxImageHandler | |
44 | //----------------------------------------------------------------------------- | |
45 | ||
46 | class WXDLLEXPORT wxImageHandler: public wxObject | |
47 | { | |
48 | DECLARE_DYNAMIC_CLASS(wxImageHandler) | |
49 | ||
50 | public: | |
51 | wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; } | |
52 | ||
53 | #if wxUSE_STREAMS | |
54 | virtual bool LoadFile( wxImage *image, wxInputStream& stream ); | |
55 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream ); | |
56 | #endif | |
57 | ||
58 | inline void SetName(const wxString& name) { m_name = name; } | |
59 | inline void SetExtension(const wxString& ext) { m_extension = ext; } | |
60 | inline void SetType(long type) { m_type = type; } | |
61 | inline void SetMimeType(const wxString& type) { m_mime = type; } | |
62 | inline wxString GetName() const { return m_name; } | |
63 | inline wxString GetExtension() const { return m_extension; } | |
64 | inline long GetType() const { return m_type; } | |
65 | inline wxString GetMimeType() const { return m_mime; } | |
66 | ||
67 | protected: | |
68 | wxString m_name; | |
69 | wxString m_extension; | |
70 | wxString m_mime; | |
71 | long m_type; | |
72 | ||
73 | }; | |
74 | ||
75 | //----------------------------------------------------------------------------- | |
76 | // wxPNGHandler | |
77 | //----------------------------------------------------------------------------- | |
78 | ||
79 | #if wxUSE_LIBPNG | |
80 | class WXDLLEXPORT wxPNGHandler: public wxImageHandler | |
81 | { | |
82 | DECLARE_DYNAMIC_CLASS(wxPNGHandler) | |
83 | ||
84 | public: | |
85 | ||
86 | inline wxPNGHandler() | |
87 | { | |
88 | m_name = "PNG file"; | |
89 | m_extension = "png"; | |
90 | m_type = wxBITMAP_TYPE_PNG; | |
91 | m_mime = "image/png"; | |
92 | }; | |
93 | ||
94 | #if wxUSE_STREAMS | |
95 | virtual bool LoadFile( wxImage *image, wxInputStream& stream ); | |
96 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream ); | |
97 | #endif | |
98 | ||
99 | }; | |
100 | #endif | |
101 | ||
102 | //----------------------------------------------------------------------------- | |
103 | // wxJPEGHandler | |
104 | //----------------------------------------------------------------------------- | |
105 | ||
106 | #if wxUSE_LIBJPEG | |
107 | class WXDLLEXPORT wxJPEGHandler: public wxImageHandler | |
108 | { | |
109 | DECLARE_DYNAMIC_CLASS(wxJPEGHandler) | |
110 | ||
111 | public: | |
112 | ||
113 | inline wxJPEGHandler() | |
114 | { | |
115 | m_name = "JPEG file"; | |
116 | m_extension = "jpg"; | |
117 | m_type = wxBITMAP_TYPE_JPEG; | |
118 | m_mime = "image/jpeg"; | |
119 | }; | |
120 | ||
121 | virtual bool LoadFile( wxImage *image, wxInputStream& stream ); | |
122 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream ); | |
123 | }; | |
124 | #endif | |
125 | ||
126 | //----------------------------------------------------------------------------- | |
127 | // wxBMPHandler | |
128 | //----------------------------------------------------------------------------- | |
129 | ||
130 | class WXDLLEXPORT wxBMPHandler: public wxImageHandler | |
131 | { | |
132 | DECLARE_DYNAMIC_CLASS(wxBMPHandler) | |
133 | ||
134 | public: | |
135 | ||
136 | inline wxBMPHandler() | |
137 | { | |
138 | m_name = "BMP file"; | |
139 | m_extension = "bmp"; | |
140 | m_type = wxBITMAP_TYPE_BMP; | |
141 | m_mime = "image/bmp"; | |
142 | }; | |
143 | ||
144 | #if wxUSE_STREAMS | |
145 | virtual bool LoadFile( wxImage *image, wxInputStream& stream ); | |
146 | #endif | |
147 | }; | |
148 | ||
149 | //----------------------------------------------------------------------------- | |
150 | // wxGIFHandler | |
151 | //----------------------------------------------------------------------------- | |
152 | ||
153 | /* why an extra headers for GIF, RR */ | |
154 | ||
155 | #include "wx/imaggif.h" | |
156 | ||
157 | //----------------------------------------------------------------------------- | |
158 | // wxImage | |
159 | //----------------------------------------------------------------------------- | |
160 | ||
161 | class WXDLLEXPORT wxImage: public wxObject | |
162 | { | |
163 | DECLARE_DYNAMIC_CLASS(wxImage) | |
164 | ||
165 | friend class WXDLLEXPORT wxImageHandler; | |
166 | ||
167 | public: | |
168 | ||
169 | wxImage(); | |
170 | wxImage( int width, int height ); | |
171 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_PNG ); | |
172 | wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG ); | |
173 | wxImage( const wxString& name, const wxString& mimetype ); | |
174 | wxImage( wxInputStream& stream, const wxString& mimetype ); | |
175 | ||
176 | wxImage( const wxImage& image ); | |
177 | wxImage( const wxImage* image ); | |
178 | ||
179 | // these functions get implemented in /src/(platform)/bitmap.cpp | |
180 | wxImage( const wxBitmap &bitmap ); | |
181 | wxBitmap ConvertToBitmap() const; | |
182 | ||
183 | void Create( int width, int height ); | |
184 | void Destroy(); | |
185 | ||
186 | wxImage Scale( int width, int height ); | |
187 | ||
188 | // these routines are slow but safe | |
189 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); | |
190 | unsigned char GetRed( int x, int y ); | |
191 | unsigned char GetGreen( int x, int y ); | |
192 | unsigned char GetBlue( int x, int y ); | |
193 | ||
194 | virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG ); | |
195 | virtual bool LoadFile( const wxString& name, const wxString& mimetype ); | |
196 | ||
197 | #if wxUSE_STREAMS | |
198 | virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG ); | |
199 | virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype ); | |
200 | #endif | |
201 | ||
202 | virtual bool SaveFile( const wxString& name, int type ); | |
203 | virtual bool SaveFile( const wxString& name, const wxString& mimetype ); | |
204 | ||
205 | #if wxUSE_STREAMS | |
206 | virtual bool SaveFile( wxOutputStream& stream, int type ); | |
207 | virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ); | |
208 | #endif | |
209 | ||
210 | bool Ok() const; | |
211 | int GetWidth() const; | |
212 | int GetHeight() const; | |
213 | ||
214 | char unsigned *GetData() const; | |
215 | void SetData( char unsigned *data ); | |
216 | ||
217 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); | |
218 | unsigned char GetMaskRed() const; | |
219 | unsigned char GetMaskGreen() const; | |
220 | unsigned char GetMaskBlue() const; | |
221 | void SetMask( bool mask = TRUE ); | |
222 | bool HasMask() const; | |
223 | ||
224 | inline wxImage& operator = (const wxImage& image) | |
225 | { if ((*this) == image) | |
226 | return (*this); | |
227 | Ref(image); | |
228 | return *this; } | |
229 | ||
230 | inline bool operator == (const wxImage& image) | |
231 | { return m_refData == image.m_refData; } | |
232 | inline bool operator != (const wxImage& image) | |
233 | { return m_refData != image.m_refData; } | |
234 | ||
235 | static inline wxList& GetHandlers() { return sm_handlers; } | |
236 | static void AddHandler( wxImageHandler *handler ); | |
237 | static void InsertHandler( wxImageHandler *handler ); | |
238 | static bool RemoveHandler( const wxString& name ); | |
239 | static wxImageHandler *FindHandler( const wxString& name ); | |
240 | static wxImageHandler *FindHandler( const wxString& extension, long imageType ); | |
241 | static wxImageHandler *FindHandler( long imageType ); | |
242 | static wxImageHandler *FindHandlerMime( const wxString& mimetype ); | |
243 | ||
244 | static void CleanUpHandlers(); | |
245 | static void InitStandardHandlers(); | |
246 | ||
247 | protected: | |
248 | ||
249 | static wxList sm_handlers; | |
250 | ||
251 | }; | |
252 | ||
253 | #endif | |
254 | // _WX_IMAGE_H_ | |
255 |