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