1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/image.cpp
4 // Author: Robert Roebling
6 // Copyright: (c) Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
26 #include "wx/module.h"
27 #include "wx/palette.h"
31 #include "wx/filefn.h"
32 #include "wx/wfstream.h"
33 #include "wx/xpmdecod.h"
38 // make the code compile with either wxFile*Stream or wxFFile*Stream:
39 #define HAS_FILE_STREAMS (wxUSE_STREAMS && (wxUSE_FILE || wxUSE_FFILE))
43 typedef wxFFileInputStream wxImageFileInputStream
;
44 typedef wxFFileOutputStream wxImageFileOutputStream
;
46 typedef wxFileInputStream wxImageFileInputStream
;
47 typedef wxFileOutputStream wxImageFileOutputStream
;
48 #endif // wxUSE_FILE/wxUSE_FFILE
49 #endif // HAS_FILE_STREAMS
52 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxImage
,WXDLLEXPORT
)
55 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
59 wxList
wxImage::sm_handlers
;
62 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
66 class wxImageRefData
: public wxObjectRefData
70 virtual ~wxImageRefData();
75 unsigned char *m_data
;
78 unsigned char m_maskRed
,m_maskGreen
,m_maskBlue
;
80 // alpha channel data, may be NULL for the formats without alpha support
81 unsigned char *m_alpha
;
85 // if true, m_data is pointer to static data and shouldn't be freed
88 // same as m_static but for m_alpha
93 #endif // wxUSE_PALETTE
95 wxArrayString m_optionNames
;
96 wxArrayString m_optionValues
;
98 wxDECLARE_NO_COPY_CLASS(wxImageRefData
);
101 wxImageRefData::wxImageRefData()
105 m_type
= wxBITMAP_TYPE_INVALID
;
107 m_alpha
= (unsigned char *) NULL
;
116 m_staticAlpha
= false;
119 wxImageRefData::~wxImageRefData()
123 if ( !m_staticAlpha
)
128 //-----------------------------------------------------------------------------
130 //-----------------------------------------------------------------------------
132 #define M_IMGDATA static_cast<wxImageRefData*>(m_refData)
134 IMPLEMENT_DYNAMIC_CLASS(wxImage
, wxObject
)
136 bool wxImage::Create(const char* const* xpmData
)
141 wxXPMDecoder decoder
;
142 (*this) = decoder
.ReadData(xpmData
);
149 bool wxImage::Create( int width
, int height
, bool clear
)
153 m_refData
= new wxImageRefData();
155 M_IMGDATA
->m_data
= (unsigned char *) malloc( width
*height
*3 );
156 if (!M_IMGDATA
->m_data
)
162 M_IMGDATA
->m_width
= width
;
163 M_IMGDATA
->m_height
= height
;
164 M_IMGDATA
->m_ok
= true;
174 bool wxImage::Create( int width
, int height
, unsigned char* data
, bool static_data
)
178 wxCHECK_MSG( data
, false, wxT("NULL data in wxImage::Create") );
180 m_refData
= new wxImageRefData();
182 M_IMGDATA
->m_data
= data
;
183 M_IMGDATA
->m_width
= width
;
184 M_IMGDATA
->m_height
= height
;
185 M_IMGDATA
->m_ok
= true;
186 M_IMGDATA
->m_static
= static_data
;
191 bool wxImage::Create( int width
, int height
, unsigned char* data
, unsigned char* alpha
, bool static_data
)
195 wxCHECK_MSG( data
, false, wxT("NULL data in wxImage::Create") );
197 m_refData
= new wxImageRefData();
199 M_IMGDATA
->m_data
= data
;
200 M_IMGDATA
->m_alpha
= alpha
;
201 M_IMGDATA
->m_width
= width
;
202 M_IMGDATA
->m_height
= height
;
203 M_IMGDATA
->m_ok
= true;
204 M_IMGDATA
->m_static
= static_data
;
205 M_IMGDATA
->m_staticAlpha
= static_data
;
210 void wxImage::Destroy()
215 void wxImage::Clear(unsigned char value
)
217 memset(M_IMGDATA
->m_data
, value
, M_IMGDATA
->m_width
*M_IMGDATA
->m_height
*3);
220 wxObjectRefData
* wxImage::CreateRefData() const
222 return new wxImageRefData
;
225 wxObjectRefData
* wxImage::CloneRefData(const wxObjectRefData
* that
) const
227 const wxImageRefData
* refData
= static_cast<const wxImageRefData
*>(that
);
228 wxCHECK_MSG(refData
->m_ok
, NULL
, wxT("invalid image") );
230 wxImageRefData
* refData_new
= new wxImageRefData
;
231 refData_new
->m_width
= refData
->m_width
;
232 refData_new
->m_height
= refData
->m_height
;
233 refData_new
->m_maskRed
= refData
->m_maskRed
;
234 refData_new
->m_maskGreen
= refData
->m_maskGreen
;
235 refData_new
->m_maskBlue
= refData
->m_maskBlue
;
236 refData_new
->m_hasMask
= refData
->m_hasMask
;
237 refData_new
->m_ok
= true;
238 unsigned size
= unsigned(refData
->m_width
) * unsigned(refData
->m_height
);
239 if (refData
->m_alpha
!= NULL
)
241 refData_new
->m_alpha
= (unsigned char*)malloc(size
);
242 memcpy(refData_new
->m_alpha
, refData
->m_alpha
, size
);
245 refData_new
->m_data
= (unsigned char*)malloc(size
);
246 memcpy(refData_new
->m_data
, refData
->m_data
, size
);
248 refData_new
->m_palette
= refData
->m_palette
;
250 refData_new
->m_optionNames
= refData
->m_optionNames
;
251 refData_new
->m_optionValues
= refData
->m_optionValues
;
255 wxImage
wxImage::Copy() const
259 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
261 image
.m_refData
= CloneRefData(m_refData
);
266 wxImage
wxImage::ShrinkBy( int xFactor
, int yFactor
) const
268 if( xFactor
== 1 && yFactor
== 1 )
273 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
275 // can't scale to/from 0 size
276 wxCHECK_MSG( (xFactor
> 0) && (yFactor
> 0), image
,
277 wxT("invalid new image size") );
279 long old_height
= M_IMGDATA
->m_height
,
280 old_width
= M_IMGDATA
->m_width
;
282 wxCHECK_MSG( (old_height
> 0) && (old_width
> 0), image
,
283 wxT("invalid old image size") );
285 long width
= old_width
/ xFactor
;
286 long height
= old_height
/ yFactor
;
288 image
.Create( width
, height
, false );
290 char unsigned *data
= image
.GetData();
292 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
294 bool hasMask
= false ;
295 unsigned char maskRed
= 0;
296 unsigned char maskGreen
= 0;
297 unsigned char maskBlue
=0 ;
299 unsigned char *source_data
= M_IMGDATA
->m_data
;
300 unsigned char *target_data
= data
;
301 unsigned char *source_alpha
= 0 ;
302 unsigned char *target_alpha
= 0 ;
303 if (M_IMGDATA
->m_hasMask
)
306 maskRed
= M_IMGDATA
->m_maskRed
;
307 maskGreen
= M_IMGDATA
->m_maskGreen
;
308 maskBlue
=M_IMGDATA
->m_maskBlue
;
310 image
.SetMaskColour( M_IMGDATA
->m_maskRed
,
311 M_IMGDATA
->m_maskGreen
,
312 M_IMGDATA
->m_maskBlue
);
316 source_alpha
= M_IMGDATA
->m_alpha
;
320 target_alpha
= image
.GetAlpha() ;
324 for (long y
= 0; y
< height
; y
++)
326 for (long x
= 0; x
< width
; x
++)
328 unsigned long avgRed
= 0 ;
329 unsigned long avgGreen
= 0;
330 unsigned long avgBlue
= 0;
331 unsigned long avgAlpha
= 0 ;
332 unsigned long counter
= 0 ;
334 for ( int y1
= 0 ; y1
< yFactor
; ++y1
)
336 long y_offset
= (y
* yFactor
+ y1
) * old_width
;
337 for ( int x1
= 0 ; x1
< xFactor
; ++x1
)
339 unsigned char *pixel
= source_data
+ 3 * ( y_offset
+ x
* xFactor
+ x1
) ;
340 unsigned char red
= pixel
[0] ;
341 unsigned char green
= pixel
[1] ;
342 unsigned char blue
= pixel
[2] ;
343 unsigned char alpha
= 255 ;
345 alpha
= *(source_alpha
+ y_offset
+ x
* xFactor
+ x1
) ;
346 if ( !hasMask
|| red
!= maskRed
|| green
!= maskGreen
|| blue
!= maskBlue
)
361 *(target_data
++) = M_IMGDATA
->m_maskRed
;
362 *(target_data
++) = M_IMGDATA
->m_maskGreen
;
363 *(target_data
++) = M_IMGDATA
->m_maskBlue
;
368 *(target_alpha
++) = (unsigned char)(avgAlpha
/ counter
) ;
369 *(target_data
++) = (unsigned char)(avgRed
/ counter
);
370 *(target_data
++) = (unsigned char)(avgGreen
/ counter
);
371 *(target_data
++) = (unsigned char)(avgBlue
/ counter
);
376 // In case this is a cursor, make sure the hotspot is scaled accordingly:
377 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
) )
378 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
,
379 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X
))/xFactor
);
380 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
) )
381 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
,
382 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y
))/yFactor
);
388 wxImage::Scale( int width
, int height
, wxImageResizeQuality quality
) const
392 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
394 // can't scale to/from 0 size
395 wxCHECK_MSG( (width
> 0) && (height
> 0), image
,
396 wxT("invalid new image size") );
398 long old_height
= M_IMGDATA
->m_height
,
399 old_width
= M_IMGDATA
->m_width
;
400 wxCHECK_MSG( (old_height
> 0) && (old_width
> 0), image
,
401 wxT("invalid old image size") );
403 // If the image's new width and height are the same as the original, no
404 // need to waste time or CPU cycles
405 if ( old_width
== width
&& old_height
== height
)
408 // resample the image using either the nearest neighbourhood, bilinear or
409 // bicubic method as specified
412 case wxIMAGE_QUALITY_BICUBIC
:
413 case wxIMAGE_QUALITY_BILINEAR
:
414 // both of these algorithms should be used for up-sampling the
415 // image only, when down-sampling always use box averaging for best
417 if ( width
< old_width
&& height
< old_height
)
418 image
= ResampleBox(width
, height
);
419 else if ( quality
== wxIMAGE_QUALITY_BILINEAR
)
420 image
= ResampleBilinear(width
, height
);
421 else if ( quality
== wxIMAGE_QUALITY_BICUBIC
)
422 image
= ResampleBicubic(width
, height
);
425 case wxIMAGE_QUALITY_NEAREST
:
426 if ( old_width
% width
== 0 && old_width
>= width
&&
427 old_height
% height
== 0 && old_height
>= height
)
429 return ShrinkBy( old_width
/ width
, old_height
/ height
);
432 image
= ResampleNearest(width
, height
);
436 // If the original image has a mask, apply the mask to the new image
437 if (M_IMGDATA
->m_hasMask
)
439 image
.SetMaskColour( M_IMGDATA
->m_maskRed
,
440 M_IMGDATA
->m_maskGreen
,
441 M_IMGDATA
->m_maskBlue
);
444 // In case this is a cursor, make sure the hotspot is scaled accordingly:
445 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
) )
446 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
,
447 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X
)*width
)/old_width
);
448 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
) )
449 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
,
450 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y
)*height
)/old_height
);
455 wxImage
wxImage::ResampleNearest(int width
, int height
) const
458 image
.Create( width
, height
, false );
460 unsigned char *data
= image
.GetData();
462 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
464 unsigned char *source_data
= M_IMGDATA
->m_data
;
465 unsigned char *target_data
= data
;
466 unsigned char *source_alpha
= 0 ;
467 unsigned char *target_alpha
= 0 ;
469 if ( !M_IMGDATA
->m_hasMask
)
471 source_alpha
= M_IMGDATA
->m_alpha
;
475 target_alpha
= image
.GetAlpha() ;
479 long old_height
= M_IMGDATA
->m_height
,
480 old_width
= M_IMGDATA
->m_width
;
481 long x_delta
= (old_width
<<16) / width
;
482 long y_delta
= (old_height
<<16) / height
;
484 unsigned char* dest_pixel
= target_data
;
487 for ( long j
= 0; j
< height
; j
++ )
489 unsigned char* src_line
= &source_data
[(y
>>16)*old_width
*3];
490 unsigned char* src_alpha_line
= source_alpha
? &source_alpha
[(y
>>16)*old_width
] : 0 ;
493 for ( long i
= 0; i
< width
; i
++ )
495 unsigned char* src_pixel
= &src_line
[(x
>>16)*3];
496 unsigned char* src_alpha_pixel
= source_alpha
? &src_alpha_line
[(x
>>16)] : 0 ;
497 dest_pixel
[0] = src_pixel
[0];
498 dest_pixel
[1] = src_pixel
[1];
499 dest_pixel
[2] = src_pixel
[2];
502 *(target_alpha
++) = *src_alpha_pixel
;
512 wxImage
wxImage::ResampleBox(int width
, int height
) const
514 // This function implements a simple pre-blur/box averaging method for
515 // downsampling that gives reasonably smooth results To scale the image
516 // down we will need to gather a grid of pixels of the size of the scale
517 // factor in each direction and then do an averaging of the pixels.
519 wxImage
ret_image(width
, height
, false);
521 const double scale_factor_x
= double(M_IMGDATA
->m_width
) / width
;
522 const double scale_factor_y
= double(M_IMGDATA
->m_height
) / height
;
524 const int scale_factor_x_2
= (int)(scale_factor_x
/ 2);
525 const int scale_factor_y_2
= (int)(scale_factor_y
/ 2);
527 unsigned char* src_data
= M_IMGDATA
->m_data
;
528 unsigned char* src_alpha
= M_IMGDATA
->m_alpha
;
529 unsigned char* dst_data
= ret_image
.GetData();
530 unsigned char* dst_alpha
= NULL
;
534 ret_image
.SetAlpha();
535 dst_alpha
= ret_image
.GetAlpha();
538 int averaged_pixels
, src_pixel_index
;
539 double sum_r
, sum_g
, sum_b
, sum_a
;
541 for ( int y
= 0; y
< height
; y
++ ) // Destination image - Y direction
543 // Source pixel in the Y direction
544 int src_y
= (int)(y
* scale_factor_y
);
546 for ( int x
= 0; x
< width
; x
++ ) // Destination image - X direction
548 // Source pixel in the X direction
549 int src_x
= (int)(x
* scale_factor_x
);
551 // Box of pixels to average
553 sum_r
= sum_g
= sum_b
= sum_a
= 0.0;
555 for ( int j
= int(src_y
- scale_factor_y
/2.0 + 1);
556 j
<= int(src_y
+ scale_factor_y_2
);
559 // We don't care to average pixels that don't exist (edges)
560 if ( j
< 0 || j
> M_IMGDATA
->m_height
- 1 )
563 for ( int i
= int(src_x
- scale_factor_x
/2.0 + 1);
564 i
<= src_x
+ scale_factor_x_2
;
567 // Don't average edge pixels
568 if ( i
< 0 || i
> M_IMGDATA
->m_width
- 1 )
571 // Calculate the actual index in our source pixels
572 src_pixel_index
= j
* M_IMGDATA
->m_width
+ i
;
574 sum_r
+= src_data
[src_pixel_index
* 3 + 0];
575 sum_g
+= src_data
[src_pixel_index
* 3 + 1];
576 sum_b
+= src_data
[src_pixel_index
* 3 + 2];
578 sum_a
+= src_alpha
[src_pixel_index
];
584 // Calculate the average from the sum and number of averaged pixels
585 dst_data
[0] = (unsigned char)(sum_r
/ averaged_pixels
);
586 dst_data
[1] = (unsigned char)(sum_g
/ averaged_pixels
);
587 dst_data
[2] = (unsigned char)(sum_b
/ averaged_pixels
);
590 *dst_alpha
++ = (unsigned char)(sum_a
/ averaged_pixels
);
597 wxImage
wxImage::ResampleBilinear(int width
, int height
) const
599 // This function implements a Bilinear algorithm for resampling.
600 wxImage
ret_image(width
, height
, false);
601 unsigned char* src_data
= M_IMGDATA
->m_data
;
602 unsigned char* src_alpha
= M_IMGDATA
->m_alpha
;
603 unsigned char* dst_data
= ret_image
.GetData();
604 unsigned char* dst_alpha
= NULL
;
608 ret_image
.SetAlpha();
609 dst_alpha
= ret_image
.GetAlpha();
611 double HFactor
= double(M_IMGDATA
->m_height
) / height
;
612 double WFactor
= double(M_IMGDATA
->m_width
) / width
;
614 int srcpixymax
= M_IMGDATA
->m_height
- 1;
615 int srcpixxmax
= M_IMGDATA
->m_width
- 1;
617 double srcpixy
, srcpixy1
, srcpixy2
, dy
, dy1
;
618 double srcpixx
, srcpixx1
, srcpixx2
, dx
, dx1
;
619 double r1
, g1
, b1
, a1
;
620 double r2
, g2
, b2
, a2
;
622 for ( int dsty
= 0; dsty
< height
; dsty
++ )
624 // We need to calculate the source pixel to interpolate from - Y-axis
625 srcpixy
= double(dsty
) * HFactor
;
626 srcpixy1
= int(srcpixy
);
627 srcpixy2
= ( srcpixy1
== srcpixymax
) ? srcpixy1
: srcpixy1
+ 1.0;
628 dy
= srcpixy
- (int)srcpixy
;
632 for ( int dstx
= 0; dstx
< width
; dstx
++ )
634 // X-axis of pixel to interpolate from
635 srcpixx
= double(dstx
) * WFactor
;
636 srcpixx1
= int(srcpixx
);
637 srcpixx2
= ( srcpixx1
== srcpixxmax
) ? srcpixx1
: srcpixx1
+ 1.0;
638 dx
= srcpixx
- (int)srcpixx
;
641 int x_offset1
= srcpixx1
< 0.0 ? 0 : srcpixx1
> srcpixxmax
? srcpixxmax
: (int)srcpixx1
;
642 int x_offset2
= srcpixx2
< 0.0 ? 0 : srcpixx2
> srcpixxmax
? srcpixxmax
: (int)srcpixx2
;
643 int y_offset1
= srcpixy1
< 0.0 ? 0 : srcpixy1
> srcpixymax
? srcpixymax
: (int)srcpixy1
;
644 int y_offset2
= srcpixy2
< 0.0 ? 0 : srcpixy2
> srcpixymax
? srcpixymax
: (int)srcpixy2
;
646 int src_pixel_index00
= y_offset1
* M_IMGDATA
->m_width
+ x_offset1
;
647 int src_pixel_index01
= y_offset1
* M_IMGDATA
->m_width
+ x_offset2
;
648 int src_pixel_index10
= y_offset2
* M_IMGDATA
->m_width
+ x_offset1
;
649 int src_pixel_index11
= y_offset2
* M_IMGDATA
->m_width
+ x_offset2
;
652 r1
= src_data
[src_pixel_index00
* 3 + 0] * dx1
+ src_data
[src_pixel_index01
* 3 + 0] * dx
;
653 g1
= src_data
[src_pixel_index00
* 3 + 1] * dx1
+ src_data
[src_pixel_index01
* 3 + 1] * dx
;
654 b1
= src_data
[src_pixel_index00
* 3 + 2] * dx1
+ src_data
[src_pixel_index01
* 3 + 2] * dx
;
656 a1
= src_alpha
[src_pixel_index00
] * dx1
+ src_alpha
[src_pixel_index01
] * dx
;
659 r2
= src_data
[src_pixel_index10
* 3 + 0] * dx1
+ src_data
[src_pixel_index11
* 3 + 0] * dx
;
660 g2
= src_data
[src_pixel_index10
* 3 + 1] * dx1
+ src_data
[src_pixel_index11
* 3 + 1] * dx
;
661 b2
= src_data
[src_pixel_index10
* 3 + 2] * dx1
+ src_data
[src_pixel_index11
* 3 + 2] * dx
;
663 a2
= src_alpha
[src_pixel_index10
] * dx1
+ src_alpha
[src_pixel_index11
] * dx
;
667 dst_data
[0] = r1
* dy1
+ r2
* dy
;
668 dst_data
[1] = g1
* dy1
+ g2
* dy
;
669 dst_data
[2] = b1
* dy1
+ b2
* dy
;
673 *dst_alpha
++ = a1
* dy1
+ a2
* dy
;
680 // The following two local functions are for the B-spline weighting of the
681 // bicubic sampling algorithm
682 static inline double spline_cube(double value
)
684 return value
<= 0.0 ? 0.0 : value
* value
* value
;
687 static inline double spline_weight(double value
)
689 return (spline_cube(value
+ 2) -
690 4 * spline_cube(value
+ 1) +
691 6 * spline_cube(value
) -
692 4 * spline_cube(value
- 1)) / 6;
695 // This is the bicubic resampling algorithm
696 wxImage
wxImage::ResampleBicubic(int width
, int height
) const
698 // This function implements a Bicubic B-Spline algorithm for resampling.
699 // This method is certainly a little slower than wxImage's default pixel
700 // replication method, however for most reasonably sized images not being
701 // upsampled too much on a fairly average CPU this difference is hardly
702 // noticeable and the results are far more pleasing to look at.
704 // This particular bicubic algorithm does pixel weighting according to a
705 // B-Spline that basically implements a Gaussian bell-like weighting
706 // kernel. Because of this method the results may appear a bit blurry when
707 // upsampling by large factors. This is basically because a slight
708 // gaussian blur is being performed to get the smooth look of the upsampled
711 // Edge pixels: 3-4 possible solutions
712 // - (Wrap/tile) Wrap the image, take the color value from the opposite
713 // side of the image.
714 // - (Mirror) Duplicate edge pixels, so that pixel at coordinate (2, n),
715 // where n is nonpositive, will have the value of (2, 1).
716 // - (Ignore) Simply ignore the edge pixels and apply the kernel only to
717 // pixels which do have all neighbours.
718 // - (Clamp) Choose the nearest pixel along the border. This takes the
719 // border pixels and extends them out to infinity.
721 // NOTE: below the y_offset and x_offset variables are being set for edge
722 // pixels using the "Mirror" method mentioned above
726 ret_image
.Create(width
, height
, false);
728 unsigned char* src_data
= M_IMGDATA
->m_data
;
729 unsigned char* src_alpha
= M_IMGDATA
->m_alpha
;
730 unsigned char* dst_data
= ret_image
.GetData();
731 unsigned char* dst_alpha
= NULL
;
735 ret_image
.SetAlpha();
736 dst_alpha
= ret_image
.GetAlpha();
739 for ( int dsty
= 0; dsty
< height
; dsty
++ )
741 // We need to calculate the source pixel to interpolate from - Y-axis
742 double srcpixy
= double(dsty
* M_IMGDATA
->m_height
) / height
;
743 double dy
= srcpixy
- (int)srcpixy
;
745 for ( int dstx
= 0; dstx
< width
; dstx
++ )
747 // X-axis of pixel to interpolate from
748 double srcpixx
= double(dstx
* M_IMGDATA
->m_width
) / width
;
749 double dx
= srcpixx
- (int)srcpixx
;
751 // Sums for each color channel
752 double sum_r
= 0, sum_g
= 0, sum_b
= 0, sum_a
= 0;
754 // Here we actually determine the RGBA values for the destination pixel
755 for ( int k
= -1; k
<= 2; k
++ )
758 int y_offset
= srcpixy
+ k
< 0.0
760 : srcpixy
+ k
>= M_IMGDATA
->m_height
761 ? M_IMGDATA
->m_height
- 1
762 : (int)(srcpixy
+ k
);
764 // Loop across the X axis
765 for ( int i
= -1; i
<= 2; i
++ )
768 int x_offset
= srcpixx
+ i
< 0.0
770 : srcpixx
+ i
>= M_IMGDATA
->m_width
771 ? M_IMGDATA
->m_width
- 1
772 : (int)(srcpixx
+ i
);
774 // Calculate the exact position where the source data
775 // should be pulled from based on the x_offset and y_offset
776 int src_pixel_index
= y_offset
*M_IMGDATA
->m_width
+ x_offset
;
778 // Calculate the weight for the specified pixel according
779 // to the bicubic b-spline kernel we're using for
782 pixel_weight
= spline_weight(i
- dx
)*spline_weight(k
- dy
);
784 // Create a sum of all velues for each color channel
785 // adjusted for the pixel's calculated weight
786 sum_r
+= src_data
[src_pixel_index
* 3 + 0] * pixel_weight
;
787 sum_g
+= src_data
[src_pixel_index
* 3 + 1] * pixel_weight
;
788 sum_b
+= src_data
[src_pixel_index
* 3 + 2] * pixel_weight
;
790 sum_a
+= src_alpha
[src_pixel_index
] * pixel_weight
;
794 // Put the data into the destination image. The summed values are
795 // of double data type and are rounded here for accuracy
796 dst_data
[0] = (unsigned char)(sum_r
+ 0.5);
797 dst_data
[1] = (unsigned char)(sum_g
+ 0.5);
798 dst_data
[2] = (unsigned char)(sum_b
+ 0.5);
802 *dst_alpha
++ = (unsigned char)sum_a
;
809 // Blur in the horizontal direction
810 wxImage
wxImage::BlurHorizontal(int blurRadius
) const
813 ret_image
.Create(M_IMGDATA
->m_width
, M_IMGDATA
->m_height
, false);
815 unsigned char* src_data
= M_IMGDATA
->m_data
;
816 unsigned char* dst_data
= ret_image
.GetData();
817 unsigned char* src_alpha
= M_IMGDATA
->m_alpha
;
818 unsigned char* dst_alpha
= NULL
;
820 // Check for a mask or alpha
823 ret_image
.SetAlpha();
824 dst_alpha
= ret_image
.GetAlpha();
826 else if ( M_IMGDATA
->m_hasMask
)
828 ret_image
.SetMaskColour(M_IMGDATA
->m_maskRed
,
829 M_IMGDATA
->m_maskGreen
,
830 M_IMGDATA
->m_maskBlue
);
833 // number of pixels we average over
834 const int blurArea
= blurRadius
*2 + 1;
836 // Horizontal blurring algorithm - average all pixels in the specified blur
837 // radius in the X or horizontal direction
838 for ( int y
= 0; y
< M_IMGDATA
->m_height
; y
++ )
840 // Variables used in the blurring algorithm
847 const unsigned char *src
;
850 // Calculate the average of all pixels in the blur radius for the first
852 for ( int kernel_x
= -blurRadius
; kernel_x
<= blurRadius
; kernel_x
++ )
854 // To deal with the pixels at the start of a row so it's not
855 // grabbing GOK values from memory at negative indices of the
856 // image's data or grabbing from the previous row
858 pixel_idx
= y
* M_IMGDATA
->m_width
;
860 pixel_idx
= kernel_x
+ y
* M_IMGDATA
->m_width
;
862 src
= src_data
+ pixel_idx
*3;
867 sum_a
+= src_alpha
[pixel_idx
];
870 dst
= dst_data
+ y
* M_IMGDATA
->m_width
*3;
871 dst
[0] = (unsigned char)(sum_r
/ blurArea
);
872 dst
[1] = (unsigned char)(sum_g
/ blurArea
);
873 dst
[2] = (unsigned char)(sum_b
/ blurArea
);
875 dst_alpha
[y
* M_IMGDATA
->m_width
] = (unsigned char)(sum_a
/ blurArea
);
877 // Now average the values of the rest of the pixels by just moving the
878 // blur radius box along the row
879 for ( int x
= 1; x
< M_IMGDATA
->m_width
; x
++ )
881 // Take care of edge pixels on the left edge by essentially
882 // duplicating the edge pixel
883 if ( x
- blurRadius
- 1 < 0 )
884 pixel_idx
= y
* M_IMGDATA
->m_width
;
886 pixel_idx
= (x
- blurRadius
- 1) + y
* M_IMGDATA
->m_width
;
888 // Subtract the value of the pixel at the left side of the blur
890 src
= src_data
+ pixel_idx
*3;
895 sum_a
-= src_alpha
[pixel_idx
];
897 // Take care of edge pixels on the right edge
898 if ( x
+ blurRadius
> M_IMGDATA
->m_width
- 1 )
899 pixel_idx
= M_IMGDATA
->m_width
- 1 + y
* M_IMGDATA
->m_width
;
901 pixel_idx
= x
+ blurRadius
+ y
* M_IMGDATA
->m_width
;
903 // Add the value of the pixel being added to the end of our box
904 src
= src_data
+ pixel_idx
*3;
909 sum_a
+= src_alpha
[pixel_idx
];
911 // Save off the averaged data
912 dst
= dst_data
+ x
*3 + y
*M_IMGDATA
->m_width
*3;
913 dst
[0] = (unsigned char)(sum_r
/ blurArea
);
914 dst
[1] = (unsigned char)(sum_g
/ blurArea
);
915 dst
[2] = (unsigned char)(sum_b
/ blurArea
);
917 dst_alpha
[x
+ y
* M_IMGDATA
->m_width
] = (unsigned char)(sum_a
/ blurArea
);
924 // Blur in the vertical direction
925 wxImage
wxImage::BlurVertical(int blurRadius
) const
928 ret_image
.Create(M_IMGDATA
->m_width
, M_IMGDATA
->m_height
, false);
930 unsigned char* src_data
= M_IMGDATA
->m_data
;
931 unsigned char* dst_data
= ret_image
.GetData();
932 unsigned char* src_alpha
= M_IMGDATA
->m_alpha
;
933 unsigned char* dst_alpha
= NULL
;
935 // Check for a mask or alpha
938 ret_image
.SetAlpha();
939 dst_alpha
= ret_image
.GetAlpha();
941 else if ( M_IMGDATA
->m_hasMask
)
943 ret_image
.SetMaskColour(M_IMGDATA
->m_maskRed
,
944 M_IMGDATA
->m_maskGreen
,
945 M_IMGDATA
->m_maskBlue
);
948 // number of pixels we average over
949 const int blurArea
= blurRadius
*2 + 1;
951 // Vertical blurring algorithm - same as horizontal but switched the
952 // opposite direction
953 for ( int x
= 0; x
< M_IMGDATA
->m_width
; x
++ )
955 // Variables used in the blurring algorithm
962 const unsigned char *src
;
965 // Calculate the average of all pixels in our blur radius box for the
966 // first pixel of the column
967 for ( int kernel_y
= -blurRadius
; kernel_y
<= blurRadius
; kernel_y
++ )
969 // To deal with the pixels at the start of a column so it's not
970 // grabbing GOK values from memory at negative indices of the
971 // image's data or grabbing from the previous column
975 pixel_idx
= x
+ kernel_y
* M_IMGDATA
->m_width
;
977 src
= src_data
+ pixel_idx
*3;
982 sum_a
+= src_alpha
[pixel_idx
];
985 dst
= dst_data
+ x
*3;
986 dst
[0] = (unsigned char)(sum_r
/ blurArea
);
987 dst
[1] = (unsigned char)(sum_g
/ blurArea
);
988 dst
[2] = (unsigned char)(sum_b
/ blurArea
);
990 dst_alpha
[x
] = (unsigned char)(sum_a
/ blurArea
);
992 // Now average the values of the rest of the pixels by just moving the
993 // box along the column from top to bottom
994 for ( int y
= 1; y
< M_IMGDATA
->m_height
; y
++ )
996 // Take care of pixels that would be beyond the top edge by
997 // duplicating the top edge pixel for the column
998 if ( y
- blurRadius
- 1 < 0 )
1001 pixel_idx
= x
+ (y
- blurRadius
- 1) * M_IMGDATA
->m_width
;
1003 // Subtract the value of the pixel at the top of our blur radius box
1004 src
= src_data
+ pixel_idx
*3;
1009 sum_a
-= src_alpha
[pixel_idx
];
1011 // Take care of the pixels that would be beyond the bottom edge of
1012 // the image similar to the top edge
1013 if ( y
+ blurRadius
> M_IMGDATA
->m_height
- 1 )
1014 pixel_idx
= x
+ (M_IMGDATA
->m_height
- 1) * M_IMGDATA
->m_width
;
1016 pixel_idx
= x
+ (blurRadius
+ y
) * M_IMGDATA
->m_width
;
1018 // Add the value of the pixel being added to the end of our box
1019 src
= src_data
+ pixel_idx
*3;
1024 sum_a
+= src_alpha
[pixel_idx
];
1026 // Save off the averaged data
1027 dst
= dst_data
+ (x
+ y
* M_IMGDATA
->m_width
) * 3;
1028 dst
[0] = (unsigned char)(sum_r
/ blurArea
);
1029 dst
[1] = (unsigned char)(sum_g
/ blurArea
);
1030 dst
[2] = (unsigned char)(sum_b
/ blurArea
);
1032 dst_alpha
[x
+ y
* M_IMGDATA
->m_width
] = (unsigned char)(sum_a
/ blurArea
);
1039 // The new blur function
1040 wxImage
wxImage::Blur(int blurRadius
) const
1043 ret_image
.Create(M_IMGDATA
->m_width
, M_IMGDATA
->m_height
, false);
1045 // Blur the image in each direction
1046 ret_image
= BlurHorizontal(blurRadius
);
1047 ret_image
= ret_image
.BlurVertical(blurRadius
);
1052 wxImage
wxImage::Rotate90( bool clockwise
) const
1056 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
1058 image
.Create( M_IMGDATA
->m_height
, M_IMGDATA
->m_width
, false );
1060 unsigned char *data
= image
.GetData();
1062 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
1064 unsigned char *source_data
= M_IMGDATA
->m_data
;
1065 unsigned char *target_data
;
1066 unsigned char *alpha_data
= 0 ;
1067 unsigned char *source_alpha
= 0 ;
1068 unsigned char *target_alpha
= 0 ;
1070 if (M_IMGDATA
->m_hasMask
)
1072 image
.SetMaskColour( M_IMGDATA
->m_maskRed
, M_IMGDATA
->m_maskGreen
, M_IMGDATA
->m_maskBlue
);
1076 source_alpha
= M_IMGDATA
->m_alpha
;
1080 alpha_data
= image
.GetAlpha() ;
1084 long height
= M_IMGDATA
->m_height
;
1085 long width
= M_IMGDATA
->m_width
;
1087 for (long j
= 0; j
< height
; j
++)
1089 for (long i
= 0; i
< width
; i
++)
1093 target_data
= data
+ (((i
+1)*height
) - j
- 1)*3;
1095 target_alpha
= alpha_data
+ (((i
+1)*height
) - j
- 1);
1099 target_data
= data
+ ((height
*(width
-1)) + j
- (i
*height
))*3;
1101 target_alpha
= alpha_data
+ ((height
*(width
-1)) + j
- (i
*height
));
1103 memcpy( target_data
, source_data
, 3 );
1108 memcpy( target_alpha
, source_alpha
, 1 );
1117 wxImage
wxImage::Mirror( bool horizontally
) const
1121 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
1123 image
.Create( M_IMGDATA
->m_width
, M_IMGDATA
->m_height
, false );
1125 unsigned char *data
= image
.GetData();
1126 unsigned char *alpha
= NULL
;
1128 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
1130 if (M_IMGDATA
->m_alpha
!= NULL
) {
1132 alpha
= image
.GetAlpha();
1133 wxCHECK_MSG( alpha
, image
, wxT("unable to create alpha channel") );
1136 if (M_IMGDATA
->m_hasMask
)
1137 image
.SetMaskColour( M_IMGDATA
->m_maskRed
, M_IMGDATA
->m_maskGreen
, M_IMGDATA
->m_maskBlue
);
1139 long height
= M_IMGDATA
->m_height
;
1140 long width
= M_IMGDATA
->m_width
;
1142 unsigned char *source_data
= M_IMGDATA
->m_data
;
1143 unsigned char *target_data
;
1147 for (long j
= 0; j
< height
; j
++)
1150 target_data
= data
-3;
1151 for (long i
= 0; i
< width
; i
++)
1153 memcpy( target_data
, source_data
, 3 );
1161 // src_alpha starts at the first pixel and increases by 1 after each step
1162 // (a step here is the copy of the alpha value of one pixel)
1163 const unsigned char *src_alpha
= M_IMGDATA
->m_alpha
;
1164 // dest_alpha starts just beyond the first line, decreases before each step,
1165 // and after each line is finished, increases by 2 widths (skipping the line
1166 // just copied and the line that will be copied next)
1167 unsigned char *dest_alpha
= alpha
+ width
;
1169 for (long jj
= 0; jj
< height
; ++jj
)
1171 for (long i
= 0; i
< width
; ++i
) {
1172 *(--dest_alpha
) = *(src_alpha
++); // copy one pixel
1174 dest_alpha
+= 2 * width
; // advance beyond the end of the next line
1180 for (long i
= 0; i
< height
; i
++)
1182 target_data
= data
+ 3*width
*(height
-1-i
);
1183 memcpy( target_data
, source_data
, (size_t)3*width
);
1184 source_data
+= 3*width
;
1189 // src_alpha starts at the first pixel and increases by 1 width after each step
1190 // (a step here is the copy of the alpha channel of an entire line)
1191 const unsigned char *src_alpha
= M_IMGDATA
->m_alpha
;
1192 // dest_alpha starts just beyond the last line (beyond the whole image)
1193 // and decreases by 1 width before each step
1194 unsigned char *dest_alpha
= alpha
+ width
* height
;
1196 for (long jj
= 0; jj
< height
; ++jj
)
1198 dest_alpha
-= width
;
1199 memcpy( dest_alpha
, src_alpha
, (size_t)width
);
1208 wxImage
wxImage::GetSubImage( const wxRect
&rect
) const
1212 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
1214 wxCHECK_MSG( (rect
.GetLeft()>=0) && (rect
.GetTop()>=0) &&
1215 (rect
.GetRight()<=GetWidth()) && (rect
.GetBottom()<=GetHeight()),
1216 image
, wxT("invalid subimage size") );
1218 const int subwidth
= rect
.GetWidth();
1219 const int subheight
= rect
.GetHeight();
1221 image
.Create( subwidth
, subheight
, false );
1223 const unsigned char *src_data
= GetData();
1224 const unsigned char *src_alpha
= M_IMGDATA
->m_alpha
;
1225 unsigned char *subdata
= image
.GetData();
1226 unsigned char *subalpha
= NULL
;
1228 wxCHECK_MSG( subdata
, image
, wxT("unable to create image") );
1230 if (src_alpha
!= NULL
) {
1232 subalpha
= image
.GetAlpha();
1233 wxCHECK_MSG( subalpha
, image
, wxT("unable to create alpha channel"));
1236 if (M_IMGDATA
->m_hasMask
)
1237 image
.SetMaskColour( M_IMGDATA
->m_maskRed
, M_IMGDATA
->m_maskGreen
, M_IMGDATA
->m_maskBlue
);
1239 const int width
= GetWidth();
1240 const int pixsoff
= rect
.GetLeft() + width
* rect
.GetTop();
1242 src_data
+= 3 * pixsoff
;
1243 src_alpha
+= pixsoff
; // won't be used if was NULL, so this is ok
1245 for (long j
= 0; j
< subheight
; ++j
)
1247 memcpy( subdata
, src_data
, 3 * subwidth
);
1248 subdata
+= 3 * subwidth
;
1249 src_data
+= 3 * width
;
1250 if (subalpha
!= NULL
) {
1251 memcpy( subalpha
, src_alpha
, subwidth
);
1252 subalpha
+= subwidth
;
1260 wxImage
wxImage::Size( const wxSize
& size
, const wxPoint
& pos
,
1261 int r_
, int g_
, int b_
) const
1265 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
1266 wxCHECK_MSG( (size
.GetWidth() > 0) && (size
.GetHeight() > 0), image
, wxT("invalid size") );
1268 int width
= GetWidth(), height
= GetHeight();
1269 image
.Create(size
.GetWidth(), size
.GetHeight(), false);
1271 unsigned char r
= (unsigned char)r_
;
1272 unsigned char g
= (unsigned char)g_
;
1273 unsigned char b
= (unsigned char)b_
;
1274 if ((r_
== -1) && (g_
== -1) && (b_
== -1))
1276 GetOrFindMaskColour( &r
, &g
, &b
);
1277 image
.SetMaskColour(r
, g
, b
);
1280 image
.SetRGB(wxRect(), r
, g
, b
);
1282 wxRect
subRect(pos
.x
, pos
.y
, width
, height
);
1283 wxRect
finalRect(0, 0, size
.GetWidth(), size
.GetHeight());
1285 finalRect
.width
-= pos
.x
;
1287 finalRect
.height
-= pos
.y
;
1289 subRect
.Intersect(finalRect
);
1291 if (!subRect
.IsEmpty())
1293 if ((subRect
.GetWidth() == width
) && (subRect
.GetHeight() == height
))
1294 image
.Paste(*this, pos
.x
, pos
.y
);
1296 image
.Paste(GetSubImage(subRect
), pos
.x
, pos
.y
);
1302 void wxImage::Paste( const wxImage
&image
, int x
, int y
)
1304 wxCHECK_RET( Ok(), wxT("invalid image") );
1305 wxCHECK_RET( image
.Ok(), wxT("invalid image") );
1311 int width
= image
.GetWidth();
1312 int height
= image
.GetHeight();
1325 if ((x
+xx
)+width
> M_IMGDATA
->m_width
)
1326 width
= M_IMGDATA
->m_width
- (x
+xx
);
1327 if ((y
+yy
)+height
> M_IMGDATA
->m_height
)
1328 height
= M_IMGDATA
->m_height
- (y
+yy
);
1330 if (width
< 1) return;
1331 if (height
< 1) return;
1333 if ((!HasMask() && !image
.HasMask()) ||
1334 (HasMask() && !image
.HasMask()) ||
1335 ((HasMask() && image
.HasMask() &&
1336 (GetMaskRed()==image
.GetMaskRed()) &&
1337 (GetMaskGreen()==image
.GetMaskGreen()) &&
1338 (GetMaskBlue()==image
.GetMaskBlue()))))
1340 unsigned char* source_data
= image
.GetData() + xx
*3 + yy
*3*image
.GetWidth();
1341 int source_step
= image
.GetWidth()*3;
1343 unsigned char* target_data
= GetData() + (x
+xx
)*3 + (y
+yy
)*3*M_IMGDATA
->m_width
;
1344 int target_step
= M_IMGDATA
->m_width
*3;
1345 for (int j
= 0; j
< height
; j
++)
1347 memcpy( target_data
, source_data
, width
*3 );
1348 source_data
+= source_step
;
1349 target_data
+= target_step
;
1353 // Copy over the alpha channel from the original image
1354 if ( image
.HasAlpha() )
1359 unsigned char* source_data
= image
.GetAlpha() + xx
+ yy
*image
.GetWidth();
1360 int source_step
= image
.GetWidth();
1362 unsigned char* target_data
= GetAlpha() + (x
+xx
) + (y
+yy
)*M_IMGDATA
->m_width
;
1363 int target_step
= M_IMGDATA
->m_width
;
1365 for (int j
= 0; j
< height
; j
++,
1366 source_data
+= source_step
,
1367 target_data
+= target_step
)
1369 memcpy( target_data
, source_data
, width
);
1373 if (!HasMask() && image
.HasMask())
1375 unsigned char r
= image
.GetMaskRed();
1376 unsigned char g
= image
.GetMaskGreen();
1377 unsigned char b
= image
.GetMaskBlue();
1379 unsigned char* source_data
= image
.GetData() + xx
*3 + yy
*3*image
.GetWidth();
1380 int source_step
= image
.GetWidth()*3;
1382 unsigned char* target_data
= GetData() + (x
+xx
)*3 + (y
+yy
)*3*M_IMGDATA
->m_width
;
1383 int target_step
= M_IMGDATA
->m_width
*3;
1385 for (int j
= 0; j
< height
; j
++)
1387 for (int i
= 0; i
< width
*3; i
+=3)
1389 if ((source_data
[i
] != r
) ||
1390 (source_data
[i
+1] != g
) ||
1391 (source_data
[i
+2] != b
))
1393 memcpy( target_data
+i
, source_data
+i
, 3 );
1396 source_data
+= source_step
;
1397 target_data
+= target_step
;
1402 void wxImage::Replace( unsigned char r1
, unsigned char g1
, unsigned char b1
,
1403 unsigned char r2
, unsigned char g2
, unsigned char b2
)
1405 wxCHECK_RET( Ok(), wxT("invalid image") );
1409 unsigned char *data
= GetData();
1411 const int w
= GetWidth();
1412 const int h
= GetHeight();
1414 for (int j
= 0; j
< h
; j
++)
1415 for (int i
= 0; i
< w
; i
++)
1417 if ((data
[0] == r1
) && (data
[1] == g1
) && (data
[2] == b1
))
1427 wxImage
wxImage::ConvertToGreyscale( double lr
, double lg
, double lb
) const
1431 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
1433 image
.Create(M_IMGDATA
->m_width
, M_IMGDATA
->m_height
, false);
1435 unsigned char *dest
= image
.GetData();
1437 wxCHECK_MSG( dest
, image
, wxT("unable to create image") );
1439 unsigned char *src
= M_IMGDATA
->m_data
;
1440 bool hasMask
= M_IMGDATA
->m_hasMask
;
1441 unsigned char maskRed
= M_IMGDATA
->m_maskRed
;
1442 unsigned char maskGreen
= M_IMGDATA
->m_maskGreen
;
1443 unsigned char maskBlue
= M_IMGDATA
->m_maskBlue
;
1446 image
.SetMaskColour(maskRed
, maskGreen
, maskBlue
);
1448 const long size
= M_IMGDATA
->m_width
* M_IMGDATA
->m_height
;
1449 for ( long i
= 0; i
< size
; i
++, src
+= 3, dest
+= 3 )
1451 // don't modify the mask
1452 if ( hasMask
&& src
[0] == maskRed
&& src
[1] == maskGreen
&& src
[2] == maskBlue
)
1454 memcpy(dest
, src
, 3);
1458 // calculate the luma
1459 double luma
= (src
[0] * lr
+ src
[1] * lg
+ src
[2] * lb
) + 0.5;
1460 dest
[0] = dest
[1] = dest
[2] = static_cast<unsigned char>(luma
);
1464 // copy the alpha channel, if any
1467 const size_t alphaSize
= GetWidth() * GetHeight();
1468 unsigned char *alpha
= (unsigned char*)malloc(alphaSize
);
1469 memcpy(alpha
, GetAlpha(), alphaSize
);
1471 image
.SetAlpha(alpha
);
1477 wxImage
wxImage::ConvertToMono( unsigned char r
, unsigned char g
, unsigned char b
) const
1481 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
1483 image
.Create( M_IMGDATA
->m_width
, M_IMGDATA
->m_height
, false );
1485 unsigned char *data
= image
.GetData();
1487 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
1489 if (M_IMGDATA
->m_hasMask
)
1491 if (M_IMGDATA
->m_maskRed
== r
&& M_IMGDATA
->m_maskGreen
== g
&&
1492 M_IMGDATA
->m_maskBlue
== b
)
1493 image
.SetMaskColour( 255, 255, 255 );
1495 image
.SetMaskColour( 0, 0, 0 );
1498 long size
= M_IMGDATA
->m_height
* M_IMGDATA
->m_width
;
1500 unsigned char *srcd
= M_IMGDATA
->m_data
;
1501 unsigned char *tard
= image
.GetData();
1503 for ( long i
= 0; i
< size
; i
++, srcd
+= 3, tard
+= 3 )
1505 if (srcd
[0] == r
&& srcd
[1] == g
&& srcd
[2] == b
)
1506 tard
[0] = tard
[1] = tard
[2] = 255;
1508 tard
[0] = tard
[1] = tard
[2] = 0;
1514 int wxImage::GetWidth() const
1516 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
1518 return M_IMGDATA
->m_width
;
1521 int wxImage::GetHeight() const
1523 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
1525 return M_IMGDATA
->m_height
;
1528 wxBitmapType
wxImage::GetType() const
1530 wxCHECK_MSG( IsOk(), wxBITMAP_TYPE_INVALID
, wxT("invalid image") );
1532 return M_IMGDATA
->m_type
;
1535 void wxImage::SetType(wxBitmapType type
)
1537 wxCHECK_RET( IsOk(), "must create the image before setting its type");
1539 // type can be wxBITMAP_TYPE_INVALID to reset the image type to default
1540 wxASSERT_MSG( type
!= wxBITMAP_TYPE_MAX
, "invalid bitmap type" );
1542 M_IMGDATA
->m_type
= type
;
1545 long wxImage::XYToIndex(int x
, int y
) const
1549 x
< M_IMGDATA
->m_width
&& y
< M_IMGDATA
->m_height
)
1551 return y
*M_IMGDATA
->m_width
+ x
;
1557 void wxImage::SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
)
1559 long pos
= XYToIndex(x
, y
);
1560 wxCHECK_RET( pos
!= -1, wxT("invalid image coordinates") );
1566 M_IMGDATA
->m_data
[ pos
] = r
;
1567 M_IMGDATA
->m_data
[ pos
+1 ] = g
;
1568 M_IMGDATA
->m_data
[ pos
+2 ] = b
;
1571 void wxImage::SetRGB( const wxRect
& rect_
, unsigned char r
, unsigned char g
, unsigned char b
)
1573 wxCHECK_RET( Ok(), wxT("invalid image") );
1578 wxRect
imageRect(0, 0, GetWidth(), GetHeight());
1579 if ( rect
== wxRect() )
1585 wxCHECK_RET( imageRect
.Contains(rect
.GetTopLeft()) &&
1586 imageRect
.Contains(rect
.GetBottomRight()),
1587 wxT("invalid bounding rectangle") );
1590 int x1
= rect
.GetLeft(),
1592 x2
= rect
.GetRight() + 1,
1593 y2
= rect
.GetBottom() + 1;
1595 unsigned char *data
wxDUMMY_INITIALIZE(NULL
);
1596 int x
, y
, width
= GetWidth();
1597 for (y
= y1
; y
< y2
; y
++)
1599 data
= M_IMGDATA
->m_data
+ (y
*width
+ x1
)*3;
1600 for (x
= x1
; x
< x2
; x
++)
1609 unsigned char wxImage::GetRed( int x
, int y
) const
1611 long pos
= XYToIndex(x
, y
);
1612 wxCHECK_MSG( pos
!= -1, 0, wxT("invalid image coordinates") );
1616 return M_IMGDATA
->m_data
[pos
];
1619 unsigned char wxImage::GetGreen( int x
, int y
) const
1621 long pos
= XYToIndex(x
, y
);
1622 wxCHECK_MSG( pos
!= -1, 0, wxT("invalid image coordinates") );
1626 return M_IMGDATA
->m_data
[pos
+1];
1629 unsigned char wxImage::GetBlue( int x
, int y
) const
1631 long pos
= XYToIndex(x
, y
);
1632 wxCHECK_MSG( pos
!= -1, 0, wxT("invalid image coordinates") );
1636 return M_IMGDATA
->m_data
[pos
+2];
1639 bool wxImage::IsOk() const
1641 // image of 0 width or height can't be considered ok - at least because it
1642 // causes crashes in ConvertToBitmap() if we don't catch it in time
1643 wxImageRefData
*data
= M_IMGDATA
;
1644 return data
&& data
->m_ok
&& data
->m_width
&& data
->m_height
;
1647 unsigned char *wxImage::GetData() const
1649 wxCHECK_MSG( Ok(), (unsigned char *)NULL
, wxT("invalid image") );
1651 return M_IMGDATA
->m_data
;
1654 void wxImage::SetData( unsigned char *data
, bool static_data
)
1656 wxCHECK_RET( Ok(), wxT("invalid image") );
1658 wxImageRefData
*newRefData
= new wxImageRefData();
1660 newRefData
->m_width
= M_IMGDATA
->m_width
;
1661 newRefData
->m_height
= M_IMGDATA
->m_height
;
1662 newRefData
->m_data
= data
;
1663 newRefData
->m_ok
= true;
1664 newRefData
->m_maskRed
= M_IMGDATA
->m_maskRed
;
1665 newRefData
->m_maskGreen
= M_IMGDATA
->m_maskGreen
;
1666 newRefData
->m_maskBlue
= M_IMGDATA
->m_maskBlue
;
1667 newRefData
->m_hasMask
= M_IMGDATA
->m_hasMask
;
1668 newRefData
->m_static
= static_data
;
1672 m_refData
= newRefData
;
1675 void wxImage::SetData( unsigned char *data
, int new_width
, int new_height
, bool static_data
)
1677 wxImageRefData
*newRefData
= new wxImageRefData();
1681 newRefData
->m_width
= new_width
;
1682 newRefData
->m_height
= new_height
;
1683 newRefData
->m_data
= data
;
1684 newRefData
->m_ok
= true;
1685 newRefData
->m_maskRed
= M_IMGDATA
->m_maskRed
;
1686 newRefData
->m_maskGreen
= M_IMGDATA
->m_maskGreen
;
1687 newRefData
->m_maskBlue
= M_IMGDATA
->m_maskBlue
;
1688 newRefData
->m_hasMask
= M_IMGDATA
->m_hasMask
;
1692 newRefData
->m_width
= new_width
;
1693 newRefData
->m_height
= new_height
;
1694 newRefData
->m_data
= data
;
1695 newRefData
->m_ok
= true;
1697 newRefData
->m_static
= static_data
;
1701 m_refData
= newRefData
;
1704 // ----------------------------------------------------------------------------
1705 // alpha channel support
1706 // ----------------------------------------------------------------------------
1708 void wxImage::SetAlpha(int x
, int y
, unsigned char alpha
)
1710 wxCHECK_RET( HasAlpha(), wxT("no alpha channel") );
1712 long pos
= XYToIndex(x
, y
);
1713 wxCHECK_RET( pos
!= -1, wxT("invalid image coordinates") );
1717 M_IMGDATA
->m_alpha
[pos
] = alpha
;
1720 unsigned char wxImage::GetAlpha(int x
, int y
) const
1722 wxCHECK_MSG( HasAlpha(), 0, wxT("no alpha channel") );
1724 long pos
= XYToIndex(x
, y
);
1725 wxCHECK_MSG( pos
!= -1, 0, wxT("invalid image coordinates") );
1727 return M_IMGDATA
->m_alpha
[pos
];
1731 wxImage::ConvertColourToAlpha(unsigned char r
, unsigned char g
, unsigned char b
)
1735 const int w
= M_IMGDATA
->m_width
;
1736 const int h
= M_IMGDATA
->m_height
;
1738 unsigned char *alpha
= GetAlpha();
1739 unsigned char *data
= GetData();
1741 for ( int y
= 0; y
< h
; y
++ )
1743 for ( int x
= 0; x
< w
; x
++ )
1755 void wxImage::SetAlpha( unsigned char *alpha
, bool static_data
)
1757 wxCHECK_RET( Ok(), wxT("invalid image") );
1763 alpha
= (unsigned char *)malloc(M_IMGDATA
->m_width
*M_IMGDATA
->m_height
);
1766 if( !M_IMGDATA
->m_staticAlpha
)
1767 free(M_IMGDATA
->m_alpha
);
1769 M_IMGDATA
->m_alpha
= alpha
;
1770 M_IMGDATA
->m_staticAlpha
= static_data
;
1773 unsigned char *wxImage::GetAlpha() const
1775 wxCHECK_MSG( Ok(), (unsigned char *)NULL
, wxT("invalid image") );
1777 return M_IMGDATA
->m_alpha
;
1780 void wxImage::InitAlpha()
1782 wxCHECK_RET( !HasAlpha(), wxT("image already has an alpha channel") );
1784 // initialize memory for alpha channel
1787 unsigned char *alpha
= M_IMGDATA
->m_alpha
;
1788 const size_t lenAlpha
= M_IMGDATA
->m_width
* M_IMGDATA
->m_height
;
1792 // use the mask to initialize the alpha channel.
1793 const unsigned char * const alphaEnd
= alpha
+ lenAlpha
;
1795 const unsigned char mr
= M_IMGDATA
->m_maskRed
;
1796 const unsigned char mg
= M_IMGDATA
->m_maskGreen
;
1797 const unsigned char mb
= M_IMGDATA
->m_maskBlue
;
1798 for ( unsigned char *src
= M_IMGDATA
->m_data
;
1802 *alpha
= (src
[0] == mr
&& src
[1] == mg
&& src
[2] == mb
)
1803 ? wxIMAGE_ALPHA_TRANSPARENT
1804 : wxIMAGE_ALPHA_OPAQUE
;
1807 M_IMGDATA
->m_hasMask
= false;
1811 // make the image fully opaque
1812 memset(alpha
, wxIMAGE_ALPHA_OPAQUE
, lenAlpha
);
1816 // ----------------------------------------------------------------------------
1818 // ----------------------------------------------------------------------------
1820 void wxImage::SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
)
1822 wxCHECK_RET( Ok(), wxT("invalid image") );
1826 M_IMGDATA
->m_maskRed
= r
;
1827 M_IMGDATA
->m_maskGreen
= g
;
1828 M_IMGDATA
->m_maskBlue
= b
;
1829 M_IMGDATA
->m_hasMask
= true;
1832 bool wxImage::GetOrFindMaskColour( unsigned char *r
, unsigned char *g
, unsigned char *b
) const
1834 wxCHECK_MSG( Ok(), false, wxT("invalid image") );
1836 if (M_IMGDATA
->m_hasMask
)
1838 if (r
) *r
= M_IMGDATA
->m_maskRed
;
1839 if (g
) *g
= M_IMGDATA
->m_maskGreen
;
1840 if (b
) *b
= M_IMGDATA
->m_maskBlue
;
1845 FindFirstUnusedColour(r
, g
, b
);
1850 unsigned char wxImage::GetMaskRed() const
1852 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
1854 return M_IMGDATA
->m_maskRed
;
1857 unsigned char wxImage::GetMaskGreen() const
1859 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
1861 return M_IMGDATA
->m_maskGreen
;
1864 unsigned char wxImage::GetMaskBlue() const
1866 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
1868 return M_IMGDATA
->m_maskBlue
;
1871 void wxImage::SetMask( bool mask
)
1873 wxCHECK_RET( Ok(), wxT("invalid image") );
1877 M_IMGDATA
->m_hasMask
= mask
;
1880 bool wxImage::HasMask() const
1882 wxCHECK_MSG( Ok(), false, wxT("invalid image") );
1884 return M_IMGDATA
->m_hasMask
;
1887 bool wxImage::IsTransparent(int x
, int y
, unsigned char threshold
) const
1889 long pos
= XYToIndex(x
, y
);
1890 wxCHECK_MSG( pos
!= -1, false, wxT("invalid image coordinates") );
1893 if ( M_IMGDATA
->m_hasMask
)
1895 const unsigned char *p
= M_IMGDATA
->m_data
+ 3*pos
;
1896 if ( p
[0] == M_IMGDATA
->m_maskRed
&&
1897 p
[1] == M_IMGDATA
->m_maskGreen
&&
1898 p
[2] == M_IMGDATA
->m_maskBlue
)
1905 if ( M_IMGDATA
->m_alpha
)
1907 if ( M_IMGDATA
->m_alpha
[pos
] < threshold
)
1909 // transparent enough
1918 bool wxImage::SetMaskFromImage(const wxImage
& mask
,
1919 unsigned char mr
, unsigned char mg
, unsigned char mb
)
1921 // check that the images are the same size
1922 if ( (M_IMGDATA
->m_height
!= mask
.GetHeight() ) || (M_IMGDATA
->m_width
!= mask
.GetWidth () ) )
1924 wxLogError( _("Image and mask have different sizes.") );
1928 // find unused colour
1929 unsigned char r
,g
,b
;
1930 if (!FindFirstUnusedColour(&r
, &g
, &b
))
1932 wxLogError( _("No unused colour in image being masked.") );
1938 unsigned char *imgdata
= GetData();
1939 unsigned char *maskdata
= mask
.GetData();
1941 const int w
= GetWidth();
1942 const int h
= GetHeight();
1944 for (int j
= 0; j
< h
; j
++)
1946 for (int i
= 0; i
< w
; i
++)
1948 if ((maskdata
[0] == mr
) && (maskdata
[1] == mg
) && (maskdata
[2] == mb
))
1959 SetMaskColour(r
, g
, b
);
1965 bool wxImage::ConvertAlphaToMask(unsigned char threshold
)
1970 unsigned char mr
, mg
, mb
;
1971 if ( !FindFirstUnusedColour(&mr
, &mg
, &mb
) )
1973 wxLogError( _("No unused colour in image being masked.") );
1977 ConvertAlphaToMask(mr
, mg
, mb
, threshold
);
1981 void wxImage::ConvertAlphaToMask(unsigned char mr
,
1984 unsigned char threshold
)
1992 SetMaskColour(mr
, mg
, mb
);
1994 unsigned char *imgdata
= GetData();
1995 unsigned char *alphadata
= GetAlpha();
1998 int h
= GetHeight();
2000 for (int y
= 0; y
< h
; y
++)
2002 for (int x
= 0; x
< w
; x
++, imgdata
+= 3, alphadata
++)
2004 if (*alphadata
< threshold
)
2013 if ( !M_IMGDATA
->m_staticAlpha
)
2014 free(M_IMGDATA
->m_alpha
);
2016 M_IMGDATA
->m_alpha
= NULL
;
2017 M_IMGDATA
->m_staticAlpha
= false;
2020 // ----------------------------------------------------------------------------
2021 // Palette functions
2022 // ----------------------------------------------------------------------------
2026 bool wxImage::HasPalette() const
2031 return M_IMGDATA
->m_palette
.Ok();
2034 const wxPalette
& wxImage::GetPalette() const
2036 wxCHECK_MSG( Ok(), wxNullPalette
, wxT("invalid image") );
2038 return M_IMGDATA
->m_palette
;
2041 void wxImage::SetPalette(const wxPalette
& palette
)
2043 wxCHECK_RET( Ok(), wxT("invalid image") );
2047 M_IMGDATA
->m_palette
= palette
;
2050 #endif // wxUSE_PALETTE
2052 // ----------------------------------------------------------------------------
2053 // Option functions (arbitrary name/value mapping)
2054 // ----------------------------------------------------------------------------
2056 void wxImage::SetOption(const wxString
& name
, const wxString
& value
)
2060 int idx
= M_IMGDATA
->m_optionNames
.Index(name
, false);
2061 if ( idx
== wxNOT_FOUND
)
2063 M_IMGDATA
->m_optionNames
.Add(name
);
2064 M_IMGDATA
->m_optionValues
.Add(value
);
2068 M_IMGDATA
->m_optionNames
[idx
] = name
;
2069 M_IMGDATA
->m_optionValues
[idx
] = value
;
2073 void wxImage::SetOption(const wxString
& name
, int value
)
2076 valStr
.Printf(wxT("%d"), value
);
2077 SetOption(name
, valStr
);
2080 wxString
wxImage::GetOption(const wxString
& name
) const
2083 return wxEmptyString
;
2085 int idx
= M_IMGDATA
->m_optionNames
.Index(name
, false);
2086 if ( idx
== wxNOT_FOUND
)
2087 return wxEmptyString
;
2089 return M_IMGDATA
->m_optionValues
[idx
];
2092 int wxImage::GetOptionInt(const wxString
& name
) const
2094 return wxAtoi(GetOption(name
));
2097 bool wxImage::HasOption(const wxString
& name
) const
2099 return M_IMGDATA
? M_IMGDATA
->m_optionNames
.Index(name
, false) != wxNOT_FOUND
2103 // ----------------------------------------------------------------------------
2105 // ----------------------------------------------------------------------------
2107 bool wxImage::LoadFile( const wxString
& WXUNUSED_UNLESS_STREAMS(filename
),
2108 wxBitmapType
WXUNUSED_UNLESS_STREAMS(type
),
2109 int WXUNUSED_UNLESS_STREAMS(index
) )
2111 #if HAS_FILE_STREAMS
2112 if (wxFileExists(filename
))
2114 wxImageFileInputStream
stream(filename
);
2115 wxBufferedInputStream
bstream( stream
);
2116 return LoadFile(bstream
, type
, index
);
2120 wxLogError( _("Can't load image from file '%s': file does not exist."), filename
.c_str() );
2124 #else // !HAS_FILE_STREAMS
2126 #endif // HAS_FILE_STREAMS
2129 bool wxImage::LoadFile( const wxString
& WXUNUSED_UNLESS_STREAMS(filename
),
2130 const wxString
& WXUNUSED_UNLESS_STREAMS(mimetype
),
2131 int WXUNUSED_UNLESS_STREAMS(index
) )
2133 #if HAS_FILE_STREAMS
2134 if (wxFileExists(filename
))
2136 wxImageFileInputStream
stream(filename
);
2137 wxBufferedInputStream
bstream( stream
);
2138 return LoadFile(bstream
, mimetype
, index
);
2142 wxLogError( _("Can't load image from file '%s': file does not exist."), filename
.c_str() );
2146 #else // !HAS_FILE_STREAMS
2148 #endif // HAS_FILE_STREAMS
2152 bool wxImage::SaveFile( const wxString
& filename
) const
2154 wxString ext
= filename
.AfterLast('.').Lower();
2156 wxImageHandler
*handler
= FindHandler(ext
, wxBITMAP_TYPE_ANY
);
2159 wxLogError(_("Can't save image to file '%s': unknown extension."),
2164 return SaveFile(filename
, handler
->GetType());
2167 bool wxImage::SaveFile( const wxString
& WXUNUSED_UNLESS_STREAMS(filename
),
2168 wxBitmapType
WXUNUSED_UNLESS_STREAMS(type
) ) const
2170 #if HAS_FILE_STREAMS
2171 wxCHECK_MSG( Ok(), false, wxT("invalid image") );
2173 ((wxImage
*)this)->SetOption(wxIMAGE_OPTION_FILENAME
, filename
);
2175 wxImageFileOutputStream
stream(filename
);
2177 if ( stream
.IsOk() )
2179 wxBufferedOutputStream
bstream( stream
);
2180 return SaveFile(bstream
, type
);
2182 #endif // HAS_FILE_STREAMS
2187 bool wxImage::SaveFile( const wxString
& WXUNUSED_UNLESS_STREAMS(filename
),
2188 const wxString
& WXUNUSED_UNLESS_STREAMS(mimetype
) ) const
2190 #if HAS_FILE_STREAMS
2191 wxCHECK_MSG( Ok(), false, wxT("invalid image") );
2193 ((wxImage
*)this)->SetOption(wxIMAGE_OPTION_FILENAME
, filename
);
2195 wxImageFileOutputStream
stream(filename
);
2197 if ( stream
.IsOk() )
2199 wxBufferedOutputStream
bstream( stream
);
2200 return SaveFile(bstream
, mimetype
);
2202 #endif // HAS_FILE_STREAMS
2207 bool wxImage::CanRead( const wxString
& WXUNUSED_UNLESS_STREAMS(name
) )
2209 #if HAS_FILE_STREAMS
2210 wxImageFileInputStream
stream(name
);
2211 return CanRead(stream
);
2217 int wxImage::GetImageCount( const wxString
& WXUNUSED_UNLESS_STREAMS(name
),
2218 wxBitmapType
WXUNUSED_UNLESS_STREAMS(type
) )
2220 #if HAS_FILE_STREAMS
2221 wxImageFileInputStream
stream(name
);
2223 return GetImageCount(stream
, type
);
2231 bool wxImage::CanRead( wxInputStream
&stream
)
2233 const wxList
& list
= GetHandlers();
2235 for ( wxList::compatibility_iterator node
= list
.GetFirst(); node
; node
= node
->GetNext() )
2237 wxImageHandler
*handler
=(wxImageHandler
*)node
->GetData();
2238 if (handler
->CanRead( stream
))
2245 int wxImage::GetImageCount( wxInputStream
&stream
, wxBitmapType type
)
2247 wxImageHandler
*handler
;
2249 if ( type
== wxBITMAP_TYPE_ANY
)
2251 const wxList
& list
= GetHandlers();
2253 for ( wxList::compatibility_iterator node
= list
.GetFirst();
2255 node
= node
->GetNext() )
2257 handler
= (wxImageHandler
*)node
->GetData();
2258 if ( handler
->CanRead(stream
) )
2260 const int count
= handler
->GetImageCount(stream
);
2267 wxLogWarning(_("No handler found for image type."));
2271 handler
= FindHandler(type
);
2275 wxLogWarning(_("No image handler for type %ld defined."), type
);
2279 if ( handler
->CanRead(stream
) )
2281 return handler
->GetImageCount(stream
);
2285 wxLogError(_("Image file is not of type %ld."), type
);
2290 bool wxImage::DoLoad(wxImageHandler
& handler
, wxInputStream
& stream
, int index
)
2292 // save the options values which can be clobbered by the handler (e.g. many
2293 // of them call Destroy() before trying to load the file)
2294 const unsigned maxWidth
= GetOptionInt(wxIMAGE_OPTION_MAX_WIDTH
),
2295 maxHeight
= GetOptionInt(wxIMAGE_OPTION_MAX_HEIGHT
);
2297 if ( !handler
.LoadFile(this, stream
, true/*verbose*/, index
) )
2300 M_IMGDATA
->m_type
= handler
.GetType();
2302 // rescale the image to the specified size if needed
2303 if ( maxWidth
|| maxHeight
)
2305 const unsigned widthOrig
= GetWidth(),
2306 heightOrig
= GetHeight();
2308 // this uses the same (trivial) algorithm as the JPEG handler
2309 unsigned width
= widthOrig
,
2310 height
= heightOrig
;
2311 while ( (maxWidth
&& width
> maxWidth
) ||
2312 (maxHeight
&& height
> maxHeight
) )
2318 if ( width
!= widthOrig
|| height
!= heightOrig
)
2319 Rescale(width
, height
, wxIMAGE_QUALITY_HIGH
);
2325 bool wxImage::LoadFile( wxInputStream
& stream
, wxBitmapType type
, int index
)
2329 wxImageHandler
*handler
;
2331 if ( type
== wxBITMAP_TYPE_ANY
)
2333 const wxList
& list
= GetHandlers();
2334 for ( wxList::compatibility_iterator node
= list
.GetFirst();
2336 node
= node
->GetNext() )
2338 handler
= (wxImageHandler
*)node
->GetData();
2339 if ( handler
->CanRead(stream
) && DoLoad(*handler
, stream
, index
) )
2343 wxLogWarning( _("No handler found for image type.") );
2347 //else: have specific type
2349 handler
= FindHandler(type
);
2352 wxLogWarning( _("No image handler for type %ld defined."), type
);
2356 if ( stream
.IsSeekable() && !handler
->CanRead(stream
) )
2358 wxLogError(_("Image file is not of type %ld."), type
);
2362 return DoLoad(*handler
, stream
, index
);
2365 bool wxImage::LoadFile( wxInputStream
& stream
, const wxString
& mimetype
, int index
)
2369 m_refData
= new wxImageRefData
;
2371 wxImageHandler
*handler
= FindHandlerMime(mimetype
);
2375 wxLogWarning( _("No image handler for type %s defined."), mimetype
.GetData() );
2379 if ( stream
.IsSeekable() && !handler
->CanRead(stream
) )
2381 wxLogError(_("Image file is not of type %s."), mimetype
);
2385 return DoLoad(*handler
, stream
, index
);
2388 bool wxImage::DoSave(wxImageHandler
& handler
, wxOutputStream
& stream
) const
2390 wxImage
* const self
= const_cast<wxImage
*>(this);
2391 if ( !handler
.SaveFile(self
, stream
) )
2394 M_IMGDATA
->m_type
= handler
.GetType();
2398 bool wxImage::SaveFile( wxOutputStream
& stream
, wxBitmapType type
) const
2400 wxCHECK_MSG( Ok(), false, wxT("invalid image") );
2402 wxImageHandler
*handler
= FindHandler(type
);
2405 wxLogWarning( _("No image handler for type %d defined."), type
);
2409 return DoSave(*handler
, stream
);
2412 bool wxImage::SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
) const
2414 wxCHECK_MSG( Ok(), false, wxT("invalid image") );
2416 wxImageHandler
*handler
= FindHandlerMime(mimetype
);
2419 wxLogWarning( _("No image handler for type %s defined."), mimetype
.GetData() );
2422 return DoSave(*handler
, stream
);
2425 #endif // wxUSE_STREAMS
2427 // ----------------------------------------------------------------------------
2428 // image I/O handlers
2429 // ----------------------------------------------------------------------------
2431 void wxImage::AddHandler( wxImageHandler
*handler
)
2433 // Check for an existing handler of the type being added.
2434 if (FindHandler( handler
->GetType() ) == 0)
2436 sm_handlers
.Append( handler
);
2440 // This is not documented behaviour, merely the simplest 'fix'
2441 // for preventing duplicate additions. If someone ever has
2442 // a good reason to add and remove duplicate handlers (and they
2443 // may) we should probably refcount the duplicates.
2444 // also an issue in InsertHandler below.
2446 wxLogDebug( wxT("Adding duplicate image handler for '%s'"),
2447 handler
->GetName().c_str() );
2452 void wxImage::InsertHandler( wxImageHandler
*handler
)
2454 // Check for an existing handler of the type being added.
2455 if (FindHandler( handler
->GetType() ) == 0)
2457 sm_handlers
.Insert( handler
);
2461 // see AddHandler for additional comments.
2462 wxLogDebug( wxT("Inserting duplicate image handler for '%s'"),
2463 handler
->GetName().c_str() );
2468 bool wxImage::RemoveHandler( const wxString
& name
)
2470 wxImageHandler
*handler
= FindHandler(name
);
2473 sm_handlers
.DeleteObject(handler
);
2481 wxImageHandler
*wxImage::FindHandler( const wxString
& name
)
2483 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
2486 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
2487 if (handler
->GetName().Cmp(name
) == 0) return handler
;
2489 node
= node
->GetNext();
2494 wxImageHandler
*wxImage::FindHandler( const wxString
& extension
, wxBitmapType bitmapType
)
2496 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
2499 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
2500 if ((bitmapType
== wxBITMAP_TYPE_ANY
) || (handler
->GetType() == bitmapType
))
2502 if (handler
->GetExtension() == extension
)
2504 if (handler
->GetAltExtensions().Index(extension
, false) != wxNOT_FOUND
)
2507 node
= node
->GetNext();
2512 wxImageHandler
*wxImage::FindHandler(wxBitmapType bitmapType
)
2514 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
2517 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
2518 if (handler
->GetType() == bitmapType
) return handler
;
2519 node
= node
->GetNext();
2524 wxImageHandler
*wxImage::FindHandlerMime( const wxString
& mimetype
)
2526 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
2529 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
2530 if (handler
->GetMimeType().IsSameAs(mimetype
, false)) return handler
;
2531 node
= node
->GetNext();
2536 void wxImage::InitStandardHandlers()
2539 AddHandler(new wxBMPHandler
);
2540 #endif // wxUSE_STREAMS
2543 void wxImage::CleanUpHandlers()
2545 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
2548 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
2549 wxList::compatibility_iterator next
= node
->GetNext();
2554 sm_handlers
.Clear();
2557 wxString
wxImage::GetImageExtWildcard()
2561 wxList
& Handlers
= wxImage::GetHandlers();
2562 wxList::compatibility_iterator Node
= Handlers
.GetFirst();
2565 wxImageHandler
* Handler
= (wxImageHandler
*)Node
->GetData();
2566 fmts
+= wxT("*.") + Handler
->GetExtension();
2567 for (size_t i
= 0; i
< Handler
->GetAltExtensions().size(); i
++)
2568 fmts
+= wxT(";*.") + Handler
->GetAltExtensions()[i
];
2569 Node
= Node
->GetNext();
2570 if ( Node
) fmts
+= wxT(";");
2573 return wxT("(") + fmts
+ wxT(")|") + fmts
;
2576 wxImage::HSVValue
wxImage::RGBtoHSV(const RGBValue
& rgb
)
2578 const double red
= rgb
.red
/ 255.0,
2579 green
= rgb
.green
/ 255.0,
2580 blue
= rgb
.blue
/ 255.0;
2582 // find the min and max intensity (and remember which one was it for the
2584 double minimumRGB
= red
;
2585 if ( green
< minimumRGB
)
2587 if ( blue
< minimumRGB
)
2590 enum { RED
, GREEN
, BLUE
} chMax
= RED
;
2591 double maximumRGB
= red
;
2592 if ( green
> maximumRGB
)
2597 if ( blue
> maximumRGB
)
2603 const double value
= maximumRGB
;
2605 double hue
= 0.0, saturation
;
2606 const double deltaRGB
= maximumRGB
- minimumRGB
;
2607 if ( wxIsNullDouble(deltaRGB
) )
2609 // Gray has no color
2618 hue
= (green
- blue
) / deltaRGB
;
2622 hue
= 2.0 + (blue
- red
) / deltaRGB
;
2626 hue
= 4.0 + (red
- green
) / deltaRGB
;
2630 wxFAIL_MSG(wxT("hue not specified"));
2639 saturation
= deltaRGB
/ maximumRGB
;
2642 return HSVValue(hue
, saturation
, value
);
2645 wxImage::RGBValue
wxImage::HSVtoRGB(const HSVValue
& hsv
)
2647 double red
, green
, blue
;
2649 if ( wxIsNullDouble(hsv
.saturation
) )
2658 double hue
= hsv
.hue
* 6.0; // sector 0 to 5
2659 int i
= (int)floor(hue
);
2660 double f
= hue
- i
; // fractional part of h
2661 double p
= hsv
.value
* (1.0 - hsv
.saturation
);
2667 green
= hsv
.value
* (1.0 - hsv
.saturation
* (1.0 - f
));
2672 red
= hsv
.value
* (1.0 - hsv
.saturation
* f
);
2680 blue
= hsv
.value
* (1.0 - hsv
.saturation
* (1.0 - f
));
2685 green
= hsv
.value
* (1.0 - hsv
.saturation
* f
);
2690 red
= hsv
.value
* (1.0 - hsv
.saturation
* (1.0 - f
));
2698 blue
= hsv
.value
* (1.0 - hsv
.saturation
* f
);
2703 return RGBValue((unsigned char)(red
* 255.0),
2704 (unsigned char)(green
* 255.0),
2705 (unsigned char)(blue
* 255.0));
2709 * Rotates the hue of each pixel of the image. angle is a double in the range
2710 * -1.0..1.0 where -1.0 is -360 degrees and 1.0 is 360 degrees
2712 void wxImage::RotateHue(double angle
)
2716 unsigned char *srcBytePtr
;
2717 unsigned char *dstBytePtr
;
2718 unsigned long count
;
2719 wxImage::HSVValue hsv
;
2720 wxImage::RGBValue rgb
;
2722 wxASSERT (angle
>= -1.0 && angle
<= 1.0);
2723 count
= M_IMGDATA
->m_width
* M_IMGDATA
->m_height
;
2724 if ( count
> 0 && !wxIsNullDouble(angle
) )
2726 srcBytePtr
= M_IMGDATA
->m_data
;
2727 dstBytePtr
= srcBytePtr
;
2730 rgb
.red
= *srcBytePtr
++;
2731 rgb
.green
= *srcBytePtr
++;
2732 rgb
.blue
= *srcBytePtr
++;
2733 hsv
= RGBtoHSV(rgb
);
2735 hsv
.hue
= hsv
.hue
+ angle
;
2737 hsv
.hue
= hsv
.hue
- 1.0;
2738 else if (hsv
.hue
< 0.0)
2739 hsv
.hue
= hsv
.hue
+ 1.0;
2741 rgb
= HSVtoRGB(hsv
);
2742 *dstBytePtr
++ = rgb
.red
;
2743 *dstBytePtr
++ = rgb
.green
;
2744 *dstBytePtr
++ = rgb
.blue
;
2745 } while (--count
!= 0);
2749 //-----------------------------------------------------------------------------
2751 //-----------------------------------------------------------------------------
2753 IMPLEMENT_ABSTRACT_CLASS(wxImageHandler
,wxObject
)
2756 int wxImageHandler::GetImageCount( wxInputStream
& stream
)
2758 // NOTE: this code is the same of wxAnimationDecoder::CanRead and
2759 // wxImageHandler::CallDoCanRead
2761 if ( !stream
.IsSeekable() )
2762 return false; // can't test unseekable stream
2764 wxFileOffset posOld
= stream
.TellI();
2765 int n
= DoGetImageCount(stream
);
2767 // restore the old position to be able to test other formats and so on
2768 if ( stream
.SeekI(posOld
) == wxInvalidOffset
)
2770 wxLogDebug(wxT("Failed to rewind the stream in wxImageHandler!"));
2772 // reading would fail anyhow as we're not at the right position
2779 bool wxImageHandler::CanRead( const wxString
& name
)
2781 if (wxFileExists(name
))
2783 wxImageFileInputStream
stream(name
);
2784 return CanRead(stream
);
2787 wxLogError( _("Can't check image format of file '%s': file does not exist."), name
.c_str() );
2792 bool wxImageHandler::CallDoCanRead(wxInputStream
& stream
)
2794 // NOTE: this code is the same of wxAnimationDecoder::CanRead and
2795 // wxImageHandler::GetImageCount
2797 if ( !stream
.IsSeekable() )
2798 return false; // can't test unseekable stream
2800 wxFileOffset posOld
= stream
.TellI();
2801 bool ok
= DoCanRead(stream
);
2803 // restore the old position to be able to test other formats and so on
2804 if ( stream
.SeekI(posOld
) == wxInvalidOffset
)
2806 wxLogDebug(wxT("Failed to rewind the stream in wxImageHandler!"));
2808 // reading would fail anyhow as we're not at the right position
2815 #endif // wxUSE_STREAMS
2819 wxImageHandler::GetResolutionFromOptions(const wxImage
& image
, int *x
, int *y
)
2821 wxCHECK_MSG( x
&& y
, wxIMAGE_RESOLUTION_NONE
, wxT("NULL pointer") );
2823 if ( image
.HasOption(wxIMAGE_OPTION_RESOLUTIONX
) &&
2824 image
.HasOption(wxIMAGE_OPTION_RESOLUTIONY
) )
2826 *x
= image
.GetOptionInt(wxIMAGE_OPTION_RESOLUTIONX
);
2827 *y
= image
.GetOptionInt(wxIMAGE_OPTION_RESOLUTIONY
);
2829 else if ( image
.HasOption(wxIMAGE_OPTION_RESOLUTION
) )
2832 *y
= image
.GetOptionInt(wxIMAGE_OPTION_RESOLUTION
);
2834 else // no resolution options specified
2839 return wxIMAGE_RESOLUTION_NONE
;
2842 // get the resolution unit too
2843 int resUnit
= image
.GetOptionInt(wxIMAGE_OPTION_RESOLUTIONUNIT
);
2846 // this is the default
2847 resUnit
= wxIMAGE_RESOLUTION_INCHES
;
2850 return (wxImageResolution
)resUnit
;
2853 // ----------------------------------------------------------------------------
2854 // image histogram stuff
2855 // ----------------------------------------------------------------------------
2858 wxImageHistogram::FindFirstUnusedColour(unsigned char *r
,
2863 unsigned char g2
) const
2865 unsigned long key
= MakeKey(r2
, g2
, b2
);
2867 while ( find(key
) != end() )
2869 // color already used
2881 wxLogError(_("No unused colour in image.") );
2887 key
= MakeKey(r2
, g2
, b2
);
2901 wxImage::FindFirstUnusedColour(unsigned char *r
,
2906 unsigned char g2
) const
2908 wxImageHistogram histogram
;
2910 ComputeHistogram(histogram
);
2912 return histogram
.FindFirstUnusedColour(r
, g
, b
, r2
, g2
, b2
);
2918 // Counts and returns the number of different colours. Optionally stops
2919 // when it exceeds 'stopafter' different colours. This is useful, for
2920 // example, to see if the image can be saved as 8-bit (256 colour or
2921 // less, in this case it would be invoked as CountColours(256)). Default
2922 // value for stopafter is -1 (don't care).
2924 unsigned long wxImage::CountColours( unsigned long stopafter
) const
2928 unsigned char r
, g
, b
;
2930 unsigned long size
, nentries
, key
;
2933 size
= GetWidth() * GetHeight();
2936 for (unsigned long j
= 0; (j
< size
) && (nentries
<= stopafter
) ; j
++)
2941 key
= wxImageHistogram::MakeKey(r
, g
, b
);
2943 if (h
.Get(key
) == NULL
)
2954 unsigned long wxImage::ComputeHistogram( wxImageHistogram
&h
) const
2956 unsigned char *p
= GetData();
2957 unsigned long nentries
= 0;
2961 const unsigned long size
= GetWidth() * GetHeight();
2963 unsigned char r
, g
, b
;
2964 for ( unsigned long n
= 0; n
< size
; n
++ )
2970 wxImageHistogramEntry
& entry
= h
[wxImageHistogram::MakeKey(r
, g
, b
)];
2972 if ( entry
.value
++ == 0 )
2973 entry
.index
= nentries
++;
2980 * Rotation code by Carlos Moreno
2983 static const double wxROTATE_EPSILON
= 1e-10;
2985 // Auxiliary function to rotate a point (x,y) with respect to point p0
2986 // make it inline and use a straight return to facilitate optimization
2987 // also, the function receives the sine and cosine of the angle to avoid
2988 // repeating the time-consuming calls to these functions -- sin/cos can
2989 // be computed and stored in the calling function.
2991 static inline wxRealPoint
2992 wxRotatePoint(const wxRealPoint
& p
, double cos_angle
, double sin_angle
,
2993 const wxRealPoint
& p0
)
2995 return wxRealPoint(p0
.x
+ (p
.x
- p0
.x
) * cos_angle
- (p
.y
- p0
.y
) * sin_angle
,
2996 p0
.y
+ (p
.y
- p0
.y
) * cos_angle
+ (p
.x
- p0
.x
) * sin_angle
);
2999 static inline wxRealPoint
3000 wxRotatePoint(double x
, double y
, double cos_angle
, double sin_angle
,
3001 const wxRealPoint
& p0
)
3003 return wxRotatePoint (wxRealPoint(x
,y
), cos_angle
, sin_angle
, p0
);
3006 wxImage
wxImage::Rotate(double angle
,
3007 const wxPoint
& centre_of_rotation
,
3009 wxPoint
*offset_after_rotation
) const
3011 // screen coordinates are a mirror image of "real" coordinates
3014 const bool has_alpha
= HasAlpha();
3016 const int w
= GetWidth();
3017 const int h
= GetHeight();
3021 // Create pointer-based array to accelerate access to wxImage's data
3022 unsigned char ** data
= new unsigned char * [h
];
3023 data
[0] = GetData();
3024 for (i
= 1; i
< h
; i
++)
3025 data
[i
] = data
[i
- 1] + (3 * w
);
3027 // Same for alpha channel
3028 unsigned char ** alpha
= NULL
;
3031 alpha
= new unsigned char * [h
];
3032 alpha
[0] = GetAlpha();
3033 for (i
= 1; i
< h
; i
++)
3034 alpha
[i
] = alpha
[i
- 1] + w
;
3037 // precompute coefficients for rotation formula
3038 const double cos_angle
= cos(angle
);
3039 const double sin_angle
= sin(angle
);
3041 // Create new Image to store the result
3042 // First, find rectangle that covers the rotated image; to do that,
3043 // rotate the four corners
3045 const wxRealPoint
p0(centre_of_rotation
.x
, centre_of_rotation
.y
);
3047 wxRealPoint p1
= wxRotatePoint (0, 0, cos_angle
, sin_angle
, p0
);
3048 wxRealPoint p2
= wxRotatePoint (0, h
, cos_angle
, sin_angle
, p0
);
3049 wxRealPoint p3
= wxRotatePoint (w
, 0, cos_angle
, sin_angle
, p0
);
3050 wxRealPoint p4
= wxRotatePoint (w
, h
, cos_angle
, sin_angle
, p0
);
3052 int x1a
= (int) floor (wxMin (wxMin(p1
.x
, p2
.x
), wxMin(p3
.x
, p4
.x
)));
3053 int y1a
= (int) floor (wxMin (wxMin(p1
.y
, p2
.y
), wxMin(p3
.y
, p4
.y
)));
3054 int x2a
= (int) ceil (wxMax (wxMax(p1
.x
, p2
.x
), wxMax(p3
.x
, p4
.x
)));
3055 int y2a
= (int) ceil (wxMax (wxMax(p1
.y
, p2
.y
), wxMax(p3
.y
, p4
.y
)));
3057 // Create rotated image
3058 wxImage
rotated (x2a
- x1a
+ 1, y2a
- y1a
+ 1, false);
3059 // With alpha channel
3063 if (offset_after_rotation
!= NULL
)
3065 *offset_after_rotation
= wxPoint (x1a
, y1a
);
3068 // the rotated (destination) image is always accessed sequentially via this
3069 // pointer, there is no need for pointer-based arrays here
3070 unsigned char *dst
= rotated
.GetData();
3072 unsigned char *alpha_dst
= has_alpha
? rotated
.GetAlpha() : NULL
;
3074 // if the original image has a mask, use its RGB values as the blank pixel,
3075 // else, fall back to default (black).
3076 unsigned char blank_r
= 0;
3077 unsigned char blank_g
= 0;
3078 unsigned char blank_b
= 0;
3082 blank_r
= GetMaskRed();
3083 blank_g
= GetMaskGreen();
3084 blank_b
= GetMaskBlue();
3085 rotated
.SetMaskColour( blank_r
, blank_g
, blank_b
);
3088 // Now, for each point of the rotated image, find where it came from, by
3089 // performing an inverse rotation (a rotation of -angle) and getting the
3090 // pixel at those coordinates
3092 const int rH
= rotated
.GetHeight();
3093 const int rW
= rotated
.GetWidth();
3095 // do the (interpolating) test outside of the loops, so that it is done
3096 // only once, instead of repeating it for each pixel.
3099 for (int y
= 0; y
< rH
; y
++)
3101 for (int x
= 0; x
< rW
; x
++)
3103 wxRealPoint src
= wxRotatePoint (x
+ x1a
, y
+ y1a
, cos_angle
, -sin_angle
, p0
);
3105 if (-0.25 < src
.x
&& src
.x
< w
- 0.75 &&
3106 -0.25 < src
.y
&& src
.y
< h
- 0.75)
3108 // interpolate using the 4 enclosing grid-points. Those
3109 // points can be obtained using floor and ceiling of the
3110 // exact coordinates of the point
3113 if (0 < src
.x
&& src
.x
< w
- 1)
3115 x1
= wxRound(floor(src
.x
));
3116 x2
= wxRound(ceil(src
.x
));
3118 else // else means that x is near one of the borders (0 or width-1)
3120 x1
= x2
= wxRound (src
.x
);
3123 if (0 < src
.y
&& src
.y
< h
- 1)
3125 y1
= wxRound(floor(src
.y
));
3126 y2
= wxRound(ceil(src
.y
));
3130 y1
= y2
= wxRound (src
.y
);
3133 // get four points and the distances (square of the distance,
3134 // for efficiency reasons) for the interpolation formula
3136 // GRG: Do not calculate the points until they are
3137 // really needed -- this way we can calculate
3138 // just one, instead of four, if d1, d2, d3
3139 // or d4 are < wxROTATE_EPSILON
3141 const double d1
= (src
.x
- x1
) * (src
.x
- x1
) + (src
.y
- y1
) * (src
.y
- y1
);
3142 const double d2
= (src
.x
- x2
) * (src
.x
- x2
) + (src
.y
- y1
) * (src
.y
- y1
);
3143 const double d3
= (src
.x
- x2
) * (src
.x
- x2
) + (src
.y
- y2
) * (src
.y
- y2
);
3144 const double d4
= (src
.x
- x1
) * (src
.x
- x1
) + (src
.y
- y2
) * (src
.y
- y2
);
3146 // Now interpolate as a weighted average of the four surrounding
3147 // points, where the weights are the distances to each of those points
3149 // If the point is exactly at one point of the grid of the source
3150 // image, then don't interpolate -- just assign the pixel
3152 // d1,d2,d3,d4 are positive -- no need for abs()
3153 if (d1
< wxROTATE_EPSILON
)
3155 unsigned char *p
= data
[y1
] + (3 * x1
);
3161 *(alpha_dst
++) = *(alpha
[y1
] + x1
);
3163 else if (d2
< wxROTATE_EPSILON
)
3165 unsigned char *p
= data
[y1
] + (3 * x2
);
3171 *(alpha_dst
++) = *(alpha
[y1
] + x2
);
3173 else if (d3
< wxROTATE_EPSILON
)
3175 unsigned char *p
= data
[y2
] + (3 * x2
);
3181 *(alpha_dst
++) = *(alpha
[y2
] + x2
);
3183 else if (d4
< wxROTATE_EPSILON
)
3185 unsigned char *p
= data
[y2
] + (3 * x1
);
3191 *(alpha_dst
++) = *(alpha
[y2
] + x1
);
3195 // weights for the weighted average are proportional to the inverse of the distance
3196 unsigned char *v1
= data
[y1
] + (3 * x1
);
3197 unsigned char *v2
= data
[y1
] + (3 * x2
);
3198 unsigned char *v3
= data
[y2
] + (3 * x2
);
3199 unsigned char *v4
= data
[y2
] + (3 * x1
);
3201 const double w1
= 1/d1
, w2
= 1/d2
, w3
= 1/d3
, w4
= 1/d4
;
3205 *(dst
++) = (unsigned char)
3206 ( (w1
* *(v1
++) + w2
* *(v2
++) +
3207 w3
* *(v3
++) + w4
* *(v4
++)) /
3208 (w1
+ w2
+ w3
+ w4
) );
3209 *(dst
++) = (unsigned char)
3210 ( (w1
* *(v1
++) + w2
* *(v2
++) +
3211 w3
* *(v3
++) + w4
* *(v4
++)) /
3212 (w1
+ w2
+ w3
+ w4
) );
3213 *(dst
++) = (unsigned char)
3214 ( (w1
* *v1
+ w2
* *v2
+
3215 w3
* *v3
+ w4
* *v4
) /
3216 (w1
+ w2
+ w3
+ w4
) );
3220 v1
= alpha
[y1
] + (x1
);
3221 v2
= alpha
[y1
] + (x2
);
3222 v3
= alpha
[y2
] + (x2
);
3223 v4
= alpha
[y2
] + (x1
);
3225 *(alpha_dst
++) = (unsigned char)
3226 ( (w1
* *v1
+ w2
* *v2
+
3227 w3
* *v3
+ w4
* *v4
) /
3228 (w1
+ w2
+ w3
+ w4
) );
3244 else // not interpolating
3246 for (int y
= 0; y
< rH
; y
++)
3248 for (int x
= 0; x
< rW
; x
++)
3250 wxRealPoint src
= wxRotatePoint (x
+ x1a
, y
+ y1a
, cos_angle
, -sin_angle
, p0
);
3252 const int xs
= wxRound (src
.x
); // wxRound rounds to the
3253 const int ys
= wxRound (src
.y
); // closest integer
3255 if (0 <= xs
&& xs
< w
&& 0 <= ys
&& ys
< h
)
3257 unsigned char *p
= data
[ys
] + (3 * xs
);
3263 *(alpha_dst
++) = *(alpha
[ys
] + (xs
));
3272 *(alpha_dst
++) = 255;
3288 // A module to allow wxImage initialization/cleanup
3289 // without calling these functions from app.cpp or from
3290 // the user's application.
3292 class wxImageModule
: public wxModule
3294 DECLARE_DYNAMIC_CLASS(wxImageModule
)
3297 bool OnInit() { wxImage::InitStandardHandlers(); return true; }
3298 void OnExit() { wxImage::CleanUpHandlers(); }
3301 IMPLEMENT_DYNAMIC_CLASS(wxImageModule
, wxModule
)
3304 #endif // wxUSE_IMAGE