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