]>
Commit | Line | Data |
---|---|---|
01111366 RR |
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" | |
bf38cbff JS |
21 | |
22 | #if wxUSE_STREAMS | |
3d05544e | 23 | #include "wx/stream.h" |
bf38cbff | 24 | #endif |
01111366 RR |
25 | |
26 | //----------------------------------------------------------------------------- | |
27 | // classes | |
28 | //----------------------------------------------------------------------------- | |
29 | ||
30 | class WXDLLEXPORT wxImageHandler; | |
9838df2c | 31 | #if wxUSE_LIBPNG |
01111366 | 32 | class WXDLLEXPORT wxPNGHandler; |
ac57418f | 33 | #endif |
56b9c741 VS |
34 | #if wxUSE_LIBJPEG |
35 | class WXDLLEXPORT wxJPEGHandler; | |
36 | #endif | |
01111366 RR |
37 | class WXDLLEXPORT wxBMPHandler; |
38 | class WXDLLEXPORT wxImage; | |
39 | ||
4bc67cc5 RR |
40 | class WXDLLEXPORT wxBitmap; |
41 | ||
01111366 RR |
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 | ||
bf38cbff | 53 | #if wxUSE_STREAMS |
3d05544e JS |
54 | virtual bool LoadFile( wxImage *image, wxInputStream& stream ); |
55 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream ); | |
bf38cbff | 56 | #endif |
01111366 RR |
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; } | |
9e9ee68e | 61 | inline void SetMimeType(const wxString& type) { m_mime = type; } |
01111366 RR |
62 | inline wxString GetName() const { return m_name; } |
63 | inline wxString GetExtension() const { return m_extension; } | |
64 | inline long GetType() const { return m_type; } | |
9e9ee68e VS |
65 | inline wxString GetMimeType() const { return m_mime; } |
66 | ||
01111366 RR |
67 | protected: |
68 | wxString m_name; | |
69 | wxString m_extension; | |
9e9ee68e | 70 | wxString m_mime; |
01111366 RR |
71 | long m_type; |
72 | ||
73 | }; | |
74 | ||
75 | //----------------------------------------------------------------------------- | |
76 | // wxPNGHandler | |
77 | //----------------------------------------------------------------------------- | |
78 | ||
9838df2c | 79 | #if wxUSE_LIBPNG |
01111366 RR |
80 | class WXDLLEXPORT wxPNGHandler: public wxImageHandler |
81 | { | |
82 | DECLARE_DYNAMIC_CLASS(wxPNGHandler) | |
83 | ||
84 | public: | |
85 | ||
fd0eed64 RR |
86 | inline wxPNGHandler() |
87 | { | |
88 | m_name = "PNG file"; | |
89 | m_extension = "png"; | |
90 | m_type = wxBITMAP_TYPE_PNG; | |
9e9ee68e | 91 | m_mime = "image/png"; |
fd0eed64 RR |
92 | }; |
93 | ||
bf38cbff | 94 | #if wxUSE_STREAMS |
3d05544e JS |
95 | virtual bool LoadFile( wxImage *image, wxInputStream& stream ); |
96 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream ); | |
bf38cbff | 97 | #endif |
01111366 | 98 | }; |
ac57418f | 99 | #endif |
01111366 | 100 | |
56b9c741 VS |
101 | //----------------------------------------------------------------------------- |
102 | // wxJPEGHandler | |
103 | //----------------------------------------------------------------------------- | |
104 | ||
9ef4a31e | 105 | #if wxUSE_LIBJPEG |
56b9c741 VS |
106 | class WXDLLEXPORT wxJPEGHandler: public wxImageHandler |
107 | { | |
108 | DECLARE_DYNAMIC_CLASS(wxJPEGHandler) | |
109 | ||
110 | public: | |
111 | ||
112 | inline wxJPEGHandler() | |
113 | { | |
114 | m_name = "JPEG file"; | |
115 | m_extension = "jpg"; | |
116 | m_type = wxBITMAP_TYPE_JPEG; | |
9e9ee68e | 117 | m_mime = "image/jpeg"; |
56b9c741 VS |
118 | }; |
119 | ||
ce4169a4 | 120 | #if wxUSE_STREAMS |
56b9c741 VS |
121 | virtual bool LoadFile( wxImage *image, wxInputStream& stream ); |
122 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream ); | |
ce4169a4 | 123 | #endif |
56b9c741 VS |
124 | }; |
125 | #endif | |
126 | ||
01111366 RR |
127 | //----------------------------------------------------------------------------- |
128 | // wxBMPHandler | |
129 | //----------------------------------------------------------------------------- | |
130 | ||
131 | class WXDLLEXPORT wxBMPHandler: public wxImageHandler | |
132 | { | |
133 | DECLARE_DYNAMIC_CLASS(wxBMPHandler) | |
134 | ||
135 | public: | |
136 | ||
fd0eed64 RR |
137 | inline wxBMPHandler() |
138 | { | |
139 | m_name = "BMP file"; | |
140 | m_extension = "bmp"; | |
141 | m_type = wxBITMAP_TYPE_BMP; | |
9e9ee68e | 142 | m_mime = "image/bmp"; |
fd0eed64 | 143 | }; |
01111366 | 144 | |
bf38cbff | 145 | #if wxUSE_STREAMS |
3d05544e | 146 | virtual bool LoadFile( wxImage *image, wxInputStream& stream ); |
bf38cbff | 147 | #endif |
01111366 | 148 | }; |
fd0eed64 | 149 | |
e1929140 RR |
150 | //----------------------------------------------------------------------------- |
151 | // wxGIFHandler | |
152 | //----------------------------------------------------------------------------- | |
153 | ||
ce4169a4 RR |
154 | class WXDLLEXPORT wxGIFHandler : public wxImageHandler |
155 | { | |
156 | DECLARE_DYNAMIC_CLASS(wxGIFHandler) | |
157 | ||
158 | public: | |
159 | ||
160 | inline wxGIFHandler() | |
161 | { | |
162 | m_name = "GIF file"; | |
163 | m_extension = "gif"; | |
164 | m_type = wxBITMAP_TYPE_GIF; | |
165 | m_mime = "image/gif"; | |
166 | }; | |
e1929140 | 167 | |
ce4169a4 RR |
168 | #if wxUSE_STREAMS |
169 | virtual bool LoadFile( wxImage *image, wxInputStream& stream ); | |
170 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream ); | |
171 | #endif | |
172 | }; | |
e1929140 | 173 | |
01111366 RR |
174 | //----------------------------------------------------------------------------- |
175 | // wxImage | |
176 | //----------------------------------------------------------------------------- | |
177 | ||
178 | class WXDLLEXPORT wxImage: public wxObject | |
179 | { | |
180 | DECLARE_DYNAMIC_CLASS(wxImage) | |
181 | ||
182 | friend class WXDLLEXPORT wxImageHandler; | |
183 | ||
184 | public: | |
185 | ||
186 | wxImage(); | |
187 | wxImage( int width, int height ); | |
188 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_PNG ); | |
3d05544e | 189 | wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG ); |
9e9ee68e VS |
190 | wxImage( const wxString& name, const wxString& mimetype ); |
191 | wxImage( wxInputStream& stream, const wxString& mimetype ); | |
192 | ||
01111366 RR |
193 | wxImage( const wxImage& image ); |
194 | wxImage( const wxImage* image ); | |
4bc67cc5 RR |
195 | |
196 | // these functions get implemented in /src/(platform)/bitmap.cpp | |
197 | wxImage( const wxBitmap &bitmap ); | |
ce9a75d2 | 198 | operator wxBitmap() const { return ConvertToBitmap(); } |
4bc67cc5 | 199 | wxBitmap ConvertToBitmap() const; |
01111366 RR |
200 | |
201 | void Create( int width, int height ); | |
202 | void Destroy(); | |
203 | ||
ce9a75d2 VZ |
204 | // return the new image with size width*height |
205 | wxImage Scale( int width, int height ) const; | |
206 | ||
207 | // rescales the image in place | |
208 | wxImage Rescale( int width, int height ) { *this = Scale(width, height); } | |
209 | ||
ef539066 RR |
210 | // these routines are slow but safe |
211 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); | |
212 | unsigned char GetRed( int x, int y ); | |
213 | unsigned char GetGreen( int x, int y ); | |
214 | unsigned char GetBlue( int x, int y ); | |
215 | ||
01111366 | 216 | virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_PNG ); |
9e9ee68e | 217 | virtual bool LoadFile( const wxString& name, const wxString& mimetype ); |
bf38cbff JS |
218 | |
219 | #if wxUSE_STREAMS | |
3d05544e | 220 | virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_PNG ); |
9e9ee68e | 221 | virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype ); |
bf38cbff JS |
222 | #endif |
223 | ||
01111366 | 224 | virtual bool SaveFile( const wxString& name, int type ); |
9e9ee68e | 225 | virtual bool SaveFile( const wxString& name, const wxString& mimetype ); |
bf38cbff JS |
226 | |
227 | #if wxUSE_STREAMS | |
3d05544e | 228 | virtual bool SaveFile( wxOutputStream& stream, int type ); |
9e9ee68e | 229 | virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ); |
bf38cbff | 230 | #endif |
01111366 RR |
231 | |
232 | bool Ok() const; | |
233 | int GetWidth() const; | |
234 | int GetHeight() const; | |
235 | ||
236 | char unsigned *GetData() const; | |
237 | void SetData( char unsigned *data ); | |
238 | ||
239 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); | |
240 | unsigned char GetMaskRed() const; | |
241 | unsigned char GetMaskGreen() const; | |
242 | unsigned char GetMaskBlue() const; | |
243 | void SetMask( bool mask = TRUE ); | |
244 | bool HasMask() const; | |
245 | ||
ce9a75d2 VZ |
246 | wxImage& operator = (const wxImage& image) |
247 | { | |
248 | if ( (*this) != image ) | |
ce3ed50d | 249 | Ref(image); |
ce9a75d2 VZ |
250 | return *this; |
251 | } | |
ce3ed50d | 252 | |
ce9a75d2 | 253 | bool operator == (const wxImage& image) |
01111366 | 254 | { return m_refData == image.m_refData; } |
ce9a75d2 | 255 | bool operator != (const wxImage& image) |
01111366 RR |
256 | { return m_refData != image.m_refData; } |
257 | ||
ce9a75d2 | 258 | static wxList& GetHandlers() { return sm_handlers; } |
01111366 RR |
259 | static void AddHandler( wxImageHandler *handler ); |
260 | static void InsertHandler( wxImageHandler *handler ); | |
261 | static bool RemoveHandler( const wxString& name ); | |
262 | static wxImageHandler *FindHandler( const wxString& name ); | |
263 | static wxImageHandler *FindHandler( const wxString& extension, long imageType ); | |
264 | static wxImageHandler *FindHandler( long imageType ); | |
9e9ee68e VS |
265 | static wxImageHandler *FindHandlerMime( const wxString& mimetype ); |
266 | ||
01111366 | 267 | static void CleanUpHandlers(); |
fd0eed64 | 268 | static void InitStandardHandlers(); |
01111366 RR |
269 | |
270 | protected: | |
271 | ||
272 | static wxList sm_handlers; | |
273 | ||
274 | }; | |
275 | ||
276 | #endif | |
277 | // _WX_IMAGE_H_ | |
9e9ee68e | 278 |