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