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