]> git.saurik.com Git - wxWidgets.git/blob - interface/image.h
revised other headers
[wxWidgets.git] / interface / image.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: image.h
3 // Purpose: interface of wxImageHandler
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxImageHandler
11 @wxheader{image.h}
12
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.
16
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.
21
22 @library{wxcore}
23 @category{FIXME}
24
25 @see wxImage, wxInitAllImageHandlers()
26 */
27 class wxImageHandler : public wxObject
28 {
29 public:
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 */
44 const wxString GetExtension() const;
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
51 @param stream
52 Opened input stream for reading image data. Currently, the stream must
53 support seeking.
54
55 @returns Number of available images. For most image handlers, this is 1
56 (exceptions are TIFF and ICO formats).
57 */
58 int GetImageCount(wxInputStream& stream);
59
60 /**
61 Gets the MIME type associated with this handler.
62 */
63 const wxString GetMimeType() const;
64
65 /**
66 Gets the name of this handler.
67 */
68 const wxString GetName() const;
69
70 /**
71 Gets the image type associated with this handler.
72 */
73 long GetType() const;
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
82 @param image
83 The image object which is to be affected by this operation.
84 @param stream
85 Opened input stream for reading image data.
86 @param verbose
87 If set to @true, errors reported by the image handler will produce
88 wxLogMessages.
89 @param index
90 The index of the image in the file (starting from zero).
91
92 @returns @true if the operation succeeded, @false otherwise.
93
94 @see wxImage::LoadFile, wxImage::SaveFile, SaveFile()
95 */
96 bool LoadFile(wxImage* image, wxInputStream& stream,
97 bool verbose = true, int index = 0);
98
99 /**
100 Saves a image in the output stream.
101
102 @param image
103 The image object which is to be affected by this operation.
104 @param stream
105 Opened output stream for writing the data.
106
107 @returns @true if the operation succeeded, @false otherwise.
108
109 @see wxImage::LoadFile, wxImage::SaveFile, LoadFile()
110 */
111 bool SaveFile(wxImage* image, wxOutputStream& stream);
112
113 /**
114 Sets the handler extension.
115
116 @param extension
117 Handler extension.
118 */
119 void SetExtension(const wxString& extension);
120
121 /**
122 Sets the handler MIME type.
123
124 @param mimename
125 Handler MIME type.
126 */
127 void SetMimeType(const wxString& mimetype);
128
129 /**
130 Sets the handler name.
131
132 @param name
133 Handler name.
134 */
135 void SetName(const wxString& name);
136 };
137
138
139
140 /**
141 @class wxImage
142 @ingroup group_class_gdi
143 @wxheader{image.h}
144
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.
151
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.
157
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.
161
162 @library{wxcore}
163 @category{gdi}
164
165 @see wxBitmap, wxInitAllImageHandlers()
166 */
167 class wxImage : public wxObject
168 {
169 public:
170 //@{
171 /**
172 Creates an image from XPM data.
173
174 @param width
175 Specifies the width of the image.
176 @param height
177 Specifies the height of the image.
178 @param name
179 Name of the file from which to load the image.
180 @param stream
181 Opened input stream from which to load the image. Currently, the stream
182 must support seeking.
183 @param type
184 May be one of the following:
185
186
187
188
189
190
191 wxBITMAP_TYPE_BMP
192
193
194
195
196 Load a Windows bitmap file.
197
198
199
200
201
202 wxBITMAP_TYPE_GIF
203
204
205
206
207 Load a GIF bitmap file.
208
209
210
211
212
213 wxBITMAP_TYPE_JPEG
214
215
216
217
218 Load a JPEG bitmap file.
219
220
221
222
223
224 wxBITMAP_TYPE_PNG
225
226
227
228
229 Load a PNG bitmap file.
230
231
232
233
234
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.
340 @param xpmData
341 A pointer to XPM image data.
342
343 @remarks Depending on how wxWidgets has been configured, not all formats
344 may be available.
345
346 @see LoadFile()
347 */
348 wxImage();
349 wxImage(const wxImage& image);
350 wxImage(const wxBitmap& bitmap);
351 wxImage(int width, int height, bool clear = true);
352 wxImage(int width, int height, unsigned char* data,
353 bool static_data = false);
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);
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);
377 See also bool CanRead(const wxString& filename);
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
386 @see @ref horzblur() BlurHorizontal, @ref vertblur() BlurVertical
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
394 @see Blur(), @ref vertblur() BlurVertical
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
402 @see Blur(), @ref horzblur() BlurHorizontal
403 */
404 wxImage BlurVertical(int blurRadius);
405
406 /**
407 Deletes all image handlers.
408 This function is called by wxWidgets on exit.
409 */
410 static void CleanUpHandlers();
411
412 /**
413 Computes the histogram of the image. @a histogram is a reference to
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 */
419 unsigned long ComputeHistogram(wxImageHistogram& histogram) const;
420
421 /**
422 If the image has alpha channel, this method converts it to mask. All pixels
423 with alpha value less than @a threshold are replaced with mask colour
424 and the alpha channel is removed. Mask colour is chosen automatically using
425 FindFirstUnusedColour().
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 */
437 wxBitmap ConvertToBitmap() const;
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,
446 double lb = 0.114) const;
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,
454 unsigned char b) const;
455
456 /**
457 Returns an identical copy of the image.
458 */
459 wxImage Copy() const;
460
461 /**
462 Creates a fresh image. If @a clear is @true, the new image will be initialized
463 to black.
464 Otherwise, the image data will be uninitialized.
465
466 @param width
467 The width of the image in pixels.
468 @param height
469 The height of the image in pixels.
470
471 @returns @true if the call succeeded, @false otherwise.
472 */
473 bool Create(int width, int height, bool clear = true);
474
475 /**
476 Destroys the image data.
477 */
478 void Destroy();
479
480 /**
481 @param r,g,b
482 Pointers to variables to save the colour.
483 @param startR,startG,startB
484 Initial values of the colour. Returned colour
485 will have RGB values equal to or greater than these.
486
487 @returns Returns @false if there is no unused colour left, @true on success.
488 */
489 bool FindFirstUnusedColour(unsigned char* r, unsigned char* g,
490 unsigned char* b,
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
499 @param name
500 The handler name.
501 @param extension
502 The file extension, such as "bmp".
503 @param imageType
504 The image type, such as wxBITMAP_TYPE_BMP.
505 @param mimetype
506 MIME type.
507
508 @returns A pointer to the handler if found, @NULL otherwise.
509
510 @see wxImageHandler
511 */
512 static wxImageHandler* FindHandler(const wxString& name);
513 static wxImageHandler* FindHandler(const wxString& extension,
514 long imageType);
515 static wxImageHandler* FindHandler(long imageType);
516 static wxImageHandler* FindHandlerMime(const wxString& mimetype);
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 */
526 unsigned char GetAlpha(int x, int y) const;
527 const unsigned char * GetAlpha() const;
528 //@}
529
530 /**
531 Returns the blue intensity at the given coordinate.
532 */
533 unsigned char GetBlue(int x, int y) const;
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.
543 You should not delete the returned pointer nor pass it to
544 SetData().
545 */
546 unsigned char* GetData() const;
547
548 /**
549 Returns the green intensity at the given coordinate.
550 */
551 unsigned char GetGreen(int x, int y) const;
552
553 /**
554 Returns the static list of image format handlers.
555
556 @see wxImageHandler
557 */
558 static wxList GetHandlers();
559
560 /**
561 Gets the height of the image in pixels.
562 */
563 int GetHeight() const;
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
571 @param name
572 Name of the file to query.
573 @param stream
574 Opened input stream with image data. Currently, the stream must support
575 seeking.
576 @param type
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
663
664
665
666 Load a XPM bitmap file.
667
668
669
670
671
672 wxBITMAP_TYPE_ICO
673
674
675
676
677 Load a Windows icon file (ICO).
678
679
680
681
682
683 wxBITMAP_TYPE_CUR
684
685
686
687
688 Load a Windows cursor file (CUR).
689
690
691
692
693
694 wxBITMAP_TYPE_ANI
695
696
697
698
699 Load a Windows animated cursor file (ANI).
700
701
702
703
704
705 wxBITMAP_TYPE_ANY
706
707
708
709
710 Will try to autodetect the format.
711
712 @returns Number of available images. For most image handlers, this is 1
713 (exceptions are TIFF and ICO formats).
714 */
715 static int GetImageCount(const wxString& filename,
716 long type = wxBITMAP_TYPE_ANY);
717 static int GetImageCount(wxInputStream& stream,
718 long type = wxBITMAP_TYPE_ANY);
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
727 "(*.ext1;*.ext2)|*.ext1;*.ext2".
728
729 @see wxImageHandler
730 */
731 static wxString GetImageExtWildcard();
732
733 /**
734 Gets the blue value of the mask colour.
735 */
736 unsigned char GetMaskBlue() const;
737
738 /**
739 Gets the green value of the mask colour.
740 */
741 unsigned char GetMaskGreen() const;
742
743 /**
744 Gets the red value of the mask colour.
745 */
746 unsigned char GetMaskRed() const;
747
748 /**
749 Gets a user-defined option. The function is case-insensitive to @e name.
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
753 @see SetOption(), GetOptionInt(), HasOption()
754 */
755 wxString GetOption(const wxString& name) const;
756
757 /**
758 Gets a user-defined option as an integer. The function is case-insensitive to
759 @e name.
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.
763 Options for wxPNGHandler
764
765 wxIMAGE_OPTION_PNG_FORMAT
766
767 Format for saving a PNG file.
768
769 wxIMAGE_OPTION_PNG_BITDEPTH
770
771 Bit depth for every channel (R/G/B/A).
772
773 Supported values for wxIMAGE_OPTION_PNG_FORMAT:
774
775 wxPNG_TYPE_COLOUR
776
777 Stores RGB image.
778
779 wxPNG_TYPE_GREY
780
781 Stores grey image, converts from RGB.
782
783 wxPNG_TYPE_GREY_RED
784
785 Stores grey image, uses red value as grey.
786
787 @see SetOption(), GetOption()
788 */
789 int GetOptionInt(const wxString& name) const;
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,
796 unsigned char b) const;
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 */
804 const wxPalette GetPalette() const;
805
806 /**
807 Returns the red intensity at the given coordinate.
808 */
809 unsigned char GetRed(int x, int y) const;
810
811 /**
812 Returns a sub image of the current one as long as the rect belongs entirely to
813 the image.
814 */
815 wxImage GetSubImage(const wxRect& rect) const;
816
817 /**
818 Gets the width of the image in pixels.
819
820 @see GetHeight()
821 */
822 int GetWidth() const;
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 */
831 HSVValue(double h = 0.0, double s = 0.0, double v = 0.0);
832
833 /**
834 Converts a color in HSV color space to RGB color space.
835 */
836 #define wxImage::RGBValue HSVtoRGB(const HSVValue& hsv) /* implementation is private */
837
838 /**
839 Returns @true if this image has alpha channel, @false otherwise.
840
841 @see GetAlpha(), SetAlpha()
842 */
843 bool HasAlpha() const;
844
845 /**
846 Returns @true if there is a mask active, @false otherwise.
847 */
848 bool HasMask() const;
849
850 /**
851 Returns @true if the given option is present. The function is case-insensitive
852 to @e name.
853
854 @see SetOption(), GetOption(), GetOptionInt()
855 */
856 bool HasOption(const wxString& name) const;
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.
869 This function is called by wxWidgets on startup, and shouldn't be called by
870 the user.
871
872 @see wxImageHandler, wxInitAllImageHandlers(), wxQuantize
873 */
874 static void InitStandardHandlers();
875
876 /**
877 Adds a handler at the start of the static list of format handlers.
878
879 @param handler
880 A new image format handler object. There is usually only one instance
881 of a given handler class in an application session.
882
883 @see wxImageHandler
884 */
885 static void InsertHandler(wxImageHandler* handler);
886
887 /**
888 Returns @true if image data is present.
889 */
890 bool IsOk() const;
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 */
897 bool IsTransparent(int x, int y, unsigned char threshold = 128) const;
898
899 //@{
900 /**
901 Loads an image from an input stream.
902
903 @param name
904 Name of the file from which to load the image.
905 @param stream
906 Opened input stream from which to load the image. Currently, the stream
907 must support seeking.
908 @param type
909 One of the following values:
910
911
912
913
914
915
916 wxBITMAP_TYPE_BMP
917
918
919
920
921 Load a Windows image file.
922
923
924
925
926
927 wxBITMAP_TYPE_GIF
928
929
930
931
932 Load a GIF image file.
933
934
935
936
937
938 wxBITMAP_TYPE_JPEG
939
940
941
942
943 Load a JPEG image file.
944
945
946
947
948
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).
1032
1033
1034
1035
1036
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')
1045 @param index
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.
1054
1055 @returns @true if the operation succeeded, @false otherwise. If the
1056 optional index parameter is out of range, @false is
1057 returned and a call to wxLogError() takes place.
1058
1059 @remarks Depending on how wxWidgets has been configured, not all formats
1060 may be available.
1061
1062 @see SaveFile()
1063 */
1064 bool LoadFile(const wxString& name,
1065 long type = wxBITMAP_TYPE_ANY,
1066 int index = -1);
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);
1074 //@}
1075
1076 /**
1077 Returns a mirrored copy of the image. The parameter @e horizontally
1078 indicates the orientation.
1079 */
1080 wxImage Mirror(bool horizontally = true) const;
1081
1082 /**
1083 Copy the data of the given @a image to the specified position in this image.
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 */
1094 RGBValue(unsigned char r = 0, unsigned char g = 0,
1095 unsigned char b = 0);
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
1106 @param name
1107 The handler name.
1108
1109 @returns @true if the handler was found and removed, @false otherwise.
1110
1111 @see wxImageHandler
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.
1126 For a description of the @a quality parameter, see the Scale() function.
1127 Returns the (modified) image itself.
1128
1129 @see Scale()
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
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
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.
1142 Returns the (modified) image itself.
1143
1144 @see Size()
1145 */
1146 wxImage Resize(const wxSize& size, const wxPoint pos,
1147 int red = -1, int green = -1,
1148 int blue = -1);
1149
1150 /**
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
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.
1155 Returns the rotated image, leaving this image intact.
1156 */
1157 wxImage Rotate(double angle, const wxPoint& rotationCentre,
1158 bool interpolating = true,
1159 wxPoint* offsetAfterRotation = NULL);
1160
1161 /**
1162 Returns a copy of the image rotated 90 degrees in the direction
1163 indicated by @e clockwise.
1164 */
1165 wxImage Rotate90(bool clockwise = true) const;
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
1179 @param name
1180 Name of the file to save the image to.
1181 @param stream
1182 Opened output stream to save the image to.
1183 @param type
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
1223
1224 wxBITMAP_TYPE_PCX
1225
1226
1227
1228
1229 Save a PCX image file (tries to save as 8-bit if possible, falls back to
1230 24-bit otherwise).
1231
1232
1233
1234
1235
1236 wxBITMAP_TYPE_PNM
1237
1238
1239
1240
1241 Save a PNM image file (as raw RGB always).
1242
1243
1244
1245
1246
1247 wxBITMAP_TYPE_TIFF
1248
1249
1250
1251
1252 Save a TIFF image file.
1253
1254
1255
1256
1257
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).
1287 @param mimetype
1288 MIME type.
1289
1290 @returns @true if the operation succeeded, @false otherwise.
1291
1292 @remarks Depending on how wxWidgets has been configured, not all formats
1293 may be available.
1294
1295 @see LoadFile()
1296 */
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;
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.
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.
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.
1323 Example:
1324
1325 @param quality
1326 Determines what method to use for resampling the image. Can be one of the
1327 following:
1328
1329
1330
1331
1332
1333
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
1351 downsampling respectively
1352
1353 @see Rescale()
1354 */
1355 wxImage Scale(int width, int height,
1356 int quality = wxIMAGE_QUALITY_NORMAL) const;
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 */
1364 void SetAlpha(unsigned char* alpha = NULL,
1365 bool static_data = false);
1366 void SetAlpha(int x, int y, unsigned char alpha);
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.
1373 The data must have been allocated with @c malloc(), @b NOT with
1374 @c operator new.
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 */
1386 void SetMask(bool hasMask = true);
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 /**
1395 @param mask
1396 The mask image to extract mask shape from. Must have same dimensions as the
1397 image.
1398 @param mr,mg,mb
1399 RGB value of pixels in mask that will be used to create the mask.
1400
1401 @returns Returns @false if mask does not have same dimensions as the image
1402 or if there is no unused colour left. Returns @true if
1403 the mask was successfully applied.
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.
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
1415 @see GetOption(), GetOptionInt(), HasOption()
1416 */
1417 void SetOption(const wxString& name, const wxString& value);
1418 void SetOption(const wxString& name, int value);
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 */
1434 void SetRGB(wxRect& rect, unsigned char red,
1435 unsigned char green,
1436 unsigned char blue);
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
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
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
1449 @see Resize()
1450 */
1451 wxImage Size(const wxSize& size, const wxPoint pos, int red = -1,
1452 int green = -1, int blue = -1) const;
1453
1454 /**
1455 Assignment operator, using @ref overview_trefcount "reference counting".
1456
1457 @param image
1458 Image to assign.
1459
1460 @returns Returns 'this' object.
1461 */
1462 wxImage operator =(const wxImage& image);
1463 };
1464
1465
1466
1467 // ============================================================================
1468 // Global functions/macros
1469 // ============================================================================
1470
1471 /**
1472 Initializes all available image handlers. For a list of available handlers,
1473 see wxImage.
1474
1475 @see wxImage, wxImageHandler
1476 */
1477 void wxInitAllImageHandlers();
1478