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
++)
261 for (long x
= 0; x
< width
; x
++)
263 unsigned long avgRed
= 0 ;
264 unsigned long avgGreen
= 0;
265 unsigned long avgBlue
= 0;
266 unsigned long counter
= 0 ;
268 for ( int y1
= 0 ; y1
< yFactor
; ++y1
)
270 long y_offset
= (y
* yFactor
+ y1
) * old_width
;
271 for ( int x1
= 0 ; x1
< xFactor
; ++x1
)
273 unsigned char *pixel
= source_data
+ 3 * ( y_offset
+ x
* xFactor
+ x1
) ;
274 unsigned char red
= pixel
[0] ;
275 unsigned char green
= pixel
[1] ;
276 unsigned char blue
= pixel
[2] ;
277 if ( !hasMask
|| red
!= maskRed
|| green
!= maskGreen
|| blue
!= maskBlue
)
288 *(target_data
++) = M_IMGDATA
->m_maskRed
;
289 *(target_data
++) = M_IMGDATA
->m_maskGreen
;
290 *(target_data
++) = M_IMGDATA
->m_maskBlue
;
294 *(target_data
++) = avgRed
/ counter
;
295 *(target_data
++) = avgGreen
/ counter
;
296 *(target_data
++) = avgBlue
/ counter
;
301 // In case this is a cursor, make sure the hotspot is scalled accordingly:
302 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
) )
303 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
,
304 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X
))/xFactor
);
305 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
) )
306 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
,
307 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y
))/yFactor
);
312 wxImage
wxImage::Scale( int width
, int height
) const
316 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
318 // can't scale to/from 0 size
319 wxCHECK_MSG( (width
> 0) && (height
> 0), image
,
320 wxT("invalid new image size") );
322 long old_height
= M_IMGDATA
->m_height
,
323 old_width
= M_IMGDATA
->m_width
;
324 wxCHECK_MSG( (old_height
> 0) && (old_width
> 0), image
,
325 wxT("invalid old image size") );
327 if ( old_width
% width
== 0 && old_width
>= width
&&
328 old_height
% height
== 0 && old_height
>= height
)
330 return ShrinkBy( old_width
/ width
, old_height
/ height
) ;
332 image
.Create( width
, height
);
334 char unsigned *data
= image
.GetData();
336 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
338 if (M_IMGDATA
->m_hasMask
)
340 image
.SetMaskColour( M_IMGDATA
->m_maskRed
,
341 M_IMGDATA
->m_maskGreen
,
342 M_IMGDATA
->m_maskBlue
);
345 char unsigned *source_data
= M_IMGDATA
->m_data
;
346 char unsigned *target_data
= data
;
349 // This is nonsense, RR.
351 // We do (x, y) -> (x, y)*oldSize/newSize but the valid values of x and y
352 // are from 0 to size-1, hence all decrement the sizes
353 long old_old_width
= old_width
;
358 for ( long j
= 0; j
<= height
; j
++ )
360 // don't crash for images with height == 1
361 long y_offset
= height
? (j
* old_height
/ height
)* old_old_width
: 0;
363 for ( long i
= 0; i
<= width
; i
++ )
365 long x_offset
= width
? (i
* old_width
) / width
: 0;
367 memcpy( target_data
, source_data
+ 3*(y_offset
+ x_offset
), 3 );
372 for (long j
= 0; j
< height
; j
++)
374 long y_offset
= (j
* old_height
/ height
) * old_width
;
376 for (long i
= 0; i
< width
; i
++)
379 source_data
+ 3*(y_offset
+ ((i
* old_width
)/ width
)),
386 // In case this is a cursor, make sure the hotspot is scalled accordingly:
387 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
) )
388 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X
,
389 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_X
)*width
)/old_width
);
390 if ( HasOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
) )
391 image
.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_Y
,
392 (GetOptionInt(wxIMAGE_OPTION_CUR_HOTSPOT_Y
)*height
)/old_height
);
397 wxImage
wxImage::Rotate90( bool clockwise
) const
401 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
403 image
.Create( M_IMGDATA
->m_height
, M_IMGDATA
->m_width
);
405 char unsigned *data
= image
.GetData();
407 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
409 if (M_IMGDATA
->m_hasMask
)
410 image
.SetMaskColour( M_IMGDATA
->m_maskRed
, M_IMGDATA
->m_maskGreen
, M_IMGDATA
->m_maskBlue
);
412 long height
= M_IMGDATA
->m_height
;
413 long width
= M_IMGDATA
->m_width
;
415 char unsigned *source_data
= M_IMGDATA
->m_data
;
416 char unsigned *target_data
;
418 for (long j
= 0; j
< height
; j
++)
420 for (long i
= 0; i
< width
; i
++)
423 target_data
= data
+ (((i
+1)*height
) - j
- 1)*3;
425 target_data
= data
+ ((height
*(width
-1)) + j
- (i
*height
))*3;
426 memcpy( target_data
, source_data
, 3 );
434 wxImage
wxImage::Mirror( bool horizontally
) const
438 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
440 image
.Create( M_IMGDATA
->m_width
, M_IMGDATA
->m_height
);
442 char unsigned *data
= image
.GetData();
444 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
446 if (M_IMGDATA
->m_hasMask
)
447 image
.SetMaskColour( M_IMGDATA
->m_maskRed
, M_IMGDATA
->m_maskGreen
, M_IMGDATA
->m_maskBlue
);
449 long height
= M_IMGDATA
->m_height
;
450 long width
= M_IMGDATA
->m_width
;
452 char unsigned *source_data
= M_IMGDATA
->m_data
;
453 char unsigned *target_data
;
457 for (long j
= 0; j
< height
; j
++)
460 target_data
= data
-3;
461 for (long i
= 0; i
< width
; i
++)
463 memcpy( target_data
, source_data
, 3 );
471 for (long i
= 0; i
< height
; i
++)
473 target_data
= data
+ 3*width
*(height
-1-i
);
474 memcpy( target_data
, source_data
, (size_t)3*width
);
475 source_data
+= 3*width
;
482 wxImage
wxImage::GetSubImage( const wxRect
&rect
) const
486 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
488 wxCHECK_MSG( (rect
.GetLeft()>=0) && (rect
.GetTop()>=0) && (rect
.GetRight()<=GetWidth()) && (rect
.GetBottom()<=GetHeight()),
489 image
, wxT("invalid subimage size") );
491 int subwidth
=rect
.GetWidth();
492 const int subheight
=rect
.GetHeight();
494 image
.Create( subwidth
, subheight
);
496 char unsigned *subdata
= image
.GetData(), *data
=GetData();
498 wxCHECK_MSG( subdata
, image
, wxT("unable to create image") );
500 if (M_IMGDATA
->m_hasMask
)
501 image
.SetMaskColour( M_IMGDATA
->m_maskRed
, M_IMGDATA
->m_maskGreen
, M_IMGDATA
->m_maskBlue
);
503 const int subleft
=3*rect
.GetLeft();
504 const int width
=3*GetWidth();
507 data
+=rect
.GetTop()*width
+subleft
;
509 for (long j
= 0; j
< subheight
; ++j
)
511 memcpy( subdata
, data
, subwidth
);
519 void wxImage::Paste( const wxImage
&image
, int x
, int y
)
521 wxCHECK_RET( Ok(), wxT("invalid image") );
522 wxCHECK_RET( image
.Ok(), wxT("invalid image") );
526 int width
= image
.GetWidth();
527 int height
= image
.GetHeight();
540 if ((x
+xx
)+width
> M_IMGDATA
->m_width
)
541 width
= M_IMGDATA
->m_width
- (x
+xx
);
542 if ((y
+yy
)+height
> M_IMGDATA
->m_height
)
543 height
= M_IMGDATA
->m_height
- (y
+yy
);
545 if (width
< 1) return;
546 if (height
< 1) return;
548 if ((!HasMask() && !image
.HasMask()) ||
549 ((HasMask() && image
.HasMask() &&
550 (GetMaskRed()==image
.GetMaskRed()) &&
551 (GetMaskGreen()==image
.GetMaskGreen()) &&
552 (GetMaskBlue()==image
.GetMaskBlue()))))
555 unsigned char* source_data
= image
.GetData() + xx
*3 + yy
*3*image
.GetWidth();
556 int source_step
= image
.GetWidth()*3;
558 unsigned char* target_data
= GetData() + (x
+xx
)*3 + (y
+yy
)*3*M_IMGDATA
->m_width
;
559 int target_step
= M_IMGDATA
->m_width
*3;
560 for (int j
= 0; j
< height
; j
++)
562 memcpy( target_data
, source_data
, width
);
563 source_data
+= source_step
;
564 target_data
+= target_step
;
569 if (!HasMask() && image
.HasMask())
571 unsigned char r
= image
.GetMaskRed();
572 unsigned char g
= image
.GetMaskGreen();
573 unsigned char b
= image
.GetMaskBlue();
576 unsigned char* source_data
= image
.GetData() + xx
*3 + yy
*3*image
.GetWidth();
577 int source_step
= image
.GetWidth()*3;
579 unsigned char* target_data
= GetData() + (x
+xx
)*3 + (y
+yy
)*3*M_IMGDATA
->m_width
;
580 int target_step
= M_IMGDATA
->m_width
*3;
582 for (int j
= 0; j
< height
; j
++)
584 for (int i
= 0; i
< width
; i
+=3)
586 if ((source_data
[i
] != r
) &&
587 (source_data
[i
+1] != g
) &&
588 (source_data
[i
+2] != b
))
590 memcpy( target_data
+i
, source_data
+i
, 3 );
593 source_data
+= source_step
;
594 target_data
+= target_step
;
599 void wxImage::Replace( unsigned char r1
, unsigned char g1
, unsigned char b1
,
600 unsigned char r2
, unsigned char g2
, unsigned char b2
)
602 wxCHECK_RET( Ok(), wxT("invalid image") );
604 char unsigned *data
= GetData();
606 const int w
= GetWidth();
607 const int h
= GetHeight();
609 for (int j
= 0; j
< h
; j
++)
610 for (int i
= 0; i
< w
; i
++)
612 if ((data
[0] == r1
) && (data
[1] == g1
) && (data
[2] == b1
))
622 wxImage
wxImage::ConvertToMono( unsigned char r
, unsigned char g
, unsigned char b
) const
626 wxCHECK_MSG( Ok(), image
, wxT("invalid image") );
628 image
.Create( M_IMGDATA
->m_width
, M_IMGDATA
->m_height
);
630 char unsigned *data
= image
.GetData();
632 wxCHECK_MSG( data
, image
, wxT("unable to create image") );
634 if (M_IMGDATA
->m_hasMask
)
636 if (M_IMGDATA
->m_maskRed
== r
&& M_IMGDATA
->m_maskGreen
== g
&&
637 M_IMGDATA
->m_maskBlue
== b
)
638 image
.SetMaskColour( 255, 255, 255 );
640 image
.SetMaskColour( 0, 0, 0 );
643 long size
= M_IMGDATA
->m_height
* M_IMGDATA
->m_width
;
645 char unsigned *srcd
= M_IMGDATA
->m_data
;
646 char unsigned *tard
= image
.GetData();
648 for ( long i
= 0; i
< size
; i
++, srcd
+= 3, tard
+= 3 )
650 if (srcd
[0] == r
&& srcd
[1] == g
&& srcd
[2] == b
)
651 tard
[0] = tard
[1] = tard
[2] = 255;
653 tard
[0] = tard
[1] = tard
[2] = 0;
659 void wxImage::SetRGB( int x
, int y
, unsigned char r
, unsigned char g
, unsigned char b
)
661 wxCHECK_RET( Ok(), wxT("invalid image") );
663 int w
= M_IMGDATA
->m_width
;
664 int h
= M_IMGDATA
->m_height
;
666 wxCHECK_RET( (x
>=0) && (y
>=0) && (x
<w
) && (y
<h
), wxT("invalid image index") );
668 long pos
= (y
* w
+ x
) * 3;
670 M_IMGDATA
->m_data
[ pos
] = r
;
671 M_IMGDATA
->m_data
[ pos
+1 ] = g
;
672 M_IMGDATA
->m_data
[ pos
+2 ] = b
;
675 unsigned char wxImage::GetRed( int x
, int y
) const
677 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
679 int w
= M_IMGDATA
->m_width
;
680 int h
= M_IMGDATA
->m_height
;
682 wxCHECK_MSG( (x
>=0) && (y
>=0) && (x
<w
) && (y
<h
), 0, wxT("invalid image index") );
684 long pos
= (y
* w
+ x
) * 3;
686 return M_IMGDATA
->m_data
[pos
];
689 unsigned char wxImage::GetGreen( int x
, int y
) const
691 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
693 int w
= M_IMGDATA
->m_width
;
694 int h
= M_IMGDATA
->m_height
;
696 wxCHECK_MSG( (x
>=0) && (y
>=0) && (x
<w
) && (y
<h
), 0, wxT("invalid image index") );
698 long pos
= (y
* w
+ x
) * 3;
700 return M_IMGDATA
->m_data
[pos
+1];
703 unsigned char wxImage::GetBlue( int x
, int y
) const
705 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
707 int w
= M_IMGDATA
->m_width
;
708 int h
= M_IMGDATA
->m_height
;
710 wxCHECK_MSG( (x
>=0) && (y
>=0) && (x
<w
) && (y
<h
), 0, wxT("invalid image index") );
712 long pos
= (y
* w
+ x
) * 3;
714 return M_IMGDATA
->m_data
[pos
+2];
717 bool wxImage::Ok() const
719 // image of 0 width or height can't be considered ok - at least because it
720 // causes crashes in ConvertToBitmap() if we don't catch it in time
721 wxImageRefData
*data
= M_IMGDATA
;
722 return data
&& data
->m_ok
&& data
->m_width
&& data
->m_height
;
725 char unsigned *wxImage::GetData() const
727 wxCHECK_MSG( Ok(), (char unsigned *)NULL
, wxT("invalid image") );
729 return M_IMGDATA
->m_data
;
732 void wxImage::SetData( char unsigned *data
)
734 wxCHECK_RET( Ok(), wxT("invalid image") );
736 wxImageRefData
*newRefData
= new wxImageRefData();
738 newRefData
->m_width
= M_IMGDATA
->m_width
;
739 newRefData
->m_height
= M_IMGDATA
->m_height
;
740 newRefData
->m_data
= data
;
741 newRefData
->m_ok
= TRUE
;
742 newRefData
->m_maskRed
= M_IMGDATA
->m_maskRed
;
743 newRefData
->m_maskGreen
= M_IMGDATA
->m_maskGreen
;
744 newRefData
->m_maskBlue
= M_IMGDATA
->m_maskBlue
;
745 newRefData
->m_hasMask
= M_IMGDATA
->m_hasMask
;
749 m_refData
= newRefData
;
752 void wxImage::SetData( char unsigned *data
, int new_width
, int new_height
)
754 wxImageRefData
*newRefData
= new wxImageRefData();
758 newRefData
->m_width
= new_width
;
759 newRefData
->m_height
= new_height
;
760 newRefData
->m_data
= data
;
761 newRefData
->m_ok
= TRUE
;
762 newRefData
->m_maskRed
= M_IMGDATA
->m_maskRed
;
763 newRefData
->m_maskGreen
= M_IMGDATA
->m_maskGreen
;
764 newRefData
->m_maskBlue
= M_IMGDATA
->m_maskBlue
;
765 newRefData
->m_hasMask
= M_IMGDATA
->m_hasMask
;
769 newRefData
->m_width
= new_width
;
770 newRefData
->m_height
= new_height
;
771 newRefData
->m_data
= data
;
772 newRefData
->m_ok
= TRUE
;
777 m_refData
= newRefData
;
780 void wxImage::SetMaskColour( unsigned char r
, unsigned char g
, unsigned char b
)
782 wxCHECK_RET( Ok(), wxT("invalid image") );
784 M_IMGDATA
->m_maskRed
= r
;
785 M_IMGDATA
->m_maskGreen
= g
;
786 M_IMGDATA
->m_maskBlue
= b
;
787 M_IMGDATA
->m_hasMask
= TRUE
;
790 unsigned char wxImage::GetMaskRed() const
792 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
794 return M_IMGDATA
->m_maskRed
;
797 unsigned char wxImage::GetMaskGreen() const
799 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
801 return M_IMGDATA
->m_maskGreen
;
804 unsigned char wxImage::GetMaskBlue() const
806 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
808 return M_IMGDATA
->m_maskBlue
;
811 void wxImage::SetMask( bool mask
)
813 wxCHECK_RET( Ok(), wxT("invalid image") );
815 M_IMGDATA
->m_hasMask
= mask
;
818 bool wxImage::HasMask() const
820 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid image") );
822 return M_IMGDATA
->m_hasMask
;
825 int wxImage::GetWidth() const
827 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
829 return M_IMGDATA
->m_width
;
832 int wxImage::GetHeight() const
834 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
836 return M_IMGDATA
->m_height
;
840 bool wxImage::FindFirstUnusedColour(
841 unsigned char *r
, unsigned char *g
, unsigned char *b
,
842 unsigned char startR
, unsigned char startG
, unsigned char startB
) const
844 wxImageHistogram histogram
;
847 ComputeHistogram(histogram
);
849 unsigned char r2
= startR
;
850 unsigned char g2
= startG
;
851 unsigned char b2
= startB
;
853 key
= (r2
<< 16) | (g2
<< 8) | b2
;
855 while ( histogram
.find(key
) != histogram
.end() )
857 // color already used
869 wxLogError( _("GetUnusedColour:: No Unused Color in image ") );
875 key
= (r2
<< 16) | (g2
<< 8) | b2
;
886 bool wxImage::SetMaskFromImage(const wxImage
& mask
,
887 unsigned char mr
, unsigned char mg
, unsigned char mb
)
889 // check that the images are the same size
890 if ( (M_IMGDATA
->m_height
!= mask
.GetHeight() ) || (M_IMGDATA
->m_width
!= mask
.GetWidth () ) )
892 wxLogError( _("Image and Mask have different sizes") );
896 // find unused colour
897 unsigned char r
,g
,b
;
898 if (!FindFirstUnusedColour(&r
, &g
, &b
))
900 wxLogError( _("No Unused Color in image being masked") );
904 char unsigned *imgdata
= GetData();
905 char unsigned *maskdata
= mask
.GetData();
907 const int w
= GetWidth();
908 const int h
= GetHeight();
910 for (int j
= 0; j
< h
; j
++)
912 for (int i
= 0; i
< w
; i
++)
914 if ((maskdata
[0] == mr
) && (maskdata
[1] == mg
) && (maskdata
[2] == mb
))
925 SetMaskColour(r
, g
, b
);
935 bool wxImage::HasPalette() const
940 return M_IMGDATA
->m_palette
.Ok();
943 const wxPalette
& wxImage::GetPalette() const
945 wxCHECK_MSG( Ok(), wxNullPalette
, wxT("invalid image") );
947 return M_IMGDATA
->m_palette
;
950 void wxImage::SetPalette(const wxPalette
& palette
)
952 wxCHECK_RET( Ok(), wxT("invalid image") );
954 M_IMGDATA
->m_palette
= palette
;
957 #endif // wxUSE_PALETTE
959 // Option functions (arbitrary name/value mapping)
960 void wxImage::SetOption(const wxString
& name
, const wxString
& value
)
962 wxCHECK_RET( Ok(), wxT("invalid image") );
964 int idx
= M_IMGDATA
->m_optionNames
.Index(name
, FALSE
);
965 if (idx
== wxNOT_FOUND
)
967 M_IMGDATA
->m_optionNames
.Add(name
);
968 M_IMGDATA
->m_optionValues
.Add(value
);
972 M_IMGDATA
->m_optionNames
[idx
] = name
;
973 M_IMGDATA
->m_optionValues
[idx
] = value
;
977 void wxImage::SetOption(const wxString
& name
, int value
)
980 valStr
.Printf(wxT("%d"), value
);
981 SetOption(name
, valStr
);
984 wxString
wxImage::GetOption(const wxString
& name
) const
986 wxCHECK_MSG( Ok(), wxEmptyString
, wxT("invalid image") );
988 int idx
= M_IMGDATA
->m_optionNames
.Index(name
, FALSE
);
989 if (idx
== wxNOT_FOUND
)
990 return wxEmptyString
;
992 return M_IMGDATA
->m_optionValues
[idx
];
995 int wxImage::GetOptionInt(const wxString
& name
) const
997 wxCHECK_MSG( Ok(), 0, wxT("invalid image") );
999 return wxAtoi(GetOption(name
));
1002 bool wxImage::HasOption(const wxString
& name
) const
1004 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid image") );
1006 return (M_IMGDATA
->m_optionNames
.Index(name
, FALSE
) != wxNOT_FOUND
);
1009 bool wxImage::LoadFile( const wxString
& filename
, long type
, int index
)
1012 if (wxFileExists(filename
))
1014 wxFileInputStream
stream(filename
);
1015 wxBufferedInputStream
bstream( stream
);
1016 return LoadFile(bstream
, type
, index
);
1020 wxLogError( _("Can't load image from file '%s': file does not exist."), filename
.c_str() );
1024 #else // !wxUSE_STREAMS
1026 #endif // wxUSE_STREAMS
1029 bool wxImage::LoadFile( const wxString
& filename
, const wxString
& mimetype
, int index
)
1032 if (wxFileExists(filename
))
1034 wxFileInputStream
stream(filename
);
1035 wxBufferedInputStream
bstream( stream
);
1036 return LoadFile(bstream
, mimetype
, index
);
1040 wxLogError( _("Can't load image from file '%s': file does not exist."), filename
.c_str() );
1044 #else // !wxUSE_STREAMS
1046 #endif // wxUSE_STREAMS
1051 bool wxImage::SaveFile( const wxString
& filename
) const
1053 wxString ext
= filename
.AfterLast('.').Lower();
1055 wxImageHandler
* pHandler
= FindHandler(ext
, -1);
1058 SaveFile(filename
, pHandler
->GetType());
1062 wxLogError(_("Can't save image to file '%s': unknown extension."), filename
.c_str());
1067 bool wxImage::SaveFile( const wxString
& filename
, int type
) const
1070 ((wxImage
*)this)->SetOption(wxIMAGE_OPTION_FILENAME
, filename
);
1072 wxFileOutputStream
stream(filename
);
1074 if ( stream
.IsOk() )
1076 wxBufferedOutputStream
bstream( stream
);
1077 return SaveFile(bstream
, type
);
1079 #endif // wxUSE_STREAMS
1084 bool wxImage::SaveFile( const wxString
& filename
, const wxString
& mimetype
) const
1087 ((wxImage
*)this)->SetOption(wxIMAGE_OPTION_FILENAME
, filename
);
1089 wxFileOutputStream
stream(filename
);
1091 if ( stream
.IsOk() )
1093 wxBufferedOutputStream
bstream( stream
);
1094 return SaveFile(bstream
, mimetype
);
1096 #endif // wxUSE_STREAMS
1101 bool wxImage::CanRead( const wxString
&name
)
1104 wxFileInputStream
stream(name
);
1105 return CanRead(stream
);
1111 int wxImage::GetImageCount( const wxString
&name
, long type
)
1114 wxFileInputStream
stream(name
);
1116 return GetImageCount(stream
, type
);
1124 bool wxImage::CanRead( wxInputStream
&stream
)
1126 const wxList
& list
= GetHandlers();
1128 for ( wxList::Node
*node
= list
.GetFirst(); node
; node
= node
->GetNext() )
1130 wxImageHandler
*handler
=(wxImageHandler
*)node
->GetData();
1131 if (handler
->CanRead( stream
))
1138 int wxImage::GetImageCount( wxInputStream
&stream
, long type
)
1140 wxImageHandler
*handler
;
1142 if ( type
== wxBITMAP_TYPE_ANY
)
1144 wxList
&list
=GetHandlers();
1146 for (wxList::Node
*node
= list
.GetFirst(); node
; node
= node
->GetNext())
1148 handler
=(wxImageHandler
*)node
->GetData();
1149 if ( handler
->CanRead(stream
) )
1150 return handler
->GetImageCount(stream
);
1154 wxLogWarning(_("No handler found for image type."));
1158 handler
= FindHandler(type
);
1162 wxLogWarning(_("No image handler for type %d defined."), type
);
1166 if ( handler
->CanRead(stream
) )
1168 return handler
->GetImageCount(stream
);
1172 wxLogError(_("Image file is not of type %d."), type
);
1177 bool wxImage::LoadFile( wxInputStream
& stream
, long type
, int index
)
1181 m_refData
= new wxImageRefData
;
1183 wxImageHandler
*handler
;
1185 if ( type
== wxBITMAP_TYPE_ANY
)
1187 wxList
&list
=GetHandlers();
1189 for ( wxList::Node
*node
= list
.GetFirst(); node
; node
= node
->GetNext() )
1191 handler
=(wxImageHandler
*)node
->GetData();
1192 if ( handler
->CanRead(stream
) )
1193 return handler
->LoadFile(this, stream
, TRUE
/*verbose*/, index
);
1197 wxLogWarning( _("No handler found for image type.") );
1201 handler
= FindHandler(type
);
1205 wxLogWarning( _("No image handler for type %d defined."), type
);
1210 return handler
->LoadFile(this, stream
, TRUE
/*verbose*/, index
);
1213 bool wxImage::LoadFile( wxInputStream
& stream
, const wxString
& mimetype
, int index
)
1217 m_refData
= new wxImageRefData
;
1219 wxImageHandler
*handler
= FindHandlerMime(mimetype
);
1223 wxLogWarning( _("No image handler for type %s defined."), mimetype
.GetData() );
1228 return handler
->LoadFile( this, stream
, TRUE
/*verbose*/, index
);
1231 bool wxImage::SaveFile( wxOutputStream
& stream
, int type
) const
1233 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid image") );
1235 wxImageHandler
*handler
= FindHandler(type
);
1239 wxLogWarning( _("No image handler for type %d defined."), type
);
1244 return handler
->SaveFile( (wxImage
*)this, stream
);
1247 bool wxImage::SaveFile( wxOutputStream
& stream
, const wxString
& mimetype
) const
1249 wxCHECK_MSG( Ok(), FALSE
, wxT("invalid image") );
1251 wxImageHandler
*handler
= FindHandlerMime(mimetype
);
1255 wxLogWarning( _("No image handler for type %s defined."), mimetype
.GetData() );
1260 return handler
->SaveFile( (wxImage
*)this, stream
);
1262 #endif // wxUSE_STREAMS
1264 void wxImage::AddHandler( wxImageHandler
*handler
)
1266 // make sure that the memory will be freed at the program end
1267 sm_handlers
.DeleteContents(TRUE
);
1269 // Check for an existing handler of the type being added.
1270 if (FindHandler( handler
->GetType() ) == 0)
1272 sm_handlers
.Append( handler
);
1276 // This is not documented behaviour, merely the simplest 'fix'
1277 // for preventing duplicate additions. If someone ever has
1278 // a good reason to add and remove duplicate handlers (and they
1279 // may) we should probably refcount the duplicates.
1280 // also an issue in InsertHandler below.
1282 wxLogDebug( _T("Adding duplicate image handler for '%s'"),
1283 handler
->GetName().c_str() );
1288 void wxImage::InsertHandler( wxImageHandler
*handler
)
1290 // make sure that the memory will be freed at the program end
1291 sm_handlers
.DeleteContents(TRUE
);
1293 // Check for an existing handler of the type being added.
1294 if (FindHandler( handler
->GetType() ) == 0)
1296 sm_handlers
.Insert( handler
);
1300 // see AddHandler for additional comments.
1301 wxLogDebug( _T("Inserting duplicate image handler for '%s'"),
1302 handler
->GetName().c_str() );
1307 bool wxImage::RemoveHandler( const wxString
& name
)
1309 wxImageHandler
*handler
= FindHandler(name
);
1312 sm_handlers
.DeleteObject(handler
);
1319 wxImageHandler
*wxImage::FindHandler( const wxString
& name
)
1321 wxNode
*node
= sm_handlers
.GetFirst();
1324 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
1325 if (handler
->GetName().Cmp(name
) == 0) return handler
;
1327 node
= node
->GetNext();
1332 wxImageHandler
*wxImage::FindHandler( const wxString
& extension
, long bitmapType
)
1334 wxNode
*node
= sm_handlers
.GetFirst();
1337 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
1338 if ( (handler
->GetExtension().Cmp(extension
) == 0) &&
1339 (bitmapType
== -1 || handler
->GetType() == bitmapType
) )
1341 node
= node
->GetNext();
1346 wxImageHandler
*wxImage::FindHandler( long bitmapType
)
1348 wxNode
*node
= sm_handlers
.GetFirst();
1351 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
1352 if (handler
->GetType() == bitmapType
) return handler
;
1353 node
= node
->GetNext();
1358 wxImageHandler
*wxImage::FindHandlerMime( const wxString
& mimetype
)
1360 wxNode
*node
= sm_handlers
.GetFirst();
1363 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
1364 if (handler
->GetMimeType().IsSameAs(mimetype
, FALSE
)) return handler
;
1365 node
= node
->GetNext();
1370 void wxImage::InitStandardHandlers()
1373 AddHandler(new wxBMPHandler
);
1374 #endif // wxUSE_STREAMS
1377 void wxImage::CleanUpHandlers()
1379 wxNode
*node
= sm_handlers
.GetFirst();
1382 wxImageHandler
*handler
= (wxImageHandler
*)node
->GetData();
1383 wxNode
*next
= node
->GetNext();
1390 //-----------------------------------------------------------------------------
1392 //-----------------------------------------------------------------------------
1394 IMPLEMENT_ABSTRACT_CLASS(wxImageHandler
,wxObject
)
1397 bool wxImageHandler::LoadFile( wxImage
*WXUNUSED(image
), wxInputStream
& WXUNUSED(stream
), bool WXUNUSED(verbose
), int WXUNUSED(index
) )
1402 bool wxImageHandler::SaveFile( wxImage
*WXUNUSED(image
), wxOutputStream
& WXUNUSED(stream
), bool WXUNUSED(verbose
) )
1407 int wxImageHandler::GetImageCount( wxInputStream
& WXUNUSED(stream
) )
1412 bool wxImageHandler::CanRead( const wxString
& name
)
1414 if (wxFileExists(name
))
1416 wxFileInputStream
stream(name
);
1417 return CanRead(stream
);
1420 wxLogError( _("Can't check image format of file '%s': file does not exist."), name
.c_str() );
1425 bool wxImageHandler::CallDoCanRead(wxInputStream
& stream
)
1427 off_t posOld
= stream
.TellI();
1428 if ( posOld
== wxInvalidOffset
)
1430 // can't test unseekable stream
1434 bool ok
= DoCanRead(stream
);
1436 // restore the old position to be able to test other formats and so on
1437 if ( stream
.SeekI(posOld
) == wxInvalidOffset
)
1439 wxLogDebug(_T("Failed to rewind the stream in wxImageHandler!"));
1441 // reading would fail anyhow as we're not at the right position
1448 #endif // wxUSE_STREAMS
1452 //-----------------------------------------------------------------------------
1453 // Deprecated wxBitmap conversion routines
1454 //-----------------------------------------------------------------------------
1456 #if WXWIN_COMPATIBILITY_2_2 && wxUSE_GUI
1459 wxBitmap
wxImage::ConvertToMonoBitmap( unsigned char red
, unsigned char green
, unsigned char blue
) const
1461 wxImage mono
= this->ConvertToMono( red
, green
, blue
);
1462 wxBitmap
bitmap( mono
, 1 );
1467 wxBitmap
wxImage::ConvertToBitmap() const
1469 wxBitmap
bitmap( *this );
1473 wxImage::wxImage( const wxBitmap
&bitmap
)
1475 *this = bitmap
.ConvertToImage();
1478 #endif // WXWIN_COMPATIBILITY_2_2 && wxUSE_GUI
1481 //-----------------------------------------------------------------------------
1484 // Counts and returns the number of different colours. Optionally stops
1485 // when it exceeds 'stopafter' different colours. This is useful, for
1486 // example, to see if the image can be saved as 8-bit (256 colour or
1487 // less, in this case it would be invoked as CountColours(256)). Default
1488 // value for stopafter is -1 (don't care).
1490 unsigned long wxImage::CountColours( unsigned long stopafter
) const
1494 unsigned char r
, g
, b
;
1496 unsigned long size
, nentries
, key
;
1499 size
= GetWidth() * GetHeight();
1502 for (unsigned long j
= 0; (j
< size
) && (nentries
<= stopafter
) ; j
++)
1507 key
= (r
<< 16) | (g
<< 8) | b
;
1509 if (h
.Get(key
) == NULL
)
1520 unsigned long wxImage::ComputeHistogram( wxImageHistogram
&h
) const
1522 unsigned char r
, g
, b
;
1524 unsigned long size
, nentries
, key
;
1529 size
= GetWidth() * GetHeight();
1532 for (unsigned long j
= 0; j
< size
; j
++)
1537 key
= (r
<< 16) | (g
<< 8) | b
;
1539 wxImageHistogramEntry
& entry
= h
[key
];
1540 if ( entry
.value
++ == 0 )
1541 entry
.index
= nentries
++;
1548 * Rotation code by Carlos Moreno
1551 // GRG: I've removed wxRotationPoint - we already have wxRealPoint which
1552 // does exactly the same thing. And I also got rid of wxRotationPixel
1553 // bacause of potential problems in architectures where alignment
1554 // is an issue, so I had to rewrite parts of the code.
1556 static const double gs_Epsilon
= 1e-10;
1558 static inline int wxCint (double x
)
1560 return (x
> 0) ? (int) (x
+ 0.5) : (int) (x
- 0.5);
1564 // Auxiliary function to rotate a point (x,y) with respect to point p0
1565 // make it inline and use a straight return to facilitate optimization
1566 // also, the function receives the sine and cosine of the angle to avoid
1567 // repeating the time-consuming calls to these functions -- sin/cos can
1568 // be computed and stored in the calling function.
1570 inline wxRealPoint
rotated_point (const wxRealPoint
& p
, double cos_angle
, double sin_angle
, const wxRealPoint
& p0
)
1572 return wxRealPoint (p0
.x
+ (p
.x
- p0
.x
) * cos_angle
- (p
.y
- p0
.y
) * sin_angle
,
1573 p0
.y
+ (p
.y
- p0
.y
) * cos_angle
+ (p
.x
- p0
.x
) * sin_angle
);
1576 inline wxRealPoint
rotated_point (double x
, double y
, double cos_angle
, double sin_angle
, const wxRealPoint
& p0
)
1578 return rotated_point (wxRealPoint(x
,y
), cos_angle
, sin_angle
, p0
);
1581 wxImage
wxImage::Rotate(double angle
, const wxPoint
& centre_of_rotation
, bool interpolating
, wxPoint
* offset_after_rotation
) const
1584 angle
= -angle
; // screen coordinates are a mirror image of "real" coordinates
1586 // Create pointer-based array to accelerate access to wxImage's data
1587 unsigned char ** data
= new unsigned char * [GetHeight()];
1589 data
[0] = GetData();
1591 for (i
= 1; i
< GetHeight(); i
++)
1592 data
[i
] = data
[i
- 1] + (3 * GetWidth());
1594 // precompute coefficients for rotation formula
1595 // (sine and cosine of the angle)
1596 const double cos_angle
= cos(angle
);
1597 const double sin_angle
= sin(angle
);
1599 // Create new Image to store the result
1600 // First, find rectangle that covers the rotated image; to do that,
1601 // rotate the four corners
1603 const wxRealPoint
p0(centre_of_rotation
.x
, centre_of_rotation
.y
);
1605 wxRealPoint p1
= rotated_point (0, 0, cos_angle
, sin_angle
, p0
);
1606 wxRealPoint p2
= rotated_point (0, GetHeight(), cos_angle
, sin_angle
, p0
);
1607 wxRealPoint p3
= rotated_point (GetWidth(), 0, cos_angle
, sin_angle
, p0
);
1608 wxRealPoint p4
= rotated_point (GetWidth(), GetHeight(), cos_angle
, sin_angle
, p0
);
1610 int x1
= (int) floor (wxMin (wxMin(p1
.x
, p2
.x
), wxMin(p3
.x
, p4
.x
)));
1611 int y1
= (int) floor (wxMin (wxMin(p1
.y
, p2
.y
), wxMin(p3
.y
, p4
.y
)));
1612 int x2
= (int) ceil (wxMax (wxMax(p1
.x
, p2
.x
), wxMax(p3
.x
, p4
.x
)));
1613 int y2
= (int) ceil (wxMax (wxMax(p1
.y
, p2
.y
), wxMax(p3
.y
, p4
.y
)));
1615 wxImage
rotated (x2
- x1
+ 1, y2
- y1
+ 1);
1617 if (offset_after_rotation
!= NULL
)
1619 *offset_after_rotation
= wxPoint (x1
, y1
);
1622 // GRG: The rotated (destination) image is always accessed
1623 // sequentially, so there is no need for a pointer-based
1624 // array here (and in fact it would be slower).
1626 unsigned char * dst
= rotated
.GetData();
1628 // GRG: if the original image has a mask, use its RGB values
1629 // as the blank pixel, else, fall back to default (black).
1631 unsigned char blank_r
= 0;
1632 unsigned char blank_g
= 0;
1633 unsigned char blank_b
= 0;
1637 blank_r
= GetMaskRed();
1638 blank_g
= GetMaskGreen();
1639 blank_b
= GetMaskBlue();
1640 rotated
.SetMaskColour( blank_r
, blank_g
, blank_b
);
1643 // Now, for each point of the rotated image, find where it came from, by
1644 // performing an inverse rotation (a rotation of -angle) and getting the
1645 // pixel at those coordinates
1647 // GRG: I've taken the (interpolating) test out of the loops, so that
1648 // it is done only once, instead of repeating it for each pixel.
1653 for (int y
= 0; y
< rotated
.GetHeight(); y
++)
1655 for (x
= 0; x
< rotated
.GetWidth(); x
++)
1657 wxRealPoint src
= rotated_point (x
+ x1
, y
+ y1
, cos_angle
, -sin_angle
, p0
);
1659 if (-0.25 < src
.x
&& src
.x
< GetWidth() - 0.75 &&
1660 -0.25 < src
.y
&& src
.y
< GetHeight() - 0.75)
1662 // interpolate using the 4 enclosing grid-points. Those
1663 // points can be obtained using floor and ceiling of the
1664 // exact coordinates of the point
1665 // C.M. 2000-02-17: when the point is near the border, special care is required.
1669 if (0 < src
.x
&& src
.x
< GetWidth() - 1)
1671 x1
= wxCint(floor(src
.x
));
1672 x2
= wxCint(ceil(src
.x
));
1674 else // else means that x is near one of the borders (0 or width-1)
1676 x1
= x2
= wxCint (src
.x
);
1679 if (0 < src
.y
&& src
.y
< GetHeight() - 1)
1681 y1
= wxCint(floor(src
.y
));
1682 y2
= wxCint(ceil(src
.y
));
1686 y1
= y2
= wxCint (src
.y
);
1689 // get four points and the distances (square of the distance,
1690 // for efficiency reasons) for the interpolation formula
1692 // GRG: Do not calculate the points until they are
1693 // really needed -- this way we can calculate
1694 // just one, instead of four, if d1, d2, d3
1695 // or d4 are < gs_Epsilon
1697 const double d1
= (src
.x
- x1
) * (src
.x
- x1
) + (src
.y
- y1
) * (src
.y
- y1
);
1698 const double d2
= (src
.x
- x2
) * (src
.x
- x2
) + (src
.y
- y1
) * (src
.y
- y1
);
1699 const double d3
= (src
.x
- x2
) * (src
.x
- x2
) + (src
.y
- y2
) * (src
.y
- y2
);
1700 const double d4
= (src
.x
- x1
) * (src
.x
- x1
) + (src
.y
- y2
) * (src
.y
- y2
);
1702 // Now interpolate as a weighted average of the four surrounding
1703 // points, where the weights are the distances to each of those points
1705 // If the point is exactly at one point of the grid of the source
1706 // image, then don't interpolate -- just assign the pixel
1708 if (d1
< gs_Epsilon
) // d1,d2,d3,d4 are positive -- no need for abs()
1710 unsigned char *p
= data
[y1
] + (3 * x1
);
1715 else if (d2
< gs_Epsilon
)
1717 unsigned char *p
= data
[y1
] + (3 * x2
);
1722 else if (d3
< gs_Epsilon
)
1724 unsigned char *p
= data
[y2
] + (3 * x2
);
1729 else if (d4
< gs_Epsilon
)
1731 unsigned char *p
= data
[y2
] + (3 * x1
);
1738 // weights for the weighted average are proportional to the inverse of the distance
1739 unsigned char *v1
= data
[y1
] + (3 * x1
);
1740 unsigned char *v2
= data
[y1
] + (3 * x2
);
1741 unsigned char *v3
= data
[y2
] + (3 * x2
);
1742 unsigned char *v4
= data
[y2
] + (3 * x1
);
1744 const double w1
= 1/d1
, w2
= 1/d2
, w3
= 1/d3
, w4
= 1/d4
;
1748 *(dst
++) = (unsigned char)
1749 ( (w1
* *(v1
++) + w2
* *(v2
++) +
1750 w3
* *(v3
++) + w4
* *(v4
++)) /
1751 (w1
+ w2
+ w3
+ w4
) );
1752 *(dst
++) = (unsigned char)
1753 ( (w1
* *(v1
++) + w2
* *(v2
++) +
1754 w3
* *(v3
++) + w4
* *(v4
++)) /
1755 (w1
+ w2
+ w3
+ w4
) );
1756 *(dst
++) = (unsigned char)
1757 ( (w1
* *(v1
++) + w2
* *(v2
++) +
1758 w3
* *(v3
++) + w4
* *(v4
++)) /
1759 (w1
+ w2
+ w3
+ w4
) );
1771 else // not interpolating
1773 for (int y
= 0; y
< rotated
.GetHeight(); y
++)
1775 for (x
= 0; x
< rotated
.GetWidth(); x
++)
1777 wxRealPoint src
= rotated_point (x
+ x1
, y
+ y1
, cos_angle
, -sin_angle
, p0
);
1779 const int xs
= wxCint (src
.x
); // wxCint rounds to the
1780 const int ys
= wxCint (src
.y
); // closest integer
1782 if (0 <= xs
&& xs
< GetWidth() &&
1783 0 <= ys
&& ys
< GetHeight())
1785 unsigned char *p
= data
[ys
] + (3 * xs
);
1809 // A module to allow wxImage initialization/cleanup
1810 // without calling these functions from app.cpp or from
1811 // the user's application.
1813 class wxImageModule
: public wxModule
1815 DECLARE_DYNAMIC_CLASS(wxImageModule
)
1818 bool OnInit() { wxImage::InitStandardHandlers(); return TRUE
; };
1819 void OnExit() { wxImage::CleanUpHandlers(); };
1822 IMPLEMENT_DYNAMIC_CLASS(wxImageModule
, wxModule
)
1825 #endif // wxUSE_IMAGE