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