]>
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$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxImageHandler | |
7c913512 | 11 | |
b3623ed5 RR |
12 | This is the base class for implementing image file loading/saving, and |
13 | image creation from data. | |
23324ae1 | 14 | It is used within wxImage and is not normally seen by the application. |
7c913512 | 15 | |
23324ae1 | 16 | If you wish to extend the capabilities of wxImage, derive a class from |
b3623ed5 | 17 | wxImageHandler and add the handler using wxImage::AddHandler in your |
23324ae1 | 18 | application initialisation. |
7c913512 | 19 | |
427c415b FM |
20 | Note that all wxImageHandlers provided by wxWidgets are part of |
21 | the @ref page_libs_wxcore library. | |
22 | For details about the default handlers, please see the section | |
23 | @ref image_handlers in the wxImage class documentation. | |
24 | ||
25 | ||
26 | @section imagehandler_note Note (Legal Issue) | |
27 | ||
28 | This software is based in part on the work of the Independent JPEG Group. | |
29 | (Applies when wxWidgets is linked with JPEG support. | |
30 | wxJPEGHandler uses libjpeg created by IJG.) | |
31 | ||
32 | ||
b3623ed5 RR |
33 | @stdobjects |
34 | ::wxNullImage | |
35 | ||
23324ae1 | 36 | @library{wxcore} |
427c415b | 37 | @category{misc} |
7c913512 | 38 | |
e54c96f1 | 39 | @see wxImage, wxInitAllImageHandlers() |
23324ae1 FM |
40 | */ |
41 | class wxImageHandler : public wxObject | |
42 | { | |
43 | public: | |
44 | /** | |
427c415b FM |
45 | Default constructor. |
46 | ||
47 | In your own default constructor, initialise the members | |
23324ae1 FM |
48 | m_name, m_extension and m_type. |
49 | */ | |
50 | wxImageHandler(); | |
51 | ||
52 | /** | |
53 | Destroys the wxImageHandler object. | |
54 | */ | |
adaaa686 | 55 | virtual ~wxImageHandler(); |
23324ae1 FM |
56 | |
57 | /** | |
58 | Gets the file extension associated with this handler. | |
59 | */ | |
427c415b | 60 | const wxString& GetExtension() const; |
23324ae1 FM |
61 | |
62 | /** | |
63 | If the image file contains more than one image and the image handler is capable | |
64 | of retrieving these individually, this function will return the number of | |
65 | available images. | |
3c4f71cc | 66 | |
7c913512 | 67 | @param stream |
427c415b FM |
68 | Opened input stream for reading image data. |
69 | Currently, the stream must support seeking. | |
3c4f71cc | 70 | |
d29a9a8a | 71 | @return Number of available images. For most image handlers, this is 1 |
427c415b | 72 | (exceptions are TIFF and ICO formats). |
23324ae1 | 73 | */ |
adaaa686 | 74 | virtual int GetImageCount(wxInputStream& stream); |
23324ae1 FM |
75 | |
76 | /** | |
77 | Gets the MIME type associated with this handler. | |
78 | */ | |
427c415b | 79 | const wxString& GetMimeType() const; |
23324ae1 FM |
80 | |
81 | /** | |
82 | Gets the name of this handler. | |
83 | */ | |
427c415b | 84 | const wxString& GetName() const; |
23324ae1 FM |
85 | |
86 | /** | |
87 | Gets the image type associated with this handler. | |
88 | */ | |
e98e625c | 89 | wxBitmapType GetType() const; |
23324ae1 FM |
90 | |
91 | /** | |
427c415b FM |
92 | Loads a image from a stream, putting the resulting data into @a image. |
93 | ||
94 | If the image file contains more than one image and the image handler is | |
95 | capable of retrieving these individually, @a index indicates which image | |
96 | to read from the stream. | |
3c4f71cc | 97 | |
7c913512 | 98 | @param image |
4cc4bfaf | 99 | The image object which is to be affected by this operation. |
7c913512 | 100 | @param stream |
4cc4bfaf | 101 | Opened input stream for reading image data. |
7c913512 | 102 | @param verbose |
4cc4bfaf | 103 | If set to @true, errors reported by the image handler will produce |
427c415b | 104 | wxLogMessages. |
7c913512 | 105 | @param index |
4cc4bfaf | 106 | The index of the image in the file (starting from zero). |
3c4f71cc | 107 | |
d29a9a8a | 108 | @return @true if the operation succeeded, @false otherwise. |
3c4f71cc | 109 | |
4cc4bfaf | 110 | @see wxImage::LoadFile, wxImage::SaveFile, SaveFile() |
23324ae1 FM |
111 | */ |
112 | bool LoadFile(wxImage* image, wxInputStream& stream, | |
4cc4bfaf | 113 | bool verbose = true, int index = 0); |
23324ae1 FM |
114 | |
115 | /** | |
116 | Saves a image in the output stream. | |
3c4f71cc | 117 | |
7c913512 | 118 | @param image |
4cc4bfaf | 119 | The image object which is to be affected by this operation. |
7c913512 | 120 | @param stream |
4cc4bfaf | 121 | Opened output stream for writing the data. |
3c4f71cc | 122 | |
d29a9a8a | 123 | @return @true if the operation succeeded, @false otherwise. |
3c4f71cc | 124 | |
4cc4bfaf | 125 | @see wxImage::LoadFile, wxImage::SaveFile, LoadFile() |
23324ae1 FM |
126 | */ |
127 | bool SaveFile(wxImage* image, wxOutputStream& stream); | |
128 | ||
129 | /** | |
130 | Sets the handler extension. | |
3c4f71cc | 131 | |
7c913512 | 132 | @param extension |
4cc4bfaf | 133 | Handler extension. |
23324ae1 FM |
134 | */ |
135 | void SetExtension(const wxString& extension); | |
136 | ||
137 | /** | |
138 | Sets the handler MIME type. | |
3c4f71cc | 139 | |
427c415b | 140 | @param mimetype |
4cc4bfaf | 141 | Handler MIME type. |
23324ae1 FM |
142 | */ |
143 | void SetMimeType(const wxString& mimetype); | |
144 | ||
145 | /** | |
146 | Sets the handler name. | |
3c4f71cc | 147 | |
7c913512 | 148 | @param name |
4cc4bfaf | 149 | Handler name. |
23324ae1 FM |
150 | */ |
151 | void SetName(const wxString& name); | |
152 | }; | |
153 | ||
154 | ||
427c415b FM |
155 | /** |
156 | Constant used to indicate the alpha value conventionally defined as | |
157 | the complete transparency. | |
158 | */ | |
159 | const unsigned char wxIMAGE_ALPHA_TRANSPARENT = 0; | |
160 | ||
161 | /** | |
162 | Constant used to indicate the alpha value conventionally defined as | |
163 | the complete opacity. | |
164 | */ | |
165 | const unsigned char wxIMAGE_ALPHA_OPAQUE = 0xff; | |
e54c96f1 | 166 | |
23324ae1 FM |
167 | /** |
168 | @class wxImage | |
7c913512 | 169 | |
427c415b FM |
170 | This class encapsulates a platform-independent image. |
171 | ||
172 | An image can be created from data, or using wxBitmap::ConvertToImage. | |
173 | An image can be loaded from a file in a variety of formats, and is extensible | |
174 | to new formats via image format handlers. Functions are available to set and | |
b3623ed5 | 175 | get image bits, so it can be used for basic image manipulation. |
7c913512 | 176 | |
427c415b FM |
177 | A wxImage cannot (currently) be drawn directly to a wxDC. |
178 | Instead, a platform-specific wxBitmap object must be created from it using | |
23324ae1 | 179 | the wxBitmap::wxBitmap(wxImage,int depth) constructor. |
b3623ed5 | 180 | This bitmap can then be drawn in a device context, using wxDC::DrawBitmap. |
7c913512 | 181 | |
23324ae1 | 182 | One colour value of the image may be used as a mask colour which will lead to |
65874118 | 183 | the automatic creation of a wxMask object associated to the bitmap object. |
7c913512 | 184 | |
427c415b FM |
185 | |
186 | @section image_alpha Alpha channel support | |
187 | ||
188 | Starting from wxWidgets 2.5.0 wxImage supports alpha channel data, that is | |
189 | in addition to a byte for the red, green and blue colour components for each | |
190 | pixel it also stores a byte representing the pixel opacity. | |
191 | ||
192 | An alpha value of 0 corresponds to a transparent pixel (null opacity) while | |
193 | a value of 255 means that the pixel is 100% opaque. | |
194 | The constants ::wxIMAGE_ALPHA_TRANSPARENT and ::wxIMAGE_ALPHA_OPAQUE can be | |
195 | used to indicate those values in a more readable form. | |
196 | ||
197 | Unlike RGB data, not all images have an alpha channel and before using | |
198 | wxImage::GetAlpha you should check if this image contains an alpha channel | |
199 | with wxImage::HasAlpha. Note that currently only the PNG format has full | |
200 | alpha channel support so only the images loaded from PNG files can have | |
201 | alpha and, if you initialize the image alpha channel yourself using | |
202 | wxImage::SetAlpha, you should save it in PNG format to avoid losing it. | |
203 | ||
204 | ||
205 | @section image_handlers Available image handlers | |
206 | ||
207 | The following image handlers are available. | |
208 | wxBMPHandler is always installed by default. | |
209 | To use other image formats, install the appropriate handler with | |
210 | wxImage::AddHandler or call ::wxInitAllImageHandlers(). | |
211 | ||
212 | - wxBMPHandler: For loading and saving, always installed. | |
213 | - wxPNGHandler: For loading (including alpha support) and saving. | |
214 | - wxJPEGHandler: For loading and saving. | |
215 | - wxGIFHandler: Only for loading, due to legal issues. | |
216 | - wxPCXHandler: For loading and saving (see below). | |
217 | - wxPNMHandler: For loading and saving (see below). | |
218 | - wxTIFFHandler: For loading and saving. | |
219 | - wxTGAHandler: For loading only. | |
220 | - wxIFFHandler: For loading only. | |
221 | - wxXPMHandler: For loading and saving. | |
222 | - wxICOHandler: For loading and saving. | |
223 | - wxCURHandler: For loading and saving. | |
224 | - wxANIHandler: For loading only. | |
225 | ||
226 | When saving in PCX format, wxPCXHandler will count the number of different | |
227 | colours in the image; if there are 256 or less colours, it will save as 8 bit, | |
228 | else it will save as 24 bit. | |
229 | ||
230 | Loading PNMs only works for ASCII or raw RGB images. | |
231 | When saving in PNM format, wxPNMHandler will always save as raw RGB. | |
232 | ||
233 | ||
23324ae1 FM |
234 | @library{wxcore} |
235 | @category{gdi} | |
7c913512 | 236 | |
65874118 FM |
237 | @stdobjects |
238 | ::wxNullImage | |
239 | ||
4e2cddc4 | 240 | @see wxBitmap, wxInitAllImageHandlers(), wxPixelData |
23324ae1 FM |
241 | */ |
242 | class wxImage : public wxObject | |
243 | { | |
244 | public: | |
427c415b FM |
245 | class RGBValue |
246 | { | |
247 | public: | |
248 | /** | |
249 | Constructor for RGBValue, an object that contains values for red, green | |
250 | and blue which represent the value of a color. | |
251 | ||
252 | It is used by wxImage::HSVtoRGB and wxImage::RGBtoHSV, which converts | |
253 | between HSV color space and RGB color space. | |
254 | */ | |
255 | RGBValue(unsigned char r=0, unsigned char g=0, unsigned char b=0); | |
256 | }; | |
257 | ||
258 | class HSVValue | |
259 | { | |
260 | public: | |
261 | /** | |
262 | Constructor for HSVValue, an object that contains values for hue, saturation | |
263 | and value which represent the value of a color. | |
264 | ||
265 | It is used by wxImage::HSVtoRGB() and wxImage::RGBtoHSV(), which converts | |
266 | between HSV color space and RGB color space. | |
267 | */ | |
268 | HSVValue(double h=0.0, double s=0.0, double v=0.0); | |
269 | }; | |
270 | ||
271 | /** | |
272 | Creates an empty wxImage object without an alpha channel. | |
b3623ed5 RR |
273 | */ |
274 | wxImage(); | |
e98e625c | 275 | |
b3623ed5 | 276 | /** |
ff3050e1 VZ |
277 | Creates an image with the given size and clears it if requested. |
278 | ||
279 | Does not create an alpha channel. | |
e98e625c | 280 | |
b3623ed5 RR |
281 | @param width |
282 | Specifies the width of the image. | |
283 | @param height | |
284 | Specifies the height of the image. | |
ff3050e1 VZ |
285 | @param clear |
286 | If @true, initialize the image to black. | |
b3623ed5 RR |
287 | */ |
288 | wxImage(int width, int height, bool clear = true); | |
e98e625c | 289 | |
23324ae1 | 290 | /** |
427c415b | 291 | Creates an image from data in memory. If @a static_data is @false |
dd067e96 RR |
292 | then the wxImage will take ownership of the data and free it |
293 | afterwards. For this, it has to be allocated with @e malloc. | |
e98e625c | 294 | |
7c913512 | 295 | @param width |
4cc4bfaf | 296 | Specifies the width of the image. |
7c913512 | 297 | @param height |
4cc4bfaf | 298 | Specifies the height of the image. |
dd067e96 RR |
299 | @param data |
300 | A pointer to RGB data | |
4e2cddc4 RR |
301 | @param static_data |
302 | Indicates if the data should be free'd after use | |
e98e625c | 303 | |
dd067e96 | 304 | */ |
dd067e96 | 305 | wxImage(int width, int height, unsigned char* data, bool static_data = false); |
e98e625c | 306 | |
dd067e96 | 307 | /** |
427c415b | 308 | Creates an image from data in memory. If @a static_data is @false |
b3623ed5 RR |
309 | then the wxImage will take ownership of the data and free it |
310 | afterwards. For this, it has to be allocated with @e malloc. | |
e98e625c | 311 | |
dd067e96 RR |
312 | @param width |
313 | Specifies the width of the image. | |
314 | @param height | |
315 | Specifies the height of the image. | |
b3623ed5 RR |
316 | @param data |
317 | A pointer to RGB data | |
318 | @param alpha | |
319 | A pointer to alpha-channel data | |
320 | @param static_data | |
321 | Indicates if the data should be free'd after use | |
e98e625c | 322 | |
4e2cddc4 | 323 | */ |
427c415b FM |
324 | wxImage(int width, int height, unsigned char* data, unsigned char* alpha, |
325 | bool static_data = false ); | |
e98e625c | 326 | |
dd067e96 RR |
327 | /** |
328 | Creates an image from XPM data. | |
e98e625c | 329 | |
dd067e96 RR |
330 | @param xpmData |
331 | A pointer to XPM image data. | |
332 | */ | |
333 | wxImage(const char* const* xpmData); | |
e98e625c | 334 | |
dd067e96 | 335 | /** |
b3623ed5 | 336 | Creates an image from a file. |
e98e625c | 337 | |
7c913512 | 338 | @param name |
4cc4bfaf | 339 | Name of the file from which to load the image. |
7c913512 | 340 | @param type |
4cc4bfaf | 341 | May be one of the following: |
4e2cddc4 RR |
342 | @li wxBITMAP_TYPE_BMP: Load a Windows bitmap file. |
343 | @li wxBITMAP_TYPE_GIF: Load a GIF bitmap file. | |
344 | @li wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file. | |
345 | @li wxBITMAP_TYPE_PNG: Load a PNG bitmap file. | |
346 | @li wxBITMAP_TYPE_PCX: Load a PCX bitmap file. | |
347 | @li wxBITMAP_TYPE_PNM: Load a PNM bitmap file. | |
348 | @li wxBITMAP_TYPE_TIF: Load a TIFF bitmap file. | |
349 | @li wxBITMAP_TYPE_TGA: Load a TGA bitmap file. | |
350 | @li wxBITMAP_TYPE_XPM: Load a XPM bitmap file. | |
351 | @li wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO). | |
352 | @li wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR). | |
353 | @li wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI). | |
354 | @li wxBITMAP_TYPE_ANY: Will try to autodetect the format. | |
4cc4bfaf FM |
355 | @param index |
356 | Index of the image to load in the case that the image file contains | |
dd067e96 RR |
357 | multiple images. This is only used by GIF, ICO and TIFF handlers. |
358 | The default value (-1) means "choose the default image" and is | |
359 | interpreted as the first image (index=0) by the GIF and TIFF handler | |
360 | and as the largest and most colourful one by the ICO handler. | |
3c4f71cc | 361 | |
427c415b FM |
362 | @remarks Depending on how wxWidgets has been configured and by which |
363 | handlers have been loaded, not all formats may be available. | |
364 | Any handler other than BMP must be previously initialized with | |
365 | wxImage::AddHandler or wxInitAllImageHandlers. | |
366 | ||
367 | @note | |
368 | You can use GetOptionInt() to get the hotspot when loading cursor files: | |
369 | @code | |
370 | int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X); | |
371 | int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y); | |
372 | @endcode | |
3c4f71cc | 373 | |
4cc4bfaf | 374 | @see LoadFile() |
23324ae1 | 375 | */ |
e98e625c VZ |
376 | wxImage(const wxString& name, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1); |
377 | ||
b3623ed5 RR |
378 | /** |
379 | Creates an image from a file using MIME-types to specify the type. | |
e98e625c | 380 | |
b3623ed5 RR |
381 | @param name |
382 | Name of the file from which to load the image. | |
b3623ed5 RR |
383 | @param mimetype |
384 | MIME type string (for example 'image/jpeg') | |
385 | @param index | |
427c415b | 386 | See description in wxImage(const wxString&, wxBitmapType, int) overload. |
b3623ed5 | 387 | */ |
dd067e96 | 388 | wxImage(const wxString& name, const wxString& mimetype, int index = -1); |
e98e625c | 389 | |
b3623ed5 RR |
390 | /** |
391 | Creates an image from a stream. | |
e98e625c | 392 | |
b3623ed5 RR |
393 | @param stream |
394 | Opened input stream from which to load the image. Currently, | |
395 | the stream must support seeking. | |
396 | @param type | |
427c415b | 397 | See description in wxImage(const wxString&, wxBitmapType, int) overload. |
b3623ed5 | 398 | @param index |
427c415b | 399 | See description in wxImage(const wxString&, wxBitmapType, int) overload. |
b3623ed5 | 400 | */ |
e98e625c VZ |
401 | wxImage(wxInputStream& stream, wxBitmapType type = wxBITMAP_TYPE_ANY, int index = -1); |
402 | ||
b3623ed5 RR |
403 | /** |
404 | Creates an image from a stream using MIME-types to specify the type. | |
e98e625c | 405 | |
b3623ed5 RR |
406 | @param stream |
407 | Opened input stream from which to load the image. Currently, | |
408 | the stream must support seeking. | |
409 | @param mimetype | |
410 | MIME type string (for example 'image/jpeg') | |
411 | @param index | |
427c415b | 412 | See description in wxImage(const wxString&, wxBitmapType, int) overload. |
b3623ed5 | 413 | */ |
dd067e96 | 414 | wxImage(wxInputStream& stream, const wxString& mimetype, int index = -1); |
e98e625c | 415 | |
23324ae1 FM |
416 | |
417 | /** | |
418 | Destructor. | |
427c415b FM |
419 | |
420 | See @ref overview_refcount_destruct "reference-counted object destruction" | |
421 | for more info. | |
23324ae1 | 422 | */ |
adaaa686 | 423 | virtual ~wxImage(); |
23324ae1 | 424 | |
23324ae1 | 425 | /** |
b3623ed5 | 426 | Register an image handler. |
23324ae1 FM |
427 | */ |
428 | static void AddHandler(wxImageHandler* handler); | |
23324ae1 FM |
429 | |
430 | /** | |
b3623ed5 | 431 | Blurs the image in both horizontal and vertical directions by the |
427c415b | 432 | specified pixel @a blurRadius. This should not be used when using |
b3623ed5 | 433 | a single mask colour for transparency. |
3c4f71cc | 434 | |
b3623ed5 | 435 | @see BlurHorizontal(), BlurVertical() |
23324ae1 | 436 | */ |
adaaa686 | 437 | wxImage Blur(int blurRadius) const; |
23324ae1 FM |
438 | |
439 | /** | |
440 | Blurs the image in the horizontal direction only. This should not be used | |
441 | when using a single mask colour for transparency. | |
3c4f71cc | 442 | |
b3623ed5 | 443 | @see Blur(), BlurVertical() |
23324ae1 | 444 | */ |
adaaa686 | 445 | wxImage BlurHorizontal(int blurRadius) const; |
23324ae1 FM |
446 | |
447 | /** | |
448 | Blurs the image in the vertical direction only. This should not be used | |
449 | when using a single mask colour for transparency. | |
3c4f71cc | 450 | |
b3623ed5 | 451 | @see Blur(), BlurHorizontal() |
23324ae1 | 452 | */ |
adaaa686 | 453 | wxImage BlurVertical(int blurRadius) const; |
e98e625c | 454 | |
b3623ed5 RR |
455 | /** |
456 | Returns @true if the current image handlers can read this file | |
457 | */ | |
adaaa686 | 458 | static bool CanRead(const wxString& filename); |
23324ae1 FM |
459 | |
460 | /** | |
461 | Deletes all image handlers. | |
23324ae1 FM |
462 | This function is called by wxWidgets on exit. |
463 | */ | |
464 | static void CleanUpHandlers(); | |
465 | ||
466 | /** | |
4cc4bfaf | 467 | Computes the histogram of the image. @a histogram is a reference to |
23324ae1 FM |
468 | wxImageHistogram object. wxImageHistogram is a specialization of |
469 | wxHashMap "template" and is defined as follows: | |
3c4f71cc | 470 | |
427c415b FM |
471 | @code |
472 | class WXDLLEXPORT wxImageHistogramEntry | |
473 | { | |
474 | public: | |
475 | wxImageHistogramEntry() : index(0), value(0) {} | |
476 | unsigned long index; | |
477 | unsigned long value; | |
478 | }; | |
479 | ||
480 | WX_DECLARE_EXPORTED_HASH_MAP(unsigned long, wxImageHistogramEntry, | |
481 | wxIntegerHash, wxIntegerEqual, | |
482 | wxImageHistogram); | |
483 | @endcode | |
484 | ||
d29a9a8a | 485 | @return Returns number of colours in the histogram. |
23324ae1 | 486 | */ |
328f5751 | 487 | unsigned long ComputeHistogram(wxImageHistogram& histogram) const; |
23324ae1 FM |
488 | |
489 | /** | |
427c415b FM |
490 | If the image has alpha channel, this method converts it to mask. |
491 | ||
492 | All pixels with alpha value less than @a threshold are replaced with mask | |
493 | colour and the alpha channel is removed. Mask colour is chosen automatically | |
494 | using FindFirstUnusedColour(). | |
495 | ||
496 | If the image image doesn't have alpha channel, ConvertAlphaToMask() does nothing. | |
3c4f71cc | 497 | |
d29a9a8a | 498 | @return @false if FindFirstUnusedColour returns @false, @true otherwise. |
23324ae1 FM |
499 | */ |
500 | bool ConvertAlphaToMask(unsigned char threshold = 128); | |
501 | ||
502 | /** | |
427c415b FM |
503 | @deprecated |
504 | Use the equivalent @ref wxBitmap::wxBitmap "wxBitmap constructor" | |
23324ae1 FM |
505 | (which takes wxImage and depth as its arguments) instead. |
506 | */ | |
328f5751 | 507 | wxBitmap ConvertToBitmap() const; |
23324ae1 FM |
508 | |
509 | /** | |
427c415b FM |
510 | Returns a greyscale version of the image. |
511 | ||
512 | The returned image uses the luminance component of the original to | |
513 | calculate the greyscale. Defaults to using the standard ITU-T BT.601 | |
514 | when converting to YUV, where every pixel equals | |
515 | (R * @a lr) + (G * @a lg) + (B * @a lb). | |
23324ae1 FM |
516 | */ |
517 | wxImage ConvertToGreyscale(double lr = 0.299, double lg = 0.587, | |
328f5751 | 518 | double lb = 0.114) const; |
23324ae1 FM |
519 | |
520 | /** | |
427c415b FM |
521 | Returns monochromatic version of the image. |
522 | ||
523 | The returned image has white colour where the original has @e (r,g,b) | |
524 | colour and black colour everywhere else. | |
23324ae1 | 525 | */ |
427c415b | 526 | wxImage ConvertToMono(unsigned char r, unsigned char g, unsigned char b) const; |
23324ae1 FM |
527 | |
528 | /** | |
529 | Returns an identical copy of the image. | |
530 | */ | |
328f5751 | 531 | wxImage Copy() const; |
23324ae1 FM |
532 | |
533 | /** | |
ff3050e1 VZ |
534 | Creates a fresh image. |
535 | ||
536 | If @a clear is @true, the new image will be initialized to black. | |
23324ae1 | 537 | Otherwise, the image data will be uninitialized. |
3c4f71cc | 538 | |
7c913512 | 539 | @param width |
4cc4bfaf | 540 | The width of the image in pixels. |
7c913512 | 541 | @param height |
4cc4bfaf | 542 | The height of the image in pixels. |
ff3050e1 VZ |
543 | @param clear |
544 | If @true, initialize the image data with zeros. | |
3c4f71cc | 545 | |
d29a9a8a | 546 | @return @true if the call succeeded, @false otherwise. |
23324ae1 | 547 | */ |
4cc4bfaf | 548 | bool Create(int width, int height, bool clear = true); |
23324ae1 FM |
549 | |
550 | /** | |
551 | Destroys the image data. | |
552 | */ | |
553 | void Destroy(); | |
554 | ||
555 | /** | |
427c415b FM |
556 | Finds the first colour that is never used in the image. |
557 | The search begins at given initial colour and continues by increasing | |
558 | R, G and B components (in this order) by 1 until an unused colour is | |
559 | found or the colour space exhausted. | |
560 | ||
561 | The parameters @a r, @a g, @a b are pointers to variables to save the colour. | |
562 | ||
563 | The parameters @a startR, @a startG, @a startB define the initial values | |
564 | of the colour. | |
565 | The returned colour will have RGB values equal to or greater than these. | |
3c4f71cc | 566 | |
d29a9a8a | 567 | @return Returns @false if there is no unused colour left, @true on success. |
427c415b FM |
568 | |
569 | @note | |
570 | This method involves computing the histogram, which is a | |
571 | computationally intensive operation. | |
23324ae1 | 572 | */ |
4cc4bfaf | 573 | bool FindFirstUnusedColour(unsigned char* r, unsigned char* g, |
adaaa686 | 574 | unsigned char* b, unsigned char startR = 1, |
23324ae1 | 575 | unsigned char startG = 0, |
adaaa686 | 576 | unsigned char startB = 0) const; |
23324ae1 | 577 | |
23324ae1 | 578 | /** |
427c415b | 579 | Finds the handler with the given name. |
3c4f71cc | 580 | |
7c913512 | 581 | @param name |
4cc4bfaf | 582 | The handler name. |
427c415b FM |
583 | |
584 | @return A pointer to the handler if found, @NULL otherwise. | |
585 | ||
586 | @see wxImageHandler | |
587 | */ | |
588 | static wxImageHandler* FindHandler(const wxString& name); | |
589 | ||
590 | /** | |
591 | Finds the handler associated with the given extension and type. | |
592 | ||
7c913512 | 593 | @param extension |
4cc4bfaf | 594 | The file extension, such as "bmp". |
7c913512 | 595 | @param imageType |
427c415b | 596 | The image type; one of the ::wxBitmapType values. |
3c4f71cc | 597 | |
d29a9a8a | 598 | @return A pointer to the handler if found, @NULL otherwise. |
3c4f71cc | 599 | |
4cc4bfaf | 600 | @see wxImageHandler |
23324ae1 | 601 | */ |
7c913512 | 602 | static wxImageHandler* FindHandler(const wxString& extension, |
e98e625c | 603 | wxBitmapType imageType); |
427c415b FM |
604 | |
605 | /** | |
606 | Finds the handler associated with the given image type. | |
607 | ||
608 | @param imageType | |
609 | The image type; one of the ::wxBitmapType values. | |
610 | ||
611 | @return A pointer to the handler if found, @NULL otherwise. | |
612 | ||
613 | @see wxImageHandler | |
614 | */ | |
e98e625c | 615 | static wxImageHandler* FindHandler(wxBitmapType imageType); |
427c415b FM |
616 | |
617 | /** | |
618 | Finds the handler associated with the given MIME type. | |
619 | ||
620 | @param mimetype | |
621 | MIME type. | |
622 | ||
623 | @return A pointer to the handler if found, @NULL otherwise. | |
624 | ||
625 | @see wxImageHandler | |
626 | */ | |
7c913512 | 627 | static wxImageHandler* FindHandlerMime(const wxString& mimetype); |
23324ae1 | 628 | |
b3623ed5 RR |
629 | /** |
630 | Return alpha value at given pixel location. | |
631 | */ | |
632 | unsigned char GetAlpha(int x, int y) const; | |
e98e625c | 633 | |
23324ae1 | 634 | /** |
427c415b FM |
635 | Returns pointer to the array storing the alpha values for this image. |
636 | ||
637 | This pointer is @NULL for the images without the alpha channel. If the image | |
23324ae1 | 638 | does have it, this pointer may be used to directly manipulate the alpha values |
b3623ed5 | 639 | which are stored as the RGB ones. |
23324ae1 | 640 | */ |
328f5751 | 641 | const unsigned char * GetAlpha() const; |
23324ae1 FM |
642 | |
643 | /** | |
644 | Returns the blue intensity at the given coordinate. | |
645 | */ | |
328f5751 | 646 | unsigned char GetBlue(int x, int y) const; |
23324ae1 FM |
647 | |
648 | /** | |
427c415b FM |
649 | Returns the image data as an array. |
650 | ||
651 | This is most often used when doing direct image manipulation. | |
652 | The return value points to an array of characters in RGBRGBRGB... format | |
653 | in the top-to-bottom, left-to-right order, that is the first RGB triplet | |
654 | corresponds to the pixel first pixel of the first row, the second one --- | |
655 | to the second pixel of the first row and so on until the end of the first | |
656 | row, with second row following after it and so on. | |
657 | ||
658 | You should not delete the returned pointer nor pass it to SetData(). | |
23324ae1 | 659 | */ |
328f5751 | 660 | unsigned char* GetData() const; |
23324ae1 FM |
661 | |
662 | /** | |
663 | Returns the green intensity at the given coordinate. | |
664 | */ | |
328f5751 | 665 | unsigned char GetGreen(int x, int y) const; |
23324ae1 FM |
666 | |
667 | /** | |
668 | Returns the static list of image format handlers. | |
3c4f71cc | 669 | |
4cc4bfaf | 670 | @see wxImageHandler |
23324ae1 FM |
671 | */ |
672 | static wxList GetHandlers(); | |
673 | ||
674 | /** | |
675 | Gets the height of the image in pixels. | |
676 | */ | |
328f5751 | 677 | int GetHeight() const; |
23324ae1 FM |
678 | |
679 | //@{ | |
680 | /** | |
427c415b FM |
681 | If the image file contains more than one image and the image handler is |
682 | capable of retrieving these individually, this function will return the | |
683 | number of available images. | |
684 | ||
685 | For the overload taking the parameter @a filename, that's the name | |
686 | of the file to query. | |
687 | For the overload taking the parameter @a stream, that's the ppened input | |
688 | stream with image data. Currently, the stream must support seeking. | |
689 | ||
690 | The parameter @a type may be one of the following values: | |
691 | @li wxBITMAP_TYPE_BMP: Load a Windows bitmap file. | |
692 | @li wxBITMAP_TYPE_GIF: Load a GIF bitmap file. | |
693 | @li wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file. | |
694 | @li wxBITMAP_TYPE_PNG: Load a PNG bitmap file. | |
695 | @li wxBITMAP_TYPE_PCX: Load a PCX bitmap file. | |
696 | @li wxBITMAP_TYPE_PNM: Load a PNM bitmap file. | |
697 | @li wxBITMAP_TYPE_TIF: Load a TIFF bitmap file. | |
698 | @li wxBITMAP_TYPE_TGA: Load a TGA bitmap file. | |
699 | @li wxBITMAP_TYPE_XPM: Load a XPM bitmap file. | |
700 | @li wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO). | |
701 | @li wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR). | |
702 | @li wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI). | |
703 | @li wxBITMAP_TYPE_ANY: Will try to autodetect the format. | |
3c4f71cc | 704 | |
d29a9a8a | 705 | @return Number of available images. For most image handlers, this is 1 |
427c415b | 706 | (exceptions are TIFF and ICO formats). |
23324ae1 FM |
707 | */ |
708 | static int GetImageCount(const wxString& filename, | |
e98e625c | 709 | wxBitmapType type = wxBITMAP_TYPE_ANY); |
7c913512 | 710 | static int GetImageCount(wxInputStream& stream, |
e98e625c | 711 | wxBitmapType type = wxBITMAP_TYPE_ANY); |
23324ae1 FM |
712 | //@} |
713 | ||
714 | /** | |
715 | Iterates all registered wxImageHandler objects, and returns a string containing | |
427c415b FM |
716 | file extension masks suitable for passing to file open/save dialog boxes. |
717 | ||
718 | @return The format of the returned string is @c "(*.ext1;*.ext2)|*.ext1;*.ext2". | |
719 | It is usually a good idea to prepend a description before passing | |
720 | the result to the dialog. | |
721 | Example: | |
722 | @code | |
723 | wxFileDialog FileDlg( this, "Choose Image", ::wxGetCwd(), "", | |
724 | _("Image Files ") + wxImage::GetImageExtWildcard(), | |
725 | wxFD_OPEN ); | |
726 | @endcode | |
3c4f71cc | 727 | |
4cc4bfaf | 728 | @see wxImageHandler |
23324ae1 FM |
729 | */ |
730 | static wxString GetImageExtWildcard(); | |
731 | ||
732 | /** | |
733 | Gets the blue value of the mask colour. | |
734 | */ | |
328f5751 | 735 | unsigned char GetMaskBlue() const; |
23324ae1 FM |
736 | |
737 | /** | |
738 | Gets the green value of the mask colour. | |
739 | */ | |
328f5751 | 740 | unsigned char GetMaskGreen() const; |
23324ae1 FM |
741 | |
742 | /** | |
743 | Gets the red value of the mask colour. | |
744 | */ | |
328f5751 | 745 | unsigned char GetMaskRed() const; |
23324ae1 FM |
746 | |
747 | /** | |
427c415b FM |
748 | Gets a user-defined option. The function is case-insensitive to @a name. |
749 | ||
23324ae1 FM |
750 | For example, when saving as a JPEG file, the option @b quality is |
751 | used, which is a number between 0 and 100 (0 is terrible, 100 is very good). | |
3c4f71cc | 752 | |
4cc4bfaf | 753 | @see SetOption(), GetOptionInt(), HasOption() |
23324ae1 | 754 | */ |
328f5751 | 755 | wxString GetOption(const wxString& name) const; |
23324ae1 FM |
756 | |
757 | /** | |
427c415b FM |
758 | Gets a user-defined option as an integer. |
759 | The function is case-insensitive to @a name. | |
760 | If the given option is not present, the function returns 0. | |
4e2cddc4 | 761 | Use HasOption() is 0 is a possibly valid value for the option. |
427c415b FM |
762 | |
763 | Options for wxPNGHandler: | |
4e2cddc4 RR |
764 | @li wxIMAGE_OPTION_PNG_FORMAT: Format for saving a PNG file. |
765 | @li wxIMAGE_OPTION_PNG_BITDEPTH: Bit depth for every channel (R/G/B/A). | |
e98e625c | 766 | |
23324ae1 | 767 | Supported values for wxIMAGE_OPTION_PNG_FORMAT: |
4e2cddc4 RR |
768 | @li wxPNG_TYPE_COLOUR: Stores RGB image. |
769 | @li wxPNG_TYPE_GREY: Stores grey image, converts from RGB. | |
770 | @li wxPNG_TYPE_GREY_RED: Stores grey image, uses red value as grey. | |
3c4f71cc | 771 | |
4cc4bfaf | 772 | @see SetOption(), GetOption() |
23324ae1 | 773 | */ |
328f5751 | 774 | int GetOptionInt(const wxString& name) const; |
23324ae1 FM |
775 | |
776 | /** | |
777 | Get the current mask colour or find a suitable unused colour that could be | |
778 | used as a mask colour. Returns @true if the image currently has a mask. | |
779 | */ | |
780 | bool GetOrFindMaskColour(unsigned char r, unsigned char g, | |
328f5751 | 781 | unsigned char b) const; |
23324ae1 FM |
782 | |
783 | /** | |
427c415b FM |
784 | Returns the palette associated with the image. |
785 | Currently the palette is only used when converting to wxBitmap under Windows. | |
786 | ||
787 | Some of the wxImage handlers have been modified to set the palette if | |
788 | one exists in the image file (usually 256 or less colour images in | |
789 | GIF or PNG format). | |
23324ae1 | 790 | */ |
427c415b | 791 | const wxPalette& GetPalette() const; |
23324ae1 FM |
792 | |
793 | /** | |
794 | Returns the red intensity at the given coordinate. | |
795 | */ | |
328f5751 | 796 | unsigned char GetRed(int x, int y) const; |
23324ae1 FM |
797 | |
798 | /** | |
427c415b FM |
799 | Returns a sub image of the current one as long as the rect belongs entirely |
800 | to the image. | |
23324ae1 | 801 | */ |
328f5751 | 802 | wxImage GetSubImage(const wxRect& rect) const; |
23324ae1 | 803 | |
591d3fa2 | 804 | /** |
427c415b FM |
805 | Gets the type of image found by LoadFile() or specified with SaveFile(). |
806 | ||
591d3fa2 VZ |
807 | @since 2.9.0 |
808 | */ | |
809 | wxBitmapType GetType() const; | |
810 | ||
23324ae1 FM |
811 | /** |
812 | Gets the width of the image in pixels. | |
3c4f71cc | 813 | |
4cc4bfaf | 814 | @see GetHeight() |
23324ae1 | 815 | */ |
328f5751 | 816 | int GetWidth() const; |
23324ae1 | 817 | |
23324ae1 FM |
818 | /** |
819 | Converts a color in HSV color space to RGB color space. | |
820 | */ | |
427c415b | 821 | wxImage::RGBValue HSVtoRGB(const wxImage::HSVValue & hsv); |
23324ae1 FM |
822 | |
823 | /** | |
824 | Returns @true if this image has alpha channel, @false otherwise. | |
3c4f71cc | 825 | |
4cc4bfaf | 826 | @see GetAlpha(), SetAlpha() |
23324ae1 | 827 | */ |
328f5751 | 828 | bool HasAlpha() const; |
23324ae1 FM |
829 | |
830 | /** | |
831 | Returns @true if there is a mask active, @false otherwise. | |
832 | */ | |
328f5751 | 833 | bool HasMask() const; |
23324ae1 FM |
834 | |
835 | /** | |
427c415b FM |
836 | Returns @true if the given option is present. |
837 | The function is case-insensitive to @a name. | |
3c4f71cc | 838 | |
4cc4bfaf | 839 | @see SetOption(), GetOption(), GetOptionInt() |
23324ae1 | 840 | */ |
328f5751 | 841 | bool HasOption(const wxString& name) const; |
23324ae1 FM |
842 | |
843 | /** | |
427c415b FM |
844 | Initializes the image alpha channel data. |
845 | ||
846 | It is an error to call it if the image already has alpha data. | |
847 | If it doesn't, alpha data will be by default initialized to all pixels | |
848 | being fully opaque. But if the image has a mask colour, all mask pixels | |
849 | will be completely transparent. | |
23324ae1 FM |
850 | */ |
851 | void InitAlpha(); | |
852 | ||
853 | /** | |
427c415b FM |
854 | Internal use only. Adds standard image format handlers. |
855 | It only install wxBMPHandler for the time being, which is used by wxBitmap. | |
856 | ||
23324ae1 FM |
857 | This function is called by wxWidgets on startup, and shouldn't be called by |
858 | the user. | |
3c4f71cc | 859 | |
e54c96f1 | 860 | @see wxImageHandler, wxInitAllImageHandlers(), wxQuantize |
23324ae1 FM |
861 | */ |
862 | static void InitStandardHandlers(); | |
863 | ||
864 | /** | |
865 | Adds a handler at the start of the static list of format handlers. | |
3c4f71cc | 866 | |
7c913512 | 867 | @param handler |
4cc4bfaf FM |
868 | A new image format handler object. There is usually only one instance |
869 | of a given handler class in an application session. | |
3c4f71cc | 870 | |
4cc4bfaf | 871 | @see wxImageHandler |
23324ae1 FM |
872 | */ |
873 | static void InsertHandler(wxImageHandler* handler); | |
874 | ||
875 | /** | |
876 | Returns @true if image data is present. | |
877 | */ | |
328f5751 | 878 | bool IsOk() const; |
23324ae1 FM |
879 | |
880 | /** | |
881 | Returns @true if the given pixel is transparent, i.e. either has the mask | |
882 | colour if this image has a mask or if this image has alpha channel and alpha | |
427c415b | 883 | value of this pixel is strictly less than @a threshold. |
23324ae1 | 884 | */ |
328f5751 | 885 | bool IsTransparent(int x, int y, unsigned char threshold = 128) const; |
23324ae1 | 886 | |
23324ae1 FM |
887 | /** |
888 | Loads an image from an input stream. | |
3c4f71cc | 889 | |
7c913512 | 890 | @param stream |
427c415b FM |
891 | Opened input stream from which to load the image. |
892 | Currently, the stream must support seeking. | |
7c913512 | 893 | @param type |
dd067e96 | 894 | May be one of the following: |
4e2cddc4 RR |
895 | @li wxBITMAP_TYPE_BMP: Load a Windows bitmap file. |
896 | @li wxBITMAP_TYPE_GIF: Load a GIF bitmap file. | |
897 | @li wxBITMAP_TYPE_JPEG: Load a JPEG bitmap file. | |
898 | @li wxBITMAP_TYPE_PNG: Load a PNG bitmap file. | |
899 | @li wxBITMAP_TYPE_PCX: Load a PCX bitmap file. | |
900 | @li wxBITMAP_TYPE_PNM: Load a PNM bitmap file. | |
901 | @li wxBITMAP_TYPE_TIF: Load a TIFF bitmap file. | |
902 | @li wxBITMAP_TYPE_TGA: Load a TGA bitmap file. | |
903 | @li wxBITMAP_TYPE_XPM: Load a XPM bitmap file. | |
904 | @li wxBITMAP_TYPE_ICO: Load a Windows icon file (ICO). | |
905 | @li wxBITMAP_TYPE_CUR: Load a Windows cursor file (CUR). | |
906 | @li wxBITMAP_TYPE_ANI: Load a Windows animated cursor file (ANI). | |
907 | @li wxBITMAP_TYPE_ANY: Will try to autodetect the format. | |
7c913512 | 908 | @param index |
4cc4bfaf | 909 | Index of the image to load in the case that the image file contains |
dd067e96 RR |
910 | multiple images. This is only used by GIF, ICO and TIFF handlers. |
911 | The default value (-1) means "choose the default image" and is | |
912 | interpreted as the first image (index=0) by the GIF and TIFF handler | |
913 | and as the largest and most colourful one by the ICO handler. | |
3c4f71cc | 914 | |
427c415b FM |
915 | @return @true if the operation succeeded, @false otherwise. |
916 | If the optional index parameter is out of range, @false is | |
917 | returned and a call to wxLogError() takes place. | |
3c4f71cc | 918 | |
23324ae1 | 919 | @remarks Depending on how wxWidgets has been configured, not all formats |
4cc4bfaf | 920 | may be available. |
3c4f71cc | 921 | |
427c415b FM |
922 | @note |
923 | You can use GetOptionInt() to get the hotspot when loading cursor files: | |
924 | @code | |
925 | int hotspot_x = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X); | |
926 | int hotspot_y = image.GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y); | |
927 | @endcode | |
928 | ||
4cc4bfaf | 929 | @see SaveFile() |
23324ae1 | 930 | */ |
427c415b FM |
931 | bool LoadFile(wxInputStream& stream, wxBitmapType type, int index = -1); |
932 | ||
933 | /** | |
934 | Loads an image from a file. | |
935 | If no handler type is provided, the library will try to autodetect the format. | |
936 | ||
937 | @param name | |
938 | Name of the file from which to load the image. | |
939 | @param type | |
940 | See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload. | |
941 | @param index | |
942 | See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload. | |
943 | */ | |
7323ff1a FM |
944 | virtual bool LoadFile(const wxString& name, |
945 | wxBitmapType type = wxBITMAP_TYPE_ANY, | |
946 | int index = -1); | |
427c415b FM |
947 | |
948 | /** | |
949 | Loads an image from a file. | |
950 | If no handler type is provided, the library will try to autodetect the format. | |
951 | ||
952 | @param name | |
953 | Name of the file from which to load the image. | |
954 | @param mimetype | |
955 | MIME type string (for example 'image/jpeg') | |
956 | @param index | |
957 | See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload. | |
958 | */ | |
fadc2df6 FM |
959 | virtual bool LoadFile(const wxString& name, const wxString& mimetype, |
960 | int index = -1); | |
427c415b FM |
961 | |
962 | ||
963 | /** | |
964 | Loads an image from an input stream. | |
965 | ||
966 | @param stream | |
967 | Opened input stream from which to load the image. | |
968 | Currently, the stream must support seeking. | |
969 | @param mimetype | |
970 | MIME type string (for example 'image/jpeg') | |
971 | @param index | |
972 | See the description in the LoadFile(wxInputStream&, wxBitmapType, int) overload. | |
973 | */ | |
7323ff1a FM |
974 | virtual bool LoadFile(wxInputStream& stream, const wxString& mimetype, |
975 | int index = -1); | |
23324ae1 FM |
976 | |
977 | /** | |
427c415b FM |
978 | Returns a mirrored copy of the image. |
979 | The parameter @a horizontally indicates the orientation. | |
23324ae1 | 980 | */ |
328f5751 | 981 | wxImage Mirror(bool horizontally = true) const; |
23324ae1 FM |
982 | |
983 | /** | |
4cc4bfaf | 984 | Copy the data of the given @a image to the specified position in this image. |
23324ae1 FM |
985 | */ |
986 | void Paste(const wxImage& image, int x, int y); | |
987 | ||
23324ae1 FM |
988 | /** |
989 | Converts a color in RGB color space to HSV color space. | |
990 | */ | |
427c415b | 991 | wxImage::HSVValue RGBtoHSV(const wxImage::RGBValue& rgb); |
23324ae1 FM |
992 | |
993 | /** | |
427c415b FM |
994 | Finds the handler with the given name, and removes it. |
995 | The handler is not deleted. | |
3c4f71cc | 996 | |
7c913512 | 997 | @param name |
4cc4bfaf | 998 | The handler name. |
3c4f71cc | 999 | |
d29a9a8a | 1000 | @return @true if the handler was found and removed, @false otherwise. |
3c4f71cc | 1001 | |
4cc4bfaf | 1002 | @see wxImageHandler |
23324ae1 FM |
1003 | */ |
1004 | static bool RemoveHandler(const wxString& name); | |
1005 | ||
1006 | /** | |
1007 | Replaces the colour specified by @e r1,g1,b1 by the colour @e r2,g2,b2. | |
1008 | */ | |
1009 | void Replace(unsigned char r1, unsigned char g1, | |
1010 | unsigned char b1, unsigned char r2, | |
1011 | unsigned char g2, unsigned char b2); | |
1012 | ||
1013 | /** | |
1014 | Changes the size of the image in-place by scaling it: after a call to this | |
427c415b FM |
1015 | function,the image will have the given width and height. |
1016 | ||
4cc4bfaf | 1017 | For a description of the @a quality parameter, see the Scale() function. |
23324ae1 | 1018 | Returns the (modified) image itself. |
3c4f71cc | 1019 | |
4cc4bfaf | 1020 | @see Scale() |
23324ae1 FM |
1021 | */ |
1022 | wxImage Rescale(int width, int height, | |
1023 | int quality = wxIMAGE_QUALITY_NORMAL); | |
1024 | ||
1025 | /** | |
1026 | Changes the size of the image in-place without scaling it by adding either a | |
427c415b FM |
1027 | border with the given colour or cropping as necessary. |
1028 | ||
1029 | The image is pasted into a new image with the given @a size and background | |
1030 | colour at the position @a pos relative to the upper left of the new image. | |
1031 | ||
1032 | If @a red = green = blue = -1 then use either the current mask colour | |
1033 | if set or find, use, and set a suitable mask colour for any newly exposed | |
1034 | areas. | |
1035 | ||
1036 | @return The (modified) image itself. | |
3c4f71cc | 1037 | |
4cc4bfaf | 1038 | @see Size() |
23324ae1 | 1039 | */ |
427c415b | 1040 | wxImage Resize(const wxSize& size, const wxPoint& pos, |
23324ae1 FM |
1041 | int red = -1, int green = -1, |
1042 | int blue = -1); | |
1043 | ||
1044 | /** | |
427c415b FM |
1045 | Rotates the image about the given point, by @a angle radians. |
1046 | ||
1047 | Passing @true to @a interpolating results in better image quality, but is slower. | |
1048 | ||
1049 | If the image has a mask, then the mask colour is used for the uncovered | |
1050 | pixels in the rotated image background. Else, black (rgb 0, 0, 0) will be used. | |
1051 | ||
23324ae1 FM |
1052 | Returns the rotated image, leaving this image intact. |
1053 | */ | |
1054 | wxImage Rotate(double angle, const wxPoint& rotationCentre, | |
4cc4bfaf | 1055 | bool interpolating = true, |
adaaa686 | 1056 | wxPoint* offsetAfterRotation = NULL) const; |
23324ae1 FM |
1057 | |
1058 | /** | |
1059 | Returns a copy of the image rotated 90 degrees in the direction | |
427c415b | 1060 | indicated by @a clockwise. |
23324ae1 | 1061 | */ |
328f5751 | 1062 | wxImage Rotate90(bool clockwise = true) const; |
23324ae1 FM |
1063 | |
1064 | /** | |
1065 | Rotates the hue of each pixel in the image by @e angle, which is a double in | |
1066 | the range of -1.0 to +1.0, where -1.0 corresponds to -360 degrees and +1.0 | |
427c415b | 1067 | corresponds to +360 degrees. |
23324ae1 FM |
1068 | */ |
1069 | void RotateHue(double angle); | |
1070 | ||
23324ae1 FM |
1071 | /** |
1072 | Saves an image in the given stream. | |
3c4f71cc | 1073 | |
7c913512 | 1074 | @param stream |
4cc4bfaf | 1075 | Opened output stream to save the image to. |
427c415b FM |
1076 | @param mimetype |
1077 | MIME type. | |
1078 | ||
1079 | @return @true if the operation succeeded, @false otherwise. | |
1080 | ||
1081 | @remarks Depending on how wxWidgets has been configured, not all formats | |
1082 | may be available. | |
1083 | ||
1084 | @note | |
1085 | You can use SetOption() to set the hotspot when saving an image | |
1086 | into a cursor file (default hotspot is in the centre of the image): | |
1087 | @code | |
1088 | image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotspotX); | |
1089 | image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotspotY); | |
1090 | @endcode | |
1091 | ||
1092 | @see LoadFile() | |
1093 | */ | |
fadc2df6 FM |
1094 | virtual bool SaveFile(wxOutputStream& stream, |
1095 | const wxString& mimetype) const; | |
427c415b FM |
1096 | |
1097 | /** | |
1098 | Saves an image in the named file. | |
1099 | ||
1100 | @param name | |
1101 | Name of the file to save the image to. | |
7c913512 | 1102 | @param type |
4cc4bfaf | 1103 | Currently these types can be used: |
4e2cddc4 RR |
1104 | @li wxBITMAP_TYPE_BMP: Save a BMP image file. |
1105 | @li wxBITMAP_TYPE_JPEG: Save a JPEG image file. | |
1106 | @li wxBITMAP_TYPE_PNG: Save a PNG image file. | |
427c415b FM |
1107 | @li wxBITMAP_TYPE_PCX: Save a PCX image file |
1108 | (tries to save as 8-bit if possible, falls back to 24-bit otherwise). | |
4e2cddc4 RR |
1109 | @li wxBITMAP_TYPE_PNM: Save a PNM image file (as raw RGB always). |
1110 | @li wxBITMAP_TYPE_TIFF: Save a TIFF image file. | |
1111 | @li wxBITMAP_TYPE_XPM: Save a XPM image file. | |
427c415b FM |
1112 | @li wxBITMAP_TYPE_ICO: Save a Windows icon file (ICO). |
1113 | The size may be up to 255 wide by 127 high. A single image is saved | |
1114 | in 8 colors at the size supplied. | |
4e2cddc4 | 1115 | @li wxBITMAP_TYPE_CUR: Save a Windows cursor file (CUR). |
427c415b | 1116 | */ |
7323ff1a | 1117 | virtual bool SaveFile(const wxString& name, wxBitmapType type) const; |
427c415b FM |
1118 | |
1119 | /** | |
1120 | Saves an image in the named file. | |
1121 | ||
1122 | @param name | |
1123 | Name of the file to save the image to. | |
7c913512 | 1124 | @param mimetype |
4cc4bfaf | 1125 | MIME type. |
427c415b | 1126 | */ |
fadc2df6 | 1127 | virtual bool SaveFile(const wxString& name, const wxString& mimetype) const; |
3c4f71cc | 1128 | |
427c415b FM |
1129 | /** |
1130 | Saves an image in the named file. | |
3c4f71cc | 1131 | |
427c415b FM |
1132 | File type is determined from the extension of the file name. |
1133 | Note that this function may fail if the extension is not recognized! | |
1134 | You can use one of the forms above to save images to files with | |
1135 | non-standard extensions. | |
3c4f71cc | 1136 | |
427c415b FM |
1137 | @param name |
1138 | Name of the file to save the image to. | |
23324ae1 | 1139 | */ |
7323ff1a | 1140 | virtual bool SaveFile(const wxString& name) const; |
427c415b FM |
1141 | |
1142 | /** | |
1143 | Saves an image in the given stream. | |
1144 | ||
1145 | @param stream | |
1146 | Opened output stream to save the image to. | |
1147 | @param type | |
1148 | MIME type. | |
1149 | */ | |
7323ff1a | 1150 | virtual bool SaveFile(wxOutputStream& stream, wxBitmapType type) const; |
23324ae1 FM |
1151 | |
1152 | /** | |
427c415b FM |
1153 | Returns a scaled version of the image. |
1154 | ||
1155 | This is also useful for scaling bitmaps in general as the only other way | |
1156 | to scale bitmaps is to blit a wxMemoryDC into another wxMemoryDC. | |
1157 | ||
1158 | The parameter @a quality determines what method to use for resampling the image. | |
1159 | Can be one of the following: | |
1160 | - wxIMAGE_QUALITY_NORMAL: Uses the normal default scaling method of pixel | |
1161 | replication | |
1162 | - wxIMAGE_QUALITY_HIGH: Uses bicubic and box averaging resampling methods | |
1163 | for upsampling and downsampling respectively | |
1164 | ||
1165 | It should be noted that although using @c wxIMAGE_QUALITY_HIGH produces much nicer | |
1166 | looking results it is a slower method. Downsampling will use the box averaging | |
1167 | method which seems to operate very fast. If you are upsampling larger images using | |
23324ae1 | 1168 | this method you will most likely notice that it is a bit slower and in extreme |
427c415b FM |
1169 | cases it will be quite substantially slower as the bicubic algorithm has to process a |
1170 | lot of data. | |
1171 | ||
23324ae1 FM |
1172 | It should also be noted that the high quality scaling may not work as expected |
1173 | when using a single mask colour for transparency, as the scaling will blur the | |
1174 | image and will therefore remove the mask partially. Using the alpha channel | |
1175 | will work. | |
e98e625c | 1176 | |
427c415b FM |
1177 | Example: |
1178 | @code | |
1179 | // get the bitmap from somewhere | |
1180 | wxBitmap bmp = ...; | |
1181 | ||
1182 | // rescale it to have size of 32*32 | |
1183 | if ( bmp.GetWidth() != 32 || bmp.GetHeight() != 32 ) | |
1184 | { | |
1185 | wxImage image = bmp.ConvertToImage(); | |
1186 | bmp = wxBitmap(image.Scale(32, 32)); | |
1187 | ||
1188 | // another possibility: | |
1189 | image.Rescale(32, 32); | |
1190 | bmp = image; | |
1191 | } | |
1192 | @endcode | |
3c4f71cc | 1193 | |
4cc4bfaf | 1194 | @see Rescale() |
23324ae1 FM |
1195 | */ |
1196 | wxImage Scale(int width, int height, | |
328f5751 | 1197 | int quality = wxIMAGE_QUALITY_NORMAL) const; |
23324ae1 | 1198 | |
e98e625c | 1199 | /** |
427c415b FM |
1200 | This function is similar to SetData() and has similar restrictions. |
1201 | ||
1202 | The pointer passed to it may however be @NULL in which case the function | |
1203 | will allocate the alpha array internally -- this is useful to add alpha | |
1204 | channel data to an image which doesn't have any. | |
1205 | ||
1206 | If the pointer is not @NULL, it must have one byte for each image pixel | |
1207 | and be allocated with malloc(). | |
1208 | wxImage takes ownership of the pointer and will free it unless @a static_data | |
1209 | parameter is set to @true -- in this case the caller should do it. | |
23324ae1 | 1210 | */ |
4cc4bfaf FM |
1211 | void SetAlpha(unsigned char* alpha = NULL, |
1212 | bool static_data = false); | |
e98e625c | 1213 | |
b3623ed5 | 1214 | /** |
427c415b FM |
1215 | Sets the alpha value for the given pixel. |
1216 | This function should only be called if the image has alpha channel data, | |
1217 | use HasAlpha() to check for this. | |
b3623ed5 | 1218 | */ |
7c913512 | 1219 | void SetAlpha(int x, int y, unsigned char alpha); |
23324ae1 FM |
1220 | |
1221 | /** | |
427c415b FM |
1222 | Sets the image data without performing checks. |
1223 | ||
1224 | The data given must have the size (width*height*3) or results will be | |
1225 | unexpected. Don't use this method if you aren't sure you know what you | |
1226 | are doing. | |
1227 | ||
23324ae1 FM |
1228 | The data must have been allocated with @c malloc(), @b NOT with |
1229 | @c operator new. | |
427c415b | 1230 | |
23324ae1 FM |
1231 | After this call the pointer to the data is owned by the wxImage object, |
1232 | that will be responsible for deleting it. | |
427c415b | 1233 | Do not pass to this function a pointer obtained through GetData(). |
23324ae1 FM |
1234 | */ |
1235 | void SetData(unsigned char* data); | |
1236 | ||
1237 | /** | |
427c415b FM |
1238 | Specifies whether there is a mask or not. |
1239 | ||
1240 | The area of the mask is determined by the current mask colour. | |
23324ae1 | 1241 | */ |
4cc4bfaf | 1242 | void SetMask(bool hasMask = true); |
23324ae1 FM |
1243 | |
1244 | /** | |
1245 | Sets the mask colour for this image (and tells the image to use the mask). | |
1246 | */ | |
1247 | void SetMaskColour(unsigned char red, unsigned char green, | |
1248 | unsigned char blue); | |
1249 | ||
1250 | /** | |
427c415b FM |
1251 | Sets image's mask so that the pixels that have RGB value of mr,mg,mb in |
1252 | mask will be masked in the image. | |
1253 | ||
1254 | This is done by first finding an unused colour in the image, setting | |
1255 | this colour as the mask colour and then using this colour to draw all | |
1256 | pixels in the image who corresponding pixel in mask has given RGB value. | |
1257 | ||
1258 | The parameter @a mask is the mask image to extract mask shape from. | |
1259 | It must have the same dimensions as the image. | |
1260 | ||
1261 | The parameters @a mr, @a mg, @a mb are the RGB values of the pixels in | |
1262 | mask that will be used to create the mask. | |
3c4f71cc | 1263 | |
d29a9a8a | 1264 | @return Returns @false if mask does not have same dimensions as the image |
427c415b FM |
1265 | or if there is no unused colour left. Returns @true if the mask |
1266 | was successfully applied. | |
1267 | ||
1268 | @note | |
1269 | Note that this method involves computing the histogram, which is a | |
1270 | computationally intensive operation. | |
23324ae1 FM |
1271 | */ |
1272 | bool SetMaskFromImage(const wxImage& mask, unsigned char mr, | |
1273 | unsigned char mg, | |
1274 | unsigned char mb); | |
1275 | ||
1276 | //@{ | |
1277 | /** | |
427c415b FM |
1278 | Sets a user-defined option. The function is case-insensitive to @a name. |
1279 | ||
23324ae1 FM |
1280 | For example, when saving as a JPEG file, the option @b quality is |
1281 | used, which is a number between 0 and 100 (0 is terrible, 100 is very good). | |
3c4f71cc | 1282 | |
4cc4bfaf | 1283 | @see GetOption(), GetOptionInt(), HasOption() |
23324ae1 FM |
1284 | */ |
1285 | void SetOption(const wxString& name, const wxString& value); | |
7c913512 | 1286 | void SetOption(const wxString& name, int value); |
23324ae1 FM |
1287 | //@} |
1288 | ||
1289 | /** | |
427c415b FM |
1290 | Associates a palette with the image. |
1291 | ||
1292 | The palette may be used when converting wxImage to wxBitmap (MSW only at present) | |
1293 | or in file save operations (none as yet). | |
23324ae1 FM |
1294 | */ |
1295 | void SetPalette(const wxPalette& palette); | |
1296 | ||
1297 | /** | |
427c415b FM |
1298 | Sets the colour of the pixels within the given rectangle. |
1299 | ||
1300 | This routine performs bounds-checks for the coordinate so it can be considered | |
1301 | a safe way to manipulate the data. | |
23324ae1 | 1302 | */ |
4cc4bfaf FM |
1303 | void SetRGB(wxRect& rect, unsigned char red, |
1304 | unsigned char green, | |
1305 | unsigned char blue); | |
23324ae1 | 1306 | |
9d1c7e84 VZ |
1307 | /** |
1308 | Set the type of image returned by GetType(). | |
1309 | ||
1310 | This method is mostly used internally by the library but can also be | |
1311 | called from the user code if the image was created from data in the | |
1312 | given bitmap format without using LoadFile() (which would set the type | |
1313 | correctly automatically). | |
1314 | ||
1315 | Notice that the image must be created before this function is called. | |
1316 | ||
1317 | @since 2.9.0 | |
1318 | ||
1319 | @param type | |
1320 | One of bitmap type constants, @c wxBITMAP_TYPE_INVALID is a valid | |
1321 | value for it and can be used to reset the bitmap type to default | |
1322 | but @c wxBITMAP_TYPE_MAX is not allowed here. | |
1323 | */ | |
1324 | void SetType(wxBitmapType type); | |
1325 | ||
23324ae1 FM |
1326 | /** |
1327 | Returns a resized version of this image without scaling it by adding either a | |
427c415b FM |
1328 | border with the given colour or cropping as necessary. |
1329 | ||
1330 | The image is pasted into a new image with the given @a size and background | |
1331 | colour at the position @a pos relative to the upper left of the new image. | |
1332 | ||
1333 | If @a red = green = blue = -1 then the areas of the larger image not covered | |
1334 | by this image are made transparent by filling them with the image mask colour | |
1335 | (which will be allocated automatically if it isn't currently set). | |
1336 | ||
1337 | Otherwise, the areas will be filled with the colour with the specified RGB components. | |
3c4f71cc | 1338 | |
4cc4bfaf | 1339 | @see Resize() |
23324ae1 | 1340 | */ |
427c415b | 1341 | wxImage Size(const wxSize& size, const wxPoint& pos, int red = -1, |
328f5751 | 1342 | int green = -1, int blue = -1) const; |
23324ae1 FM |
1343 | |
1344 | /** | |
427c415b | 1345 | Assignment operator, using @ref overview_refcount "reference counting". |
3c4f71cc | 1346 | |
7c913512 | 1347 | @param image |
4cc4bfaf | 1348 | Image to assign. |
3c4f71cc | 1349 | |
d29a9a8a | 1350 | @return Returns 'this' object. |
23324ae1 FM |
1351 | */ |
1352 | wxImage operator =(const wxImage& image); | |
1353 | }; | |
1354 | ||
23324ae1 FM |
1355 | // ============================================================================ |
1356 | // Global functions/macros | |
1357 | // ============================================================================ | |
1358 | ||
8cd06fb5 BP |
1359 | /** @ingroup group_funcmacro_appinitterm */ |
1360 | //@{ | |
1361 | ||
23324ae1 FM |
1362 | /** |
1363 | Initializes all available image handlers. For a list of available handlers, | |
1364 | see wxImage. | |
7c913512 | 1365 | |
4cc4bfaf | 1366 | @see wxImage, wxImageHandler |
027c1c27 BP |
1367 | |
1368 | @header{wx/image.h} | |
23324ae1 FM |
1369 | */ |
1370 | void wxInitAllImageHandlers(); | |
1371 | ||
8cd06fb5 BP |
1372 | //@} |
1373 |