]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/image.h
use CLSCTX_ALL instead of CLSCTX_LOCAL_SERVER in CreateInstance() (#9868)
[wxWidgets.git] / interface / wx / image.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: image.h
e54c96f1 3// Purpose: interface of wxImageHandler
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxImageHandler
7c913512 11
b3623ed5
RR
12 This is the base class for implementing image file loading/saving, and
13 image creation from data.
23324ae1 14 It is used within wxImage and is not normally seen by the application.
7c913512 15
23324ae1 16 If you wish to extend the capabilities of wxImage, derive a class from
b3623ed5 17 wxImageHandler and add the handler using wxImage::AddHandler in your
23324ae1 18 application initialisation.
7c913512 19
b3623ed5
RR
20 @stdobjects
21 ::wxNullImage
22
23324ae1
FM
23 @library{wxcore}
24 @category{FIXME}
7c913512 25
e54c96f1 26 @see wxImage, wxInitAllImageHandlers()
d29a9a8a
BP
27
28 @todo Document all image handler types, indicating their library.
23324ae1
FM
29*/
30class wxImageHandler : public wxObject
31{
32public:
33 /**
34 Default constructor. In your own default constructor, initialise the members
35 m_name, m_extension and m_type.
36 */
37 wxImageHandler();
38
39 /**
40 Destroys the wxImageHandler object.
41 */
42 ~wxImageHandler();
43
44 /**
45 Gets the file extension associated with this handler.
46 */
328f5751 47 const wxString GetExtension() const;
23324ae1
FM
48
49 /**
50 If the image file contains more than one image and the image handler is capable
51 of retrieving these individually, this function will return the number of
52 available images.
3c4f71cc 53
7c913512 54 @param stream
4cc4bfaf
FM
55 Opened input stream for reading image data. Currently, the stream must
56 support seeking.
3c4f71cc 57
d29a9a8a 58 @return Number of available images. For most image handlers, this is 1
4cc4bfaf 59 (exceptions are TIFF and ICO formats).
23324ae1
FM
60 */
61 int GetImageCount(wxInputStream& stream);
62
63 /**
64 Gets the MIME type associated with this handler.
65 */
328f5751 66 const wxString GetMimeType() const;
23324ae1
FM
67
68 /**
69 Gets the name of this handler.
70 */
328f5751 71 const wxString GetName() const;
23324ae1
FM
72
73 /**
74 Gets the image type associated with this handler.
75 */
e98e625c 76 wxBitmapType GetType() const;
23324ae1
FM
77
78 /**
79 Loads a image from a stream, putting the resulting data into @e image. If the
80 image file contains
81 more than one image and the image handler is capable of retrieving these
82 individually, @e index
83 indicates which image to read from the stream.
3c4f71cc 84
7c913512 85 @param image
4cc4bfaf 86 The image object which is to be affected by this operation.
7c913512 87 @param stream
4cc4bfaf 88 Opened input stream for reading image data.
7c913512 89 @param verbose
4cc4bfaf
FM
90 If set to @true, errors reported by the image handler will produce
91 wxLogMessages.
7c913512 92 @param index
4cc4bfaf 93 The index of the image in the file (starting from zero).
3c4f71cc 94
d29a9a8a 95 @return @true if the operation succeeded, @false otherwise.
3c4f71cc 96
4cc4bfaf 97 @see wxImage::LoadFile, wxImage::SaveFile, SaveFile()
23324ae1
FM
98 */
99 bool LoadFile(wxImage* image, wxInputStream& stream,
4cc4bfaf 100 bool verbose = true, int index = 0);
23324ae1
FM
101
102 /**
103 Saves a image in the output stream.
3c4f71cc 104
7c913512 105 @param image
4cc4bfaf 106 The image object which is to be affected by this operation.
7c913512 107 @param stream
4cc4bfaf 108 Opened output stream for writing the data.
3c4f71cc 109
d29a9a8a 110 @return @true if the operation succeeded, @false otherwise.
3c4f71cc 111
4cc4bfaf 112 @see wxImage::LoadFile, wxImage::SaveFile, LoadFile()
23324ae1
FM
113 */
114 bool SaveFile(wxImage* image, wxOutputStream& stream);
115
116 /**
117 Sets the handler extension.
3c4f71cc 118
7c913512 119 @param extension
4cc4bfaf 120 Handler extension.
23324ae1
FM
121 */
122 void SetExtension(const wxString& extension);
123
124 /**
125 Sets the handler MIME type.
3c4f71cc 126
7c913512 127 @param mimename
4cc4bfaf 128 Handler MIME type.
23324ae1
FM
129 */
130 void SetMimeType(const wxString& mimetype);
131
132 /**
133 Sets the handler name.
3c4f71cc 134
7c913512 135 @param name
4cc4bfaf 136 Handler name.
23324ae1
FM
137 */
138 void SetName(const wxString& name);
139};
140
141
e54c96f1 142
23324ae1
FM
143/**
144 @class wxImage
7c913512 145
b3623ed5
RR
146 This class encapsulates a platform-independent image. An image can be
147 created from data, or using wxBitmap::ConvertToImage. An image can be
148 loaded from a file in a variety of formats, and is extensible to new
149 formats via image format handlers. Functions are available to set and
150 get image bits, so it can be used for basic image manipulation.
7c913512 151
23324ae1
FM
152 A wxImage cannot (currently) be drawn directly to a wxDC. Instead,
153 a platform-specific wxBitmap object must be created from it using
154 the wxBitmap::wxBitmap(wxImage,int depth) constructor.
b3623ed5 155 This bitmap can then be drawn in a device context, using wxDC::DrawBitmap.
7c913512 156
23324ae1 157 One colour value of the image may be used as a mask colour which will lead to
65874118 158 the automatic creation of a wxMask object associated to the bitmap object.
7c913512 159
23324ae1
FM
160 @library{wxcore}
161 @category{gdi}
7c913512 162
65874118
FM
163 @stdobjects
164 ::wxNullImage
165
4e2cddc4 166 @see wxBitmap, wxInitAllImageHandlers(), wxPixelData
23324ae1
FM
167*/
168class wxImage : public wxObject
169{
170public:
e98e625c 171
b3623ed5
RR
172 /**
173 Creates an empty wxImage object without an alpha channel.
174 */
175 wxImage();
e98e625c 176
b3623ed5 177 /**
ff3050e1
VZ
178 Creates an image with the given size and clears it if requested.
179
180 Does not create an alpha channel.
e98e625c 181
b3623ed5
RR
182 @param width
183 Specifies the width of the image.
184 @param height
185 Specifies the height of the image.
ff3050e1
VZ
186 @param clear
187 If @true, initialize the image to black.
b3623ed5
RR
188 */
189 wxImage(int width, int height, bool clear = true);
e98e625c 190
23324ae1 191 /**
dd067e96
RR
192 Creates an image from data in memory. If static_data is false
193 then the wxImage will take ownership of the data and free it
194 afterwards. For this, it has to be allocated with @e malloc.
e98e625c 195
7c913512 196 @param width
4cc4bfaf 197 Specifies the width of the image.
7c913512 198 @param height
4cc4bfaf 199 Specifies the height of the image.
dd067e96
RR
200 @param data
201 A pointer to RGB data
4e2cddc4
RR
202 @param static_data
203 Indicates if the data should be free'd after use
e98e625c 204
dd067e96 205 */
dd067e96 206 wxImage(int width, int height, unsigned char* data, bool static_data = false);
e98e625c 207
dd067e96 208 /**
b3623ed5
RR
209 Creates an image from data in memory. If static_data is false
210 then the wxImage will take ownership of the data and free it
211 afterwards. For this, it has to be allocated with @e malloc.
e98e625c 212
dd067e96
RR
213 @param width
214 Specifies the width of the image.
215 @param height
216 Specifies the height of the image.
b3623ed5
RR
217 @param data
218 A pointer to RGB data
219 @param alpha
220 A pointer to alpha-channel data
221 @param static_data
222 Indicates if the data should be free'd after use
e98e625c 223
4e2cddc4 224 */
b3623ed5 225 wxImage(int width, int height, unsigned char* data, unsigned char* alpha, bool static_data = false );
e98e625c 226
dd067e96
RR
227 /**
228 Creates an image from XPM data.
e98e625c 229
dd067e96
RR
230 @param xpmData
231 A pointer to XPM image data.
232 */
233 wxImage(const char* const* xpmData);
e98e625c 234
dd067e96 235 /**
b3623ed5 236 Creates an image from a file.
e98e625c 237
7c913512 238 @param name
4cc4bfaf 239 Name of the file from which to load the image.
7c913512 240 @param type
4cc4bfaf 241 May be one of the following:
4e2cddc4
RR
242 @li wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
243 @li wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
244 @li wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
245 @li wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
246 @li wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
247 @li wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
248 @li wxBITMAP_TYPE_TIF: Load a TIFF bitmap file.
249 @li wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
250 @li wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
251 @li wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
252 @li wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
253 @li wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
254 @li wxBITMAP_TYPE_ANY: Will try to autodetect the format.
4cc4bfaf
FM
255 @param index
256 Index of the image to load in the case that the image file contains
dd067e96
RR
257 multiple images. This is only used by GIF, ICO and TIFF handlers.
258 The default value (-1) means "choose the default image" and is
259 interpreted as the first image (index=0) by the GIF and TIFF handler
260 and as the largest and most colourful one by the ICO handler.
3c4f71cc 261
23324ae1 262 @remarks Depending on how wxWidgets has been configured, not all formats
4cc4bfaf 263 may be available.
3c4f71cc 264
4cc4bfaf 265 @see LoadFile()
23324ae1 266 */
e98e625c
VZ
267 wxImage(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1);
268
b3623ed5
RR
269 /**
270 Creates an image from a file using MIME-types to specify the type.
e98e625c 271
b3623ed5
RR
272 @param name
273 Name of the file from which to load the image.
274 @param type
275 See above
276 @param mimetype
277 MIME type string (for example 'image/jpeg')
278 @param index
279 See above
280 */
dd067e96 281 wxImage(const wxString& name, const wxString& mimetype, int index = -1);
e98e625c 282
b3623ed5
RR
283 /**
284 Creates an image from a stream.
e98e625c 285
b3623ed5
RR
286 @param stream
287 Opened input stream from which to load the image. Currently,
288 the stream must support seeking.
289 @param type
290 See above
291 @param index
292 See above.
293 */
e98e625c
VZ
294 wxImage(wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1);
295
b3623ed5
RR
296 /**
297 Creates an image from a stream using MIME-types to specify the type.
e98e625c 298
b3623ed5
RR
299 @param stream
300 Opened input stream from which to load the image. Currently,
301 the stream must support seeking.
302 @param mimetype
303 MIME type string (for example 'image/jpeg')
304 @param index
305 See above.
306 */
dd067e96 307 wxImage(wxInputStream& stream, const wxString& mimetype, int index = -1);
e98e625c 308
23324ae1
FM
309
310 /**
311 Destructor.
312 See @ref overview_refcountdestruct "reference-counted object destruction" for
313 more info.
314 */
315 ~wxImage();
316
23324ae1 317 /**
b3623ed5 318 Register an image handler.
23324ae1
FM
319 */
320 static void AddHandler(wxImageHandler* handler);
23324ae1
FM
321
322 /**
b3623ed5
RR
323 Blurs the image in both horizontal and vertical directions by the
324 specified pixel @e blurRadius. This should not be used when using
325 a single mask colour for transparency.
3c4f71cc 326
b3623ed5 327 @see BlurHorizontal(), BlurVertical()
23324ae1
FM
328 */
329 wxImage Blur(int blurRadius);
330
331 /**
332 Blurs the image in the horizontal direction only. This should not be used
333 when using a single mask colour for transparency.
3c4f71cc 334
b3623ed5 335 @see Blur(), BlurVertical()
23324ae1
FM
336 */
337 wxImage BlurHorizontal(int blurRadius);
338
339 /**
340 Blurs the image in the vertical direction only. This should not be used
341 when using a single mask colour for transparency.
3c4f71cc 342
b3623ed5 343 @see Blur(), BlurHorizontal()
23324ae1
FM
344 */
345 wxImage BlurVertical(int blurRadius);
e98e625c 346
b3623ed5
RR
347 /**
348 Returns @true if the current image handlers can read this file
349 */
350 bool CanRead(const wxString& filename);
23324ae1
FM
351
352 /**
353 Deletes all image handlers.
23324ae1
FM
354 This function is called by wxWidgets on exit.
355 */
356 static void CleanUpHandlers();
357
358 /**
4cc4bfaf 359 Computes the histogram of the image. @a histogram is a reference to
23324ae1
FM
360 wxImageHistogram object. wxImageHistogram is a specialization of
361 wxHashMap "template" and is defined as follows:
3c4f71cc 362
d29a9a8a 363 @return Returns number of colours in the histogram.
23324ae1 364 */
328f5751 365 unsigned long ComputeHistogram(wxImageHistogram& histogram) const;
23324ae1
FM
366
367 /**
368 If the image has alpha channel, this method converts it to mask. All pixels
4cc4bfaf 369 with alpha value less than @a threshold are replaced with mask colour
23324ae1
FM
370 and the alpha channel is removed. Mask colour is chosen automatically using
371 FindFirstUnusedColour().
23324ae1
FM
372 If the image image doesn't have alpha channel,
373 ConvertAlphaToMask does nothing.
3c4f71cc 374
d29a9a8a 375 @return @false if FindFirstUnusedColour returns @false, @true otherwise.
23324ae1
FM
376 */
377 bool ConvertAlphaToMask(unsigned char threshold = 128);
378
379 /**
380 Deprecated, use equivalent @ref wxBitmap::ctor "wxBitmap constructor"
381 (which takes wxImage and depth as its arguments) instead.
382 */
328f5751 383 wxBitmap ConvertToBitmap() const;
23324ae1
FM
384
385 /**
386 Returns a greyscale version of the image. The returned image uses the luminance
387 component of the original to calculate the greyscale. Defaults to using
388 ITU-T BT.601 when converting to YUV, where every pixel equals
389 (R * @e lr) + (G * @e lg) + (B * @e lb).
390 */
391 wxImage ConvertToGreyscale(double lr = 0.299, double lg = 0.587,
328f5751 392 double lb = 0.114) const;
23324ae1
FM
393
394 /**
395 Returns monochromatic version of the image. The returned image has white
396 colour where the original has @e (r,g,b) colour and black colour
397 everywhere else.
398 */
399 wxImage ConvertToMono(unsigned char r, unsigned char g,
328f5751 400 unsigned char b) const;
23324ae1
FM
401
402 /**
403 Returns an identical copy of the image.
404 */
328f5751 405 wxImage Copy() const;
23324ae1
FM
406
407 /**
ff3050e1
VZ
408 Creates a fresh image.
409
410 If @a clear is @true, the new image will be initialized to black.
23324ae1 411 Otherwise, the image data will be uninitialized.
3c4f71cc 412
7c913512 413 @param width
4cc4bfaf 414 The width of the image in pixels.
7c913512 415 @param height
4cc4bfaf 416 The height of the image in pixels.
ff3050e1
VZ
417 @param clear
418 If @true, initialize the image data with zeros.
3c4f71cc 419
d29a9a8a 420 @return @true if the call succeeded, @false otherwise.
23324ae1 421 */
4cc4bfaf 422 bool Create(int width, int height, bool clear = true);
23324ae1
FM
423
424 /**
425 Destroys the image data.
426 */
427 void Destroy();
428
429 /**
7c913512 430 @param r,g,b
4cc4bfaf 431 Pointers to variables to save the colour.
7c913512 432 @param startR,startG,startB
4cc4bfaf
FM
433 Initial values of the colour. Returned colour
434 will have RGB values equal to or greater than these.
3c4f71cc 435
d29a9a8a 436 @return Returns @false if there is no unused colour left, @true on success.
23324ae1 437 */
4cc4bfaf
FM
438 bool FindFirstUnusedColour(unsigned char* r, unsigned char* g,
439 unsigned char* b,
23324ae1
FM
440 unsigned char startR = 1,
441 unsigned char startG = 0,
442 unsigned char startB = 0);
443
444 //@{
445 /**
446 Finds the handler associated with the given MIME type.
3c4f71cc 447
7c913512 448 @param name
4cc4bfaf 449 The handler name.
7c913512 450 @param extension
4cc4bfaf 451 The file extension, such as "bmp".
7c913512 452 @param imageType
4cc4bfaf 453 The image type, such as wxBITMAP_TYPE_BMP.
7c913512 454 @param mimetype
4cc4bfaf 455 MIME type.
3c4f71cc 456
d29a9a8a 457 @return A pointer to the handler if found, @NULL otherwise.
3c4f71cc 458
4cc4bfaf 459 @see wxImageHandler
23324ae1
FM
460 */
461 static wxImageHandler* FindHandler(const wxString& name);
7c913512 462 static wxImageHandler* FindHandler(const wxString& extension,
e98e625c
VZ
463 wxBitmapType imageType);
464 static wxImageHandler* FindHandler(wxBitmapType imageType);
7c913512 465 static wxImageHandler* FindHandlerMime(const wxString& mimetype);
23324ae1
FM
466 //@}
467
b3623ed5
RR
468 /**
469 Return alpha value at given pixel location.
470 */
471 unsigned char GetAlpha(int x, int y) const;
e98e625c 472
23324ae1
FM
473 /**
474 Returns pointer to the array storing the alpha values for this image. This
475 pointer is @NULL for the images without the alpha channel. If the image
476 does have it, this pointer may be used to directly manipulate the alpha values
b3623ed5 477 which are stored as the RGB ones.
23324ae1 478 */
328f5751 479 const unsigned char * GetAlpha() const;
23324ae1
FM
480
481 /**
482 Returns the blue intensity at the given coordinate.
483 */
328f5751 484 unsigned char GetBlue(int x, int y) const;
23324ae1
FM
485
486 /**
487 Returns the image data as an array. This is most often used when doing
488 direct image manipulation. The return value points to an array of
489 characters in RGBRGBRGB... format in the top-to-bottom, left-to-right
490 order, that is the first RGB triplet corresponds to the pixel first pixel of
491 the first row, the second one --- to the second pixel of the first row and so
492 on until the end of the first row, with second row following after it and so
493 on.
23324ae1
FM
494 You should not delete the returned pointer nor pass it to
495 SetData().
496 */
328f5751 497 unsigned char* GetData() const;
23324ae1
FM
498
499 /**
500 Returns the green intensity at the given coordinate.
501 */
328f5751 502 unsigned char GetGreen(int x, int y) const;
23324ae1
FM
503
504 /**
505 Returns the static list of image format handlers.
3c4f71cc 506
4cc4bfaf 507 @see wxImageHandler
23324ae1
FM
508 */
509 static wxList GetHandlers();
510
511 /**
512 Gets the height of the image in pixels.
513 */
328f5751 514 int GetHeight() const;
23324ae1
FM
515
516 //@{
517 /**
518 If the image file contains more than one image and the image handler is capable
519 of retrieving these individually, this function will return the number of
520 available images.
3c4f71cc 521
7c913512 522 @param name
4cc4bfaf 523 Name of the file to query.
7c913512 524 @param stream
dd067e96
RR
525 Opened input stream with image data. Currently, the stream must
526 support seeking.
7c913512 527 @param type
4cc4bfaf 528 May be one of the following:
4e2cddc4
RR
529 @li wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
530 @li wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
531 @li wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
532 @li wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
533 @li wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
534 @li wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
535 @li wxBITMAP_TYPE_TIF: Load a TIFF bitmap file.
536 @li wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
537 @li wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
538 @li wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
539 @li wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
540 @li wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
541 @li wxBITMAP_TYPE_ANY: Will try to autodetect the format.
3c4f71cc 542
d29a9a8a 543 @return Number of available images. For most image handlers, this is 1
4cc4bfaf 544 (exceptions are TIFF and ICO formats).
23324ae1
FM
545 */
546 static int GetImageCount(const wxString& filename,
e98e625c 547 wxBitmapType type = wxBITMAP_TYPE_ANY);
7c913512 548 static int GetImageCount(wxInputStream& stream,
e98e625c 549 wxBitmapType type = wxBITMAP_TYPE_ANY);
23324ae1
FM
550 //@}
551
552 /**
553 Iterates all registered wxImageHandler objects, and returns a string containing
554 file extension masks
555 suitable for passing to file open/save dialog boxes.
3c4f71cc 556
d29a9a8a 557 @return The format of the returned string is
4cc4bfaf 558 "(*.ext1;*.ext2)|*.ext1;*.ext2".
3c4f71cc 559
4cc4bfaf 560 @see wxImageHandler
23324ae1
FM
561 */
562 static wxString GetImageExtWildcard();
563
564 /**
565 Gets the blue value of the mask colour.
566 */
328f5751 567 unsigned char GetMaskBlue() const;
23324ae1
FM
568
569 /**
570 Gets the green value of the mask colour.
571 */
328f5751 572 unsigned char GetMaskGreen() const;
23324ae1
FM
573
574 /**
575 Gets the red value of the mask colour.
576 */
328f5751 577 unsigned char GetMaskRed() const;
23324ae1
FM
578
579 /**
580 Gets a user-defined option. The function is case-insensitive to @e name.
23324ae1
FM
581 For example, when saving as a JPEG file, the option @b quality is
582 used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
3c4f71cc 583
4cc4bfaf 584 @see SetOption(), GetOptionInt(), HasOption()
23324ae1 585 */
328f5751 586 wxString GetOption(const wxString& name) const;
23324ae1
FM
587
588 /**
4e2cddc4 589 Gets a user-defined option as an integer. The function is case-insensitive
e98e625c 590 to @e name. If the given option is not present, the function returns 0.
4e2cddc4 591 Use HasOption() is 0 is a possibly valid value for the option.
23324ae1 592 Options for wxPNGHandler
4e2cddc4
RR
593 @li wxIMAGE_OPTION_PNG_FORMAT: Format for saving a PNG file.
594 @li wxIMAGE_OPTION_PNG_BITDEPTH: Bit depth for every channel (R/G/B/A).
e98e625c 595
23324ae1 596 Supported values for wxIMAGE_OPTION_PNG_FORMAT:
4e2cddc4
RR
597 @li wxPNG_TYPE_COLOUR: Stores RGB image.
598 @li wxPNG_TYPE_GREY: Stores grey image, converts from RGB.
599 @li wxPNG_TYPE_GREY_RED: Stores grey image, uses red value as grey.
3c4f71cc 600
4cc4bfaf 601 @see SetOption(), GetOption()
23324ae1 602 */
328f5751 603 int GetOptionInt(const wxString& name) const;
23324ae1
FM
604
605 /**
606 Get the current mask colour or find a suitable unused colour that could be
607 used as a mask colour. Returns @true if the image currently has a mask.
608 */
609 bool GetOrFindMaskColour(unsigned char r, unsigned char g,
328f5751 610 unsigned char b) const;
23324ae1
FM
611
612 /**
613 Returns the palette associated with the image. Currently the palette is only
614 used when converting to wxBitmap under Windows. Some of the wxImage handlers
615 have been modified to set the palette if one exists in the image file (usually
616 256 or less colour images in GIF or PNG format).
617 */
328f5751 618 const wxPalette GetPalette() const;
23324ae1
FM
619
620 /**
621 Returns the red intensity at the given coordinate.
622 */
328f5751 623 unsigned char GetRed(int x, int y) const;
23324ae1
FM
624
625 /**
626 Returns a sub image of the current one as long as the rect belongs entirely to
627 the image.
628 */
328f5751 629 wxImage GetSubImage(const wxRect& rect) const;
23324ae1 630
591d3fa2
VZ
631 /**
632 Gets the type of image found by LoadFile or specified with SaveFile
633 @since 2.9.0
634 */
635 wxBitmapType GetType() const;
636
23324ae1
FM
637 /**
638 Gets the width of the image in pixels.
3c4f71cc 639
4cc4bfaf 640 @see GetHeight()
23324ae1 641 */
328f5751 642 int GetWidth() const;
23324ae1
FM
643
644 /**
645 Constructor for HSVValue, an object that contains values for hue, saturation
646 and value which
647 represent the value of a color. It is used by HSVtoRGB()
648 and RGBtoHSV(), which
649 converts between HSV color space and RGB color space.
650 */
7c913512 651 HSVValue(double h = 0.0, double s = 0.0, double v = 0.0);
23324ae1
FM
652
653 /**
654 Converts a color in HSV color space to RGB color space.
655 */
4cc4bfaf 656#define wxImage::RGBValue HSVtoRGB(const HSVValue& hsv) /* implementation is private */
23324ae1
FM
657
658 /**
659 Returns @true if this image has alpha channel, @false otherwise.
3c4f71cc 660
4cc4bfaf 661 @see GetAlpha(), SetAlpha()
23324ae1 662 */
328f5751 663 bool HasAlpha() const;
23324ae1
FM
664
665 /**
666 Returns @true if there is a mask active, @false otherwise.
667 */
328f5751 668 bool HasMask() const;
23324ae1
FM
669
670 /**
671 Returns @true if the given option is present. The function is case-insensitive
672 to @e name.
3c4f71cc 673
4cc4bfaf 674 @see SetOption(), GetOption(), GetOptionInt()
23324ae1 675 */
328f5751 676 bool HasOption(const wxString& name) const;
23324ae1
FM
677
678 /**
679 Initializes the image alpha channel data. It is an error to call it
680 if the image already has alpha data. If it doesn't, alpha data will be
681 by default initialized to all pixels being fully opaque. But if the image has a
682 a mask colour, all mask pixels will be completely transparent.
683 */
684 void InitAlpha();
685
686 /**
687 Internal use only. Adds standard image format handlers. It only install BMP
688 for the time being, which is used by wxBitmap.
23324ae1
FM
689 This function is called by wxWidgets on startup, and shouldn't be called by
690 the user.
3c4f71cc 691
e54c96f1 692 @see wxImageHandler, wxInitAllImageHandlers(), wxQuantize
23324ae1
FM
693 */
694 static void InitStandardHandlers();
695
696 /**
697 Adds a handler at the start of the static list of format handlers.
3c4f71cc 698
7c913512 699 @param handler
4cc4bfaf
FM
700 A new image format handler object. There is usually only one instance
701 of a given handler class in an application session.
3c4f71cc 702
4cc4bfaf 703 @see wxImageHandler
23324ae1
FM
704 */
705 static void InsertHandler(wxImageHandler* handler);
706
707 /**
708 Returns @true if image data is present.
709 */
328f5751 710 bool IsOk() const;
23324ae1
FM
711
712 /**
713 Returns @true if the given pixel is transparent, i.e. either has the mask
714 colour if this image has a mask or if this image has alpha channel and alpha
715 value of this pixel is strictly less than @e threshold.
716 */
328f5751 717 bool IsTransparent(int x, int y, unsigned char threshold = 128) const;
23324ae1
FM
718
719 //@{
720 /**
721 Loads an image from an input stream.
3c4f71cc 722
7c913512 723 @param name
4cc4bfaf 724 Name of the file from which to load the image.
7c913512 725 @param stream
dd067e96
RR
726 Opened input stream from which to load the image. Currently, the
727 stream must support seeking.
7c913512 728 @param type
dd067e96 729 May be one of the following:
4e2cddc4
RR
730 @li wxBITMAP_TYPE_BMP: Load a Windows bitmap file.
731 @li wxBITMAP_TYPE_GIF: Load a GIF bitmap file.
732 @li wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file.
733 @li wxBITMAP_TYPE_PNG: Load a PNG bitmap file.
734 @li wxBITMAP_TYPE_PCX: Load a PCX bitmap file.
735 @li wxBITMAP_TYPE_PNM: Load a PNM bitmap file.
736 @li wxBITMAP_TYPE_TIF: Load a TIFF bitmap file.
737 @li wxBITMAP_TYPE_TGA: Load a TGA bitmap file.
738 @li wxBITMAP_TYPE_XPM: Load a XPM bitmap file.
739 @li wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO).
740 @li wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR).
741 @li wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI).
742 @li wxBITMAP_TYPE_ANY: Will try to autodetect the format.
4cc4bfaf
FM
743 @param mimetype
744 MIME type string (for example 'image/jpeg')
7c913512 745 @param index
4cc4bfaf 746 Index of the image to load in the case that the image file contains
dd067e96
RR
747 multiple images. This is only used by GIF, ICO and TIFF handlers.
748 The default value (-1) means "choose the default image" and is
749 interpreted as the first image (index=0) by the GIF and TIFF handler
750 and as the largest and most colourful one by the ICO handler.
3c4f71cc 751
d29a9a8a 752 @return @true if the operation succeeded, @false otherwise. If the
4cc4bfaf
FM
753 optional index parameter is out of range, @false is
754 returned and a call to wxLogError() takes place.
3c4f71cc 755
23324ae1 756 @remarks Depending on how wxWidgets has been configured, not all formats
4cc4bfaf 757 may be available.
3c4f71cc 758
4cc4bfaf 759 @see SaveFile()
23324ae1
FM
760 */
761 bool LoadFile(const wxString& name,
e98e625c 762 wxBitmapType type = wxBITMAP_TYPE_ANY,
23324ae1 763 int index = -1);
7c913512
FM
764 bool LoadFile(const wxString& name, const wxString& mimetype,
765 int index = -1);
e98e625c 766 bool LoadFile(wxInputStream& stream, wxBitmapType type,
7c913512
FM
767 int index = -1);
768 bool LoadFile(wxInputStream& stream,
769 const wxString& mimetype,
770 int index = -1);
23324ae1
FM
771 //@}
772
773 /**
774 Returns a mirrored copy of the image. The parameter @e horizontally
775 indicates the orientation.
776 */
328f5751 777 wxImage Mirror(bool horizontally = true) const;
23324ae1
FM
778
779 /**
4cc4bfaf 780 Copy the data of the given @a image to the specified position in this image.
23324ae1
FM
781 */
782 void Paste(const wxImage& image, int x, int y);
783
784 /**
785 Constructor for RGBValue, an object that contains values for red, green and
786 blue which
787 represent the value of a color. It is used by HSVtoRGB()
788 and RGBtoHSV(), which
789 converts between HSV color space and RGB color space.
790 */
7c913512
FM
791 RGBValue(unsigned char r = 0, unsigned char g = 0,
792 unsigned char b = 0);
23324ae1
FM
793
794 /**
795 Converts a color in RGB color space to HSV color space.
796 */
797#define wxImage::HSVValue RGBtoHSV(const RGBValue& rgb) /* implementation is private */
798
799 /**
800 Finds the handler with the given name, and removes it. The handler
801 is not deleted.
3c4f71cc 802
7c913512 803 @param name
4cc4bfaf 804 The handler name.
3c4f71cc 805
d29a9a8a 806 @return @true if the handler was found and removed, @false otherwise.
3c4f71cc 807
4cc4bfaf 808 @see wxImageHandler
23324ae1
FM
809 */
810 static bool RemoveHandler(const wxString& name);
811
812 /**
813 Replaces the colour specified by @e r1,g1,b1 by the colour @e r2,g2,b2.
814 */
815 void Replace(unsigned char r1, unsigned char g1,
816 unsigned char b1, unsigned char r2,
817 unsigned char g2, unsigned char b2);
818
819 /**
820 Changes the size of the image in-place by scaling it: after a call to this
821 function,
822 the image will have the given width and height.
4cc4bfaf 823 For a description of the @a quality parameter, see the Scale() function.
23324ae1 824 Returns the (modified) image itself.
3c4f71cc 825
4cc4bfaf 826 @see Scale()
23324ae1
FM
827 */
828 wxImage Rescale(int width, int height,
829 int quality = wxIMAGE_QUALITY_NORMAL);
830
831 /**
832 Changes the size of the image in-place without scaling it by adding either a
833 border
834 with the given colour or cropping as necessary. The image is pasted into a new
4cc4bfaf
FM
835 image with the given @a size and background colour at the position @e pos
836 relative to the upper left of the new image. If @a red = green = blue = -1
23324ae1
FM
837 then use either the current mask colour if set or find, use, and set a
838 suitable mask colour for any newly exposed areas.
23324ae1 839 Returns the (modified) image itself.
3c4f71cc 840
4cc4bfaf 841 @see Size()
23324ae1
FM
842 */
843 wxImage Resize(const wxSize& size, const wxPoint pos,
844 int red = -1, int green = -1,
845 int blue = -1);
846
847 /**
4cc4bfaf
FM
848 Rotates the image about the given point, by @a angle radians. Passing @true
849 to @a interpolating results in better image quality, but is slower. If the
23324ae1
FM
850 image has a mask, then the mask colour is used for the uncovered pixels in the
851 rotated image background. Else, black (rgb 0, 0, 0) will be used.
23324ae1
FM
852 Returns the rotated image, leaving this image intact.
853 */
854 wxImage Rotate(double angle, const wxPoint& rotationCentre,
4cc4bfaf
FM
855 bool interpolating = true,
856 wxPoint* offsetAfterRotation = NULL);
23324ae1
FM
857
858 /**
859 Returns a copy of the image rotated 90 degrees in the direction
860 indicated by @e clockwise.
861 */
328f5751 862 wxImage Rotate90(bool clockwise = true) const;
23324ae1
FM
863
864 /**
865 Rotates the hue of each pixel in the image by @e angle, which is a double in
866 the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0
867 corresponds
868 to +360 degrees.
869 */
870 void RotateHue(double angle);
871
872 //@{
873 /**
874 Saves an image in the given stream.
3c4f71cc 875
7c913512 876 @param name
4cc4bfaf 877 Name of the file to save the image to.
7c913512 878 @param stream
4cc4bfaf 879 Opened output stream to save the image to.
7c913512 880 @param type
4cc4bfaf 881 Currently these types can be used:
4e2cddc4
RR
882 @li wxBITMAP_TYPE_BMP: Save a BMP image file.
883 @li wxBITMAP_TYPE_JPEG: Save a JPEG image file.
884 @li wxBITMAP_TYPE_PNG: Save a PNG image file.
885 @li wxBITMAP_TYPE_PCX: Save a PCX image file (tries to save as 8-bit if possible,
dd067e96 886 falls back to 24-bit otherwise).
4e2cddc4
RR
887 @li wxBITMAP_TYPE_PNM: Save a PNM image file (as raw RGB always).
888 @li wxBITMAP_TYPE_TIFF: Save a TIFF image file.
889 @li wxBITMAP_TYPE_XPM: Save a XPM image file.
890 @li wxBITMAP_TYPE_ICO: Save a Windows icon file (ICO) (the size may
dd067e96
RR
891 be up to 255 wide by 127 high. A single image is saved in 8 colors
892 at the size supplied).
4e2cddc4 893 @li wxBITMAP_TYPE_CUR: Save a Windows cursor file (CUR).
7c913512 894 @param mimetype
4cc4bfaf 895 MIME type.
3c4f71cc 896
d29a9a8a 897 @return @true if the operation succeeded, @false otherwise.
3c4f71cc 898
23324ae1 899 @remarks Depending on how wxWidgets has been configured, not all formats
4cc4bfaf 900 may be available.
3c4f71cc 901
4cc4bfaf 902 @see LoadFile()
23324ae1 903 */
328f5751
FM
904 bool SaveFile(const wxString& name, int type) const;
905 const bool SaveFile(const wxString& name,
906 const wxString& mimetype) const;
907 const bool SaveFile(const wxString& name) const;
908 const bool SaveFile(wxOutputStream& stream, int type) const;
909 const bool SaveFile(wxOutputStream& stream,
910 const wxString& mimetype) const;
23324ae1
FM
911 //@}
912
913 /**
914 Returns a scaled version of the image. This is also useful for
915 scaling bitmaps in general as the only other way to scale bitmaps
916 is to blit a wxMemoryDC into another wxMemoryDC.
23324ae1
FM
917 It should be noted that although using wxIMAGE_QUALITY_HIGH produces much nicer
918 looking results it is a slower method. Downsampling will use the box averaging
919 method
920 which seems to operate very fast. If you are upsampling larger images using
921 this method you will most likely notice that it is a bit slower and in extreme
922 cases
923 it will be quite substantially slower as the bicubic algorithm has to process a
924 lot of
925 data.
23324ae1
FM
926 It should also be noted that the high quality scaling may not work as expected
927 when using a single mask colour for transparency, as the scaling will blur the
928 image and will therefore remove the mask partially. Using the alpha channel
929 will work.
23324ae1 930 Example:
3c4f71cc 931
7c913512 932 @param quality
e98e625c
VZ
933 Determines what method to use for resampling the image.
934
4e2cddc4
RR
935 Can be one of the following:
936 @li wxIMAGE_QUALITY_NORMAL: Uses the normal default scaling method of
dd067e96 937 pixel replication
4e2cddc4 938 @li wxIMAGE_QUALITY_HIGH: Uses bicubic and box averaging resampling
dd067e96 939 methods for upsampling and downsampling respectively
3c4f71cc 940
4cc4bfaf 941 @see Rescale()
23324ae1
FM
942 */
943 wxImage Scale(int width, int height,
328f5751 944 int quality = wxIMAGE_QUALITY_NORMAL) const;
23324ae1 945
e98e625c 946 /**
b3623ed5
RR
947 Assigns new data as alpha channel to the image.
948 If @e static_data is false the data will be
949 free()'d after use.
23324ae1 950 */
4cc4bfaf
FM
951 void SetAlpha(unsigned char* alpha = NULL,
952 bool static_data = false);
e98e625c 953
b3623ed5
RR
954 /**
955 Sets the alpha value for the given pixel. This function should only be
956 called if the image has alpha channel data, use HasAlpha() to
957 check for this.
958 */
7c913512 959 void SetAlpha(int x, int y, unsigned char alpha);
23324ae1
FM
960
961 /**
962 Sets the image data without performing checks. The data given must have
963 the size (width*height*3) or results will be unexpected. Don't use this
964 method if you aren't sure you know what you are doing.
23324ae1
FM
965 The data must have been allocated with @c malloc(), @b NOT with
966 @c operator new.
23324ae1
FM
967 After this call the pointer to the data is owned by the wxImage object,
968 that will be responsible for deleting it.
969 Do not pass to this function a pointer obtained through
970 GetData().
971 */
972 void SetData(unsigned char* data);
973
974 /**
975 Specifies whether there is a mask or not. The area of the mask is determined by
976 the current mask colour.
977 */
4cc4bfaf 978 void SetMask(bool hasMask = true);
23324ae1
FM
979
980 /**
981 Sets the mask colour for this image (and tells the image to use the mask).
982 */
983 void SetMaskColour(unsigned char red, unsigned char green,
984 unsigned char blue);
985
986 /**
7c913512 987 @param mask
4cc4bfaf 988 The mask image to extract mask shape from. Must have same dimensions as the
23324ae1 989 image.
7c913512 990 @param mr,mg,mb
4cc4bfaf 991 RGB value of pixels in mask that will be used to create the mask.
3c4f71cc 992
d29a9a8a 993 @return Returns @false if mask does not have same dimensions as the image
4cc4bfaf
FM
994 or if there is no unused colour left. Returns @true if
995 the mask was successfully applied.
23324ae1
FM
996 */
997 bool SetMaskFromImage(const wxImage& mask, unsigned char mr,
998 unsigned char mg,
999 unsigned char mb);
1000
1001 //@{
1002 /**
1003 Sets a user-defined option. The function is case-insensitive to @e name.
23324ae1
FM
1004 For example, when saving as a JPEG file, the option @b quality is
1005 used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
3c4f71cc 1006
4cc4bfaf 1007 @see GetOption(), GetOptionInt(), HasOption()
23324ae1
FM
1008 */
1009 void SetOption(const wxString& name, const wxString& value);
7c913512 1010 void SetOption(const wxString& name, int value);
23324ae1
FM
1011 //@}
1012
1013 /**
1014 Associates a palette with the image. The palette may be used when converting
1015 wxImage to wxBitmap (MSW only at present) or in file save operations (none as
1016 yet).
1017 */
1018 void SetPalette(const wxPalette& palette);
1019
1020 /**
1021 Sets the colour of the pixels within the given rectangle. This routine performs
1022 bounds-checks for the coordinate so it can be considered a safe way to
1023 manipulate the
1024 data.
1025 */
4cc4bfaf
FM
1026 void SetRGB(wxRect& rect, unsigned char red,
1027 unsigned char green,
1028 unsigned char blue);
23324ae1 1029
9d1c7e84
VZ
1030 /**
1031 Set the type of image returned by GetType().
1032
1033 This method is mostly used internally by the library but can also be
1034 called from the user code if the image was created from data in the
1035 given bitmap format without using LoadFile() (which would set the type
1036 correctly automatically).
1037
1038 Notice that the image must be created before this function is called.
1039
1040 @since 2.9.0
1041
1042 @param type
1043 One of bitmap type constants, @c wxBITMAP_TYPE_INVALID is a valid
1044 value for it and can be used to reset the bitmap type to default
1045 but @c wxBITMAP_TYPE_MAX is not allowed here.
1046 */
1047 void SetType(wxBitmapType type);
1048
23324ae1
FM
1049 /**
1050 Returns a resized version of this image without scaling it by adding either a
1051 border
1052 with the given colour or cropping as necessary. The image is pasted into a new
4cc4bfaf
FM
1053 image with the given @a size and background colour at the position @e pos
1054 relative to the upper left of the new image. If @a red = green = blue = -1
23324ae1
FM
1055 then the areas of the larger image not covered by this image are made
1056 transparent by filling them with the image mask colour (which will be allocated
1057 automatically if it isn't currently set). Otherwise, the areas will be filled
1058 with the colour with the specified RGB components.
3c4f71cc 1059
4cc4bfaf 1060 @see Resize()
23324ae1
FM
1061 */
1062 wxImage Size(const wxSize& size, const wxPoint pos, int red = -1,
328f5751 1063 int green = -1, int blue = -1) const;
23324ae1
FM
1064
1065 /**
1066 Assignment operator, using @ref overview_trefcount "reference counting".
3c4f71cc 1067
7c913512 1068 @param image
4cc4bfaf 1069 Image to assign.
3c4f71cc 1070
d29a9a8a 1071 @return Returns 'this' object.
23324ae1
FM
1072 */
1073 wxImage operator =(const wxImage& image);
1074};
1075
23324ae1
FM
1076// ============================================================================
1077// Global functions/macros
1078// ============================================================================
1079
8cd06fb5
BP
1080/** @ingroup group_funcmacro_appinitterm */
1081//@{
1082
23324ae1
FM
1083/**
1084 Initializes all available image handlers. For a list of available handlers,
1085 see wxImage.
7c913512 1086
4cc4bfaf 1087 @see wxImage, wxImageHandler
027c1c27
BP
1088
1089 @header{wx/image.h}
23324ae1
FM
1090*/
1091void wxInitAllImageHandlers();
1092
8cd06fb5
BP
1093//@}
1094