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