]>
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" |
952ae1e8 | 22 | #include "wx/hashmap.h" |
bf38cbff JS |
23 | |
24 | #if wxUSE_STREAMS | |
b9943f8e | 25 | # include "wx/stream.h" |
bf38cbff | 26 | #endif |
01111366 | 27 | |
775c6f0c VS |
28 | #if wxUSE_IMAGE |
29 | ||
fd94e8aa VS |
30 | #define wxIMAGE_OPTION_FILENAME wxString(_T("FileName")) |
31 | ||
01111366 RR |
32 | //----------------------------------------------------------------------------- |
33 | // classes | |
34 | //----------------------------------------------------------------------------- | |
35 | ||
36 | class WXDLLEXPORT wxImageHandler; | |
01111366 RR |
37 | class WXDLLEXPORT wxImage; |
38 | ||
39 | //----------------------------------------------------------------------------- | |
40 | // wxImageHandler | |
41 | //----------------------------------------------------------------------------- | |
42 | ||
43 | class WXDLLEXPORT wxImageHandler: public wxObject | |
44 | { | |
01111366 | 45 | public: |
be25e480 | 46 | wxImageHandler() { m_name = ""; m_extension = ""; m_type = 0; } |
01111366 | 47 | |
bf38cbff | 48 | #if wxUSE_STREAMS |
d394f479 | 49 | virtual bool LoadFile( wxImage *image, wxInputStream& stream, bool verbose=TRUE, int index=-1 ); |
be25e480 | 50 | virtual bool SaveFile( wxImage *image, wxOutputStream& stream, bool verbose=TRUE ); |
8f177c8e | 51 | |
649d13e8 | 52 | virtual int GetImageCount( wxInputStream& stream ); |
0828c087 | 53 | |
be25e480 RR |
54 | bool CanRead( wxInputStream& stream ) { return DoCanRead(stream); } |
55 | bool CanRead( const wxString& name ); | |
8f177c8e | 56 | #endif // wxUSE_STREAMS |
01111366 | 57 | |
be25e480 RR |
58 | void SetName(const wxString& name) { m_name = name; } |
59 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
60 | void SetType(long type) { m_type = type; } | |
61 | void SetMimeType(const wxString& type) { m_mime = type; } | |
62 | wxString GetName() const { return m_name; } | |
63 | wxString GetExtension() const { return m_extension; } | |
64 | long GetType() const { return m_type; } | |
65 | wxString GetMimeType() const { return m_mime; } | |
9e9ee68e | 66 | |
01111366 | 67 | protected: |
8f177c8e | 68 | #if wxUSE_STREAMS |
be25e480 | 69 | virtual bool DoCanRead( wxInputStream& stream ) = 0; |
8f177c8e | 70 | #endif // wxUSE_STREAMS |
995612e2 | 71 | |
be25e480 RR |
72 | wxString m_name; |
73 | wxString m_extension; | |
74 | wxString m_mime; | |
75 | long m_type; | |
aaf46fd6 | 76 | |
be25e480 RR |
77 | private: |
78 | DECLARE_CLASS(wxImageHandler) | |
8f177c8e VZ |
79 | }; |
80 | ||
01111366 | 81 | //----------------------------------------------------------------------------- |
952ae1e8 | 82 | // wxImageHistogram |
01111366 RR |
83 | //----------------------------------------------------------------------------- |
84 | ||
952ae1e8 | 85 | class WXDLLEXPORT wxImageHistogramEntry |
c9d01afd GRG |
86 | { |
87 | public: | |
952ae1e8 | 88 | wxImageHistogramEntry() : index(0), value(0) {} |
c9d01afd GRG |
89 | unsigned long index; |
90 | unsigned long value; | |
91 | }; | |
92 | ||
952ae1e8 VS |
93 | WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry, |
94 | wxIntegerHash, wxIntegerEqual, | |
95 | wxImageHistogram); | |
96 | ||
97 | //----------------------------------------------------------------------------- | |
98 | // wxImage | |
99 | //----------------------------------------------------------------------------- | |
100 | ||
01111366 RR |
101 | class WXDLLEXPORT wxImage: public wxObject |
102 | { | |
01111366 | 103 | public: |
be25e480 RR |
104 | wxImage(); |
105 | wxImage( int width, int height ); | |
f6bcfd97 | 106 | wxImage( int width, int height, unsigned char* data, bool static_data = FALSE ); |
60d43ad8 VS |
107 | wxImage( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); |
108 | wxImage( const wxString& name, const wxString& mimetype, int index = -1 ); | |
aaf46fd6 VZ |
109 | |
110 | #if wxUSE_STREAMS | |
60d43ad8 VS |
111 | wxImage( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 ); |
112 | wxImage( wxInputStream& stream, const wxString& mimetype, int index = -1 ); | |
aaf46fd6 | 113 | #endif // wxUSE_STREAMS |
01111366 | 114 | |
be25e480 RR |
115 | wxImage( const wxImage& image ); |
116 | wxImage( const wxImage* image ); | |
9e9ee68e | 117 | |
ef8f37e0 | 118 | #if WXWIN_COMPATIBILITY_2_2 && wxUSE_GUI |
fd859211 | 119 | // convertion to/from wxBitmap (deprecated, use wxBitmap's methods instead): |
be25e480 | 120 | wxImage( const wxBitmap &bitmap ); |
be25e480 | 121 | wxBitmap ConvertToBitmap() const; |
82ea63e6 | 122 | #ifdef __WXGTK__ |
f515c25a | 123 | wxBitmap ConvertToMonoBitmap( unsigned char red, unsigned char green, unsigned char blue ) const; |
fd859211 | 124 | #endif |
82ea63e6 | 125 | #endif |
23280650 | 126 | |
be25e480 | 127 | void Create( int width, int height ); |
f6bcfd97 | 128 | void Create( int width, int height, unsigned char* data, bool static_data = FALSE ); |
be25e480 | 129 | void Destroy(); |
01111366 | 130 | |
f6bcfd97 BP |
131 | // creates an identical copy of the image (the = operator |
132 | // just raises the ref count) | |
133 | wxImage Copy() const; | |
aaf46fd6 | 134 | |
be25e480 RR |
135 | // return the new image with size width*height |
136 | wxImage GetSubImage( const wxRect& ) const; | |
aaf46fd6 | 137 | |
f6bcfd97 BP |
138 | // pastes image into this instance and takes care of |
139 | // the mask colour and out of bounds problems | |
aaf46fd6 | 140 | void Paste( const wxImage &image, int x, int y ); |
23280650 | 141 | |
be25e480 RR |
142 | // return the new image with size width*height |
143 | wxImage Scale( int width, int height ) const; | |
7b2471a0 | 144 | |
be25e480 RR |
145 | // rescales the image in place |
146 | wxImage& Rescale( int width, int height ) { return *this = Scale(width, height); } | |
ce9a75d2 | 147 | |
7a632f10 JS |
148 | // Rotates the image about the given point, 'angle' radians. |
149 | // Returns the rotated image, leaving this image intact. | |
150 | wxImage Rotate(double angle, const wxPoint & centre_of_rotation, | |
f6bcfd97 BP |
151 | bool interpolating = TRUE, wxPoint * offset_after_rotation = (wxPoint*) NULL) const; |
152 | ||
153 | wxImage Rotate90( bool clockwise = TRUE ) const; | |
154 | wxImage Mirror( bool horizontally = TRUE ) const; | |
7a632f10 | 155 | |
be25e480 RR |
156 | // replace one colour with another |
157 | void Replace( unsigned char r1, unsigned char g1, unsigned char b1, | |
158 | unsigned char r2, unsigned char g2, unsigned char b2 ); | |
aaf46fd6 | 159 | |
fd859211 | 160 | // convert to monochrome image (<r,g,b> will be replaced by white, everything else by black) |
f515c25a | 161 | wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const; |
ce9a75d2 | 162 | |
be25e480 RR |
163 | // these routines are slow but safe |
164 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); | |
f6bcfd97 BP |
165 | unsigned char GetRed( int x, int y ) const; |
166 | unsigned char GetGreen( int x, int y ) const; | |
167 | unsigned char GetBlue( int x, int y ) const; | |
23280650 | 168 | |
1f5b2017 VS |
169 | // find first colour that is not used in the image and has higher |
170 | // RGB values than <startR,startG,startB> | |
171 | bool FindFirstUnusedColour( unsigned char *r, unsigned char *g, unsigned char *b, | |
aaf46fd6 | 172 | unsigned char startR = 1, unsigned char startG = 0, |
e0a76d8d | 173 | unsigned char startB = 0 ) const; |
1f5b2017 | 174 | // Set image's mask to the area of 'mask' that has <r,g,b> colour |
aaf46fd6 | 175 | bool SetMaskFromImage(const wxImage & mask, |
1f5b2017 | 176 | unsigned char mr, unsigned char mg, unsigned char mb); |
52b64b0a | 177 | |
be25e480 | 178 | static bool CanRead( const wxString& name ); |
649d13e8 | 179 | static int GetImageCount( const wxString& name, long type = wxBITMAP_TYPE_ANY ); |
60d43ad8 VS |
180 | virtual bool LoadFile( const wxString& name, long type = wxBITMAP_TYPE_ANY, int index = -1 ); |
181 | virtual bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 ); | |
bf38cbff JS |
182 | |
183 | #if wxUSE_STREAMS | |
be25e480 | 184 | static bool CanRead( wxInputStream& stream ); |
649d13e8 | 185 | static int GetImageCount( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY ); |
60d43ad8 VS |
186 | virtual bool LoadFile( wxInputStream& stream, long type = wxBITMAP_TYPE_ANY, int index = -1 ); |
187 | virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 ); | |
bf38cbff JS |
188 | #endif |
189 | ||
45647dcf | 190 | virtual bool SaveFile( const wxString& name ) const; |
e0a76d8d VS |
191 | virtual bool SaveFile( const wxString& name, int type ) const; |
192 | virtual bool SaveFile( const wxString& name, const wxString& mimetype ) const; | |
bf38cbff JS |
193 | |
194 | #if wxUSE_STREAMS | |
e0a76d8d VS |
195 | virtual bool SaveFile( wxOutputStream& stream, int type ) const; |
196 | virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ) const; | |
bf38cbff | 197 | #endif |
01111366 | 198 | |
be25e480 RR |
199 | bool Ok() const; |
200 | int GetWidth() const; | |
201 | int GetHeight() const; | |
202 | ||
203 | char unsigned *GetData() const; | |
204 | void SetData( char unsigned *data ); | |
f6bcfd97 | 205 | void SetData( char unsigned *data, int new_width, int new_height ); |
5e5437e0 JS |
206 | |
207 | // Mask functions | |
be25e480 RR |
208 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); |
209 | unsigned char GetMaskRed() const; | |
210 | unsigned char GetMaskGreen() const; | |
211 | unsigned char GetMaskBlue() const; | |
212 | void SetMask( bool mask = TRUE ); | |
213 | bool HasMask() const; | |
214 | ||
d275c7eb | 215 | #if wxUSE_PALETTE |
5e5437e0 JS |
216 | // Palette functions |
217 | bool HasPalette() const; | |
218 | const wxPalette& GetPalette() const; | |
219 | void SetPalette(const wxPalette& palette); | |
d275c7eb | 220 | #endif // wxUSE_PALETTE |
5e5437e0 JS |
221 | |
222 | // Option functions (arbitrary name/value mapping) | |
223 | void SetOption(const wxString& name, const wxString& value); | |
224 | void SetOption(const wxString& name, int value); | |
225 | wxString GetOption(const wxString& name) const; | |
226 | int GetOptionInt(const wxString& name) const; | |
227 | bool HasOption(const wxString& name) const; | |
3f4fc796 | 228 | |
e0a76d8d | 229 | unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ) const; |
952ae1e8 VS |
230 | |
231 | // Computes the histogram of the image and fills a hash table, indexed | |
232 | // with integer keys built as 0xRRGGBB, containing wxImageHistogramEntry | |
233 | // objects. Each of them contains an 'index' (useful to build a palette | |
234 | // with the image colours) and a 'value', which is the number of pixels | |
235 | // in the image with that colour. | |
236 | // Returned value: # of entries in the histogram | |
e0a76d8d | 237 | unsigned long ComputeHistogram( wxImageHistogram &h ) const; |
be25e480 RR |
238 | |
239 | wxImage& operator = (const wxImage& image) | |
240 | { | |
241 | if ( (*this) != image ) | |
242 | Ref(image); | |
243 | return *this; | |
244 | } | |
245 | ||
246 | bool operator == (const wxImage& image) | |
247 | { return m_refData == image.m_refData; } | |
248 | bool operator != (const wxImage& image) | |
249 | { return m_refData != image.m_refData; } | |
250 | ||
251 | static wxList& GetHandlers() { return sm_handlers; } | |
252 | static void AddHandler( wxImageHandler *handler ); | |
253 | static void InsertHandler( wxImageHandler *handler ); | |
254 | static bool RemoveHandler( const wxString& name ); | |
255 | static wxImageHandler *FindHandler( const wxString& name ); | |
256 | static wxImageHandler *FindHandler( const wxString& extension, long imageType ); | |
257 | static wxImageHandler *FindHandler( long imageType ); | |
258 | static wxImageHandler *FindHandlerMime( const wxString& mimetype ); | |
259 | ||
260 | static void CleanUpHandlers(); | |
261 | static void InitStandardHandlers(); | |
c9d01afd | 262 | |
01111366 | 263 | protected: |
5e5437e0 | 264 | static wxList sm_handlers; |
01111366 | 265 | |
be25e480 RR |
266 | private: |
267 | friend class WXDLLEXPORT wxImageHandler; | |
23280650 | 268 | |
be25e480 | 269 | DECLARE_DYNAMIC_CLASS(wxImage) |
01111366 RR |
270 | }; |
271 | ||
8f493002 | 272 | |
a091d18c | 273 | extern void WXDLLEXPORT wxInitAllImageHandlers(); |
b5a4a47d | 274 | |
fd859211 | 275 | WXDLLEXPORT_DATA(extern wxImage) wxNullImage; |
8f493002 VS |
276 | |
277 | //----------------------------------------------------------------------------- | |
278 | // wxImage handlers | |
279 | //----------------------------------------------------------------------------- | |
280 | ||
281 | #include "wx/imagbmp.h" | |
282 | #include "wx/imagpng.h" | |
283 | #include "wx/imaggif.h" | |
284 | #include "wx/imagpcx.h" | |
285 | #include "wx/imagjpeg.h" | |
286 | #include "wx/imagtiff.h" | |
287 | #include "wx/imagpnm.h" | |
775c6f0c | 288 | #include "wx/imagxpm.h" |
4b6b4dfc | 289 | #include "wx/imagiff.h" |
775c6f0c VS |
290 | |
291 | #endif // wxUSE_IMAGE | |
8f493002 | 292 | |
01111366 RR |
293 | #endif |
294 | // _WX_IMAGE_H_ | |
9e9ee68e | 295 |