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