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