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