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