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