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