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