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