]> git.saurik.com Git - wxWidgets.git/blame - interface/image.h
Added the function and macro group pages for Doxygen.
[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.
50
7c913512 51 @param stream
4cc4bfaf
FM
52 Opened input stream for reading image data. Currently, the stream must
53 support seeking.
23324ae1
FM
54
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.
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).
23324ae1
FM
91
92 @returns @true if the operation succeeded, @false otherwise.
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.
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.
23324ae1
FM
106
107 @returns @true if the operation succeeded, @false otherwise.
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.
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.
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.
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
3db7c3b1 142 @ingroup group_class_gdi
23324ae1 143 @wxheader{image.h}
7c913512 144
23324ae1
FM
145 This class encapsulates a platform-independent image. An image can be created
146 from data, or using wxBitmap::ConvertToImage. An image
147 can be loaded from a file in a variety of formats, and is extensible to new
148 formats
149 via image format handlers. Functions are available to set and get image bits, so
150 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.
155 This bitmap can then
156 be drawn in a device context, using wxDC::DrawBitmap.
7c913512 157
23324ae1
FM
158 One colour value of the image may be used as a mask colour which will lead to
159 the automatic
160 creation of a wxMask object associated to the bitmap object.
7c913512 161
23324ae1
FM
162 @library{wxcore}
163 @category{gdi}
7c913512 164
e54c96f1 165 @see wxBitmap, wxInitAllImageHandlers()
23324ae1
FM
166*/
167class wxImage : public wxObject
168{
169public:
170 //@{
171 /**
172 Creates an image from XPM data.
173
7c913512 174 @param width
4cc4bfaf 175 Specifies the width of the image.
7c913512 176 @param height
4cc4bfaf 177 Specifies the height of the image.
7c913512 178 @param name
4cc4bfaf 179 Name of the file from which to load the image.
7c913512 180 @param stream
4cc4bfaf
FM
181 Opened input stream from which to load the image. Currently, the stream
182 must support seeking.
7c913512 183 @param type
4cc4bfaf 184 May be one of the following:
23324ae1 185
23324ae1
FM
186
187
23324ae1 188
23324ae1
FM
189
190
4cc4bfaf 191 wxBITMAP_TYPE_BMP
23324ae1 192
23324ae1
FM
193
194
23324ae1 195
4cc4bfaf 196 Load a Windows bitmap file.
23324ae1
FM
197
198
23324ae1 199
23324ae1
FM
200
201
4cc4bfaf 202 wxBITMAP_TYPE_GIF
23324ae1 203
23324ae1
FM
204
205
23324ae1 206
4cc4bfaf 207 Load a GIF bitmap file.
23324ae1
FM
208
209
23324ae1 210
23324ae1
FM
211
212
4cc4bfaf 213 wxBITMAP_TYPE_JPEG
23324ae1 214
23324ae1
FM
215
216
23324ae1 217
4cc4bfaf 218 Load a JPEG bitmap file.
23324ae1
FM
219
220
23324ae1 221
23324ae1
FM
222
223
4cc4bfaf 224 wxBITMAP_TYPE_PNG
23324ae1 225
23324ae1
FM
226
227
23324ae1 228
4cc4bfaf 229 Load a PNG bitmap file.
23324ae1
FM
230
231
23324ae1 232
23324ae1 233
23324ae1 234
4cc4bfaf
FM
235 wxBITMAP_TYPE_PCX
236
237
238
239
240 Load a PCX bitmap file.
241
242
243
244
245
246 wxBITMAP_TYPE_PNM
247
248
249
250
251 Load a PNM bitmap file.
252
253
254
255
256
257 wxBITMAP_TYPE_TIF
258
259
260
261
262 Load a TIFF bitmap file.
263
264
265
266
267
268 wxBITMAP_TYPE_TGA
269
270
271
272
273 Load a TGA bitmap file.
274
275
276
277
278
279 wxBITMAP_TYPE_XPM
280
281
282
283
284 Load a XPM bitmap file.
285
286
287
288
289
290 wxBITMAP_TYPE_ICO
291
292
293
294
295 Load a Windows icon file (ICO).
296
297
298
299
300
301 wxBITMAP_TYPE_CUR
302
303
304
305
306 Load a Windows cursor file (CUR).
307
308
309
310
311
312 wxBITMAP_TYPE_ANI
313
314
315
316
317 Load a Windows animated cursor file (ANI).
318
319
320
321
322
323 wxBITMAP_TYPE_ANY
324
325
326
327
328 Will try to autodetect the format.
329 @param mimetype
330 MIME type string (for example 'image/jpeg')
331 @param index
332 Index of the image to load in the case that the image file contains
333 multiple images.
334 This is only used by GIF, ICO and TIFF handlers. The default value (-1)
335 means
336 "choose the default image" and is interpreted as the first image (index=0)
337 by
338 the GIF and TIFF handler and as the largest and most colourful one by the
339 ICO handler.
7c913512 340 @param xpmData
4cc4bfaf 341 A pointer to XPM image data.
23324ae1
FM
342
343 @remarks Depending on how wxWidgets has been configured, not all formats
4cc4bfaf 344 may be available.
23324ae1 345
4cc4bfaf 346 @see LoadFile()
23324ae1
FM
347 */
348 wxImage();
7c913512
FM
349 wxImage(const wxImage& image);
350 wxImage(const wxBitmap& bitmap);
4cc4bfaf 351 wxImage(int width, int height, bool clear = true);
7c913512 352 wxImage(int width, int height, unsigned char* data,
4cc4bfaf 353 bool static_data = false);
7c913512
FM
354 wxImage(const wxString& name, long type = wxBITMAP_TYPE_ANY,
355 int index = -1);
356 wxImage(const wxString& name, const wxString& mimetype,
357 int index = -1);
358 wxImage(wxInputStream& stream, long type = wxBITMAP_TYPE_ANY,
359 int index = -1);
360 wxImage(wxInputStream& stream, const wxString& mimetype,
361 int index = -1);
362 wxImage(const char* const* xpmData);
23324ae1
FM
363 //@}
364
365 /**
366 Destructor.
367 See @ref overview_refcountdestruct "reference-counted object destruction" for
368 more info.
369 */
370 ~wxImage();
371
372 //@{
373 /**
374 returns @true if the current image handlers can read this file
375 */
376 static void AddHandler(wxImageHandler* handler);
7c913512 377 See also bool CanRead(const wxString& filename);
23324ae1
FM
378 //@}
379
380 /**
381 Blurs the image in both horizontal and vertical directions by the specified
382 pixel
383 @e blurRadius. This should not be used when using a single mask colour
384 for transparency.
385
4cc4bfaf 386 @see @ref horzblur() BlurHorizontal, @ref vertblur() BlurVertical
23324ae1
FM
387 */
388 wxImage Blur(int blurRadius);
389
390 /**
391 Blurs the image in the horizontal direction only. This should not be used
392 when using a single mask colour for transparency.
393
4cc4bfaf 394 @see Blur(), @ref vertblur() BlurVertical
23324ae1
FM
395 */
396 wxImage BlurHorizontal(int blurRadius);
397
398 /**
399 Blurs the image in the vertical direction only. This should not be used
400 when using a single mask colour for transparency.
401
4cc4bfaf 402 @see Blur(), @ref horzblur() BlurHorizontal
23324ae1
FM
403 */
404 wxImage BlurVertical(int blurRadius);
405
406 /**
407 Deletes all image handlers.
23324ae1
FM
408 This function is called by wxWidgets on exit.
409 */
410 static void CleanUpHandlers();
411
412 /**
4cc4bfaf 413 Computes the histogram of the image. @a histogram is a reference to
23324ae1
FM
414 wxImageHistogram object. wxImageHistogram is a specialization of
415 wxHashMap "template" and is defined as follows:
416
417 @returns Returns number of colours in the histogram.
418 */
328f5751 419 unsigned long ComputeHistogram(wxImageHistogram& histogram) const;
23324ae1
FM
420
421 /**
422 If the image has alpha channel, this method converts it to mask. All pixels
4cc4bfaf 423 with alpha value less than @a threshold are replaced with mask colour
23324ae1
FM
424 and the alpha channel is removed. Mask colour is chosen automatically using
425 FindFirstUnusedColour().
23324ae1
FM
426 If the image image doesn't have alpha channel,
427 ConvertAlphaToMask does nothing.
428
429 @returns @false if FindFirstUnusedColour returns @false, @true otherwise.
430 */
431 bool ConvertAlphaToMask(unsigned char threshold = 128);
432
433 /**
434 Deprecated, use equivalent @ref wxBitmap::ctor "wxBitmap constructor"
435 (which takes wxImage and depth as its arguments) instead.
436 */
328f5751 437 wxBitmap ConvertToBitmap() const;
23324ae1
FM
438
439 /**
440 Returns a greyscale version of the image. The returned image uses the luminance
441 component of the original to calculate the greyscale. Defaults to using
442 ITU-T BT.601 when converting to YUV, where every pixel equals
443 (R * @e lr) + (G * @e lg) + (B * @e lb).
444 */
445 wxImage ConvertToGreyscale(double lr = 0.299, double lg = 0.587,
328f5751 446 double lb = 0.114) const;
23324ae1
FM
447
448 /**
449 Returns monochromatic version of the image. The returned image has white
450 colour where the original has @e (r,g,b) colour and black colour
451 everywhere else.
452 */
453 wxImage ConvertToMono(unsigned char r, unsigned char g,
328f5751 454 unsigned char b) const;
23324ae1
FM
455
456 /**
457 Returns an identical copy of the image.
458 */
328f5751 459 wxImage Copy() const;
23324ae1
FM
460
461 /**
4cc4bfaf 462 Creates a fresh image. If @a clear is @true, the new image will be initialized
23324ae1
FM
463 to black.
464 Otherwise, the image data will be uninitialized.
465
7c913512 466 @param width
4cc4bfaf 467 The width of the image in pixels.
7c913512 468 @param height
4cc4bfaf 469 The height of the image in pixels.
23324ae1
FM
470
471 @returns @true if the call succeeded, @false otherwise.
472 */
4cc4bfaf 473 bool Create(int width, int height, bool clear = true);
23324ae1
FM
474
475 /**
476 Destroys the image data.
477 */
478 void Destroy();
479
480 /**
7c913512 481 @param r,g,b
4cc4bfaf 482 Pointers to variables to save the colour.
7c913512 483 @param startR,startG,startB
4cc4bfaf
FM
484 Initial values of the colour. Returned colour
485 will have RGB values equal to or greater than these.
23324ae1
FM
486
487 @returns Returns @false if there is no unused colour left, @true on success.
488 */
4cc4bfaf
FM
489 bool FindFirstUnusedColour(unsigned char* r, unsigned char* g,
490 unsigned char* b,
23324ae1
FM
491 unsigned char startR = 1,
492 unsigned char startG = 0,
493 unsigned char startB = 0);
494
495 //@{
496 /**
497 Finds the handler associated with the given MIME type.
498
7c913512 499 @param name
4cc4bfaf 500 The handler name.
7c913512 501 @param extension
4cc4bfaf 502 The file extension, such as "bmp".
7c913512 503 @param imageType
4cc4bfaf 504 The image type, such as wxBITMAP_TYPE_BMP.
7c913512 505 @param mimetype
4cc4bfaf 506 MIME type.
23324ae1
FM
507
508 @returns A pointer to the handler if found, @NULL otherwise.
509
4cc4bfaf 510 @see wxImageHandler
23324ae1
FM
511 */
512 static wxImageHandler* FindHandler(const wxString& name);
7c913512
FM
513 static wxImageHandler* FindHandler(const wxString& extension,
514 long imageType);
515 static wxImageHandler* FindHandler(long imageType);
516 static wxImageHandler* FindHandlerMime(const wxString& mimetype);
23324ae1
FM
517 //@}
518
519 //@{
520 /**
521 Returns pointer to the array storing the alpha values for this image. This
522 pointer is @NULL for the images without the alpha channel. If the image
523 does have it, this pointer may be used to directly manipulate the alpha values
524 which are stored as the @ref getdata() RGB ones.
525 */
328f5751
FM
526 unsigned char GetAlpha(int x, int y) const;
527 const unsigned char * GetAlpha() const;
23324ae1
FM
528 //@}
529
530 /**
531 Returns the blue intensity at the given coordinate.
532 */
328f5751 533 unsigned char GetBlue(int x, int y) const;
23324ae1
FM
534
535 /**
536 Returns the image data as an array. This is most often used when doing
537 direct image manipulation. The return value points to an array of
538 characters in RGBRGBRGB... format in the top-to-bottom, left-to-right
539 order, that is the first RGB triplet corresponds to the pixel first pixel of
540 the first row, the second one --- to the second pixel of the first row and so
541 on until the end of the first row, with second row following after it and so
542 on.
23324ae1
FM
543 You should not delete the returned pointer nor pass it to
544 SetData().
545 */
328f5751 546 unsigned char* GetData() const;
23324ae1
FM
547
548 /**
549 Returns the green intensity at the given coordinate.
550 */
328f5751 551 unsigned char GetGreen(int x, int y) const;
23324ae1
FM
552
553 /**
554 Returns the static list of image format handlers.
555
4cc4bfaf 556 @see wxImageHandler
23324ae1
FM
557 */
558 static wxList GetHandlers();
559
560 /**
561 Gets the height of the image in pixels.
562 */
328f5751 563 int GetHeight() const;
23324ae1
FM
564
565 //@{
566 /**
567 If the image file contains more than one image and the image handler is capable
568 of retrieving these individually, this function will return the number of
569 available images.
570
7c913512 571 @param name
4cc4bfaf 572 Name of the file to query.
7c913512 573 @param stream
4cc4bfaf
FM
574 Opened input stream with image data. Currently, the stream must support
575 seeking.
7c913512 576 @param type
4cc4bfaf
FM
577 May be one of the following:
578
579
580
581
582
583
584 wxBITMAP_TYPE_BMP
585
586
587
588
589 Load a Windows bitmap file.
590
591
592
593
594
595 wxBITMAP_TYPE_GIF
596
597
598
599
600 Load a GIF bitmap file.
601
602
603
604
605
606 wxBITMAP_TYPE_JPEG
607
608
609
610
611 Load a JPEG bitmap file.
612
613
614
615
616
617 wxBITMAP_TYPE_PNG
618
619
620
621
622 Load a PNG bitmap file.
623
624
625
626
627
628 wxBITMAP_TYPE_PCX
629
630
631
632
633 Load a PCX bitmap file.
634
635
636
637
638
639 wxBITMAP_TYPE_PNM
640
641
642
643
644 Load a PNM bitmap file.
645
646
647
648
649
650 wxBITMAP_TYPE_TIF
651
652
653
654
655 Load a TIFF bitmap file.
656
657
658
659
660
661 wxBITMAP_TYPE_XPM
662
23324ae1 663
23324ae1
FM
664
665
4cc4bfaf 666 Load a XPM bitmap file.
23324ae1 667
23324ae1
FM
668
669
23324ae1 670
23324ae1 671
4cc4bfaf 672 wxBITMAP_TYPE_ICO
23324ae1 673
23324ae1 674
23324ae1
FM
675
676
4cc4bfaf 677 Load a Windows icon file (ICO).
23324ae1 678
23324ae1
FM
679
680
23324ae1 681
23324ae1 682
4cc4bfaf 683 wxBITMAP_TYPE_CUR
23324ae1 684
23324ae1 685
23324ae1
FM
686
687
4cc4bfaf 688 Load a Windows cursor file (CUR).
23324ae1 689
23324ae1
FM
690
691
23324ae1 692
23324ae1 693
4cc4bfaf 694 wxBITMAP_TYPE_ANI
23324ae1 695
23324ae1 696
23324ae1
FM
697
698
4cc4bfaf 699 Load a Windows animated cursor file (ANI).
23324ae1 700
23324ae1
FM
701
702
23324ae1 703
23324ae1 704
4cc4bfaf 705 wxBITMAP_TYPE_ANY
23324ae1 706
4cc4bfaf
FM
707
708
709
710 Will try to autodetect the format.
23324ae1
FM
711
712 @returns Number of available images. For most image handlers, this is 1
4cc4bfaf 713 (exceptions are TIFF and ICO formats).
23324ae1
FM
714 */
715 static int GetImageCount(const wxString& filename,
716 long type = wxBITMAP_TYPE_ANY);
7c913512
FM
717 static int GetImageCount(wxInputStream& stream,
718 long type = wxBITMAP_TYPE_ANY);
23324ae1
FM
719 //@}
720
721 /**
722 Iterates all registered wxImageHandler objects, and returns a string containing
723 file extension masks
724 suitable for passing to file open/save dialog boxes.
725
726 @returns The format of the returned string is
4cc4bfaf 727 "(*.ext1;*.ext2)|*.ext1;*.ext2".
23324ae1 728
4cc4bfaf 729 @see wxImageHandler
23324ae1
FM
730 */
731 static wxString GetImageExtWildcard();
732
733 /**
734 Gets the blue value of the mask colour.
735 */
328f5751 736 unsigned char GetMaskBlue() const;
23324ae1
FM
737
738 /**
739 Gets the green value of the mask colour.
740 */
328f5751 741 unsigned char GetMaskGreen() const;
23324ae1
FM
742
743 /**
744 Gets the red value of the mask colour.
745 */
328f5751 746 unsigned char GetMaskRed() const;
23324ae1
FM
747
748 /**
749 Gets a user-defined option. The function is case-insensitive to @e name.
23324ae1
FM
750 For example, when saving as a JPEG file, the option @b quality is
751 used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
752
4cc4bfaf 753 @see SetOption(), GetOptionInt(), HasOption()
23324ae1 754 */
328f5751 755 wxString GetOption(const wxString& name) const;
23324ae1
FM
756
757 /**
758 Gets a user-defined option as an integer. The function is case-insensitive to
759 @e name.
23324ae1
FM
760 If the given option is not present, the function returns 0. Use
761 HasOption() is 0 is a possibly valid value
762 for the option.
23324ae1
FM
763 Options for wxPNGHandler
764
23324ae1
FM
765 wxIMAGE_OPTION_PNG_FORMAT
766
23324ae1
FM
767 Format for saving a PNG file.
768
769 wxIMAGE_OPTION_PNG_BITDEPTH
770
23324ae1
FM
771 Bit depth for every channel (R/G/B/A).
772
773 Supported values for wxIMAGE_OPTION_PNG_FORMAT:
774
23324ae1
FM
775 wxPNG_TYPE_COLOUR
776
23324ae1
FM
777 Stores RGB image.
778
779 wxPNG_TYPE_GREY
780
23324ae1
FM
781 Stores grey image, converts from RGB.
782
783 wxPNG_TYPE_GREY_RED
784
23324ae1
FM
785 Stores grey image, uses red value as grey.
786
4cc4bfaf 787 @see SetOption(), GetOption()
23324ae1 788 */
328f5751 789 int GetOptionInt(const wxString& name) const;
23324ae1
FM
790
791 /**
792 Get the current mask colour or find a suitable unused colour that could be
793 used as a mask colour. Returns @true if the image currently has a mask.
794 */
795 bool GetOrFindMaskColour(unsigned char r, unsigned char g,
328f5751 796 unsigned char b) const;
23324ae1
FM
797
798 /**
799 Returns the palette associated with the image. Currently the palette is only
800 used when converting to wxBitmap under Windows. Some of the wxImage handlers
801 have been modified to set the palette if one exists in the image file (usually
802 256 or less colour images in GIF or PNG format).
803 */
328f5751 804 const wxPalette GetPalette() const;
23324ae1
FM
805
806 /**
807 Returns the red intensity at the given coordinate.
808 */
328f5751 809 unsigned char GetRed(int x, int y) const;
23324ae1
FM
810
811 /**
812 Returns a sub image of the current one as long as the rect belongs entirely to
813 the image.
814 */
328f5751 815 wxImage GetSubImage(const wxRect& rect) const;
23324ae1
FM
816
817 /**
818 Gets the width of the image in pixels.
819
4cc4bfaf 820 @see GetHeight()
23324ae1 821 */
328f5751 822 int GetWidth() const;
23324ae1
FM
823
824 /**
825 Constructor for HSVValue, an object that contains values for hue, saturation
826 and value which
827 represent the value of a color. It is used by HSVtoRGB()
828 and RGBtoHSV(), which
829 converts between HSV color space and RGB color space.
830 */
7c913512 831 HSVValue(double h = 0.0, double s = 0.0, double v = 0.0);
23324ae1
FM
832
833 /**
834 Converts a color in HSV color space to RGB color space.
835 */
4cc4bfaf 836#define wxImage::RGBValue HSVtoRGB(const HSVValue& hsv) /* implementation is private */
23324ae1
FM
837
838 /**
839 Returns @true if this image has alpha channel, @false otherwise.
840
4cc4bfaf 841 @see GetAlpha(), SetAlpha()
23324ae1 842 */
328f5751 843 bool HasAlpha() const;
23324ae1
FM
844
845 /**
846 Returns @true if there is a mask active, @false otherwise.
847 */
328f5751 848 bool HasMask() const;
23324ae1
FM
849
850 /**
851 Returns @true if the given option is present. The function is case-insensitive
852 to @e name.
853
4cc4bfaf 854 @see SetOption(), GetOption(), GetOptionInt()
23324ae1 855 */
328f5751 856 bool HasOption(const wxString& name) const;
23324ae1
FM
857
858 /**
859 Initializes the image alpha channel data. It is an error to call it
860 if the image already has alpha data. If it doesn't, alpha data will be
861 by default initialized to all pixels being fully opaque. But if the image has a
862 a mask colour, all mask pixels will be completely transparent.
863 */
864 void InitAlpha();
865
866 /**
867 Internal use only. Adds standard image format handlers. It only install BMP
868 for the time being, which is used by wxBitmap.
23324ae1
FM
869 This function is called by wxWidgets on startup, and shouldn't be called by
870 the user.
871
e54c96f1 872 @see wxImageHandler, wxInitAllImageHandlers(), wxQuantize
23324ae1
FM
873 */
874 static void InitStandardHandlers();
875
876 /**
877 Adds a handler at the start of the static list of format handlers.
878
7c913512 879 @param handler
4cc4bfaf
FM
880 A new image format handler object. There is usually only one instance
881 of a given handler class in an application session.
23324ae1 882
4cc4bfaf 883 @see wxImageHandler
23324ae1
FM
884 */
885 static void InsertHandler(wxImageHandler* handler);
886
887 /**
888 Returns @true if image data is present.
889 */
328f5751 890 bool IsOk() const;
23324ae1
FM
891
892 /**
893 Returns @true if the given pixel is transparent, i.e. either has the mask
894 colour if this image has a mask or if this image has alpha channel and alpha
895 value of this pixel is strictly less than @e threshold.
896 */
328f5751 897 bool IsTransparent(int x, int y, unsigned char threshold = 128) const;
23324ae1
FM
898
899 //@{
900 /**
901 Loads an image from an input stream.
902
7c913512 903 @param name
4cc4bfaf 904 Name of the file from which to load the image.
7c913512 905 @param stream
4cc4bfaf
FM
906 Opened input stream from which to load the image. Currently, the stream
907 must support seeking.
7c913512 908 @param type
4cc4bfaf 909 One of the following values:
23324ae1 910
23324ae1
FM
911
912
23324ae1 913
23324ae1
FM
914
915
4cc4bfaf 916 wxBITMAP_TYPE_BMP
23324ae1 917
23324ae1
FM
918
919
23324ae1 920
4cc4bfaf 921 Load a Windows image file.
23324ae1
FM
922
923
23324ae1 924
23324ae1
FM
925
926
4cc4bfaf 927 wxBITMAP_TYPE_GIF
23324ae1 928
23324ae1
FM
929
930
23324ae1 931
4cc4bfaf 932 Load a GIF image file.
23324ae1
FM
933
934
23324ae1 935
23324ae1
FM
936
937
4cc4bfaf 938 wxBITMAP_TYPE_JPEG
23324ae1 939
23324ae1
FM
940
941
23324ae1 942
4cc4bfaf 943 Load a JPEG image file.
23324ae1
FM
944
945
23324ae1 946
23324ae1
FM
947
948
4cc4bfaf
FM
949 wxBITMAP_TYPE_PCX
950
951
952
953
954 Load a PCX image file.
955
956
957
958
959
960 wxBITMAP_TYPE_PNG
961
962
963
964
965 Load a PNG image file.
966
967
968
969
970
971 wxBITMAP_TYPE_PNM
972
973
974
975
976 Load a PNM image file.
977
978
979
980
981
982 wxBITMAP_TYPE_TIF
983
984
985
986
987 Load a TIFF image file.
988
989
990
991
992
993 wxBITMAP_TYPE_XPM
994
995
996
997
998 Load a XPM image file.
999
1000
1001
1002
1003
1004 wxBITMAP_TYPE_ICO
1005
1006
1007
1008
1009 Load a Windows icon file (ICO).
1010
1011
1012
1013
1014
1015 wxBITMAP_TYPE_CUR
1016
1017
1018
1019
1020 Load a Windows cursor file (CUR).
1021
1022
1023
1024
1025
1026 wxBITMAP_TYPE_ANI
1027
1028
1029
1030
1031 Load a Windows animated cursor file (ANI).
23324ae1 1032
23324ae1
FM
1033
1034
23324ae1 1035
23324ae1 1036
4cc4bfaf
FM
1037 wxBITMAP_TYPE_ANY
1038
1039
1040
1041
1042 Will try to autodetect the format.
1043 @param mimetype
1044 MIME type string (for example 'image/jpeg')
7c913512 1045 @param index
4cc4bfaf
FM
1046 Index of the image to load in the case that the image file contains
1047 multiple images.
1048 This is only used by GIF, ICO and TIFF handlers. The default value (-1)
1049 means
1050 "choose the default image" and is interpreted as the first image (index=0)
1051 by
1052 the GIF and TIFF handler and as the largest and most colourful one by the
1053 ICO handler.
23324ae1
FM
1054
1055 @returns @true if the operation succeeded, @false otherwise. If the
4cc4bfaf
FM
1056 optional index parameter is out of range, @false is
1057 returned and a call to wxLogError() takes place.
23324ae1
FM
1058
1059 @remarks Depending on how wxWidgets has been configured, not all formats
4cc4bfaf 1060 may be available.
23324ae1 1061
4cc4bfaf 1062 @see SaveFile()
23324ae1
FM
1063 */
1064 bool LoadFile(const wxString& name,
1065 long type = wxBITMAP_TYPE_ANY,
1066 int index = -1);
7c913512
FM
1067 bool LoadFile(const wxString& name, const wxString& mimetype,
1068 int index = -1);
1069 bool LoadFile(wxInputStream& stream, long type,
1070 int index = -1);
1071 bool LoadFile(wxInputStream& stream,
1072 const wxString& mimetype,
1073 int index = -1);
23324ae1
FM
1074 //@}
1075
1076 /**
1077 Returns a mirrored copy of the image. The parameter @e horizontally
1078 indicates the orientation.
1079 */
328f5751 1080 wxImage Mirror(bool horizontally = true) const;
23324ae1
FM
1081
1082 /**
4cc4bfaf 1083 Copy the data of the given @a image to the specified position in this image.
23324ae1
FM
1084 */
1085 void Paste(const wxImage& image, int x, int y);
1086
1087 /**
1088 Constructor for RGBValue, an object that contains values for red, green and
1089 blue which
1090 represent the value of a color. It is used by HSVtoRGB()
1091 and RGBtoHSV(), which
1092 converts between HSV color space and RGB color space.
1093 */
7c913512
FM
1094 RGBValue(unsigned char r = 0, unsigned char g = 0,
1095 unsigned char b = 0);
23324ae1
FM
1096
1097 /**
1098 Converts a color in RGB color space to HSV color space.
1099 */
1100#define wxImage::HSVValue RGBtoHSV(const RGBValue& rgb) /* implementation is private */
1101
1102 /**
1103 Finds the handler with the given name, and removes it. The handler
1104 is not deleted.
1105
7c913512 1106 @param name
4cc4bfaf 1107 The handler name.
23324ae1
FM
1108
1109 @returns @true if the handler was found and removed, @false otherwise.
1110
4cc4bfaf 1111 @see wxImageHandler
23324ae1
FM
1112 */
1113 static bool RemoveHandler(const wxString& name);
1114
1115 /**
1116 Replaces the colour specified by @e r1,g1,b1 by the colour @e r2,g2,b2.
1117 */
1118 void Replace(unsigned char r1, unsigned char g1,
1119 unsigned char b1, unsigned char r2,
1120 unsigned char g2, unsigned char b2);
1121
1122 /**
1123 Changes the size of the image in-place by scaling it: after a call to this
1124 function,
1125 the image will have the given width and height.
4cc4bfaf 1126 For a description of the @a quality parameter, see the Scale() function.
23324ae1
FM
1127 Returns the (modified) image itself.
1128
4cc4bfaf 1129 @see Scale()
23324ae1
FM
1130 */
1131 wxImage Rescale(int width, int height,
1132 int quality = wxIMAGE_QUALITY_NORMAL);
1133
1134 /**
1135 Changes the size of the image in-place without scaling it by adding either a
1136 border
1137 with the given colour or cropping as necessary. The image is pasted into a new
4cc4bfaf
FM
1138 image with the given @a size and background colour at the position @e pos
1139 relative to the upper left of the new image. If @a red = green = blue = -1
23324ae1
FM
1140 then use either the current mask colour if set or find, use, and set a
1141 suitable mask colour for any newly exposed areas.
23324ae1
FM
1142 Returns the (modified) image itself.
1143
4cc4bfaf 1144 @see Size()
23324ae1
FM
1145 */
1146 wxImage Resize(const wxSize& size, const wxPoint pos,
1147 int red = -1, int green = -1,
1148 int blue = -1);
1149
1150 /**
4cc4bfaf
FM
1151 Rotates the image about the given point, by @a angle radians. Passing @true
1152 to @a interpolating results in better image quality, but is slower. If the
23324ae1
FM
1153 image has a mask, then the mask colour is used for the uncovered pixels in the
1154 rotated image background. Else, black (rgb 0, 0, 0) will be used.
23324ae1
FM
1155 Returns the rotated image, leaving this image intact.
1156 */
1157 wxImage Rotate(double angle, const wxPoint& rotationCentre,
4cc4bfaf
FM
1158 bool interpolating = true,
1159 wxPoint* offsetAfterRotation = NULL);
23324ae1
FM
1160
1161 /**
1162 Returns a copy of the image rotated 90 degrees in the direction
1163 indicated by @e clockwise.
1164 */
328f5751 1165 wxImage Rotate90(bool clockwise = true) const;
23324ae1
FM
1166
1167 /**
1168 Rotates the hue of each pixel in the image by @e angle, which is a double in
1169 the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0
1170 corresponds
1171 to +360 degrees.
1172 */
1173 void RotateHue(double angle);
1174
1175 //@{
1176 /**
1177 Saves an image in the given stream.
1178
7c913512 1179 @param name
4cc4bfaf 1180 Name of the file to save the image to.
7c913512 1181 @param stream
4cc4bfaf 1182 Opened output stream to save the image to.
7c913512 1183 @param type
4cc4bfaf
FM
1184 Currently these types can be used:
1185
1186
1187
1188
1189
1190
1191 wxBITMAP_TYPE_BMP
1192
1193
1194
1195
1196 Save a BMP image file.
1197
1198
1199
1200
1201
1202 wxBITMAP_TYPE_JPEG
1203
1204
1205
1206
1207 Save a JPEG image file.
1208
1209
1210
1211
1212
1213 wxBITMAP_TYPE_PNG
1214
1215
1216
1217
1218 Save a PNG image file.
1219
1220
1221
1222
23324ae1 1223
4cc4bfaf 1224 wxBITMAP_TYPE_PCX
23324ae1
FM
1225
1226
23324ae1 1227
23324ae1 1228
4cc4bfaf
FM
1229 Save a PCX image file (tries to save as 8-bit if possible, falls back to
1230 24-bit otherwise).
23324ae1 1231
23324ae1 1232
23324ae1
FM
1233
1234
23324ae1 1235
4cc4bfaf 1236 wxBITMAP_TYPE_PNM
23324ae1
FM
1237
1238
23324ae1 1239
23324ae1 1240
4cc4bfaf 1241 Save a PNM image file (as raw RGB always).
23324ae1 1242
23324ae1 1243
23324ae1
FM
1244
1245
23324ae1 1246
4cc4bfaf 1247 wxBITMAP_TYPE_TIFF
23324ae1
FM
1248
1249
23324ae1 1250
23324ae1 1251
4cc4bfaf 1252 Save a TIFF image file.
23324ae1 1253
23324ae1 1254
23324ae1
FM
1255
1256
23324ae1 1257
4cc4bfaf
FM
1258 wxBITMAP_TYPE_XPM
1259
1260
1261
1262
1263 Save a XPM image file.
1264
1265
1266
1267
1268
1269 wxBITMAP_TYPE_ICO
1270
1271
1272
1273
1274 Save a Windows icon file (ICO) (the size may be up to 255 wide by 127 high.
1275 A single image is saved in 8 colors at the size supplied).
1276
1277
1278
1279
1280
1281 wxBITMAP_TYPE_CUR
1282
1283
1284
1285
1286 Save a Windows cursor file (CUR).
7c913512 1287 @param mimetype
4cc4bfaf 1288 MIME type.
23324ae1
FM
1289
1290 @returns @true if the operation succeeded, @false otherwise.
1291
1292 @remarks Depending on how wxWidgets has been configured, not all formats
4cc4bfaf 1293 may be available.
23324ae1 1294
4cc4bfaf 1295 @see LoadFile()
23324ae1 1296 */
328f5751
FM
1297 bool SaveFile(const wxString& name, int type) const;
1298 const bool SaveFile(const wxString& name,
1299 const wxString& mimetype) const;
1300 const bool SaveFile(const wxString& name) const;
1301 const bool SaveFile(wxOutputStream& stream, int type) const;
1302 const bool SaveFile(wxOutputStream& stream,
1303 const wxString& mimetype) const;
23324ae1
FM
1304 //@}
1305
1306 /**
1307 Returns a scaled version of the image. This is also useful for
1308 scaling bitmaps in general as the only other way to scale bitmaps
1309 is to blit a wxMemoryDC into another wxMemoryDC.
23324ae1
FM
1310 It should be noted that although using wxIMAGE_QUALITY_HIGH produces much nicer
1311 looking results it is a slower method. Downsampling will use the box averaging
1312 method
1313 which seems to operate very fast. If you are upsampling larger images using
1314 this method you will most likely notice that it is a bit slower and in extreme
1315 cases
1316 it will be quite substantially slower as the bicubic algorithm has to process a
1317 lot of
1318 data.
23324ae1
FM
1319 It should also be noted that the high quality scaling may not work as expected
1320 when using a single mask colour for transparency, as the scaling will blur the
1321 image and will therefore remove the mask partially. Using the alpha channel
1322 will work.
23324ae1
FM
1323 Example:
1324
7c913512 1325 @param quality
4cc4bfaf 1326 Determines what method to use for resampling the image. Can be one of the
23324ae1
FM
1327 following:
1328
23324ae1
FM
1329
1330
23324ae1 1331
23324ae1
FM
1332
1333
4cc4bfaf
FM
1334 wxIMAGE_QUALITY_NORMAL
1335
1336
1337
1338
1339 Uses the normal default scaling method of pixel replication
1340
1341
1342
1343
1344
1345 wxIMAGE_QUALITY_HIGH
1346
1347
1348
1349
1350 Uses bicubic and box averaging resampling methods for upsampling and
23324ae1
FM
1351 downsampling respectively
1352
4cc4bfaf 1353 @see Rescale()
23324ae1
FM
1354 */
1355 wxImage Scale(int width, int height,
328f5751 1356 int quality = wxIMAGE_QUALITY_NORMAL) const;
23324ae1
FM
1357
1358 //@{
1359 /**
1360 Sets the alpha value for the given pixel. This function should only be called
1361 if the image has alpha channel data, use HasAlpha() to
1362 check for this.
1363 */
4cc4bfaf
FM
1364 void SetAlpha(unsigned char* alpha = NULL,
1365 bool static_data = false);
7c913512 1366 void SetAlpha(int x, int y, unsigned char alpha);
23324ae1
FM
1367 //@}
1368
1369 /**
1370 Sets the image data without performing checks. The data given must have
1371 the size (width*height*3) or results will be unexpected. Don't use this
1372 method if you aren't sure you know what you are doing.
23324ae1
FM
1373 The data must have been allocated with @c malloc(), @b NOT with
1374 @c operator new.
23324ae1
FM
1375 After this call the pointer to the data is owned by the wxImage object,
1376 that will be responsible for deleting it.
1377 Do not pass to this function a pointer obtained through
1378 GetData().
1379 */
1380 void SetData(unsigned char* data);
1381
1382 /**
1383 Specifies whether there is a mask or not. The area of the mask is determined by
1384 the current mask colour.
1385 */
4cc4bfaf 1386 void SetMask(bool hasMask = true);
23324ae1
FM
1387
1388 /**
1389 Sets the mask colour for this image (and tells the image to use the mask).
1390 */
1391 void SetMaskColour(unsigned char red, unsigned char green,
1392 unsigned char blue);
1393
1394 /**
7c913512 1395 @param mask
4cc4bfaf 1396 The mask image to extract mask shape from. Must have same dimensions as the
23324ae1 1397 image.
7c913512 1398 @param mr,mg,mb
4cc4bfaf 1399 RGB value of pixels in mask that will be used to create the mask.
23324ae1
FM
1400
1401 @returns Returns @false if mask does not have same dimensions as the image
4cc4bfaf
FM
1402 or if there is no unused colour left. Returns @true if
1403 the mask was successfully applied.
23324ae1
FM
1404 */
1405 bool SetMaskFromImage(const wxImage& mask, unsigned char mr,
1406 unsigned char mg,
1407 unsigned char mb);
1408
1409 //@{
1410 /**
1411 Sets a user-defined option. The function is case-insensitive to @e name.
23324ae1
FM
1412 For example, when saving as a JPEG file, the option @b quality is
1413 used, which is a number between 0 and 100 (0 is terrible, 100 is very good).
1414
4cc4bfaf 1415 @see GetOption(), GetOptionInt(), HasOption()
23324ae1
FM
1416 */
1417 void SetOption(const wxString& name, const wxString& value);
7c913512 1418 void SetOption(const wxString& name, int value);
23324ae1
FM
1419 //@}
1420
1421 /**
1422 Associates a palette with the image. The palette may be used when converting
1423 wxImage to wxBitmap (MSW only at present) or in file save operations (none as
1424 yet).
1425 */
1426 void SetPalette(const wxPalette& palette);
1427
1428 /**
1429 Sets the colour of the pixels within the given rectangle. This routine performs
1430 bounds-checks for the coordinate so it can be considered a safe way to
1431 manipulate the
1432 data.
1433 */
4cc4bfaf
FM
1434 void SetRGB(wxRect& rect, unsigned char red,
1435 unsigned char green,
1436 unsigned char blue);
23324ae1
FM
1437
1438 /**
1439 Returns a resized version of this image without scaling it by adding either a
1440 border
1441 with the given colour or cropping as necessary. The image is pasted into a new
4cc4bfaf
FM
1442 image with the given @a size and background colour at the position @e pos
1443 relative to the upper left of the new image. If @a red = green = blue = -1
23324ae1
FM
1444 then the areas of the larger image not covered by this image are made
1445 transparent by filling them with the image mask colour (which will be allocated
1446 automatically if it isn't currently set). Otherwise, the areas will be filled
1447 with the colour with the specified RGB components.
1448
4cc4bfaf 1449 @see Resize()
23324ae1
FM
1450 */
1451 wxImage Size(const wxSize& size, const wxPoint pos, int red = -1,
328f5751 1452 int green = -1, int blue = -1) const;
23324ae1
FM
1453
1454 /**
1455 Assignment operator, using @ref overview_trefcount "reference counting".
1456
7c913512 1457 @param image
4cc4bfaf 1458 Image to assign.
23324ae1
FM
1459
1460 @returns Returns 'this' object.
1461 */
1462 wxImage operator =(const wxImage& image);
1463};
1464
1465
e54c96f1 1466
23324ae1
FM
1467// ============================================================================
1468// Global functions/macros
1469// ============================================================================
1470
1471/**
1472 Initializes all available image handlers. For a list of available handlers,
1473 see wxImage.
7c913512 1474
4cc4bfaf 1475 @see wxImage, wxImageHandler
23324ae1
FM
1476*/
1477void wxInitAllImageHandlers();
1478