1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "image.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
26 #include "wx/bitmap.h"
30 #include "wx/filefn.h"
31 #include "wx/wfstream.h"
33 #include "wx/module.h"
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
49 class wxImageRefData
: public wxObjectRefData
57 unsigned char *m_data
;
59 unsigned char m_maskRed
,m_maskGreen
,m_maskBlue
;
64 #endif // wxUSE_PALETTE
65 wxArrayString m_optionNames
;
66 wxArrayString m_optionValues
;
68 DECLARE_NO_COPY_CLASS(wxImageRefData
)
71 wxImageRefData::wxImageRefData()
75 m_data
= (unsigned char*) NULL
;
84 wxImageRefData::~wxImageRefData()
86 if (m_data
&& !m_static
)
90 wxList
wxImage::sm_handlers
;
94 //-----------------------------------------------------------------------------
96 #define M_IMGDATA ((wxImageRefData *)m_refData)
98 IMPLEMENT_DYNAMIC_CLASS(wxImage
, wxObject
)
104 wxImage::wxImage( int width
, int height
)
106 Create( width
, height
);
109 wxImage::wxImage( int width
, int height
, unsigned char* data
, bool static_data
)
111 Create( width
, height
, data
, static_data
);
114 wxImage::wxImage( const wxString
& name
, long type
, int index
)
116 LoadFile( name
, type
, index
);
119 wxImage::wxImage( const wxString
& name
, const wxString
& mimetype
, int index
)
121 LoadFile( name
, mimetype
, index
);
125 wxImage::wxImage( wxInputStream
& stream
, long type
, int index
)
127 LoadFile( stream
, type
, index
);
130 wxImage::wxImage( wxInputStream
& stream
, const wxString
& mimetype
, int index
)
132 LoadFile( stream
, mimetype
, index
);
134 #endif // wxUSE_STREAMS
136 wxImage::wxImage( const wxImage
& image
)
142 wxImage::wxImage( const wxImage
* image
)
144 if (image
) Ref(*image
);
147 void wxImage::Create( int width
, int height
)
151 m_refData
= new wxImageRefData();
153 M_IMGDATA
->m_data
= (unsigned char *) malloc( width
*height
*3 );
154 if (M_IMGDATA
->m_data
)
156 for (int l
= 0; l
< width
*height
*3; l
++) M_IMGDATA
->m_data
[l
] = 0;
158 M_IMGDATA
->m_width
= width
;
159 M_IMGDATA
->m_height
= height
;
160 M_IMGDATA
->m_ok
= TRUE
;
168 void wxImage::Create( int width
, int height
, unsigned char* data
, bool static_data
)
172 m_refData
= new wxImageRefData();
174 M_IMGDATA
->m_data
= data
;
175 if (M_IMGDATA
->m_data
)
177 M_IMGDATA
->m_width
= width
;
178 M_IMGDATA
->m_height
= height
;
179 M_IMGDATA
->m_ok
= TRUE
;
180 M_IMGDATA
->m_static
= static_data
;
188 void wxImage::Destroy()
193 wxImage
wxImage::Copy() const
197 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
199 image
.Create( M_IMGDATA
->m_width
, M_IMGDATA
->m_height
);
201 char unsigned *data
= image
.GetData();
203 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
205 image
.SetMaskColour( M_IMGDATA
->m_maskRed
, M_IMGDATA
->m_maskGreen
, M_IMGDATA
->m_maskBlue
);
206 image
.SetMask( M_IMGDATA
->m_hasMask
);
208 memcpy( data
, GetData(), M_IMGDATA
->m_width
*M_IMGDATA
->m_height
*3 );
213 wxImage
wxImage::ShrinkBy( int xFactor
, int yFactor
) const
215 if( xFactor
== 1 && yFactor
== 1 )
220 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
222 // can't scale to/from 0 size
223 wxCHECK_MSG( (xFactor
> 0) && (yFactor
> 0), image
,
224 wxT("invalid new image size") );
226 long old_height
= M_IMGDATA
->m_height
,
227 old_width
= M_IMGDATA
->m_width
;
229 wxCHECK_MSG( (old_height
> 0) && (old_width
> 0), image
,
230 wxT("invalid old image size") );
232 long width
= old_width
/ xFactor
;
233 long height
= old_height
/ yFactor
;
235 image
.Create( width
, height
);
237 char unsigned *data
= image
.GetData();
239 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
241 bool hasMask
= false ;
242 unsigned char maskRed
= 0;
243 unsigned char maskGreen
= 0;
244 unsigned char maskBlue
=0 ;
245 if (M_IMGDATA
->m_hasMask
)
248 maskRed
= M_IMGDATA
->m_maskRed
;
249 maskGreen
= M_IMGDATA
->m_maskGreen
;
250 maskBlue
=M_IMGDATA
->m_maskBlue
;
252 image
.SetMaskColour( M_IMGDATA
->m_maskRed
,
253 M_IMGDATA
->m_maskGreen
,
254 M_IMGDATA
->m_maskBlue
);
256 char unsigned *source_data
= M_IMGDATA
->m_data
;
257 char unsigned *target_data
= data
;
259 for (long y
= 0; y
< height
; y
++)
262 for (long x
= 0; x
< width
; x
++)
264 unsigned long avgRed
= 0 ;
265 unsigned long avgGreen
= 0;
266 unsigned long avgBlue
= 0;
267 unsigned long counter
= 0 ;
269 for ( int y1
= 0 ; y1
< yFactor
; ++y1
)
271 long y_offset
= (y
* yFactor
+ y1
) * old_width
;
272 for ( int x1
= 0 ; x1
< xFactor
; ++x1
)
274 unsigned char *pixel
= source_data
+ 3 * ( y_offset
+ x
* xFactor
+ x1
) ;
275 unsigned char red
= pixel
[0] ;
276 unsigned char green
= pixel
[1] ;
277 unsigned char blue
= pixel
[2] ;
278 if ( !hasMask
|| red
!= maskRed
|| green
!= maskGreen
|| blue
!= maskBlue
)
289 *(target_data
++) = M_IMGDATA
->m_maskRed
;
290 *(target_data
++) = M_IMGDATA
->m_maskGreen
;
291 *(target_data
++) = M_IMGDATA
->m_maskBlue
;
295 *(target_data
++) = avgRed
/ counter
;
296 *(target_data
++) = avgGreen
/ counter
;
297 *(target_data
++) = avgBlue
/ counter
;
302 // In case this is a cursor, make sure the hotspot is scalled accordingly:
303 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
) )
304 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
,
305 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X
))/xFactor
);
306 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
) )
307 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
,
308 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y
))/yFactor
);
313 wxImage
wxImage::Scale( int width
, int height
) const
317 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
319 // can't scale to/from 0 size
320 wxCHECK_MSG( (width
> 0) && (height
> 0), image
,
321 wxT("invalid new image size") );
323 long old_height
= M_IMGDATA
->m_height
,
324 old_width
= M_IMGDATA
->m_width
;
325 wxCHECK_MSG( (old_height
> 0) && (old_width
> 0), image
,
326 wxT("invalid old image size") );
328 if ( old_width
% width
== 0 && old_width
>= width
&&
329 old_height
% height
== 0 && old_height
>= height
)
331 return ShrinkBy( old_width
/ width
, old_height
/ height
) ;
333 image
.Create( width
, height
);
335 char unsigned *data
= image
.GetData();
337 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
339 if (M_IMGDATA
->m_hasMask
)
341 image
.SetMaskColour( M_IMGDATA
->m_maskRed
,
342 M_IMGDATA
->m_maskGreen
,
343 M_IMGDATA
->m_maskBlue
);
346 char unsigned *source_data
= M_IMGDATA
->m_data
;
347 char unsigned *target_data
= data
;
350 // This is nonsense, RR.
352 // We do (x, y) -> (x, y)*oldSize/newSize but the valid values of x and y
353 // are from 0 to size-1, hence all decrement the sizes
354 long old_old_width
= old_width
;
359 for ( long j
= 0; j
<= height
; j
++ )
361 // don't crash for images with height == 1
362 long y_offset
= height
? (j
* old_height
/ height
)* old_old_width
: 0;
364 for ( long i
= 0; i
<= width
; i
++ )
366 long x_offset
= width
? (i
* old_width
) / width
: 0;
368 memcpy( target_data
, source_data
+ 3*(y_offset
+ x_offset
), 3 );
373 for (long j
= 0; j
< height
; j
++)
375 long y_offset
= (j
* old_height
/ height
) * old_width
;
377 for (long i
= 0; i
< width
; i
++)
380 source_data
+ 3*(y_offset
+ ((i
* old_width
)/ width
)),
387 // In case this is a cursor, make sure the hotspot is scalled accordingly:
388 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
) )
389 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
,
390 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X
)*width
)/old_width
);
391 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
) )
392 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
,
393 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y
)*height
)/old_height
);
398 wxImage
wxImage::Rotate90( bool clockwise
) const
402 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
404 image
.Create( M_IMGDATA
->m_height
, M_IMGDATA
->m_width
);
406 char unsigned *data
= image
.GetData();
408 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
410 if (M_IMGDATA
->m_hasMask
)
411 image
.SetMaskColour( M_IMGDATA
->m_maskRed
, M_IMGDATA
->m_maskGreen
, M_IMGDATA
->m_maskBlue
);
413 long height
= M_IMGDATA
->m_height
;
414 long width
= M_IMGDATA
->m_width
;
416 char unsigned *source_data
= M_IMGDATA
->m_data
;
417 char unsigned *target_data
;
419 for (long j
= 0; j
< height
; j
++)
421 for (long i
= 0; i
< width
; i
++)
424 target_data
= data
+ (((i
+1)*height
) - j
- 1)*3;
426 target_data
= data
+ ((height
*(width
-1)) + j
- (i
*height
))*3;
427 memcpy( target_data
, source_data
, 3 );
435 wxImage
wxImage::Mirror( bool horizontally
) const
439 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
441 image
.Create( M_IMGDATA
->m_width
, M_IMGDATA
->m_height
);
443 char unsigned *data
= image
.GetData();
445 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
447 if (M_IMGDATA
->m_hasMask
)
448 image
.SetMaskColour( M_IMGDATA
->m_maskRed
, M_IMGDATA
->m_maskGreen
, M_IMGDATA
->m_maskBlue
);
450 long height
= M_IMGDATA
->m_height
;
451 long width
= M_IMGDATA
->m_width
;
453 char unsigned *source_data
= M_IMGDATA
->m_data
;
454 char unsigned *target_data
;
458 for (long j
= 0; j
< height
; j
++)
461 target_data
= data
-3;
462 for (long i
= 0; i
< width
; i
++)
464 memcpy( target_data
, source_data
, 3 );
472 for (long i
= 0; i
< height
; i
++)
474 target_data
= data
+ 3*width
*(height
-1-i
);
475 memcpy( target_data
, source_data
, (size_t)3*width
);
476 source_data
+= 3*width
;
483 wxImage
wxImage::GetSubImage( const wxRect
&rect
) const
487 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
489 wxCHECK_MSG( (rect
.GetLeft()>=0) && (rect
.GetTop()>=0) && (rect
.GetRight()<=GetWidth()) && (rect
.GetBottom()<=GetHeight()),
490 image
, wxT("invalid subimage size") );
492 int subwidth
=rect
.GetWidth();
493 const int subheight
=rect
.GetHeight();
495 image
.Create( subwidth
, subheight
);
497 char unsigned *subdata
= image
.GetData(), *data
=GetData();
499 wxCHECK_MSG( subdata
, image
, wxT("unable to create image") );
501 if (M_IMGDATA
->m_hasMask
)
502 image
.SetMaskColour( M_IMGDATA
->m_maskRed
, M_IMGDATA
->m_maskGreen
, M_IMGDATA
->m_maskBlue
);
504 const int subleft
=3*rect
.GetLeft();
505 const int width
=3*GetWidth();
508 data
+=rect
.GetTop()*width
+subleft
;
510 for (long j
= 0; j
< subheight
; ++j
)
512 memcpy( subdata
, data
, subwidth
);
520 void wxImage::Paste( const wxImage
&image
, int x
, int y
)
522 wxCHECK_RET( Ok(), wxT("invalid image") );
523 wxCHECK_RET( image
.Ok(), wxT("invalid image") );
527 int width
= image
.GetWidth();
528 int height
= image
.GetHeight();
541 if ((x
+xx
)+width
> M_IMGDATA
->m_width
)
542 width
= M_IMGDATA
->m_width
- (x
+xx
);
543 if ((y
+yy
)+height
> M_IMGDATA
->m_height
)
544 height
= M_IMGDATA
->m_height
- (y
+yy
);
546 if (width
< 1) return;
547 if (height
< 1) return;
549 if ((!HasMask() && !image
.HasMask()) ||
550 ((HasMask() && image
.HasMask() &&
551 (GetMaskRed()==image
.GetMaskRed()) &&
552 (GetMaskGreen()==image
.GetMaskGreen()) &&
553 (GetMaskBlue()==image
.GetMaskBlue()))))
556 unsigned char* source_data
= image
.GetData() + xx
*3 + yy
*3*image
.GetWidth();
557 int source_step
= image
.GetWidth()*3;
559 unsigned char* target_data
= GetData() + (x
+xx
)*3 + (y
+yy
)*3*M_IMGDATA
->m_width
;
560 int target_step
= M_IMGDATA
->m_width
*3;
561 for (int j
= 0; j
< height
; j
++)
563 memcpy( target_data
, source_data
, width
);
564 source_data
+= source_step
;
565 target_data
+= target_step
;
570 if (!HasMask() && image
.HasMask())
572 unsigned char r
= image
.GetMaskRed();
573 unsigned char g
= image
.GetMaskGreen();
574 unsigned char b
= image
.GetMaskBlue();
577 unsigned char* source_data
= image
.GetData() + xx
*3 + yy
*3*image
.GetWidth();
578 int source_step
= image
.GetWidth()*3;
580 unsigned char* target_data
= GetData() + (x
+xx
)*3 + (y
+yy
)*3*M_IMGDATA
->m_width
;
581 int target_step
= M_IMGDATA
->m_width
*3;
583 for (int j
= 0; j
< height
; j
++)
585 for (int i
= 0; i
< width
; i
+=3)
587 if ((source_data
[i
] != r
) &&
588 (source_data
[i
+1] != g
) &&
589 (source_data
[i
+2] != b
))
591 memcpy( target_data
+i
, source_data
+i
, 3 );
594 source_data
+= source_step
;
595 target_data
+= target_step
;
600 void wxImage::Replace( unsigned char r1
, unsigned char g1
, unsigned char b1
,
601 unsigned char r2
, unsigned char g2
, unsigned char b2
)
603 wxCHECK_RET( Ok(), wxT("invalid image") );
605 char unsigned *data
= GetData();
607 const int w
= GetWidth();
608 const int h
= GetHeight();
610 for (int j
= 0; j
< h
; j
++)
611 for (int i
= 0; i
< w
; i
++)
613 if ((data
[0] == r1
) && (data
[1] == g1
) && (data
[2] == b1
))
623 wxImage
wxImage::ConvertToMono( unsigned char r
, unsigned char g
, unsigned char b
) const
627 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
629 image
.Create( M_IMGDATA
->m_width
, M_IMGDATA
->m_height
);
631 char unsigned *data
= image
.GetData();
633 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
635 if (M_IMGDATA
->m_hasMask
)
637 if (M_IMGDATA
->m_maskRed
== r
&& M_IMGDATA
->m_maskGreen
== g
&&
638 M_IMGDATA
->m_maskBlue
== b
)
639 image
.SetMaskColour( 255, 255, 255 );
641 image
.SetMaskColour( 0, 0, 0 );
644 long size
= M_IMGDATA
->m_height
* M_IMGDATA
->m_width
;
646 char unsigned *srcd
= M_IMGDATA
->m_data
;
647 char unsigned *tard
= image
.GetData();
649 for ( long i
= 0; i
< size
; i
++, srcd
+= 3, tard
+= 3 )
651 if (srcd
[0] == r
&& srcd
[1] == g
&& srcd
[2] == b
)
652 tard
[0] = tard
[1] = tard
[2] = 255;
654 tard
[0] = tard
[1] = tard
[2] = 0;
660 void wxImage::SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
)
662 wxCHECK_RET( Ok(), wxT("invalid image") );
664 int w
= M_IMGDATA
->m_width
;
665 int h
= M_IMGDATA
->m_height
;
667 wxCHECK_RET( (x
>=0) && (y
>=0) && (x
<w
) && (y
<h
), wxT("invalid image index") );
669 long pos
= (y
* w
+ x
) * 3;
671 M_IMGDATA
->m_data
[ pos
] = r
;
672 M_IMGDATA
->m_data
[ pos
+1 ] = g
;
673 M_IMGDATA
->m_data
[ pos
+2 ] = b
;
676 unsigned char wxImage::GetRed( int x
, int y
) const
678 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
680 int w
= M_IMGDATA
->m_width
;
681 int h
= M_IMGDATA
->m_height
;
683 wxCHECK_MSG( (x
>=0) && (y
>=0) && (x
<w
) && (y
<h
), 0, wxT("invalid image index") );
685 long pos
= (y
* w
+ x
) * 3;
687 return M_IMGDATA
->m_data
[pos
];
690 unsigned char wxImage::GetGreen( int x
, int y
) const
692 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
694 int w
= M_IMGDATA
->m_width
;
695 int h
= M_IMGDATA
->m_height
;
697 wxCHECK_MSG( (x
>=0) && (y
>=0) && (x
<w
) && (y
<h
), 0, wxT("invalid image index") );
699 long pos
= (y
* w
+ x
) * 3;
701 return M_IMGDATA
->m_data
[pos
+1];
704 unsigned char wxImage::GetBlue( int x
, int y
) const
706 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
708 int w
= M_IMGDATA
->m_width
;
709 int h
= M_IMGDATA
->m_height
;
711 wxCHECK_MSG( (x
>=0) && (y
>=0) && (x
<w
) && (y
<h
), 0, wxT("invalid image index") );
713 long pos
= (y
* w
+ x
) * 3;
715 return M_IMGDATA
->m_data
[pos
+2];
718 bool wxImage::Ok() const
720 // image of 0 width or height can't be considered ok - at least because it
721 // causes crashes in ConvertToBitmap() if we don't catch it in time
722 wxImageRefData
*data
= M_IMGDATA
;
723 return data
&& data
->m_ok
&& data
->m_width
&& data
->m_height
;
726 char unsigned *wxImage::GetData() const
728 wxCHECK_MSG( Ok(), (char unsigned *)NULL
, wxT("invalid image") );
730 return M_IMGDATA
->m_data
;
733 void wxImage::SetData( char unsigned *data
)
735 wxCHECK_RET( Ok(), wxT("invalid image") );
737 wxImageRefData
*newRefData
= new wxImageRefData();
739 newRefData
->m_width
= M_IMGDATA
->m_width
;
740 newRefData
->m_height
= M_IMGDATA
->m_height
;
741 newRefData
->m_data
= data
;
742 newRefData
->m_ok
= TRUE
;
743 newRefData
->m_maskRed
= M_IMGDATA
->m_maskRed
;
744 newRefData
->m_maskGreen
= M_IMGDATA
->m_maskGreen
;
745 newRefData
->m_maskBlue
= M_IMGDATA
->m_maskBlue
;
746 newRefData
->m_hasMask
= M_IMGDATA
->m_hasMask
;
750 m_refData
= newRefData
;
753 void wxImage::SetData( char unsigned *data
, int new_width
, int new_height
)
755 wxImageRefData
*newRefData
= new wxImageRefData();
759 newRefData
->m_width
= new_width
;
760 newRefData
->m_height
= new_height
;
761 newRefData
->m_data
= data
;
762 newRefData
->m_ok
= TRUE
;
763 newRefData
->m_maskRed
= M_IMGDATA
->m_maskRed
;
764 newRefData
->m_maskGreen
= M_IMGDATA
->m_maskGreen
;
765 newRefData
->m_maskBlue
= M_IMGDATA
->m_maskBlue
;
766 newRefData
->m_hasMask
= M_IMGDATA
->m_hasMask
;
770 newRefData
->m_width
= new_width
;
771 newRefData
->m_height
= new_height
;
772 newRefData
->m_data
= data
;
773 newRefData
->m_ok
= TRUE
;
778 m_refData
= newRefData
;
781 void wxImage::SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
)
783 wxCHECK_RET( Ok(), wxT("invalid image") );
785 M_IMGDATA
->m_maskRed
= r
;
786 M_IMGDATA
->m_maskGreen
= g
;
787 M_IMGDATA
->m_maskBlue
= b
;
788 M_IMGDATA
->m_hasMask
= TRUE
;
791 unsigned char wxImage::GetMaskRed() const
793 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
795 return M_IMGDATA
->m_maskRed
;
798 unsigned char wxImage::GetMaskGreen() const
800 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
802 return M_IMGDATA
->m_maskGreen
;
805 unsigned char wxImage::GetMaskBlue() const
807 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
809 return M_IMGDATA
->m_maskBlue
;
812 void wxImage::SetMask( bool mask
)
814 wxCHECK_RET( Ok(), wxT("invalid image") );
816 M_IMGDATA
->m_hasMask
= mask
;
819 bool wxImage::HasMask() const
821 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid image") );
823 return M_IMGDATA
->m_hasMask
;
826 int wxImage::GetWidth() const
828 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
830 return M_IMGDATA
->m_width
;
833 int wxImage::GetHeight() const
835 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
837 return M_IMGDATA
->m_height
;
841 bool wxImage::FindFirstUnusedColour(
842 unsigned char *r
, unsigned char *g
, unsigned char *b
,
843 unsigned char startR
, unsigned char startG
, unsigned char startB
) const
845 wxImageHistogram histogram
;
848 ComputeHistogram(histogram
);
850 unsigned char r2
= startR
;
851 unsigned char g2
= startG
;
852 unsigned char b2
= startB
;
854 key
= (r2
<< 16) | (g2
<< 8) | b2
;
856 while ( histogram
.find(key
) != histogram
.end() )
858 // color already used
870 wxLogError( _("GetUnusedColour:: No Unused Color in image ") );
876 key
= (r2
<< 16) | (g2
<< 8) | b2
;
887 bool wxImage::SetMaskFromImage(const wxImage
& mask
,
888 unsigned char mr
, unsigned char mg
, unsigned char mb
)
890 // check that the images are the same size
891 if ( (M_IMGDATA
->m_height
!= mask
.GetHeight() ) || (M_IMGDATA
->m_width
!= mask
.GetWidth () ) )
893 wxLogError( _("Image and Mask have different sizes") );
897 // find unused colour
898 unsigned char r
,g
,b
;
899 if (!FindFirstUnusedColour(&r
, &g
, &b
))
901 wxLogError( _("No Unused Color in image being masked") );
905 char unsigned *imgdata
= GetData();
906 char unsigned *maskdata
= mask
.GetData();
908 const int w
= GetWidth();
909 const int h
= GetHeight();
911 for (int j
= 0; j
< h
; j
++)
913 for (int i
= 0; i
< w
; i
++)
915 if ((maskdata
[0] == mr
) && (maskdata
[1] == mg
) && (maskdata
[2] == mb
))
926 SetMaskColour(r
, g
, b
);
936 bool wxImage::HasPalette() const
941 return M_IMGDATA
->m_palette
.Ok();
944 const wxPalette
& wxImage::GetPalette() const
946 wxCHECK_MSG( Ok(), wxNullPalette
, wxT("invalid image") );
948 return M_IMGDATA
->m_palette
;
951 void wxImage::SetPalette(const wxPalette
& palette
)
953 wxCHECK_RET( Ok(), wxT("invalid image") );
955 M_IMGDATA
->m_palette
= palette
;
958 #endif // wxUSE_PALETTE
960 // Option functions (arbitrary name/value mapping)
961 void wxImage::SetOption(const wxString
& name
, const wxString
& value
)
963 wxCHECK_RET( Ok(), wxT("invalid image") );
965 int idx
= M_IMGDATA
->m_optionNames
.Index(name
, FALSE
);
966 if (idx
== wxNOT_FOUND
)
968 M_IMGDATA
->m_optionNames
.Add(name
);
969 M_IMGDATA
->m_optionValues
.Add(value
);
973 M_IMGDATA
->m_optionNames
[idx
] = name
;
974 M_IMGDATA
->m_optionValues
[idx
] = value
;
978 void wxImage::SetOption(const wxString
& name
, int value
)
981 valStr
.Printf(wxT("%d"), value
);
982 SetOption(name
, valStr
);
985 wxString
wxImage::GetOption(const wxString
& name
) const
987 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid image") );
989 int idx
= M_IMGDATA
->m_optionNames
.Index(name
, FALSE
);
990 if (idx
== wxNOT_FOUND
)
991 return wxEmptyString
;
993 return M_IMGDATA
->m_optionValues
[idx
];
996 int wxImage::GetOptionInt(const wxString
& name
) const
998 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
1000 return wxAtoi(GetOption(name
));
1003 bool wxImage::HasOption(const wxString
& name
) const
1005 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid image") );
1007 return (M_IMGDATA
->m_optionNames
.Index(name
, FALSE
) != wxNOT_FOUND
);
1010 bool wxImage::LoadFile( const wxString
& filename
, long type
, int index
)
1013 if (wxFileExists(filename
))
1015 wxFileInputStream
stream(filename
);
1016 wxBufferedInputStream
bstream( stream
);
1017 return LoadFile(bstream
, type
, index
);
1021 wxLogError( _("Can't load image from file '%s': file does not exist."), filename
.c_str() );
1025 #else // !wxUSE_STREAMS
1027 #endif // wxUSE_STREAMS
1030 bool wxImage::LoadFile( const wxString
& filename
, const wxString
& mimetype
, int index
)
1033 if (wxFileExists(filename
))
1035 wxFileInputStream
stream(filename
);
1036 wxBufferedInputStream
bstream( stream
);
1037 return LoadFile(bstream
, mimetype
, index
);
1041 wxLogError( _("Can't load image from file '%s': file does not exist."), filename
.c_str() );
1045 #else // !wxUSE_STREAMS
1047 #endif // wxUSE_STREAMS
1052 bool wxImage::SaveFile( const wxString
& filename
) const
1054 wxString ext
= filename
.AfterLast('.').Lower();
1056 wxImageHandler
* pHandler
= FindHandler(ext
, -1);
1059 SaveFile(filename
, pHandler
->GetType());
1063 wxLogError(_("Can't save image to file '%s': unknown extension."), filename
.c_str());
1068 bool wxImage::SaveFile( const wxString
& filename
, int type
) const
1071 ((wxImage
*)this)->SetOption(wxIMAGE_OPTION_FILENAME
, filename
);
1073 wxFileOutputStream
stream(filename
);
1075 if ( stream
.IsOk() )
1077 wxBufferedOutputStream
bstream( stream
);
1078 return SaveFile(bstream
, type
);
1080 #endif // wxUSE_STREAMS
1085 bool wxImage::SaveFile( const wxString
& filename
, const wxString
& mimetype
) const
1088 ((wxImage
*)this)->SetOption(wxIMAGE_OPTION_FILENAME
, filename
);
1090 wxFileOutputStream
stream(filename
);
1092 if ( stream
.IsOk() )
1094 wxBufferedOutputStream
bstream( stream
);
1095 return SaveFile(bstream
, mimetype
);
1097 #endif // wxUSE_STREAMS
1102 bool wxImage::CanRead( const wxString
&name
)
1105 wxFileInputStream
stream(name
);
1106 return CanRead(stream
);
1112 int wxImage::GetImageCount( const wxString
&name
, long type
)
1115 wxFileInputStream
stream(name
);
1117 return GetImageCount(stream
, type
);
1125 bool wxImage::CanRead( wxInputStream
&stream
)
1127 const wxList
& list
= GetHandlers();
1129 for ( wxList::Node
*node
= list
.GetFirst(); node
; node
= node
->GetNext() )
1131 wxImageHandler
*handler
=(wxImageHandler
*)node
->GetData();
1132 if (handler
->CanRead( stream
))
1139 int wxImage::GetImageCount( wxInputStream
&stream
, long type
)
1141 wxImageHandler
*handler
;
1143 if ( type
== wxBITMAP_TYPE_ANY
)
1145 wxList
&list
=GetHandlers();
1147 for (wxList::Node
*node
= list
.GetFirst(); node
; node
= node
->GetNext())
1149 handler
=(wxImageHandler
*)node
->GetData();
1150 if ( handler
->CanRead(stream
) )
1151 return handler
->GetImageCount(stream
);
1155 wxLogWarning(_("No handler found for image type."));
1159 handler
= FindHandler(type
);
1163 wxLogWarning(_("No image handler for type %d defined."), type
);
1167 if ( handler
->CanRead(stream
) )
1169 return handler
->GetImageCount(stream
);
1173 wxLogError(_("Image file is not of type %d."), type
);
1178 bool wxImage::LoadFile( wxInputStream
& stream
, long type
, int index
)
1182 m_refData
= new wxImageRefData
;
1184 wxImageHandler
*handler
;
1186 if ( type
== wxBITMAP_TYPE_ANY
)
1188 wxList
&list
=GetHandlers();
1190 for ( wxList::Node
*node
= list
.GetFirst(); node
; node
= node
->GetNext() )
1192 handler
=(wxImageHandler
*)node
->GetData();
1193 if ( handler
->CanRead(stream
) )
1194 return handler
->LoadFile(this, stream
, TRUE
/*verbose*/, index
);
1198 wxLogWarning( _("No handler found for image type.") );
1202 handler
= FindHandler(type
);
1206 wxLogWarning( _("No image handler for type %d defined."), type
);
1211 return handler
->LoadFile(this, stream
, TRUE
/*verbose*/, index
);
1214 bool wxImage::LoadFile( wxInputStream
& stream
, const wxString
& mimetype
, int index
)
1218 m_refData
= new wxImageRefData
;
1220 wxImageHandler
*handler
= FindHandlerMime(mimetype
);
1224 wxLogWarning( _("No image handler for type %s defined."), mimetype
.GetData() );
1229 return handler
->LoadFile( this, stream
, TRUE
/*verbose*/, index
);
1232 bool wxImage::SaveFile( wxOutputStream
& stream
, int type
) const
1234 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid image") );
1236 wxImageHandler
*handler
= FindHandler(type
);
1240 wxLogWarning( _("No image handler for type %d defined."), type
);
1245 return handler
->SaveFile( (wxImage
*)this, stream
);
1248 bool wxImage::SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
) const
1250 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid image") );
1252 wxImageHandler
*handler
= FindHandlerMime(mimetype
);
1256 wxLogWarning( _("No image handler for type %s defined."), mimetype
.GetData() );
1261 return handler
->SaveFile( (wxImage
*)this, stream
);
1263 #endif // wxUSE_STREAMS
1265 void wxImage::AddHandler( wxImageHandler
*handler
)
1267 // make sure that the memory will be freed at the program end
1268 sm_handlers
.DeleteContents(TRUE
);
1270 // Check for an existing handler of the type being added.
1271 if (FindHandler( handler
->GetType() ) == 0)
1273 sm_handlers
.Append( handler
);
1277 // This is not documented behaviour, merely the simplest 'fix'
1278 // for preventing duplicate additions. If someone ever has
1279 // a good reason to add and remove duplicate handlers (and they
1280 // may) we should probably refcount the duplicates.
1281 // also an issue in InsertHandler below.
1283 wxLogDebug( _T("Adding duplicate image handler for '%s'"),
1284 handler
->GetName().c_str() );
1289 void wxImage::InsertHandler( wxImageHandler
*handler
)
1291 // make sure that the memory will be freed at the program end
1292 sm_handlers
.DeleteContents(TRUE
);
1294 // Check for an existing handler of the type being added.
1295 if (FindHandler( handler
->GetType() ) == 0)
1297 sm_handlers
.Insert( handler
);
1301 // see AddHandler for additional comments.
1302 wxLogDebug( _T("Inserting duplicate image handler for '%s'"),
1303 handler
->GetName().c_str() );
1308 bool wxImage::RemoveHandler( const wxString
& name
)
1310 wxImageHandler
*handler
= FindHandler(name
);
1313 sm_handlers
.DeleteObject(handler
);
1320 wxImageHandler
*wxImage::FindHandler( const wxString
& name
)
1322 wxNode
*node
= sm_handlers
.GetFirst();
1325 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
1326 if (handler
->GetName().Cmp(name
) == 0) return handler
;
1328 node
= node
->GetNext();
1333 wxImageHandler
*wxImage::FindHandler( const wxString
& extension
, long bitmapType
)
1335 wxNode
*node
= sm_handlers
.GetFirst();
1338 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
1339 if ( (handler
->GetExtension().Cmp(extension
) == 0) &&
1340 (bitmapType
== -1 || handler
->GetType() == bitmapType
) )
1342 node
= node
->GetNext();
1347 wxImageHandler
*wxImage::FindHandler( long bitmapType
)
1349 wxNode
*node
= sm_handlers
.GetFirst();
1352 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
1353 if (handler
->GetType() == bitmapType
) return handler
;
1354 node
= node
->GetNext();
1359 wxImageHandler
*wxImage::FindHandlerMime( const wxString
& mimetype
)
1361 wxNode
*node
= sm_handlers
.GetFirst();
1364 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
1365 if (handler
->GetMimeType().IsSameAs(mimetype
, FALSE
)) return handler
;
1366 node
= node
->GetNext();
1371 void wxImage::InitStandardHandlers()
1374 AddHandler(new wxBMPHandler
);
1375 #endif // wxUSE_STREAMS
1378 void wxImage::CleanUpHandlers()
1380 wxNode
*node
= sm_handlers
.GetFirst();
1383 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
1384 wxNode
*next
= node
->GetNext();
1391 //-----------------------------------------------------------------------------
1393 //-----------------------------------------------------------------------------
1395 IMPLEMENT_ABSTRACT_CLASS(wxImageHandler
,wxObject
)
1398 bool wxImageHandler::LoadFile( wxImage
*WXUNUSED(image
), wxInputStream
& WXUNUSED(stream
), bool WXUNUSED(verbose
), int WXUNUSED(index
) )
1403 bool wxImageHandler::SaveFile( wxImage
*WXUNUSED(image
), wxOutputStream
& WXUNUSED(stream
), bool WXUNUSED(verbose
) )
1408 int wxImageHandler::GetImageCount( wxInputStream
& WXUNUSED(stream
) )
1413 bool wxImageHandler::CanRead( const wxString
& name
)
1415 if (wxFileExists(name
))
1417 wxFileInputStream
stream(name
);
1418 return CanRead(stream
);
1421 wxLogError( _("Can't check image format of file '%s': file does not exist."), name
.c_str() );
1426 bool wxImageHandler::CallDoCanRead(wxInputStream
& stream
)
1428 off_t posOld
= stream
.TellI();
1429 if ( posOld
== wxInvalidOffset
)
1431 // can't test unseekable stream
1435 bool ok
= DoCanRead(stream
);
1437 // restore the old position to be able to test other formats and so on
1438 if ( stream
.SeekI(posOld
) == wxInvalidOffset
)
1440 wxLogDebug(_T("Failed to rewind the stream in wxImageHandler!"));
1442 // reading would fail anyhow as we're not at the right position
1449 #endif // wxUSE_STREAMS
1453 //-----------------------------------------------------------------------------
1454 // Deprecated wxBitmap conversion routines
1455 //-----------------------------------------------------------------------------
1457 #if WXWIN_COMPATIBILITY_2_2 && wxUSE_GUI
1460 wxBitmap
wxImage::ConvertToMonoBitmap( unsigned char red
, unsigned char green
, unsigned char blue
) const
1462 wxImage mono
= this->ConvertToMono( red
, green
, blue
);
1463 wxBitmap
bitmap( mono
, 1 );
1468 wxBitmap
wxImage::ConvertToBitmap() const
1470 wxBitmap
bitmap( *this );
1474 wxImage::wxImage( const wxBitmap
&bitmap
)
1476 *this = bitmap
.ConvertToImage();
1479 #endif // WXWIN_COMPATIBILITY_2_2 && wxUSE_GUI
1482 //-----------------------------------------------------------------------------
1485 // Counts and returns the number of different colours. Optionally stops
1486 // when it exceeds 'stopafter' different colours. This is useful, for
1487 // example, to see if the image can be saved as 8-bit (256 colour or
1488 // less, in this case it would be invoked as CountColours(256)). Default
1489 // value for stopafter is -1 (don't care).
1491 unsigned long wxImage::CountColours( unsigned long stopafter
) const
1495 unsigned char r
, g
, b
;
1497 unsigned long size
, nentries
, key
;
1500 size
= GetWidth() * GetHeight();
1503 for (unsigned long j
= 0; (j
< size
) && (nentries
<= stopafter
) ; j
++)
1508 key
= (r
<< 16) | (g
<< 8) | b
;
1510 if (h
.Get(key
) == NULL
)
1521 unsigned long wxImage::ComputeHistogram( wxImageHistogram
&h
) const
1523 unsigned char r
, g
, b
;
1525 unsigned long size
, nentries
, key
;
1530 size
= GetWidth() * GetHeight();
1533 for (unsigned long j
= 0; j
< size
; j
++)
1538 key
= (r
<< 16) | (g
<< 8) | b
;
1540 wxImageHistogramEntry
& entry
= h
[key
];
1541 if ( entry
.value
++ == 0 )
1542 entry
.index
= nentries
++;
1549 * Rotation code by Carlos Moreno
1552 // GRG: I've removed wxRotationPoint - we already have wxRealPoint which
1553 // does exactly the same thing. And I also got rid of wxRotationPixel
1554 // bacause of potential problems in architectures where alignment
1555 // is an issue, so I had to rewrite parts of the code.
1557 static const double gs_Epsilon
= 1e-10;
1559 static inline int wxCint (double x
)
1561 return (x
> 0) ? (int) (x
+ 0.5) : (int) (x
- 0.5);
1565 // Auxiliary function to rotate a point (x,y) with respect to point p0
1566 // make it inline and use a straight return to facilitate optimization
1567 // also, the function receives the sine and cosine of the angle to avoid
1568 // repeating the time-consuming calls to these functions -- sin/cos can
1569 // be computed and stored in the calling function.
1571 inline wxRealPoint
rotated_point (const wxRealPoint
& p
, double cos_angle
, double sin_angle
, const wxRealPoint
& p0
)
1573 return wxRealPoint (p0
.x
+ (p
.x
- p0
.x
) * cos_angle
- (p
.y
- p0
.y
) * sin_angle
,
1574 p0
.y
+ (p
.y
- p0
.y
) * cos_angle
+ (p
.x
- p0
.x
) * sin_angle
);
1577 inline wxRealPoint
rotated_point (double x
, double y
, double cos_angle
, double sin_angle
, const wxRealPoint
& p0
)
1579 return rotated_point (wxRealPoint(x
,y
), cos_angle
, sin_angle
, p0
);
1582 wxImage
wxImage::Rotate(double angle
, const wxPoint
& centre_of_rotation
, bool interpolating
, wxPoint
* offset_after_rotation
) const
1585 angle
= -angle
; // screen coordinates are a mirror image of "real" coordinates
1587 // Create pointer-based array to accelerate access to wxImage's data
1588 unsigned char ** data
= new unsigned char * [GetHeight()];
1590 data
[0] = GetData();
1592 for (i
= 1; i
< GetHeight(); i
++)
1593 data
[i
] = data
[i
- 1] + (3 * GetWidth());
1595 // precompute coefficients for rotation formula
1596 // (sine and cosine of the angle)
1597 const double cos_angle
= cos(angle
);
1598 const double sin_angle
= sin(angle
);
1600 // Create new Image to store the result
1601 // First, find rectangle that covers the rotated image; to do that,
1602 // rotate the four corners
1604 const wxRealPoint
p0(centre_of_rotation
.x
, centre_of_rotation
.y
);
1606 wxRealPoint p1
= rotated_point (0, 0, cos_angle
, sin_angle
, p0
);
1607 wxRealPoint p2
= rotated_point (0, GetHeight(), cos_angle
, sin_angle
, p0
);
1608 wxRealPoint p3
= rotated_point (GetWidth(), 0, cos_angle
, sin_angle
, p0
);
1609 wxRealPoint p4
= rotated_point (GetWidth(), GetHeight(), cos_angle
, sin_angle
, p0
);
1611 int x1
= (int) floor (wxMin (wxMin(p1
.x
, p2
.x
), wxMin(p3
.x
, p4
.x
)));
1612 int y1
= (int) floor (wxMin (wxMin(p1
.y
, p2
.y
), wxMin(p3
.y
, p4
.y
)));
1613 int x2
= (int) ceil (wxMax (wxMax(p1
.x
, p2
.x
), wxMax(p3
.x
, p4
.x
)));
1614 int y2
= (int) ceil (wxMax (wxMax(p1
.y
, p2
.y
), wxMax(p3
.y
, p4
.y
)));
1616 wxImage
rotated (x2
- x1
+ 1, y2
- y1
+ 1);
1618 if (offset_after_rotation
!= NULL
)
1620 *offset_after_rotation
= wxPoint (x1
, y1
);
1623 // GRG: The rotated (destination) image is always accessed
1624 // sequentially, so there is no need for a pointer-based
1625 // array here (and in fact it would be slower).
1627 unsigned char * dst
= rotated
.GetData();
1629 // GRG: if the original image has a mask, use its RGB values
1630 // as the blank pixel, else, fall back to default (black).
1632 unsigned char blank_r
= 0;
1633 unsigned char blank_g
= 0;
1634 unsigned char blank_b
= 0;
1638 blank_r
= GetMaskRed();
1639 blank_g
= GetMaskGreen();
1640 blank_b
= GetMaskBlue();
1641 rotated
.SetMaskColour( blank_r
, blank_g
, blank_b
);
1644 // Now, for each point of the rotated image, find where it came from, by
1645 // performing an inverse rotation (a rotation of -angle) and getting the
1646 // pixel at those coordinates
1648 // GRG: I've taken the (interpolating) test out of the loops, so that
1649 // it is done only once, instead of repeating it for each pixel.
1654 for (int y
= 0; y
< rotated
.GetHeight(); y
++)
1656 for (x
= 0; x
< rotated
.GetWidth(); x
++)
1658 wxRealPoint src
= rotated_point (x
+ x1
, y
+ y1
, cos_angle
, -sin_angle
, p0
);
1660 if (-0.25 < src
.x
&& src
.x
< GetWidth() - 0.75 &&
1661 -0.25 < src
.y
&& src
.y
< GetHeight() - 0.75)
1663 // interpolate using the 4 enclosing grid-points. Those
1664 // points can be obtained using floor and ceiling of the
1665 // exact coordinates of the point
1666 // C.M. 2000-02-17: when the point is near the border, special care is required.
1670 if (0 < src
.x
&& src
.x
< GetWidth() - 1)
1672 x1
= wxCint(floor(src
.x
));
1673 x2
= wxCint(ceil(src
.x
));
1675 else // else means that x is near one of the borders (0 or width-1)
1677 x1
= x2
= wxCint (src
.x
);
1680 if (0 < src
.y
&& src
.y
< GetHeight() - 1)
1682 y1
= wxCint(floor(src
.y
));
1683 y2
= wxCint(ceil(src
.y
));
1687 y1
= y2
= wxCint (src
.y
);
1690 // get four points and the distances (square of the distance,
1691 // for efficiency reasons) for the interpolation formula
1693 // GRG: Do not calculate the points until they are
1694 // really needed -- this way we can calculate
1695 // just one, instead of four, if d1, d2, d3
1696 // or d4 are < gs_Epsilon
1698 const double d1
= (src
.x
- x1
) * (src
.x
- x1
) + (src
.y
- y1
) * (src
.y
- y1
);
1699 const double d2
= (src
.x
- x2
) * (src
.x
- x2
) + (src
.y
- y1
) * (src
.y
- y1
);
1700 const double d3
= (src
.x
- x2
) * (src
.x
- x2
) + (src
.y
- y2
) * (src
.y
- y2
);
1701 const double d4
= (src
.x
- x1
) * (src
.x
- x1
) + (src
.y
- y2
) * (src
.y
- y2
);
1703 // Now interpolate as a weighted average of the four surrounding
1704 // points, where the weights are the distances to each of those points
1706 // If the point is exactly at one point of the grid of the source
1707 // image, then don't interpolate -- just assign the pixel
1709 if (d1
< gs_Epsilon
) // d1,d2,d3,d4 are positive -- no need for abs()
1711 unsigned char *p
= data
[y1
] + (3 * x1
);
1716 else if (d2
< gs_Epsilon
)
1718 unsigned char *p
= data
[y1
] + (3 * x2
);
1723 else if (d3
< gs_Epsilon
)
1725 unsigned char *p
= data
[y2
] + (3 * x2
);
1730 else if (d4
< gs_Epsilon
)
1732 unsigned char *p
= data
[y2
] + (3 * x1
);
1739 // weights for the weighted average are proportional to the inverse of the distance
1740 unsigned char *v1
= data
[y1
] + (3 * x1
);
1741 unsigned char *v2
= data
[y1
] + (3 * x2
);
1742 unsigned char *v3
= data
[y2
] + (3 * x2
);
1743 unsigned char *v4
= data
[y2
] + (3 * x1
);
1745 const double w1
= 1/d1
, w2
= 1/d2
, w3
= 1/d3
, w4
= 1/d4
;
1749 *(dst
++) = (unsigned char)
1750 ( (w1
* *(v1
++) + w2
* *(v2
++) +
1751 w3
* *(v3
++) + w4
* *(v4
++)) /
1752 (w1
+ w2
+ w3
+ w4
) );
1753 *(dst
++) = (unsigned char)
1754 ( (w1
* *(v1
++) + w2
* *(v2
++) +
1755 w3
* *(v3
++) + w4
* *(v4
++)) /
1756 (w1
+ w2
+ w3
+ w4
) );
1757 *(dst
++) = (unsigned char)
1758 ( (w1
* *(v1
++) + w2
* *(v2
++) +
1759 w3
* *(v3
++) + w4
* *(v4
++)) /
1760 (w1
+ w2
+ w3
+ w4
) );
1772 else // not interpolating
1774 for (int y
= 0; y
< rotated
.GetHeight(); y
++)
1776 for (x
= 0; x
< rotated
.GetWidth(); x
++)
1778 wxRealPoint src
= rotated_point (x
+ x1
, y
+ y1
, cos_angle
, -sin_angle
, p0
);
1780 const int xs
= wxCint (src
.x
); // wxCint rounds to the
1781 const int ys
= wxCint (src
.y
); // closest integer
1783 if (0 <= xs
&& xs
< GetWidth() &&
1784 0 <= ys
&& ys
< GetHeight())
1786 unsigned char *p
= data
[ys
] + (3 * xs
);
1810 // A module to allow wxImage initialization/cleanup
1811 // without calling these functions from app.cpp or from
1812 // the user's application.
1814 class wxImageModule
: public wxModule
1816 DECLARE_DYNAMIC_CLASS(wxImageModule
)
1819 bool OnInit() { wxImage::InitStandardHandlers(); return TRUE
; };
1820 void OnExit() { wxImage::CleanUpHandlers(); };
1823 IMPLEMENT_DYNAMIC_CLASS(wxImageModule
, wxModule
)
1826 #endif // wxUSE_IMAGE