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