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