]>
Commit | Line | Data |
---|---|---|
01111366 | 1 | ///////////////////////////////////////////////////////////////////////////// |
155ecd4c | 2 | // Name: wx/image.h |
01111366 RR |
3 | // Purpose: wxImage class |
4 | // Author: Robert Roebling | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: (c) Robert Roebling | |
65571936 | 7 | // Licence: wxWindows licence |
01111366 RR |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | #ifndef _WX_IMAGE_H_ | |
11 | #define _WX_IMAGE_H_ | |
12 | ||
2ecf902b | 13 | #include "wx/defs.h" |
155ecd4c WS |
14 | |
15 | #if wxUSE_IMAGE | |
16 | ||
01111366 RR |
17 | #include "wx/object.h" |
18 | #include "wx/string.h" | |
19 | #include "wx/gdicmn.h" | |
952ae1e8 | 20 | #include "wx/hashmap.h" |
48889bca | 21 | #include "wx/arrstr.h" |
bf38cbff JS |
22 | |
23 | #if wxUSE_STREAMS | |
b9943f8e | 24 | # include "wx/stream.h" |
bf38cbff | 25 | #endif |
01111366 | 26 | |
66f21994 VZ |
27 | // on some systems (Unixware 7.x) index is defined as a macro in the headers |
28 | // which breaks the compilation below | |
29 | #undef index | |
30 | ||
9a83f860 VZ |
31 | #define wxIMAGE_OPTION_QUALITY wxString(wxT("quality")) |
32 | #define wxIMAGE_OPTION_FILENAME wxString(wxT("FileName")) | |
fd94e8aa | 33 | |
9a83f860 VZ |
34 | #define wxIMAGE_OPTION_RESOLUTION wxString(wxT("Resolution")) |
35 | #define wxIMAGE_OPTION_RESOLUTIONX wxString(wxT("ResolutionX")) | |
36 | #define wxIMAGE_OPTION_RESOLUTIONY wxString(wxT("ResolutionY")) | |
fe9308c6 | 37 | |
9a83f860 | 38 | #define wxIMAGE_OPTION_RESOLUTIONUNIT wxString(wxT("ResolutionUnit")) |
fe9308c6 | 39 | |
9a83f860 VZ |
40 | #define wxIMAGE_OPTION_MAX_WIDTH wxString(wxT("MaxWidth")) |
41 | #define wxIMAGE_OPTION_MAX_HEIGHT wxString(wxT("MaxHeight")) | |
36abe9d4 | 42 | |
fe9308c6 | 43 | // constants used with wxIMAGE_OPTION_RESOLUTIONUNIT |
361f4288 VZ |
44 | // |
45 | // NB: don't change these values, they correspond to libjpeg constants | |
46 | enum wxImageResolution | |
fe9308c6 | 47 | { |
361f4288 VZ |
48 | // Resolution not specified |
49 | wxIMAGE_RESOLUTION_NONE = 0, | |
50 | ||
51 | // Resolution specified in inches | |
fe9308c6 | 52 | wxIMAGE_RESOLUTION_INCHES = 1, |
361f4288 VZ |
53 | |
54 | // Resolution specified in centimeters | |
fe9308c6 VZ |
55 | wxIMAGE_RESOLUTION_CM = 2 |
56 | }; | |
57 | ||
07aaa1a4 | 58 | // Constants for wxImage::Scale() for determining the level of quality |
180f3c74 | 59 | enum wxImageResizeQuality |
07aaa1a4 | 60 | { |
180f3c74 VZ |
61 | // different image resizing algorithms used by Scale() and Rescale() |
62 | wxIMAGE_QUALITY_NEAREST = 0, | |
63 | wxIMAGE_QUALITY_BILINEAR = 1, | |
64 | wxIMAGE_QUALITY_BICUBIC = 2, | |
65 | ||
66 | // default quality is low (but fast) | |
67 | wxIMAGE_QUALITY_NORMAL = wxIMAGE_QUALITY_NEAREST, | |
68 | ||
69 | // highest (but best) quality | |
70 | wxIMAGE_QUALITY_HIGH = wxIMAGE_QUALITY_BICUBIC | |
07aaa1a4 RR |
71 | }; |
72 | ||
21dc4be5 VZ |
73 | // alpha channel values: fully transparent, default threshold separating |
74 | // transparent pixels from opaque for a few functions dealing with alpha and | |
75 | // fully opaque | |
76 | const unsigned char wxIMAGE_ALPHA_TRANSPARENT = 0; | |
77 | const unsigned char wxIMAGE_ALPHA_THRESHOLD = 0x80; | |
78 | const unsigned char wxIMAGE_ALPHA_OPAQUE = 0xff; | |
79 | ||
01111366 RR |
80 | //----------------------------------------------------------------------------- |
81 | // classes | |
82 | //----------------------------------------------------------------------------- | |
83 | ||
b5dbe15d VS |
84 | class WXDLLIMPEXP_FWD_CORE wxImageHandler; |
85 | class WXDLLIMPEXP_FWD_CORE wxImage; | |
86 | class WXDLLIMPEXP_FWD_CORE wxPalette; | |
01111366 | 87 | |
6f5d7825 RR |
88 | //----------------------------------------------------------------------------- |
89 | // wxVariant support | |
90 | //----------------------------------------------------------------------------- | |
91 | ||
92 | #if wxUSE_VARIANT | |
93 | #include "wx/variant.h" | |
53a2db12 | 94 | DECLARE_VARIANT_OBJECT_EXPORTED(wxImage,WXDLLIMPEXP_CORE) |
6f5d7825 RR |
95 | #endif |
96 | ||
01111366 RR |
97 | //----------------------------------------------------------------------------- |
98 | // wxImageHandler | |
99 | //----------------------------------------------------------------------------- | |
100 | ||
53a2db12 | 101 | class WXDLLIMPEXP_CORE wxImageHandler: public wxObject |
01111366 | 102 | { |
01111366 | 103 | public: |
d84afea9 | 104 | wxImageHandler() |
e98e625c | 105 | : m_name(wxEmptyString), m_extension(wxEmptyString), m_mime(), m_type(wxBITMAP_TYPE_INVALID) |
d84afea9 | 106 | { } |
01111366 | 107 | |
bf38cbff | 108 | #if wxUSE_STREAMS |
8faef7cc FM |
109 | // NOTE: LoadFile and SaveFile are not pure virtuals to allow derived classes |
110 | // to implement only one of the two | |
03647350 | 111 | virtual bool LoadFile( wxImage *WXUNUSED(image), wxInputStream& WXUNUSED(stream), |
8faef7cc FM |
112 | bool WXUNUSED(verbose)=true, int WXUNUSED(index)=-1 ) |
113 | { return false; } | |
03647350 | 114 | virtual bool SaveFile( wxImage *WXUNUSED(image), wxOutputStream& WXUNUSED(stream), |
8faef7cc FM |
115 | bool WXUNUSED(verbose)=true ) |
116 | { return false; } | |
117 | ||
118 | int GetImageCount( wxInputStream& stream ); | |
119 | // save the stream position, call DoGetImageCount() and restore the position | |
0828c087 | 120 | |
39d16996 | 121 | bool CanRead( wxInputStream& stream ) { return CallDoCanRead(stream); } |
be25e480 | 122 | bool CanRead( const wxString& name ); |
8f177c8e | 123 | #endif // wxUSE_STREAMS |
01111366 | 124 | |
be25e480 RR |
125 | void SetName(const wxString& name) { m_name = name; } |
126 | void SetExtension(const wxString& ext) { m_extension = ext; } | |
099c2c7d | 127 | void SetAltExtensions(const wxArrayString& exts) { m_altExtensions = exts; } |
e98e625c | 128 | void SetType(wxBitmapType type) { m_type = type; } |
be25e480 | 129 | void SetMimeType(const wxString& type) { m_mime = type; } |
452418c4 PC |
130 | const wxString& GetName() const { return m_name; } |
131 | const wxString& GetExtension() const { return m_extension; } | |
ba4800d3 | 132 | const wxArrayString& GetAltExtensions() const { return m_altExtensions; } |
e98e625c | 133 | wxBitmapType GetType() const { return m_type; } |
452418c4 | 134 | const wxString& GetMimeType() const { return m_mime; } |
9e9ee68e | 135 | |
831b64f3 | 136 | #if WXWIN_COMPATIBILITY_2_8 |
0ddec397 VZ |
137 | wxDEPRECATED( |
138 | void SetType(long type) { SetType((wxBitmapType)type); } | |
139 | ) | |
140 | #endif // WXWIN_COMPATIBILITY_2_8 | |
141 | ||
01111366 | 142 | protected: |
8f177c8e | 143 | #if wxUSE_STREAMS |
8faef7cc FM |
144 | // NOTE: this function is allowed to change the current stream position |
145 | // since GetImageCount() will take care of restoring it later | |
03647350 | 146 | virtual int DoGetImageCount( wxInputStream& WXUNUSED(stream) ) |
8faef7cc | 147 | { return 1; } // default return value is 1 image |
03647350 | 148 | |
8faef7cc FM |
149 | // NOTE: this function is allowed to change the current stream position |
150 | // since CallDoCanRead() will take care of restoring it later | |
be25e480 | 151 | virtual bool DoCanRead( wxInputStream& stream ) = 0; |
995612e2 | 152 | |
39d16996 VZ |
153 | // save the stream position, call DoCanRead() and restore the position |
154 | bool CallDoCanRead(wxInputStream& stream); | |
55472691 | 155 | #endif // wxUSE_STREAMS |
39d16996 | 156 | |
361f4288 VZ |
157 | // helper for the derived classes SaveFile() implementations: returns the |
158 | // values of x- and y-resolution options specified as the image options if | |
159 | // any | |
160 | static wxImageResolution | |
161 | GetResolutionFromOptions(const wxImage& image, int *x, int *y); | |
162 | ||
163 | ||
be25e480 RR |
164 | wxString m_name; |
165 | wxString m_extension; | |
ba4800d3 | 166 | wxArrayString m_altExtensions; |
be25e480 | 167 | wxString m_mime; |
e98e625c | 168 | wxBitmapType m_type; |
aaf46fd6 | 169 | |
be25e480 RR |
170 | private: |
171 | DECLARE_CLASS(wxImageHandler) | |
8f177c8e VZ |
172 | }; |
173 | ||
01111366 | 174 | //----------------------------------------------------------------------------- |
952ae1e8 | 175 | // wxImageHistogram |
01111366 RR |
176 | //----------------------------------------------------------------------------- |
177 | ||
53a2db12 | 178 | class WXDLLIMPEXP_CORE wxImageHistogramEntry |
c9d01afd GRG |
179 | { |
180 | public: | |
66f21994 | 181 | wxImageHistogramEntry() { index = value = 0; } |
c9d01afd GRG |
182 | unsigned long index; |
183 | unsigned long value; | |
184 | }; | |
185 | ||
952ae1e8 VS |
186 | WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry, |
187 | wxIntegerHash, wxIntegerEqual, | |
3f5c62f9 | 188 | wxImageHistogramBase); |
487659e0 | 189 | |
53a2db12 | 190 | class WXDLLIMPEXP_CORE wxImageHistogram : public wxImageHistogramBase |
487659e0 VZ |
191 | { |
192 | public: | |
193 | wxImageHistogram() : wxImageHistogramBase(256) { } | |
194 | ||
195 | // get the key in the histogram for the given RGB values | |
196 | static unsigned long MakeKey(unsigned char r, | |
197 | unsigned char g, | |
198 | unsigned char b) | |
199 | { | |
200 | return (r << 16) | (g << 8) | b; | |
201 | } | |
202 | ||
203 | // find first colour that is not used in the image and has higher | |
204 | // RGB values than RGB(startR, startG, startB) | |
205 | // | |
206 | // returns true and puts this colour in r, g, b (each of which may be NULL) | |
207 | // on success or returns false if there are no more free colours | |
208 | bool FindFirstUnusedColour(unsigned char *r, | |
209 | unsigned char *g, | |
210 | unsigned char *b, | |
211 | unsigned char startR = 1, | |
212 | unsigned char startG = 0, | |
213 | unsigned char startB = 0 ) const; | |
214 | }; | |
952ae1e8 VS |
215 | |
216 | //----------------------------------------------------------------------------- | |
217 | // wxImage | |
218 | //----------------------------------------------------------------------------- | |
219 | ||
53a2db12 | 220 | class WXDLLIMPEXP_CORE wxImage: public wxObject |
01111366 | 221 | { |
01111366 | 222 | public: |
978d3d36 VZ |
223 | // red, green and blue are 8 bit unsigned integers in the range of 0..255 |
224 | // We use the identifier RGBValue instead of RGB, since RGB is #defined | |
225 | class RGBValue | |
226 | { | |
227 | public: | |
228 | RGBValue(unsigned char r=0, unsigned char g=0, unsigned char b=0) | |
229 | : red(r), green(g), blue(b) {} | |
ec85956a | 230 | unsigned char red; |
978d3d36 VZ |
231 | unsigned char green; |
232 | unsigned char blue; | |
233 | }; | |
234 | ||
235 | // hue, saturation and value are doubles in the range 0.0..1.0 | |
236 | class HSVValue | |
237 | { | |
238 | public: | |
239 | HSVValue(double h=0.0, double s=0.0, double v=0.0) | |
240 | : hue(h), saturation(s), value(v) {} | |
ec85956a | 241 | double hue; |
978d3d36 VZ |
242 | double saturation; |
243 | double value; | |
244 | }; | |
978d3d36 | 245 | |
e98e625c | 246 | wxImage() {} |
72a9034b FM |
247 | wxImage( int width, int height, bool clear = true ) |
248 | { Create( width, height, clear ); } | |
249 | wxImage( int width, int height, unsigned char* data, bool static_data = false ) | |
250 | { Create( width, height, data, static_data ); } | |
251 | wxImage( int width, int height, unsigned char* data, unsigned char* alpha, bool static_data = false ) | |
252 | { Create( width, height, data, alpha, static_data ); } | |
253 | ||
254 | // ctor variants using wxSize: | |
255 | wxImage( const wxSize& sz, bool clear = true ) | |
256 | { Create( sz, clear ); } | |
257 | wxImage( const wxSize& sz, unsigned char* data, bool static_data = false ) | |
258 | { Create( sz, data, static_data ); } | |
259 | wxImage( const wxSize& sz, unsigned char* data, unsigned char* alpha, bool static_data = false ) | |
260 | { Create( sz, data, alpha, static_data ); } | |
261 | ||
262 | wxImage( const wxString& name, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1 ) | |
263 | { LoadFile( name, type, index ); } | |
264 | wxImage( const wxString& name, const wxString& mimetype, int index = -1 ) | |
265 | { LoadFile( name, mimetype, index ); } | |
266 | wxImage( const char* const* xpmData ) | |
267 | { Create(xpmData); } | |
aaf46fd6 VZ |
268 | |
269 | #if wxUSE_STREAMS | |
72a9034b FM |
270 | wxImage( wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1 ) |
271 | { LoadFile( stream, type, index ); } | |
272 | wxImage( wxInputStream& stream, const wxString& mimetype, int index = -1 ) | |
273 | { LoadFile( stream, mimetype, index ); } | |
aaf46fd6 | 274 | #endif // wxUSE_STREAMS |
01111366 | 275 | |
452418c4 | 276 | bool Create( const char* const* xpmData ); |
29b7b6ca PC |
277 | #ifdef __BORLANDC__ |
278 | // needed for Borland 5.5 | |
5c33522f VZ |
279 | wxImage( char** xpmData ) { Create(const_cast<const char* const*>(xpmData)); } |
280 | bool Create( char** xpmData ) { return Create(const_cast<const char* const*>(xpmData)); } | |
29b7b6ca | 281 | #endif |
72a9034b FM |
282 | |
283 | bool Create( int width, int height, bool clear = true ); | |
284 | bool Create( int width, int height, unsigned char* data, bool static_data = false ); | |
285 | bool Create( int width, int height, unsigned char* data, unsigned char* alpha, bool static_data = false ); | |
03647350 | 286 | |
72a9034b FM |
287 | // Create() variants using wxSize: |
288 | bool Create( const wxSize& sz, bool clear = true ) | |
289 | { return Create(sz.GetWidth(), sz.GetHeight(), clear); } | |
290 | bool Create( const wxSize& sz, unsigned char* data, bool static_data = false ) | |
291 | { return Create(sz.GetWidth(), sz.GetHeight(), data, static_data); } | |
292 | bool Create( const wxSize& sz, unsigned char* data, unsigned char* alpha, bool static_data = false ) | |
293 | { return Create(sz.GetWidth(), sz.GetHeight(), data, alpha, static_data); } | |
294 | ||
be25e480 | 295 | void Destroy(); |
03647350 | 296 | |
fc3762b5 FM |
297 | // initialize the image data with zeroes |
298 | void Clear(unsigned char value = 0); | |
01111366 | 299 | |
f6bcfd97 BP |
300 | // creates an identical copy of the image (the = operator |
301 | // just raises the ref count) | |
302 | wxImage Copy() const; | |
aaf46fd6 | 303 | |
be25e480 | 304 | // return the new image with size width*height |
b737ad10 RR |
305 | wxImage GetSubImage( const wxRect& rect) const; |
306 | ||
307 | // Paste the image or part of this image into an image of the given size at the pos | |
308 | // any newly exposed areas will be filled with the rgb colour | |
2ecf902b | 309 | // by default if r = g = b = -1 then fill with this image's mask colour or find and |
b737ad10 | 310 | // set a suitable mask colour |
2ecf902b | 311 | wxImage Size( const wxSize& size, const wxPoint& pos, |
b737ad10 | 312 | int r = -1, int g = -1, int b = -1 ) const; |
aaf46fd6 | 313 | |
f6bcfd97 BP |
314 | // pastes image into this instance and takes care of |
315 | // the mask colour and out of bounds problems | |
aaf46fd6 | 316 | void Paste( const wxImage &image, int x, int y ); |
23280650 | 317 | |
be25e480 | 318 | // return the new image with size width*height |
180f3c74 VZ |
319 | wxImage Scale( int width, int height, |
320 | wxImageResizeQuality quality = wxIMAGE_QUALITY_NORMAL ) const; | |
07aaa1a4 RR |
321 | |
322 | // box averager and bicubic filters for up/down sampling | |
180f3c74 | 323 | wxImage ResampleNearest(int width, int height) const; |
07aaa1a4 | 324 | wxImage ResampleBox(int width, int height) const; |
180f3c74 | 325 | wxImage ResampleBilinear(int width, int height) const; |
07aaa1a4 RR |
326 | wxImage ResampleBicubic(int width, int height) const; |
327 | ||
328 | // blur the image according to the specified pixel radius | |
24904055 VZ |
329 | wxImage Blur(int radius) const; |
330 | wxImage BlurHorizontal(int radius) const; | |
331 | wxImage BlurVertical(int radius) const; | |
bf78c81c | 332 | |
534f0312 | 333 | wxImage ShrinkBy( int xFactor , int yFactor ) const ; |
7b2471a0 | 334 | |
be25e480 | 335 | // rescales the image in place |
180f3c74 VZ |
336 | wxImage& Rescale( int width, int height, |
337 | wxImageResizeQuality quality = wxIMAGE_QUALITY_NORMAL ) | |
338 | { return *this = Scale(width, height, quality); } | |
ce9a75d2 | 339 | |
b737ad10 | 340 | // resizes the image in place |
2ecf902b | 341 | wxImage& Resize( const wxSize& size, const wxPoint& pos, |
b737ad10 RR |
342 | int r = -1, int g = -1, int b = -1 ) { return *this = Size(size, pos, r, g, b); } |
343 | ||
7a632f10 JS |
344 | // Rotates the image about the given point, 'angle' radians. |
345 | // Returns the rotated image, leaving this image intact. | |
346 | wxImage Rotate(double angle, const wxPoint & centre_of_rotation, | |
d3b9f782 | 347 | bool interpolating = true, wxPoint * offset_after_rotation = NULL) const; |
f6bcfd97 | 348 | |
7beb59f3 | 349 | wxImage Rotate90( bool clockwise = true ) const; |
8524dec3 | 350 | wxImage Rotate180() const; |
7beb59f3 | 351 | wxImage Mirror( bool horizontally = true ) const; |
7a632f10 | 352 | |
be25e480 RR |
353 | // replace one colour with another |
354 | void Replace( unsigned char r1, unsigned char g1, unsigned char b1, | |
355 | unsigned char r2, unsigned char g2, unsigned char b2 ); | |
aaf46fd6 | 356 | |
ec85956a | 357 | // Convert to greyscale image. Uses the luminance component (Y) of the image. |
198c264d JS |
358 | // The luma value (YUV) is calculated using (R * weight_r) + (G * weight_g) + (B * weight_b), defaults to ITU-T BT.601 |
359 | wxImage ConvertToGreyscale(double weight_r, double weight_g, double weight_b) const; | |
360 | wxImage ConvertToGreyscale(void) const; | |
ec85956a | 361 | |
ff5ad794 VS |
362 | // convert to monochrome image (<r,g,b> will be replaced by white, |
363 | // everything else by black) | |
f515c25a | 364 | wxImage ConvertToMono( unsigned char r, unsigned char g, unsigned char b ) const; |
ce9a75d2 | 365 | |
198c264d JS |
366 | // Convert to disabled (dimmed) image. |
367 | wxImage ConvertToDisabled(unsigned char brightness = 255) const; | |
368 | ||
be25e480 RR |
369 | // these routines are slow but safe |
370 | void SetRGB( int x, int y, unsigned char r, unsigned char g, unsigned char b ); | |
b737ad10 | 371 | void SetRGB( const wxRect& rect, unsigned char r, unsigned char g, unsigned char b ); |
f6bcfd97 BP |
372 | unsigned char GetRed( int x, int y ) const; |
373 | unsigned char GetGreen( int x, int y ) const; | |
374 | unsigned char GetBlue( int x, int y ) const; | |
23280650 | 375 | |
487659e0 | 376 | void SetAlpha(int x, int y, unsigned char alpha); |
d30ee785 | 377 | unsigned char GetAlpha(int x, int y) const; |
487659e0 | 378 | |
1f5b2017 VS |
379 | // find first colour that is not used in the image and has higher |
380 | // RGB values than <startR,startG,startB> | |
381 | bool FindFirstUnusedColour( unsigned char *r, unsigned char *g, unsigned char *b, | |
aaf46fd6 | 382 | unsigned char startR = 1, unsigned char startG = 0, |
e0a76d8d | 383 | unsigned char startB = 0 ) const; |
1f5b2017 | 384 | // Set image's mask to the area of 'mask' that has <r,g,b> colour |
aaf46fd6 | 385 | bool SetMaskFromImage(const wxImage & mask, |
1f5b2017 | 386 | unsigned char mr, unsigned char mg, unsigned char mb); |
52b64b0a | 387 | |
c1099d92 VZ |
388 | // converts image's alpha channel to mask (choosing mask colour |
389 | // automatically or using the specified colour for the mask), if it has | |
390 | // any, does nothing otherwise: | |
21dc4be5 | 391 | bool ConvertAlphaToMask(unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD); |
878f28d8 | 392 | bool ConvertAlphaToMask(unsigned char mr, unsigned char mg, unsigned char mb, |
c1099d92 VZ |
393 | unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD); |
394 | ||
ff5ad794 | 395 | |
6408deed RR |
396 | // This method converts an image where the original alpha |
397 | // information is only available as a shades of a colour | |
398 | // (actually shades of grey) typically when you draw anti- | |
399 | // aliased text into a bitmap. The DC drawinf routines | |
400 | // draw grey values on the black background although they | |
401 | // actually mean to draw white with differnt alpha values. | |
402 | // This method reverses it, assuming a black (!) background | |
16cba29d | 403 | // and white text (actually only the red channel is read). |
6408deed RR |
404 | // The method will then fill up the whole image with the |
405 | // colour given. | |
16cba29d | 406 | bool ConvertColourToAlpha( unsigned char r, unsigned char g, unsigned char b ); |
6408deed | 407 | |
be25e480 | 408 | static bool CanRead( const wxString& name ); |
e98e625c VZ |
409 | static int GetImageCount( const wxString& name, wxBitmapType type = wxBITMAP_TYPE_ANY ); |
410 | virtual bool LoadFile( const wxString& name, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1 ); | |
60d43ad8 | 411 | virtual bool LoadFile( const wxString& name, const wxString& mimetype, int index = -1 ); |
bf38cbff JS |
412 | |
413 | #if wxUSE_STREAMS | |
be25e480 | 414 | static bool CanRead( wxInputStream& stream ); |
e98e625c VZ |
415 | static int GetImageCount( wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY ); |
416 | virtual bool LoadFile( wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1 ); | |
60d43ad8 | 417 | virtual bool LoadFile( wxInputStream& stream, const wxString& mimetype, int index = -1 ); |
bf38cbff JS |
418 | #endif |
419 | ||
45647dcf | 420 | virtual bool SaveFile( const wxString& name ) const; |
e98e625c | 421 | virtual bool SaveFile( const wxString& name, wxBitmapType type ) const; |
e0a76d8d | 422 | virtual bool SaveFile( const wxString& name, const wxString& mimetype ) const; |
bf38cbff JS |
423 | |
424 | #if wxUSE_STREAMS | |
e98e625c | 425 | virtual bool SaveFile( wxOutputStream& stream, wxBitmapType type ) const; |
e0a76d8d | 426 | virtual bool SaveFile( wxOutputStream& stream, const wxString& mimetype ) const; |
bf38cbff | 427 | #endif |
01111366 | 428 | |
b7cacb43 VZ |
429 | bool Ok() const { return IsOk(); } |
430 | bool IsOk() const; | |
be25e480 RR |
431 | int GetWidth() const; |
432 | int GetHeight() const; | |
433 | ||
c74b07ac FM |
434 | wxSize GetSize() const |
435 | { return wxSize(GetWidth(), GetHeight()); } | |
436 | ||
591d3fa2 VZ |
437 | // Gets the type of image found by LoadFile or specified with SaveFile |
438 | wxBitmapType GetType() const; | |
439 | ||
9d1c7e84 VZ |
440 | // Set the image type, this is normally only called if the image is being |
441 | // created from data in the given format but not using LoadFile() (e.g. | |
442 | // wxGIFDecoder uses this) | |
443 | void SetType(wxBitmapType type); | |
444 | ||
487659e0 VZ |
445 | // these functions provide fastest access to wxImage data but should be |
446 | // used carefully as no checks are done | |
447 | unsigned char *GetData() const; | |
4013de12 RD |
448 | void SetData( unsigned char *data, bool static_data=false ); |
449 | void SetData( unsigned char *data, int new_width, int new_height, bool static_data=false ); | |
487659e0 VZ |
450 | |
451 | unsigned char *GetAlpha() const; // may return NULL! | |
452 | bool HasAlpha() const { return GetAlpha() != NULL; } | |
4013de12 | 453 | void SetAlpha(unsigned char *alpha = NULL, bool static_data=false); |
828f0936 | 454 | void InitAlpha(); |
90fbb09a | 455 | void ClearAlpha(); |
5e5437e0 | 456 | |
21dc4be5 VZ |
457 | // return true if this pixel is masked or has alpha less than specified |
458 | // threshold | |
459 | bool IsTransparent(int x, int y, | |
460 | unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD) const; | |
461 | ||
5e5437e0 | 462 | // Mask functions |
be25e480 | 463 | void SetMaskColour( unsigned char r, unsigned char g, unsigned char b ); |
b737ad10 RR |
464 | // Get the current mask colour or find a suitable colour |
465 | // returns true if using current mask colour | |
466 | bool GetOrFindMaskColour( unsigned char *r, unsigned char *g, unsigned char *b ) const; | |
be25e480 RR |
467 | unsigned char GetMaskRed() const; |
468 | unsigned char GetMaskGreen() const; | |
469 | unsigned char GetMaskBlue() const; | |
7beb59f3 | 470 | void SetMask( bool mask = true ); |
be25e480 RR |
471 | bool HasMask() const; |
472 | ||
d275c7eb | 473 | #if wxUSE_PALETTE |
5e5437e0 JS |
474 | // Palette functions |
475 | bool HasPalette() const; | |
476 | const wxPalette& GetPalette() const; | |
477 | void SetPalette(const wxPalette& palette); | |
d275c7eb | 478 | #endif // wxUSE_PALETTE |
5e5437e0 JS |
479 | |
480 | // Option functions (arbitrary name/value mapping) | |
481 | void SetOption(const wxString& name, const wxString& value); | |
482 | void SetOption(const wxString& name, int value); | |
483 | wxString GetOption(const wxString& name) const; | |
484 | int GetOptionInt(const wxString& name) const; | |
485 | bool HasOption(const wxString& name) const; | |
3f4fc796 | 486 | |
e0a76d8d | 487 | unsigned long CountColours( unsigned long stopafter = (unsigned long) -1 ) const; |
952ae1e8 VS |
488 | |
489 | // Computes the histogram of the image and fills a hash table, indexed | |
490 | // with integer keys built as 0xRRGGBB, containing wxImageHistogramEntry | |
bf78c81c RD |
491 | // objects. Each of them contains an 'index' (useful to build a palette |
492 | // with the image colours) and a 'value', which is the number of pixels | |
952ae1e8 VS |
493 | // in the image with that colour. |
494 | // Returned value: # of entries in the histogram | |
e0a76d8d | 495 | unsigned long ComputeHistogram( wxImageHistogram &h ) const; |
be25e480 | 496 | |
978d3d36 VZ |
497 | // Rotates the hue of each pixel of the image. angle is a double in the range |
498 | // -1.0..1.0 where -1.0 is -360 degrees and 1.0 is 360 degrees | |
499 | void RotateHue(double angle); | |
978d3d36 | 500 | |
be25e480 RR |
501 | static wxList& GetHandlers() { return sm_handlers; } |
502 | static void AddHandler( wxImageHandler *handler ); | |
503 | static void InsertHandler( wxImageHandler *handler ); | |
504 | static bool RemoveHandler( const wxString& name ); | |
505 | static wxImageHandler *FindHandler( const wxString& name ); | |
e98e625c VZ |
506 | static wxImageHandler *FindHandler( const wxString& extension, wxBitmapType imageType ); |
507 | static wxImageHandler *FindHandler( wxBitmapType imageType ); | |
9e0560c1 | 508 | |
be25e480 RR |
509 | static wxImageHandler *FindHandlerMime( const wxString& mimetype ); |
510 | ||
939fadc8 JS |
511 | static wxString GetImageExtWildcard(); |
512 | ||
be25e480 RR |
513 | static void CleanUpHandlers(); |
514 | static void InitStandardHandlers(); | |
c9d01afd | 515 | |
978d3d36 VZ |
516 | static HSVValue RGBtoHSV(const RGBValue& rgb); |
517 | static RGBValue HSVtoRGB(const HSVValue& hsv); | |
978d3d36 | 518 | |
831b64f3 | 519 | #if WXWIN_COMPATIBILITY_2_8 |
70bf3295 SC |
520 | wxDEPRECATED_CONSTRUCTOR( |
521 | wxImage(const wxString& name, long type, int index = -1) | |
0ddec397 VZ |
522 | { |
523 | LoadFile(name, (wxBitmapType)type, index); | |
524 | } | |
525 | ) | |
526 | ||
527 | #if wxUSE_STREAMS | |
70bf3295 SC |
528 | wxDEPRECATED_CONSTRUCTOR( |
529 | wxImage(wxInputStream& stream, long type, int index = -1) | |
0ddec397 VZ |
530 | { |
531 | LoadFile(stream, (wxBitmapType)type, index); | |
532 | } | |
533 | ) | |
534 | ||
535 | wxDEPRECATED( | |
536 | bool LoadFile(wxInputStream& stream, long type, int index = -1) | |
537 | { | |
538 | return LoadFile(stream, (wxBitmapType)type, index); | |
539 | } | |
540 | ) | |
541 | ||
542 | wxDEPRECATED( | |
543 | bool SaveFile(wxOutputStream& stream, long type) const | |
544 | { | |
545 | return SaveFile(stream, (wxBitmapType)type); | |
546 | } | |
547 | ) | |
548 | #endif // wxUSE_STREAMS | |
549 | ||
9e0560c1 VZ |
550 | wxDEPRECATED( |
551 | bool LoadFile(const wxString& name, long type, int index = -1) | |
552 | { | |
553 | return LoadFile(name, (wxBitmapType)type, index); | |
554 | } | |
555 | ) | |
556 | ||
0ddec397 VZ |
557 | wxDEPRECATED( |
558 | bool SaveFile(const wxString& name, long type) const | |
559 | { | |
560 | return SaveFile(name, (wxBitmapType)type); | |
561 | } | |
562 | ) | |
563 | ||
564 | wxDEPRECATED( | |
565 | static wxImageHandler *FindHandler(const wxString& ext, long type) | |
566 | { | |
567 | return FindHandler(ext, (wxBitmapType)type); | |
568 | } | |
569 | ) | |
570 | ||
9e0560c1 VZ |
571 | wxDEPRECATED( |
572 | static wxImageHandler *FindHandler(long imageType) | |
573 | { | |
574 | return FindHandler((wxBitmapType)imageType); | |
575 | } | |
576 | ) | |
577 | #endif // WXWIN_COMPATIBILITY_2_8 | |
978d3d36 | 578 | |
01111366 | 579 | protected: |
5e5437e0 | 580 | static wxList sm_handlers; |
01111366 | 581 | |
5644ac46 VZ |
582 | // return the index of the point with the given coordinates or -1 if the |
583 | // image is invalid of the coordinates are out of range | |
584 | // | |
585 | // note that index must be multiplied by 3 when using it with RGB array | |
586 | long XYToIndex(int x, int y) const; | |
587 | ||
a0f81e9f PC |
588 | virtual wxObjectRefData* CreateRefData() const; |
589 | virtual wxObjectRefData* CloneRefData(const wxObjectRefData* data) const; | |
590 | ||
be25e480 | 591 | private: |
b5dbe15d | 592 | friend class WXDLLIMPEXP_FWD_CORE wxImageHandler; |
23280650 | 593 | |
496dbbe7 VZ |
594 | // Possible values for MakeEmptyClone() flags. |
595 | enum | |
596 | { | |
597 | // Create an image with the same orientation as this one. This is the | |
598 | // default and only exists for symmetry with SwapOrientation. | |
599 | Clone_SameOrientation = 0, | |
600 | ||
601 | // Create an image with the same height as this image width and the | |
602 | // same width as this image height. | |
603 | Clone_SwapOrientation = 1 | |
604 | }; | |
605 | ||
606 | // Returns a new blank image with the same dimensions (or with width and | |
607 | // height swapped if Clone_SwapOrientation flag is given), alpha, and mask | |
608 | // as this image itself. This is used by several functions creating | |
609 | // modified versions of this image. | |
610 | wxImage MakeEmptyClone(int flags = Clone_SameOrientation) const; | |
611 | ||
591d3fa2 VZ |
612 | #if wxUSE_STREAMS |
613 | // read the image from the specified stream updating image type if | |
614 | // successful | |
615 | bool DoLoad(wxImageHandler& handler, wxInputStream& stream, int index); | |
616 | ||
617 | // write the image to the specified stream and also update the image type | |
618 | // if successful | |
619 | bool DoSave(wxImageHandler& handler, wxOutputStream& stream) const; | |
620 | #endif // wxUSE_STREAMS | |
621 | ||
be25e480 | 622 | DECLARE_DYNAMIC_CLASS(wxImage) |
01111366 RR |
623 | }; |
624 | ||
8f493002 | 625 | |
53a2db12 | 626 | extern void WXDLLIMPEXP_CORE wxInitAllImageHandlers(); |
b5a4a47d | 627 | |
53a2db12 | 628 | extern WXDLLIMPEXP_DATA_CORE(wxImage) wxNullImage; |
8f493002 VS |
629 | |
630 | //----------------------------------------------------------------------------- | |
631 | // wxImage handlers | |
632 | //----------------------------------------------------------------------------- | |
633 | ||
634 | #include "wx/imagbmp.h" | |
635 | #include "wx/imagpng.h" | |
636 | #include "wx/imaggif.h" | |
637 | #include "wx/imagpcx.h" | |
638 | #include "wx/imagjpeg.h" | |
3af706cc | 639 | #include "wx/imagtga.h" |
8f493002 VS |
640 | #include "wx/imagtiff.h" |
641 | #include "wx/imagpnm.h" | |
775c6f0c | 642 | #include "wx/imagxpm.h" |
4b6b4dfc | 643 | #include "wx/imagiff.h" |
775c6f0c VS |
644 | |
645 | #endif // wxUSE_IMAGE | |
8f493002 | 646 | |
01111366 RR |
647 | #endif |
648 | // _WX_IMAGE_H_ |