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