]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/image.h
Use correct font instead of DEFAULT_GUI_FONT.
[wxWidgets.git] / interface / wx / image.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: image.h
427c415b 3// Purpose: interface of wxImageHandler and wxImage
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
09b898e0
VZ
9/**
10 Possible values for the image resolution option.
11
12 @see wxImage::GetOptionInt().
13 */
14enum wxImageResolution
15{
16 /// Resolution not specified.
17 wxIMAGE_RESOLUTION_NONE = 0,
18
19 /// Resolution specified in inches.
20 wxIMAGE_RESOLUTION_INCHES = 1,
21
22 /// Resolution specified in centimetres.
23 wxIMAGE_RESOLUTION_CM = 2
24};
25
26/**
27 Possible values for PNG image type option.
28
29 @see wxImage::GetOptionInt().
30 */
31enum wxImagePNGType
32{
33 wxPNG_TYPE_COLOUR = 0, ///< Colour PNG image.
34 wxPNG_TYPE_GREY = 2, ///< Greyscale PNG image converted from RGB.
35 wxPNG_TYPE_GREY_RED = 3 ///< Greyscale PNG image using red as grey.
36};
37
23324ae1
FM
38/**
39 @class wxImageHandler
7c913512 40
b3623ed5
RR
41 This is the base class for implementing image file loading/saving, and
42 image creation from data.
23324ae1 43 It is used within wxImage and is not normally seen by the application.
7c913512 44
23324ae1 45 If you wish to extend the capabilities of wxImage, derive a class from
b3623ed5 46 wxImageHandler and add the handler using wxImage::AddHandler in your
c83d207b 47 application initialization.
7c913512 48
427c415b
FM
49 Note that all wxImageHandlers provided by wxWidgets are part of
50 the @ref page_libs_wxcore library.
51 For details about the default handlers, please see the section
52 @ref image_handlers in the wxImage class documentation.
53
54
55 @section imagehandler_note Note (Legal Issue)
56
57 This software is based in part on the work of the Independent JPEG Group.
58 (Applies when wxWidgets is linked with JPEG support.
59 wxJPEGHandler uses libjpeg created by IJG.)
60
61
b3623ed5
RR
62 @stdobjects
63 ::wxNullImage
64
23324ae1 65 @library{wxcore}
3c99e2fd 66 @category{gdi}
7c913512 67
e54c96f1 68 @see wxImage, wxInitAllImageHandlers()
23324ae1
FM
69*/
70class wxImageHandler : public wxObject
71{
72public:
73 /**
427c415b
FM
74 Default constructor.
75
76 In your own default constructor, initialise the members
23324ae1
FM
77 m_name, m_extension and m_type.
78 */
79 wxImageHandler();
80
81 /**
82 Destroys the wxImageHandler object.
83 */
adaaa686 84 virtual ~wxImageHandler();
23324ae1 85
8faef7cc
FM
86 /**
87 Returns @true if this handler supports the image format contained in the
88 given stream.
89
90 This function doesn't modify the current stream position (because it
91 restores the original position before returning; this however requires the
92 stream to be seekable; see wxStreamBase::IsSeekable).
93 */
94 bool CanRead( wxInputStream& stream );
95
96 /**
97 Returns @true if this handler supports the image format contained in the
98 file with the given name.
99
100 This function doesn't modify the current stream position (because it
101 restores the original position before returning; this however requires the
102 stream to be seekable; see wxStreamBase::IsSeekable).
103 */
104 bool CanRead( const wxString& filename );
105
23324ae1 106 /**
ba4800d3
VZ
107 Gets the preferred file extension associated with this handler.
108
109 @see GetAltExtensions()
23324ae1 110 */
427c415b 111 const wxString& GetExtension() const;
23324ae1 112
ba4800d3
VZ
113 /**
114 Returns the other file extensions associated with this handler.
115
116 The preferred extension for this handler is returned by GetExtension().
117
118 @since 2.9.0
119 */
120 const wxArrayString& GetAltExtensions() const;
121
23324ae1
FM
122 /**
123 If the image file contains more than one image and the image handler is capable
124 of retrieving these individually, this function will return the number of
125 available images.
3c4f71cc 126
7c913512 127 @param stream
427c415b 128 Opened input stream for reading image data.
8faef7cc
FM
129 This function doesn't modify the current stream position (because it
130 restores the original position before returning; this however requires the
131 stream to be seekable; see wxStreamBase::IsSeekable).
3c4f71cc 132
d29a9a8a 133 @return Number of available images. For most image handlers, this is 1
85fcb94f
VZ
134 (exceptions are TIFF and ICO formats as well as animated GIFs
135 for which this function returns the number of frames in the
136 animation).
23324ae1 137 */
adaaa686 138 virtual int GetImageCount(wxInputStream& stream);
23324ae1
FM
139
140 /**
141 Gets the MIME type associated with this handler.
142 */
427c415b 143 const wxString& GetMimeType() const;
23324ae1
FM
144
145 /**
146 Gets the name of this handler.
147 */
427c415b 148 const wxString& GetName() const;
23324ae1
FM
149
150 /**
151 Gets the image type associated with this handler.
152 */
e98e625c 153 wxBitmapType GetType() const;
23324ae1
FM
154
155 /**
427c415b
FM
156 Loads a image from a stream, putting the resulting data into @a image.
157
158 If the image file contains more than one image and the image handler is
159 capable of retrieving these individually, @a index indicates which image
160 to read from the stream.
3c4f71cc 161
7c913512 162 @param image
4cc4bfaf 163 The image object which is to be affected by this operation.
7c913512 164 @param stream
4cc4bfaf 165 Opened input stream for reading image data.
7c913512 166 @param verbose
4cc4bfaf 167 If set to @true, errors reported by the image handler will produce
427c415b 168 wxLogMessages.
7c913512 169 @param index
4cc4bfaf 170 The index of the image in the file (starting from zero).
3c4f71cc 171
d29a9a8a 172 @return @true if the operation succeeded, @false otherwise.
3c4f71cc 173
4cc4bfaf 174 @see wxImage::LoadFile, wxImage::SaveFile, SaveFile()
23324ae1 175 */
5267aefd
FM
176 virtual bool LoadFile(wxImage* image, wxInputStream& stream,
177 bool verbose = true, int index = -1);
23324ae1
FM
178
179 /**
180 Saves a image in the output stream.
3c4f71cc 181
7c913512 182 @param image
4cc4bfaf 183 The image object which is to be affected by this operation.
7c913512 184 @param stream
4cc4bfaf 185 Opened output stream for writing the data.
f21dd16b
FM
186 @param verbose
187 If set to @true, errors reported by the image handler will produce
188 wxLogMessages.
3c4f71cc 189
d29a9a8a 190 @return @true if the operation succeeded, @false otherwise.
3c4f71cc 191
4cc4bfaf 192 @see wxImage::LoadFile, wxImage::SaveFile, LoadFile()
23324ae1 193 */
5267aefd
FM
194 virtual bool SaveFile(wxImage* image, wxOutputStream& stream,
195 bool verbose = true);
23324ae1
FM
196
197 /**
ba4800d3 198 Sets the preferred file extension associated with this handler.
3c4f71cc 199
7c913512 200 @param extension
ba4800d3
VZ
201 File extension without leading dot.
202
203 @see SetAltExtensions()
23324ae1
FM
204 */
205 void SetExtension(const wxString& extension);
206
ba4800d3
VZ
207 /**
208 Sets the alternative file extensions associated with this handler.
209
210 @param extensions
211 Array of file extensions.
212
213 @see SetExtension()
214
215 @since 2.9.0
216 */
217 void SetAltExtensions(const wxArrayString& extensions);
218
23324ae1
FM
219 /**
220 Sets the handler MIME type.
3c4f71cc 221
427c415b 222 @param mimetype
4cc4bfaf 223 Handler MIME type.
23324ae1
FM
224 */
225 void SetMimeType(const wxString& mimetype);
226
227 /**
228 Sets the handler name.
3c4f71cc 229
7c913512 230 @param name
4cc4bfaf 231 Handler name.
23324ae1
FM
232 */
233 void SetName(const wxString& name);
234};
235
236
427c415b
FM
237/**
238 Constant used to indicate the alpha value conventionally defined as
239 the complete transparency.
240*/
241const unsigned char wxIMAGE_ALPHA_TRANSPARENT = 0;
242
243/**
244 Constant used to indicate the alpha value conventionally defined as
245 the complete opacity.
246*/
247const unsigned char wxIMAGE_ALPHA_OPAQUE = 0xff;
e54c96f1 248
23324ae1
FM
249/**
250 @class wxImage
7c913512 251
427c415b
FM
252 This class encapsulates a platform-independent image.
253
254 An image can be created from data, or using wxBitmap::ConvertToImage.
255 An image can be loaded from a file in a variety of formats, and is extensible
256 to new formats via image format handlers. Functions are available to set and
b3623ed5 257 get image bits, so it can be used for basic image manipulation.
7c913512 258
427c415b
FM
259 A wxImage cannot (currently) be drawn directly to a wxDC.
260 Instead, a platform-specific wxBitmap object must be created from it using
23324ae1 261 the wxBitmap::wxBitmap(wxImage,int depth) constructor.
b3623ed5 262 This bitmap can then be drawn in a device context, using wxDC::DrawBitmap.
7c913512 263
23324ae1 264 One colour value of the image may be used as a mask colour which will lead to
65874118 265 the automatic creation of a wxMask object associated to the bitmap object.
7c913512 266
427c415b
FM
267
268 @section image_alpha Alpha channel support
269
270 Starting from wxWidgets 2.5.0 wxImage supports alpha channel data, that is
271 in addition to a byte for the red, green and blue colour components for each
272 pixel it also stores a byte representing the pixel opacity.
273
274 An alpha value of 0 corresponds to a transparent pixel (null opacity) while
275 a value of 255 means that the pixel is 100% opaque.
276 The constants ::wxIMAGE_ALPHA_TRANSPARENT and ::wxIMAGE_ALPHA_OPAQUE can be
277 used to indicate those values in a more readable form.
278
0241477a
VZ
279 While all images have RGB data, not all images have an alpha channel. Before
280 using wxImage::GetAlpha you should check if this image contains an alpha
281 channel with wxImage::HasAlpha. Note that currently only the PNG format has
282 full alpha channel support so only the images loaded from PNG files can have
427c415b
FM
283 alpha and, if you initialize the image alpha channel yourself using
284 wxImage::SetAlpha, you should save it in PNG format to avoid losing it.
285
286
287 @section image_handlers Available image handlers
288
289 The following image handlers are available.
290 wxBMPHandler is always installed by default.
291 To use other image formats, install the appropriate handler with
292 wxImage::AddHandler or call ::wxInitAllImageHandlers().
293
294 - wxBMPHandler: For loading and saving, always installed.
295 - wxPNGHandler: For loading (including alpha support) and saving.
296 - wxJPEGHandler: For loading and saving.
297 - wxGIFHandler: Only for loading, due to legal issues.
298 - wxPCXHandler: For loading and saving (see below).
299 - wxPNMHandler: For loading and saving (see below).
300 - wxTIFFHandler: For loading and saving.
301 - wxTGAHandler: For loading only.
302 - wxIFFHandler: For loading only.
303 - wxXPMHandler: For loading and saving.
304 - wxICOHandler: For loading and saving.
305 - wxCURHandler: For loading and saving.
306 - wxANIHandler: For loading only.
307
308 When saving in PCX format, wxPCXHandler will count the number of different
309 colours in the image; if there are 256 or less colours, it will save as 8 bit,
310 else it will save as 24 bit.
311
312 Loading PNMs only works for ASCII or raw RGB images.
313 When saving in PNM format, wxPNMHandler will always save as raw RGB.
314
315
23324ae1
FM
316 @library{wxcore}
317 @category{gdi}
7c913512 318
65874118
FM
319 @stdobjects
320 ::wxNullImage
321
4e2cddc4 322 @see wxBitmap, wxInitAllImageHandlers(), wxPixelData
23324ae1
FM
323*/
324class wxImage : public wxObject
325{
326public:
72a9034b
FM
327 /**
328 A simple class which stores red, green and blue values as 8 bit unsigned integers
329 in the range of 0-255.
330 */
427c415b
FM
331 class RGBValue
332 {
333 public:
334 /**
335 Constructor for RGBValue, an object that contains values for red, green
336 and blue which represent the value of a color.
337
72a9034b 338 It is used by wxImage::HSVtoRGB and wxImage::RGBtoHSV, which convert
427c415b
FM
339 between HSV color space and RGB color space.
340 */
341 RGBValue(unsigned char r=0, unsigned char g=0, unsigned char b=0);
342 };
343
72a9034b
FM
344 /**
345 A simple class which stores hue, saturation and value as doubles in the range 0.0-1.0.
346 */
427c415b
FM
347 class HSVValue
348 {
349 public:
350 /**
351 Constructor for HSVValue, an object that contains values for hue, saturation
352 and value which represent the value of a color.
353
72a9034b 354 It is used by wxImage::HSVtoRGB() and wxImage::RGBtoHSV(), which convert
427c415b
FM
355 between HSV color space and RGB color space.
356 */
357 HSVValue(double h=0.0, double s=0.0, double v=0.0);
358 };
359
360 /**
361 Creates an empty wxImage object without an alpha channel.
b3623ed5
RR
362 */
363 wxImage();
e98e625c 364
b3623ed5 365 /**
ff3050e1
VZ
366 Creates an image with the given size and clears it if requested.
367
368 Does not create an alpha channel.
e98e625c 369
b3623ed5
RR
370 @param width
371 Specifies the width of the image.
372 @param height
373 Specifies the height of the image.
ff3050e1
VZ
374 @param clear
375 If @true, initialize the image to black.
b3623ed5
RR
376 */
377 wxImage(int width, int height, bool clear = true);
72a9034b
FM
378
379 /**
380 @overload
381 */
382 wxImage(const wxSize& sz, bool clear = true);
e98e625c 383
23324ae1 384 /**
427c415b 385 Creates an image from data in memory. If @a static_data is @false
dd067e96
RR
386 then the wxImage will take ownership of the data and free it
387 afterwards. For this, it has to be allocated with @e malloc.
e98e625c 388
7c913512 389 @param width
4cc4bfaf 390 Specifies the width of the image.
7c913512 391 @param height
4cc4bfaf 392 Specifies the height of the image.
dd067e96
RR
393 @param data
394 A pointer to RGB data
4e2cddc4
RR
395 @param static_data
396 Indicates if the data should be free'd after use
e98e625c 397
dd067e96 398 */
72a9034b 399 wxImage(int width, int height, unsigned char* data, bool static_data = false);
e98e625c 400
72a9034b
FM
401 /**
402 @overload
403 */
404 wxImage(const wxSize& sz, unsigned char* data, bool static_data = false);
405
dd067e96 406 /**
427c415b 407 Creates an image from data in memory. If @a static_data is @false
b3623ed5
RR
408 then the wxImage will take ownership of the data and free it
409 afterwards. For this, it has to be allocated with @e malloc.
e98e625c 410
dd067e96
RR
411 @param width
412 Specifies the width of the image.
413 @param height
414 Specifies the height of the image.
b3623ed5
RR
415 @param data
416 A pointer to RGB data
417 @param alpha
418 A pointer to alpha-channel data
419 @param static_data
420 Indicates if the data should be free'd after use
e98e625c 421
4e2cddc4 422 */
427c415b
FM
423 wxImage(int width, int height, unsigned char* data, unsigned char* alpha,
424 bool static_data = false );
e98e625c 425
72a9034b
FM
426 /**
427 @overload
428 */
429 wxImage(const wxSize& sz, unsigned char* data, unsigned char* data, unsigned char* alpha,
430 bool static_data = false);
431
dd067e96
RR
432 /**
433 Creates an image from XPM data.
e98e625c 434
dd067e96
RR
435 @param xpmData
436 A pointer to XPM image data.
437 */
438 wxImage(const char* const* xpmData);
e98e625c 439
dd067e96 440 /**
b3623ed5 441 Creates an image from a file.
e98e625c 442
7c913512 443 @param name
4cc4bfaf 444 Name of the file from which to load the image.
7c913512 445 @param type
4cc4bfaf 446 May be one of the following:
4e2cddc4
RR
447 @li wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
448 @li wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
449 @li wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
450 @li wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
451 @li wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
452 @li wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
453 @li wxBITMAP_TYPE_TIF: Load a TIFF bitmap file.
454 @li wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
455 @li wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
456 @li wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
457 @li wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
458 @li wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
459 @li wxBITMAP_TYPE_ANY: Will try to autodetect the format.
4cc4bfaf
FM
460 @param index
461 Index of the image to load in the case that the image file contains
dd067e96
RR
462 multiple images. This is only used by GIF, ICO and TIFF handlers.
463 The default value (-1) means "choose the default image" and is
464 interpreted as the first image (index=0) by the GIF and TIFF handler
465 and as the largest and most colourful one by the ICO handler.
3c4f71cc 466
427c415b
FM
467 @remarks Depending on how wxWidgets has been configured and by which
468 handlers have been loaded, not all formats may be available.
469 Any handler other than BMP must be previously initialized with
470 wxImage::AddHandler or wxInitAllImageHandlers.
471
472 @note
473 You can use GetOptionInt() to get the hotspot when loading cursor files:
474 @code
475 int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
476 int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
477 @endcode
3c4f71cc 478
4cc4bfaf 479 @see LoadFile()
23324ae1 480 */
e98e625c
VZ
481 wxImage(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1);
482
b3623ed5
RR
483 /**
484 Creates an image from a file using MIME-types to specify the type.
e98e625c 485
b3623ed5
RR
486 @param name
487 Name of the file from which to load the image.
b3623ed5
RR
488 @param mimetype
489 MIME type string (for example 'image/jpeg')
490 @param index
427c415b 491 See description in wxImage(const wxString&, wxBitmapType, int) overload.
b3623ed5 492 */
dd067e96 493 wxImage(const wxString& name, const wxString& mimetype, int index = -1);
e98e625c 494
b3623ed5
RR
495 /**
496 Creates an image from a stream.
e98e625c 497
b3623ed5
RR
498 @param stream
499 Opened input stream from which to load the image. Currently,
500 the stream must support seeking.
501 @param type
427c415b 502 See description in wxImage(const wxString&, wxBitmapType, int) overload.
b3623ed5 503 @param index
427c415b 504 See description in wxImage(const wxString&, wxBitmapType, int) overload.
b3623ed5 505 */
e98e625c
VZ
506 wxImage(wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1);
507
b3623ed5
RR
508 /**
509 Creates an image from a stream using MIME-types to specify the type.
e98e625c 510
b3623ed5
RR
511 @param stream
512 Opened input stream from which to load the image. Currently,
513 the stream must support seeking.
514 @param mimetype
515 MIME type string (for example 'image/jpeg')
516 @param index
427c415b 517 See description in wxImage(const wxString&, wxBitmapType, int) overload.
b3623ed5 518 */
dd067e96 519 wxImage(wxInputStream& stream, const wxString& mimetype, int index = -1);
e98e625c 520
23324ae1
FM
521 /**
522 Destructor.
427c415b
FM
523
524 See @ref overview_refcount_destruct "reference-counted object destruction"
525 for more info.
23324ae1 526 */
adaaa686 527 virtual ~wxImage();
23324ae1 528
72a9034b
FM
529
530
23324ae1 531 /**
72a9034b 532 @name Image creation, initialization and deletion functions
23324ae1 533 */
72a9034b
FM
534 //@{
535
536 /**
537 Returns an identical copy of this image.
538 */
539 wxImage Copy() const;
540
541 /**
542 Creates a fresh image.
543 See wxImage::wxImage(int,int,bool) for more info.
544
545 @return @true if the call succeeded, @false otherwise.
546 */
547 bool Create(int width, int height, bool clear = true);
548
549 /**
550 @overload
551 */
552 bool Create( const wxSize& sz, bool clear = true );
553
554 /**
555 Creates a fresh image.
556 See wxImage::wxImage(int,int,unsigned char*,bool) for more info.
557
558 @return @true if the call succeeded, @false otherwise.
559 */
560 bool Create( int width, int height, unsigned char* data, bool static_data = false );
561
562 /**
563 @overload
564 */
565 bool Create( const wxSize& sz, unsigned char* data, bool static_data = false );
566
567 /**
568 Creates a fresh image.
569 See wxImage::wxImage(int,int,unsigned char*,unsigned char*,bool) for more info.
570
571 @return @true if the call succeeded, @false otherwise.
572 */
573 bool Create( int width, int height, unsigned char* data, unsigned char* alpha, bool static_data = false );
574
575 /**
576 @overload
577 */
578 bool Create( const wxSize& sz, unsigned char* data, unsigned char* alpha, bool static_data = false );
579
580 /**
581 Initialize the image data with zeroes (the default) or with the
582 byte value given as @a value.
583
584 @since 2.9.0
585 */
586 void Clear(unsigned char value = 0);
587
588 /**
589 Destroys the image data.
590 */
591 void Destroy();
592
593 /**
594 Initializes the image alpha channel data.
595
596 It is an error to call it if the image already has alpha data.
597 If it doesn't, alpha data will be by default initialized to all pixels
598 being fully opaque. But if the image has a mask colour, all mask pixels
599 will be completely transparent.
600 */
601 void InitAlpha();
602
603 //@}
604
605
606 /**
607 @name Image manipulation functions
608 */
609 //@{
23324ae1
FM
610
611 /**
b3623ed5 612 Blurs the image in both horizontal and vertical directions by the
427c415b 613 specified pixel @a blurRadius. This should not be used when using
b3623ed5 614 a single mask colour for transparency.
3c4f71cc 615
b3623ed5 616 @see BlurHorizontal(), BlurVertical()
23324ae1 617 */
adaaa686 618 wxImage Blur(int blurRadius) const;
23324ae1
FM
619
620 /**
621 Blurs the image in the horizontal direction only. This should not be used
622 when using a single mask colour for transparency.
3c4f71cc 623
b3623ed5 624 @see Blur(), BlurVertical()
23324ae1 625 */
adaaa686 626 wxImage BlurHorizontal(int blurRadius) const;
23324ae1
FM
627
628 /**
629 Blurs the image in the vertical direction only. This should not be used
630 when using a single mask colour for transparency.
3c4f71cc 631
b3623ed5 632 @see Blur(), BlurHorizontal()
23324ae1 633 */
adaaa686 634 wxImage BlurVertical(int blurRadius) const;
e98e625c 635
b3623ed5 636 /**
72a9034b
FM
637 Returns a mirrored copy of the image.
638 The parameter @a horizontally indicates the orientation.
b3623ed5 639 */
72a9034b 640 wxImage Mirror(bool horizontally = true) const;
23324ae1
FM
641
642 /**
72a9034b 643 Copy the data of the given @a image to the specified position in this image.
23324ae1 644 */
72a9034b 645 void Paste(const wxImage& image, int x, int y);
23324ae1
FM
646
647 /**
72a9034b
FM
648 Replaces the colour specified by @e r1,g1,b1 by the colour @e r2,g2,b2.
649 */
650 void Replace(unsigned char r1, unsigned char g1,
651 unsigned char b1, unsigned char r2,
652 unsigned char g2, unsigned char b2);
653
654 /**
655 Changes the size of the image in-place by scaling it: after a call to this
656 function,the image will have the given width and height.
657
658 For a description of the @a quality parameter, see the Scale() function.
659 Returns the (modified) image itself.
660
661 @see Scale()
662 */
663 wxImage& Rescale(int width, int height,
664 int quality = wxIMAGE_QUALITY_NORMAL);
665
666 /**
667 Changes the size of the image in-place without scaling it by adding either a
668 border with the given colour or cropping as necessary.
669
670 The image is pasted into a new image with the given @a size and background
671 colour at the position @a pos relative to the upper left of the new image.
672
673 If @a red = green = blue = -1 then use either the current mask colour
674 if set or find, use, and set a suitable mask colour for any newly exposed
675 areas.
676
677 @return The (modified) image itself.
678
679 @see Size()
680 */
681 wxImage& Resize(const wxSize& size, const wxPoint& pos, int red = -1,
682 int green = -1, int blue = -1);
683
684 /**
685 Rotates the image about the given point, by @a angle radians.
686
687 Passing @true to @a interpolating results in better image quality, but is slower.
688
689 If the image has a mask, then the mask colour is used for the uncovered
690 pixels in the rotated image background. Else, black (rgb 0, 0, 0) will be used.
691
692 Returns the rotated image, leaving this image intact.
693 */
694 wxImage Rotate(double angle, const wxPoint& rotationCentre,
695 bool interpolating = true,
696 wxPoint* offsetAfterRotation = NULL) const;
697
698 /**
699 Returns a copy of the image rotated 90 degrees in the direction
700 indicated by @a clockwise.
701 */
702 wxImage Rotate90(bool clockwise = true) const;
703
704 /**
705 Rotates the hue of each pixel in the image by @e angle, which is a double in
706 the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0
707 corresponds to +360 degrees.
708 */
709 void RotateHue(double angle);
710
711 /**
712 Returns a scaled version of the image.
713
714 This is also useful for scaling bitmaps in general as the only other way
715 to scale bitmaps is to blit a wxMemoryDC into another wxMemoryDC.
716
717 The parameter @a quality determines what method to use for resampling the image.
718 Can be one of the following:
719 - wxIMAGE_QUALITY_NORMAL: Uses the normal default scaling method of pixel
720 replication
721 - wxIMAGE_QUALITY_HIGH: Uses bicubic and box averaging resampling methods
722 for upsampling and downsampling respectively
723
724 It should be noted that although using @c wxIMAGE_QUALITY_HIGH produces much nicer
725 looking results it is a slower method. Downsampling will use the box averaging
726 method which seems to operate very fast. If you are upsampling larger images using
727 this method you will most likely notice that it is a bit slower and in extreme
728 cases it will be quite substantially slower as the bicubic algorithm has to process a
729 lot of data.
730
731 It should also be noted that the high quality scaling may not work as expected
732 when using a single mask colour for transparency, as the scaling will blur the
733 image and will therefore remove the mask partially. Using the alpha channel
734 will work.
3c4f71cc 735
72a9034b 736 Example:
427c415b 737 @code
72a9034b
FM
738 // get the bitmap from somewhere
739 wxBitmap bmp = ...;
740
741 // rescale it to have size of 32*32
742 if ( bmp.GetWidth() != 32 || bmp.GetHeight() != 32 )
427c415b 743 {
72a9034b
FM
744 wxImage image = bmp.ConvertToImage();
745 bmp = wxBitmap(image.Scale(32, 32));
427c415b 746
72a9034b
FM
747 // another possibility:
748 image.Rescale(32, 32);
749 bmp = image;
750 }
427c415b
FM
751 @endcode
752
72a9034b 753 @see Rescale()
23324ae1 754 */
72a9034b
FM
755 wxImage Scale(int width, int height,
756 int quality = wxIMAGE_QUALITY_NORMAL) const;
757
758 /**
759 Returns a resized version of this image without scaling it by adding either a
760 border with the given colour or cropping as necessary.
761
762 The image is pasted into a new image with the given @a size and background
763 colour at the position @a pos relative to the upper left of the new image.
764
765 If @a red = green = blue = -1 then the areas of the larger image not covered
766 by this image are made transparent by filling them with the image mask colour
767 (which will be allocated automatically if it isn't currently set).
768
769 Otherwise, the areas will be filled with the colour with the specified RGB components.
770
771 @see Resize()
772 */
773 wxImage Size(const wxSize& size, const wxPoint& pos, int red = -1,
774 int green = -1, int blue = -1) const;
775
776 //@}
23324ae1 777
72a9034b
FM
778
779 /**
780 @name Conversion functions
781 */
c1099d92 782 //@{
72a9034b 783
23324ae1 784 /**
427c415b
FM
785 If the image has alpha channel, this method converts it to mask.
786
c1099d92
VZ
787 If the image has an alpha channel, all pixels with alpha value less
788 than @a threshold are replaced with the mask colour and the alpha
789 channel is removed. Otherwise nothing is done.
3c99e2fd 790
c1099d92
VZ
791 The mask colour is chosen automatically using
792 FindFirstUnusedColour() by this function, see the overload below if you
793 this is not appropriate.
3c4f71cc 794
d29a9a8a 795 @return @false if FindFirstUnusedColour returns @false, @true otherwise.
23324ae1 796 */
5267aefd 797 bool ConvertAlphaToMask(unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD);
23324ae1 798
c1099d92
VZ
799 /**
800 If the image has alpha channel, this method converts it to mask using
801 the specified colour as the mask colour.
802
803 If the image has an alpha channel, all pixels with alpha value less
804 than @a threshold are replaced with the mask colour and the alpha
805 channel is removed. Otherwise nothing is done.
806
807 @since 2.9.0
808
809 @param mr
810 The red component of the mask colour.
811 @param mg
812 The green component of the mask colour.
813 @param mb
814 The blue component of the mask colour.
815 @param threshold
816 Pixels with alpha channel values below the given threshold are
817 considered to be transparent, i.e. the corresponding mask pixels
818 are set. Pixels with the alpha values above the threshold are
819 considered to be opaque.
820
821 */
3c99e2fd 822 void ConvertAlphaToMask(unsigned char mr, unsigned char mg, unsigned char mb,
c1099d92 823 unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD);
c1099d92 824
23324ae1 825 /**
427c415b
FM
826 Returns a greyscale version of the image.
827
828 The returned image uses the luminance component of the original to
829 calculate the greyscale. Defaults to using the standard ITU-T BT.601
830 when converting to YUV, where every pixel equals
831 (R * @a lr) + (G * @a lg) + (B * @a lb).
23324ae1 832 */
5267aefd 833 wxImage ConvertToGreyscale(double lr = 0.299, double lg = 0.587, double lb = 1.114) const;
23324ae1
FM
834
835 /**
427c415b
FM
836 Returns monochromatic version of the image.
837
838 The returned image has white colour where the original has @e (r,g,b)
839 colour and black colour everywhere else.
23324ae1 840 */
427c415b 841 wxImage ConvertToMono(unsigned char r, unsigned char g, unsigned char b) const;
72a9034b
FM
842
843 //@}
844
845
23324ae1 846 /**
72a9034b 847 @name Miscellaneous functions
23324ae1 848 */
72a9034b
FM
849 //@{
850
23324ae1 851 /**
72a9034b
FM
852 Computes the histogram of the image. @a histogram is a reference to
853 wxImageHistogram object. wxImageHistogram is a specialization of
854 wxHashMap "template" and is defined as follows:
ff3050e1 855
72a9034b
FM
856 @code
857 class WXDLLEXPORT wxImageHistogramEntry
858 {
859 public:
860 wxImageHistogramEntry() : index(0), value(0) {}
861 unsigned long index;
862 unsigned long value;
863 };
3c4f71cc 864
72a9034b
FM
865 WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry,
866 wxIntegerHash, wxIntegerEqual,
867 wxImageHistogram);
868 @endcode
3c4f71cc 869
72a9034b 870 @return Returns number of colours in the histogram.
23324ae1 871 */
72a9034b
FM
872 unsigned long ComputeHistogram(wxImageHistogram& histogram) const;
873
fc3762b5 874 /**
72a9034b
FM
875 Finds the first colour that is never used in the image.
876 The search begins at given initial colour and continues by increasing
877 R, G and B components (in this order) by 1 until an unused colour is
878 found or the colour space exhausted.
427c415b
FM
879
880 The parameters @a r, @a g, @a b are pointers to variables to save the colour.
881
882 The parameters @a startR, @a startG, @a startB define the initial values
883 of the colour.
884 The returned colour will have RGB values equal to or greater than these.
3c4f71cc 885
d29a9a8a 886 @return Returns @false if there is no unused colour left, @true on success.
427c415b
FM
887
888 @note
889 This method involves computing the histogram, which is a
890 computationally intensive operation.
23324ae1 891 */
4cc4bfaf 892 bool FindFirstUnusedColour(unsigned char* r, unsigned char* g,
adaaa686 893 unsigned char* b, unsigned char startR = 1,
23324ae1 894 unsigned char startG = 0,
adaaa686 895 unsigned char startB = 0) const;
23324ae1 896
23324ae1 897 /**
72a9034b 898 Assignment operator, using @ref overview_refcount "reference counting".
427c415b 899
72a9034b
FM
900 @param image
901 Image to assign.
427c415b 902
72a9034b 903 @return Returns 'this' object.
427c415b 904 */
72a9034b
FM
905 wxImage& operator=(const wxImage& image);
906
907 //@}
908
909
b3623ed5 910 /**
72a9034b 911 @name Getters
b3623ed5 912 */
72a9034b 913 //@{
e98e625c 914
23324ae1 915 /**
427c415b
FM
916 Returns pointer to the array storing the alpha values for this image.
917
918 This pointer is @NULL for the images without the alpha channel. If the image
23324ae1 919 does have it, this pointer may be used to directly manipulate the alpha values
b3623ed5 920 which are stored as the RGB ones.
23324ae1 921 */
0a98423e 922 unsigned char* GetAlpha() const;
23324ae1 923
23324ae1 924 /**
427c415b
FM
925 Returns the image data as an array.
926
927 This is most often used when doing direct image manipulation.
928 The return value points to an array of characters in RGBRGBRGB... format
929 in the top-to-bottom, left-to-right order, that is the first RGB triplet
930 corresponds to the pixel first pixel of the first row, the second one ---
931 to the second pixel of the first row and so on until the end of the first
932 row, with second row following after it and so on.
933
934 You should not delete the returned pointer nor pass it to SetData().
23324ae1 935 */
328f5751 936 unsigned char* GetData() const;
23324ae1
FM
937
938 /**
72a9034b 939 Return alpha value at given pixel location.
23324ae1 940 */
72a9034b 941 unsigned char GetAlpha(int x, int y) const;
23324ae1
FM
942
943 /**
72a9034b 944 Returns the red intensity at the given coordinate.
23324ae1 945 */
72a9034b 946 unsigned char GetRed(int x, int y) const;
23324ae1
FM
947
948 /**
72a9034b 949 Returns the green intensity at the given coordinate.
23324ae1 950 */
72a9034b 951 unsigned char GetGreen(int x, int y) const;
23324ae1 952
23324ae1 953 /**
72a9034b 954 Returns the blue intensity at the given coordinate.
23324ae1 955 */
72a9034b 956 unsigned char GetBlue(int x, int y) const;
23324ae1
FM
957
958 /**
72a9034b
FM
959 Gets the red value of the mask colour.
960 */
961 unsigned char GetMaskRed() const;
3c4f71cc 962
72a9034b
FM
963 /**
964 Gets the green value of the mask colour.
23324ae1 965 */
72a9034b 966 unsigned char GetMaskGreen() const;
23324ae1
FM
967
968 /**
969 Gets the blue value of the mask colour.
970 */
328f5751 971 unsigned char GetMaskBlue() const;
23324ae1
FM
972
973 /**
72a9034b
FM
974 Gets the width of the image in pixels.
975
976 @see GetHeight(), GetSize()
23324ae1 977 */
72a9034b 978 int GetWidth() const;
23324ae1
FM
979
980 /**
72a9034b
FM
981 Gets the height of the image in pixels.
982
983 @see GetWidth(), GetSize()
23324ae1 984 */
72a9034b
FM
985 int GetHeight() const;
986
987 /**
988 Returns the size of the image in pixels.
989
990 @since 2.9.0
23324ae1 991
72a9034b
FM
992 @see GetHeight(), GetWidth()
993 */
994 wxSize GetSize() const;
995
23324ae1 996 /**
09b898e0 997 Gets a user-defined string-valued option.
427c415b 998
09b898e0 999 Currently the only defined string option is
d19ce8c4 1000 @li @c wxIMAGE_OPTION_FILENAME: The name of the file from which the image
09b898e0 1001 was loaded.
3c4f71cc 1002
09b898e0
VZ
1003 @param name
1004 The name of the option, case-insensitive.
1005 @return
1006 The value of the option or an empty string if not found. Use
1007 HasOption() if an empty string can be a valid option value.
d19ce8c4
FM
1008
1009 @see SetOption(), GetOptionInt(), HasOption()
23324ae1 1010 */
328f5751 1011 wxString GetOption(const wxString& name) const;
23324ae1
FM
1012
1013 /**
09b898e0
VZ
1014 Gets a user-defined integer-valued option.
1015
427c415b
FM
1016 The function is case-insensitive to @a name.
1017 If the given option is not present, the function returns 0.
4e2cddc4 1018 Use HasOption() is 0 is a possibly valid value for the option.
427c415b 1019
09b898e0 1020 Generic options:
d19ce8c4 1021 @li @c wxIMAGE_OPTION_MAX_WIDTH and @c wxIMAGE_OPTION_MAX_HEIGHT: If either
36abe9d4
VZ
1022 of these options is specified, the loaded image will be scaled down
1023 (preserving its aspect ratio) so that its width is less than the
1024 max width given if it is not 0 @em and its height is less than the
1025 max height given if it is not 0. This is typically used for loading
1026 thumbnails and the advantage of using these options compared to
1027 calling Rescale() after loading is that some handlers (only JPEG
1028 one right now) support rescaling the image during loading which is
1029 vastly more efficient than loading the entire huge image and
1030 rescaling it later (if these options are not supported by the
1031 handler, this is still what happens however). These options must be
1032 set before calling LoadFile() to have any effect.
1033
d19ce8c4 1034 @li @c wxIMAGE_OPTION_QUALITY: JPEG quality used when saving. This is an
09b898e0
VZ
1035 integer in 0..100 range with 0 meaning very poor and 100 excellent
1036 (but very badly compressed). This option is currently ignored for
1037 the other formats.
1038
d19ce8c4 1039 @li @c wxIMAGE_OPTION_RESOLUTIONUNIT: The value of this option determines
09b898e0
VZ
1040 whether the resolution of the image is specified in centimetres or
1041 inches, see wxImageResolution enum elements.
1042
d19ce8c4
FM
1043 @li @c wxIMAGE_OPTION_RESOLUTION, @c wxIMAGE_OPTION_RESOLUTIONX and
1044 @c wxIMAGE_OPTION_RESOLUTIONY: These options define the resolution of
1045 the image in the units corresponding to @c wxIMAGE_OPTION_RESOLUTIONUNIT
09b898e0
VZ
1046 options value. The first option can be set before saving the image
1047 to set both horizontal and vertical resolution to the same value.
1048 The X and Y options are set by the image handlers if they support
1049 the image resolution (currently BMP, JPEG and TIFF handlers do) and
1050 the image provides the resolution information and can be queried
1051 after loading the image.
1052
1053 Options specific to wxPNGHandler:
d19ce8c4 1054 @li @c wxIMAGE_OPTION_PNG_FORMAT: Format for saving a PNG file, see
09b898e0 1055 wxImagePNGType for the supported values.
d19ce8c4
FM
1056 @li @c wxIMAGE_OPTION_PNG_BITDEPTH: Bit depth for every channel (R/G/B/A).
1057 @li @c wxIMAGE_OPTION_PNG_FILTER: Filter for saving a PNG file, see libpng
1058 (http://www.libpng.org/pub/png/libpng-1.2.5-manual.html) for possible values
1059 (e.g. PNG_FILTER_NONE, PNG_FILTER_SUB, PNG_FILTER_UP, etc).
1060 @li @c wxIMAGE_OPTION_PNG_COMPRESSION_LEVEL: Compression level (0..9) for
1061 saving a PNG file. An high value creates smaller-but-slower PNG file.
1062 Note that unlike other formats (e.g. JPEG) the PNG format is always
1063 lossless and thus this compression level doesn't tradeoff the image
1064 quality.
1065 @li @c wxIMAGE_OPTION_PNG_COMPRESSION_MEM_LEVEL: Compression memory usage
1066 level (1..9) for saving a PNG file. An high value means the saving
1067 process consumes more memory, but may create smaller PNG file.
1068 @li @c wxIMAGE_OPTION_PNG_COMPRESSION_STRATEGY: Possible values are 0 for
1069 default strategy, 1 for filter, and 2 for Huffman-only.
1070 You can use OptiPNG (http://optipng.sourceforge.net/) to get a suitable
1071 value for your application.
1072 @li @c wxIMAGE_OPTION_PNG_COMPRESSION_BUFFER_SIZE: Internal buffer size
1073 (in bytes) for saving a PNG file. Ideally this should be as big as
1074 the resulting PNG file. Use this option if your application produces
1075 images with small size variation.
09b898e0
VZ
1076
1077 @param name
1078 The name of the option, case-insensitive.
1079 @return
d19ce8c4
FM
1080 The value of the option or 0 if not found.
1081 Use HasOption() if 0 can be a valid option value.
1082
1083 @see SetOption(), GetOption()
23324ae1 1084 */
328f5751 1085 int GetOptionInt(const wxString& name) const;
23324ae1
FM
1086
1087 /**
1088 Get the current mask colour or find a suitable unused colour that could be
1089 used as a mask colour. Returns @true if the image currently has a mask.
1090 */
5267aefd
FM
1091 bool GetOrFindMaskColour(unsigned char* r, unsigned char* g,
1092 unsigned char* b) const;
23324ae1
FM
1093
1094 /**
427c415b
FM
1095 Returns the palette associated with the image.
1096 Currently the palette is only used when converting to wxBitmap under Windows.
1097
1098 Some of the wxImage handlers have been modified to set the palette if
1099 one exists in the image file (usually 256 or less colour images in
1100 GIF or PNG format).
23324ae1 1101 */
427c415b 1102 const wxPalette& GetPalette() const;
23324ae1 1103
23324ae1 1104 /**
427c415b
FM
1105 Returns a sub image of the current one as long as the rect belongs entirely
1106 to the image.
23324ae1 1107 */
328f5751 1108 wxImage GetSubImage(const wxRect& rect) const;
23324ae1 1109
591d3fa2 1110 /**
427c415b
FM
1111 Gets the type of image found by LoadFile() or specified with SaveFile().
1112
591d3fa2
VZ
1113 @since 2.9.0
1114 */
1115 wxBitmapType GetType() const;
1116
23324ae1
FM
1117 /**
1118 Returns @true if this image has alpha channel, @false otherwise.
3c4f71cc 1119
4cc4bfaf 1120 @see GetAlpha(), SetAlpha()
23324ae1 1121 */
328f5751 1122 bool HasAlpha() const;
23324ae1
FM
1123
1124 /**
1125 Returns @true if there is a mask active, @false otherwise.
1126 */
328f5751 1127 bool HasMask() const;
23324ae1
FM
1128
1129 /**
427c415b
FM
1130 Returns @true if the given option is present.
1131 The function is case-insensitive to @a name.
3c4f71cc 1132
d19ce8c4
FM
1133 The lists of the currently supported options are in GetOption() and
1134 GetOptionInt() function docs.
1135
4cc4bfaf 1136 @see SetOption(), GetOption(), GetOptionInt()
23324ae1 1137 */
328f5751 1138 bool HasOption(const wxString& name) const;
23324ae1 1139
23324ae1
FM
1140 /**
1141 Returns @true if image data is present.
1142 */
328f5751 1143 bool IsOk() const;
23324ae1
FM
1144
1145 /**
1146 Returns @true if the given pixel is transparent, i.e. either has the mask
1147 colour if this image has a mask or if this image has alpha channel and alpha
427c415b 1148 value of this pixel is strictly less than @a threshold.
23324ae1 1149 */
5267aefd
FM
1150 bool IsTransparent(int x, int y,
1151 unsigned char threshold = wxIMAGE_ALPHA_THRESHOLD) const;
23324ae1 1152
72a9034b
FM
1153 //@}
1154
1155
1156 /**
1157 @name Loading and saving functions
1158 */
1159 //@{
1160
23324ae1
FM
1161 /**
1162 Loads an image from an input stream.
3c4f71cc 1163
7c913512 1164 @param stream
427c415b
FM
1165 Opened input stream from which to load the image.
1166 Currently, the stream must support seeking.
7c913512 1167 @param type
dd067e96 1168 May be one of the following:
4e2cddc4
RR
1169 @li wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
1170 @li wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
1171 @li wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
1172 @li wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
1173 @li wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
1174 @li wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
1175 @li wxBITMAP_TYPE_TIF: Load a TIFF bitmap file.
1176 @li wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
1177 @li wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
1178 @li wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
1179 @li wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
1180 @li wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
1181 @li wxBITMAP_TYPE_ANY: Will try to autodetect the format.
7c913512 1182 @param index
4cc4bfaf 1183 Index of the image to load in the case that the image file contains
dd067e96
RR
1184 multiple images. This is only used by GIF, ICO and TIFF handlers.
1185 The default value (-1) means "choose the default image" and is
1186 interpreted as the first image (index=0) by the GIF and TIFF handler
1187 and as the largest and most colourful one by the ICO handler.
3c4f71cc 1188
427c415b
FM
1189 @return @true if the operation succeeded, @false otherwise.
1190 If the optional index parameter is out of range, @false is
1191 returned and a call to wxLogError() takes place.
3c4f71cc 1192
23324ae1 1193 @remarks Depending on how wxWidgets has been configured, not all formats
4cc4bfaf 1194 may be available.
3c4f71cc 1195
427c415b
FM
1196 @note
1197 You can use GetOptionInt() to get the hotspot when loading cursor files:
1198 @code
1199 int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X);
1200 int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y);
1201 @endcode
1202
4cc4bfaf 1203 @see SaveFile()
23324ae1 1204 */
0a98423e
FM
1205 virtual bool LoadFile(wxInputStream& stream,
1206 wxBitmapType type = wxBITMAP_TYPE_ANY,
1207 int index = -1);
427c415b
FM
1208
1209 /**
1210 Loads an image from a file.
1211 If no handler type is provided, the library will try to autodetect the format.
1212
1213 @param name
1214 Name of the file from which to load the image.
1215 @param type
1216 See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.
1217 @param index
1218 See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.
1219 */
7323ff1a
FM
1220 virtual bool LoadFile(const wxString& name,
1221 wxBitmapType type = wxBITMAP_TYPE_ANY,
1222 int index = -1);
427c415b
FM
1223
1224 /**
1225 Loads an image from a file.
1226 If no handler type is provided, the library will try to autodetect the format.
1227
1228 @param name
1229 Name of the file from which to load the image.
1230 @param mimetype
1231 MIME type string (for example 'image/jpeg')
1232 @param index
1233 See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.
1234 */
fadc2df6
FM
1235 virtual bool LoadFile(const wxString& name, const wxString& mimetype,
1236 int index = -1);
427c415b 1237
427c415b
FM
1238 /**
1239 Loads an image from an input stream.
1240
1241 @param stream
1242 Opened input stream from which to load the image.
1243 Currently, the stream must support seeking.
1244 @param mimetype
1245 MIME type string (for example 'image/jpeg')
1246 @param index
1247 See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload.
1248 */
7323ff1a
FM
1249 virtual bool LoadFile(wxInputStream& stream, const wxString& mimetype,
1250 int index = -1);
23324ae1
FM
1251
1252 /**
72a9034b 1253 Saves an image in the given stream.
23324ae1 1254
72a9034b
FM
1255 @param stream
1256 Opened output stream to save the image to.
1257 @param mimetype
1258 MIME type.
23324ae1 1259
72a9034b 1260 @return @true if the operation succeeded, @false otherwise.
23324ae1 1261
72a9034b
FM
1262 @remarks Depending on how wxWidgets has been configured, not all formats
1263 may be available.
427c415b
FM
1264
1265 @note
1266 You can use SetOption() to set the hotspot when saving an image
1267 into a cursor file (default hotspot is in the centre of the image):
1268 @code
1269 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotspotX);
1270 image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotspotY);
1271 @endcode
1272
1273 @see LoadFile()
1274 */
fadc2df6
FM
1275 virtual bool SaveFile(wxOutputStream& stream,
1276 const wxString& mimetype) const;
427c415b
FM
1277
1278 /**
1279 Saves an image in the named file.
1280
1281 @param name
1282 Name of the file to save the image to.
7c913512 1283 @param type
4cc4bfaf 1284 Currently these types can be used:
4e2cddc4
RR
1285 @li wxBITMAP_TYPE_BMP: Save a BMP image file.
1286 @li wxBITMAP_TYPE_JPEG: Save a JPEG image file.
1287 @li wxBITMAP_TYPE_PNG: Save a PNG image file.
427c415b
FM
1288 @li wxBITMAP_TYPE_PCX: Save a PCX image file
1289 (tries to save as 8-bit if possible, falls back to 24-bit otherwise).
4e2cddc4
RR
1290 @li wxBITMAP_TYPE_PNM: Save a PNM image file (as raw RGB always).
1291 @li wxBITMAP_TYPE_TIFF: Save a TIFF image file.
1292 @li wxBITMAP_TYPE_XPM: Save a XPM image file.
427c415b
FM
1293 @li wxBITMAP_TYPE_ICO: Save a Windows icon file (ICO).
1294 The size may be up to 255 wide by 127 high. A single image is saved
1295 in 8 colors at the size supplied.
4e2cddc4 1296 @li wxBITMAP_TYPE_CUR: Save a Windows cursor file (CUR).
427c415b 1297 */
7323ff1a 1298 virtual bool SaveFile(const wxString& name, wxBitmapType type) const;
427c415b
FM
1299
1300 /**
1301 Saves an image in the named file.
1302
1303 @param name
1304 Name of the file to save the image to.
7c913512 1305 @param mimetype
4cc4bfaf 1306 MIME type.
427c415b 1307 */
fadc2df6 1308 virtual bool SaveFile(const wxString& name, const wxString& mimetype) const;
3c4f71cc 1309
427c415b
FM
1310 /**
1311 Saves an image in the named file.
3c4f71cc 1312
427c415b
FM
1313 File type is determined from the extension of the file name.
1314 Note that this function may fail if the extension is not recognized!
1315 You can use one of the forms above to save images to files with
1316 non-standard extensions.
3c4f71cc 1317
427c415b
FM
1318 @param name
1319 Name of the file to save the image to.
23324ae1 1320 */
7323ff1a 1321 virtual bool SaveFile(const wxString& name) const;
427c415b
FM
1322
1323 /**
1324 Saves an image in the given stream.
1325
1326 @param stream
1327 Opened output stream to save the image to.
1328 @param type
1329 MIME type.
1330 */
7323ff1a 1331 virtual bool SaveFile(wxOutputStream& stream, wxBitmapType type) const;
23324ae1 1332
72a9034b 1333 //@}
e98e625c 1334
427c415b 1335
427c415b 1336
72a9034b
FM
1337 /**
1338 @name Setters
23324ae1 1339 */
72a9034b 1340 //@{
23324ae1 1341
e98e625c 1342 /**
427c415b
FM
1343 This function is similar to SetData() and has similar restrictions.
1344
1345 The pointer passed to it may however be @NULL in which case the function
1346 will allocate the alpha array internally -- this is useful to add alpha
1347 channel data to an image which doesn't have any.
1348
1349 If the pointer is not @NULL, it must have one byte for each image pixel
1350 and be allocated with malloc().
1351 wxImage takes ownership of the pointer and will free it unless @a static_data
1352 parameter is set to @true -- in this case the caller should do it.
23324ae1 1353 */
4cc4bfaf
FM
1354 void SetAlpha(unsigned char* alpha = NULL,
1355 bool static_data = false);
e98e625c 1356
b3623ed5 1357 /**
427c415b
FM
1358 Sets the alpha value for the given pixel.
1359 This function should only be called if the image has alpha channel data,
1360 use HasAlpha() to check for this.
b3623ed5 1361 */
7c913512 1362 void SetAlpha(int x, int y, unsigned char alpha);
23324ae1
FM
1363
1364 /**
427c415b
FM
1365 Sets the image data without performing checks.
1366
1367 The data given must have the size (width*height*3) or results will be
1368 unexpected. Don't use this method if you aren't sure you know what you
1369 are doing.
1370
23324ae1
FM
1371 The data must have been allocated with @c malloc(), @b NOT with
1372 @c operator new.
427c415b 1373
72a9034b
FM
1374 If @a static_data is @false, after this call the pointer to the data is
1375 owned by the wxImage object, that will be responsible for deleting it.
427c415b 1376 Do not pass to this function a pointer obtained through GetData().
23324ae1 1377 */
0a98423e 1378 void SetData(unsigned char* data, bool static_data = false);
72a9034b
FM
1379
1380 /**
1381 @overload
1382 */
0a98423e
FM
1383 void SetData(unsigned char* data, int new_width, int new_height,
1384 bool static_data = false);
23324ae1
FM
1385
1386 /**
427c415b
FM
1387 Specifies whether there is a mask or not.
1388
1389 The area of the mask is determined by the current mask colour.
23324ae1 1390 */
4cc4bfaf 1391 void SetMask(bool hasMask = true);
23324ae1
FM
1392
1393 /**
1394 Sets the mask colour for this image (and tells the image to use the mask).
1395 */
1396 void SetMaskColour(unsigned char red, unsigned char green,
1397 unsigned char blue);
1398
1399 /**
427c415b
FM
1400 Sets image's mask so that the pixels that have RGB value of mr,mg,mb in
1401 mask will be masked in the image.
1402
1403 This is done by first finding an unused colour in the image, setting
1404 this colour as the mask colour and then using this colour to draw all
1405 pixels in the image who corresponding pixel in mask has given RGB value.
1406
1407 The parameter @a mask is the mask image to extract mask shape from.
1408 It must have the same dimensions as the image.
1409
1410 The parameters @a mr, @a mg, @a mb are the RGB values of the pixels in
1411 mask that will be used to create the mask.
3c4f71cc 1412
d29a9a8a 1413 @return Returns @false if mask does not have same dimensions as the image
427c415b
FM
1414 or if there is no unused colour left. Returns @true if the mask
1415 was successfully applied.
1416
1417 @note
1418 Note that this method involves computing the histogram, which is a
1419 computationally intensive operation.
23324ae1
FM
1420 */
1421 bool SetMaskFromImage(const wxImage& mask, unsigned char mr,
1422 unsigned char mg,
1423 unsigned char mb);
1424
23324ae1 1425 /**
427c415b
FM
1426 Sets a user-defined option. The function is case-insensitive to @a name.
1427
23324ae1
FM
1428 For example, when saving as a JPEG file, the option @b quality is
1429 used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
3c4f71cc 1430
d19ce8c4
FM
1431 The lists of the currently supported options are in GetOption() and
1432 GetOptionInt() function docs.
1433
4cc4bfaf 1434 @see GetOption(), GetOptionInt(), HasOption()
23324ae1
FM
1435 */
1436 void SetOption(const wxString& name, const wxString& value);
72a9034b
FM
1437
1438 /**
1439 @overload
1440 */
7c913512 1441 void SetOption(const wxString& name, int value);
23324ae1
FM
1442
1443 /**
427c415b
FM
1444 Associates a palette with the image.
1445
1446 The palette may be used when converting wxImage to wxBitmap (MSW only at present)
1447 or in file save operations (none as yet).
23324ae1
FM
1448 */
1449 void SetPalette(const wxPalette& palette);
1450
1451 /**
427c415b
FM
1452 Sets the colour of the pixels within the given rectangle.
1453
1454 This routine performs bounds-checks for the coordinate so it can be considered
1455 a safe way to manipulate the data.
23324ae1 1456 */
0a98423e
FM
1457 void SetRGB(const wxRect& rect,
1458 unsigned char red,
4cc4bfaf
FM
1459 unsigned char green,
1460 unsigned char blue);
23324ae1 1461
9d1c7e84
VZ
1462 /**
1463 Set the type of image returned by GetType().
1464
1465 This method is mostly used internally by the library but can also be
1466 called from the user code if the image was created from data in the
1467 given bitmap format without using LoadFile() (which would set the type
1468 correctly automatically).
1469
1470 Notice that the image must be created before this function is called.
1471
1472 @since 2.9.0
1473
1474 @param type
1475 One of bitmap type constants, @c wxBITMAP_TYPE_INVALID is a valid
1476 value for it and can be used to reset the bitmap type to default
1477 but @c wxBITMAP_TYPE_MAX is not allowed here.
1478 */
1479 void SetType(wxBitmapType type);
1480
72a9034b
FM
1481 //@}
1482
1483
1484
23324ae1 1485 /**
72a9034b
FM
1486 @name Handler management functions
1487 */
1488 //@{
1489
1490 /**
1491 Register an image handler.
1492 See @ref image_handlers for a list of the available handlers.
1493 */
1494 static void AddHandler(wxImageHandler* handler);
427c415b 1495
72a9034b
FM
1496 /**
1497 Deletes all image handlers.
1498 This function is called by wxWidgets on exit.
1499 */
1500 static void CleanUpHandlers();
1501
1502 /**
1503 Finds the handler with the given name.
427c415b 1504
72a9034b
FM
1505 @param name
1506 The handler name.
427c415b 1507
72a9034b 1508 @return A pointer to the handler if found, @NULL otherwise.
3c4f71cc 1509
72a9034b 1510 @see wxImageHandler
23324ae1 1511 */
72a9034b 1512 static wxImageHandler* FindHandler(const wxString& name);
23324ae1
FM
1513
1514 /**
72a9034b 1515 Finds the handler associated with the given extension and type.
3c4f71cc 1516
72a9034b
FM
1517 @param extension
1518 The file extension, such as "bmp".
1519 @param imageType
1520 The image type; one of the ::wxBitmapType values.
3c4f71cc 1521
72a9034b
FM
1522 @return A pointer to the handler if found, @NULL otherwise.
1523
1524 @see wxImageHandler
23324ae1 1525 */
72a9034b
FM
1526 static wxImageHandler* FindHandler(const wxString& extension,
1527 wxBitmapType imageType);
1528
1529 /**
1530 Finds the handler associated with the given image type.
1531
1532 @param imageType
1533 The image type; one of the ::wxBitmapType values.
1534
1535 @return A pointer to the handler if found, @NULL otherwise.
1536
1537 @see wxImageHandler
1538 */
1539 static wxImageHandler* FindHandler(wxBitmapType imageType);
1540
1541 /**
1542 Finds the handler associated with the given MIME type.
1543
1544 @param mimetype
1545 MIME type.
1546
1547 @return A pointer to the handler if found, @NULL otherwise.
1548
1549 @see wxImageHandler
1550 */
1551 static wxImageHandler* FindHandlerMime(const wxString& mimetype);
1552
1553 /**
1554 Returns the static list of image format handlers.
1555
1556 @see wxImageHandler
1557 */
1558 static wxList& GetHandlers();
1559
1560 /**
1561 Internal use only. Adds standard image format handlers.
1562 It only install wxBMPHandler for the time being, which is used by wxBitmap.
1563
1564 This function is called by wxWidgets on startup, and shouldn't be called by
1565 the user.
1566
1567 @see wxImageHandler, wxInitAllImageHandlers(), wxQuantize
1568 */
1569 static void InitStandardHandlers();
1570
1571 /**
1572 Adds a handler at the start of the static list of format handlers.
1573
1574 @param handler
1575 A new image format handler object. There is usually only one instance
1576 of a given handler class in an application session.
1577
1578 @see wxImageHandler
1579 */
1580 static void InsertHandler(wxImageHandler* handler);
1581
1582 /**
1583 Finds the handler with the given name, and removes it.
1584 The handler is not deleted.
1585
1586 @param name
1587 The handler name.
1588
1589 @return @true if the handler was found and removed, @false otherwise.
1590
1591 @see wxImageHandler
1592 */
1593 static bool RemoveHandler(const wxString& name);
1594
1595 //@}
1596
1597
1598 /**
8faef7cc
FM
1599 Returns @true if at least one of the available image handlers can read
1600 the file with the given name.
1601
1602 See wxImageHandler::CanRead for more info.
72a9034b
FM
1603 */
1604 static bool CanRead(const wxString& filename);
8faef7cc
FM
1605
1606 /**
1607 Returns @true if at least one of the available image handlers can read
1608 the data in the given stream.
1609
1610 See wxImageHandler::CanRead for more info.
1611 */
1612 static bool CanRead(wxInputStream& stream);
72a9034b
FM
1613
1614 //@{
1615 /**
1616 If the image file contains more than one image and the image handler is
1617 capable of retrieving these individually, this function will return the
1618 number of available images.
1619
1620 For the overload taking the parameter @a filename, that's the name
1621 of the file to query.
8faef7cc
FM
1622 For the overload taking the parameter @a stream, that's the opened input
1623 stream with image data.
1624
1625 See wxImageHandler::GetImageCount() for more info.
72a9034b
FM
1626
1627 The parameter @a type may be one of the following values:
1628 @li wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
1629 @li wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
1630 @li wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
1631 @li wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
1632 @li wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
1633 @li wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
1634 @li wxBITMAP_TYPE_TIF: Load a TIFF bitmap file.
1635 @li wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
1636 @li wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
1637 @li wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
1638 @li wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
1639 @li wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
1640 @li wxBITMAP_TYPE_ANY: Will try to autodetect the format.
1641
1642 @return Number of available images. For most image handlers, this is 1
85fcb94f
VZ
1643 (exceptions are TIFF and ICO formats as well as animated GIFs
1644 for which this function returns the number of frames in the
1645 animation).
72a9034b
FM
1646 */
1647 static int GetImageCount(const wxString& filename,
1648 wxBitmapType type = wxBITMAP_TYPE_ANY);
1649 static int GetImageCount(wxInputStream& stream,
1650 wxBitmapType type = wxBITMAP_TYPE_ANY);
1651 //@}
1652
1653 /**
1654 Iterates all registered wxImageHandler objects, and returns a string containing
1655 file extension masks suitable for passing to file open/save dialog boxes.
1656
1657 @return The format of the returned string is @c "(*.ext1;*.ext2)|*.ext1;*.ext2".
1658 It is usually a good idea to prepend a description before passing
1659 the result to the dialog.
1660 Example:
1661 @code
1662 wxFileDialog FileDlg( this, "Choose Image", ::wxGetCwd(), "",
1663 _("Image Files ") + wxImage::GetImageExtWildcard(),
1664 wxFD_OPEN );
1665 @endcode
1666
1667 @see wxImageHandler
1668 */
1669 static wxString GetImageExtWildcard();
1670
1671 /**
1672 Converts a color in RGB color space to HSV color space.
1673 */
1674 static wxImage::HSVValue RGBtoHSV(const wxImage::RGBValue& rgb);
1675
1676 /**
1677 Converts a color in HSV color space to RGB color space.
1678 */
1679 static wxImage::RGBValue HSVtoRGB(const wxImage::HSVValue& hsv);
23324ae1
FM
1680};
1681
336aecf1
FM
1682/**
1683 An instance of an empty image without an alpha channel.
1684*/
1685wxImage wxNullImage;
1686
1687
23324ae1
FM
1688// ============================================================================
1689// Global functions/macros
1690// ============================================================================
1691
b21126db 1692/** @addtogroup group_funcmacro_appinitterm */
8cd06fb5
BP
1693//@{
1694
23324ae1
FM
1695/**
1696 Initializes all available image handlers. For a list of available handlers,
1697 see wxImage.
c83d207b 1698 If you don't need/want all image handlers loaded
7c913512 1699
4cc4bfaf 1700 @see wxImage, wxImageHandler
027c1c27
BP
1701
1702 @header{wx/image.h}
23324ae1
FM
1703*/
1704void wxInitAllImageHandlers();
1705
8cd06fb5
BP
1706//@}
1707