1 #############################################################################
3 ## Purpose: XS for Wx::Image
4 ## Author: Mattia Barbon
7 ## RCS-ID: $Id: Image.xs 2626 2009-10-18 22:48:17Z mbarbon $
8 ## Copyright: (c) 2000-2003, 2005-2009 Mattia Barbon
9 ## Licence: This program is free software; you can redistribute it and/or
10 ## modify it under the same terms as Perl itself
11 #############################################################################
14 #include <wx/bitmap.h>
15 #include "cpp/streams.h"
16 #include "cpp/overload.h"
18 MODULE=Wx PACKAGE=Wx::Image
24 MATCH_VOIDM_REDISP( newNull )
25 MATCH_REDISP( wxPliOvl_wico, newIcon )
26 MATCH_REDISP( wxPliOvl_wbmp, newBitmap )
27 MATCH_REDISP( wxPliOvl_wist_n, newStreamType )
28 MATCH_REDISP( wxPliOvl_wist_s, newStreamMIME )
29 MATCH_REDISP_COUNT( wxPliOvl_n_n, newWH, 2 )
30 MATCH_REDISP( wxPliOvl_n_n_s, newData )
31 MATCH_REDISP( wxPliOvl_n_n_s_s, newDataAlpha )
32 MATCH_REDISP( wxPliOvl_s_n, newNameType )
33 MATCH_REDISP( wxPliOvl_s_s, newNameMIME )
34 END_OVERLOAD( Wx::Image::new )
40 RETVAL = new wxImage();
45 newWH( CLASS, width, height )
50 RETVAL = new wxImage( width, height );
55 newData( CLASS, width, height, dt )
62 unsigned char* data = (unsigned char*)SvPV( dt, len );
63 unsigned char* newdata;
65 if( len != (STRLEN) width * height * 3 )
67 croak( "not enough data in image constructor" );
69 newdata = (unsigned char*)malloc( width * height * 3 );
70 memcpy( newdata, data, width * height * 3 );
72 RETVAL = new wxImage( width, height, newdata );
76 #if WXPERL_W_VERSION_GE( 2, 5, 3 )
79 newDataAlpha( CLASS, width, height, dt, al )
86 STRLEN len_data, len_alpha;
87 unsigned char* data = (unsigned char*)SvPV( dt, len_data );
88 unsigned char* alpha = (unsigned char*)SvPV( al, len_alpha );
90 if( len_data != (STRLEN) width * height * 3 ||
91 len_alpha != (STRLEN) width * height )
93 croak( "not enough data in image constructor" );
95 unsigned char* newdata = (unsigned char*) malloc( len_data );
96 memcpy( newdata, data, len_data );
97 unsigned char* newalpha = (unsigned char*) malloc( len_alpha );
98 memcpy( newalpha, alpha, len_alpha );
100 RETVAL = new wxImage( width, height, newdata, newalpha );
107 newNameType( CLASS, name, type, index = -1 )
113 RETVAL = new wxImage( name, type, index );
118 newNameMIME( CLASS, name, mimetype, index = -1 )
124 RETVAL = new wxImage( name, mimetype, index );
129 newStreamType( CLASS, stream, type, index = -1 )
131 wxPliInputStream stream
135 RETVAL = new wxImage( stream, type, index );
140 newStreamMIME( CLASS, stream, mime, index = -1 )
142 wxPliInputStream stream
146 RETVAL = new wxImage( stream, mime, index );
151 newBitmap( CLASS, bitmap )
154 RETVAL = new wxImage( bitmap->ConvertToImage() );
158 newIcon( CLASS, icon )
161 wxBitmap tmp; tmp.CopyFromIcon( *icon );
162 RETVAL = new wxImage( tmp.ConvertToImage() );
168 wxPli_thread_sv_clone( aTHX_ CLASS, (wxPliCloneSV)wxPli_detach_object );
174 wxPli_thread_sv_unregister( aTHX_ "Wx::Image", THIS, ST(0) );
178 AddHandler( handler )
179 wxImageHandler* handler
181 wxImage::AddHandler( handler );
184 wxImage::ConvertToMono( r, g, b )
189 RETVAL = new wxImage( THIS->ConvertToMono( r, g, b ) );
193 #if WXPERL_W_VERSION_GE( 2, 5, 3 )
196 wxImage::ConvertAlphaToMask( threshold = 128 )
197 unsigned char threshold
201 #if WXPERL_W_VERSION_GE( 2, 5, 4 )
204 wxImage::ConvertColourToAlpha( r, g, b )
211 #if WXPERL_W_VERSION_GE( 2, 7, 0 )
214 wxImage::ConvertToGreyscale()
216 RETVAL = new wxImage( THIS->ConvertToGreyscale() );
225 RETVAL = new wxImage( THIS->Copy() );
230 wxImage::Create( width, height )
238 FindHandlerName( name )
241 RETVAL = wxImage::FindHandler( name );
246 FindHandlerExtType( extension, type )
250 RETVAL = wxImage::FindHandler( extension, type );
255 FindHandlerType( type )
258 RETVAL = wxImage::FindHandler( type );
263 FindHandlerMime( mime )
266 RETVAL = wxImage::FindHandlerMime( mime );
270 #if WXPERL_W_VERSION_GE( 2, 5, 3 )
273 wxImage::GetAlpha( ... )
276 MATCH_VOIDM_REDISP( GetAlphaData )
277 MATCH_REDISP( wxPliOvl_n_n, GetAlphaXY )
278 END_OVERLOAD( Wx::Image::GetAlpha )
281 wxImage::GetAlphaXY( x, y )
285 RETVAL = THIS->GetAlpha( x, y );
289 wxImage::GetAlphaData()
291 unsigned char* alpha = THIS->GetAlpha();
296 RETVAL = newSVpvn( (char*) alpha, THIS->GetWidth() * THIS->GetHeight() );
305 STRLEN len = THIS->GetWidth() * THIS->GetHeight() * 3;
306 RETVAL = newSVpvn( (char*)THIS->GetData(), len );
311 wxImage::GetBlue( x, y )
316 wxImage::GetGreen( x, y )
321 wxImage::GetRed( x, y )
329 wxImage::GetMaskBlue()
332 wxImage::GetMaskGreen()
335 wxImage::GetMaskRed()
338 wxImage::GetOption( name )
342 wxImage::GetOptionInt( name )
346 wxImage::GetPalette()
348 RETVAL = new wxPalette( THIS->GetPalette() );
353 wxImage::GetSubImage( rect )
356 RETVAL = new wxImage( THIS->GetSubImage( *rect ) );
363 #if WXPERL_W_VERSION_GE( 2, 5, 3 )
370 #if WXPERL_W_VERSION_GE( 2, 5, 4 )
377 #if WXPERL_W_VERSION_GE( 2, 6, 1 )
380 wxImage::IsTransparent( x, y, threshold = wxIMAGE_ALPHA_THRESHOLD )
383 unsigned char threshold
391 wxImage::HasOption( name )
395 wxImage::HasPalette()
398 InsertHandler( handler )
399 wxImageHandler* handler
401 wxImage::InsertHandler( handler );
404 wxImage::LoadFile( ... )
407 MATCH_REDISP( wxPliOvl_wist_n, LoadStreamType )
408 MATCH_REDISP( wxPliOvl_wist_s, LoadStreamMIME )
409 MATCH_REDISP( wxPliOvl_s_n, LoadFileType )
410 MATCH_REDISP( wxPliOvl_s_s, LoadFileMIME )
411 END_OVERLOAD( Wx::Image::LoadFile )
414 wxImage::LoadFileType( name, type, index = -1 )
419 RETVAL = THIS->LoadFile( name, type, index );
424 wxImage::LoadFileMIME( name, type, index = -1 )
429 RETVAL = THIS->LoadFile( name, type, index );
434 wxImage::LoadStreamType( stream, type, index = -1 )
435 wxPliInputStream stream
439 RETVAL = THIS->LoadFile( stream, type, index );
444 wxImage::LoadStreamMIME( stream, type, index = -1 )
445 wxPliInputStream stream
449 RETVAL = THIS->LoadFile( stream, type, index );
456 #if WXPERL_W_VERSION_GE( 2, 8, 0 )
464 wxImage::SaveFile( ... )
467 MATCH_REDISP( wxPliOvl_wost_n, SaveFileSType )
468 MATCH_REDISP( wxPliOvl_wost_s, SaveFileSMIME )
469 MATCH_REDISP( wxPliOvl_s_n, SaveFileType )
470 MATCH_REDISP( wxPliOvl_s_s, SaveFileMIME )
471 MATCH_REDISP( wxPliOvl_s, SaveFileOnly )
472 END_OVERLOAD( Wx::Image::SaveFile )
475 wxImage::SaveFileOnly( name )
478 RETVAL = THIS->SaveFile( name );
483 wxImage::SaveFileType( name, type )
487 RETVAL = THIS->SaveFile( name, type );
492 wxImage::SaveFileMIME( name, type )
496 RETVAL = THIS->SaveFile( name, type );
501 wxImage::SaveStreamType( stream, type )
502 wxPliOutputStream stream
505 RETVAL = THIS->SaveFile( stream, type );
510 wxImage::SaveStreamMIME( stream, type )
511 wxPliOutputStream stream
514 RETVAL = THIS->SaveFile( stream, type );
519 wxImage::Mirror( horizontally = true )
522 RETVAL = new wxImage( THIS->Mirror( horizontally ) );
526 wxImage::Replace( r1, g1, b1, r2, g2, b2 )
534 #if WXPERL_W_VERSION_GE( 2, 8, 0 )
537 wxImage::Rescale( width, height, quality = wxIMAGE_QUALITY_NORMAL )
540 wxImageResizeQuality quality
542 RETVAL = new wxImage( THIS->Rescale( width, height, quality ) );
549 wxImage::Rescale( width, height )
553 RETVAL = new wxImage( THIS->Rescale( width, height ) );
560 wxImage::Rotate( angle, centre, interpolating = true )
568 result = new wxImage( THIS->Rotate( angle, centre, interpolating, &after ) );
569 XPUSHs( wxPli_object_2_sv( aTHX_ sv_newmortal(), result ) );
570 if( GIMME_V == G_ARRAY ) {
571 PUSHs( wxPli_non_object_2_sv( aTHX_ sv_newmortal(),
572 new wxPoint( after ), "Wx::Point" ) );
575 #if WXPERL_W_VERSION_GE( 2, 6, 3 )
578 wxImage::RotateHue( angle )
584 wxImage::Rotate90( clockwise = true )
587 RETVAL = new wxImage( THIS->Rotate90( clockwise ) );
591 #if WXPERL_W_VERSION_GE( 2, 4, 1 )
594 wxImage::ShrinkBy( xfactor, yfactor )
598 RETVAL = new wxImage( THIS->ShrinkBy( xfactor, yfactor ) );
603 #if WXPERL_W_VERSION_GE( 2, 8, 0 )
606 wxImage::Scale( width, height, quality = wxIMAGE_QUALITY_NORMAL )
609 wxImageResizeQuality quality
611 RETVAL = new wxImage( THIS->Scale( width, height, quality ) );
618 wxImage::Scale( width, height )
622 RETVAL = new wxImage( THIS->Scale( width, height ) );
628 #if WXPERL_W_VERSION_GE( 2, 5, 3 )
631 wxImage::SetAlpha( ... )
634 MATCH_REDISP( wxPliOvl_s, SetAlphaData )
635 MATCH_REDISP( wxPliOvl_n_n_n, SetAlphaXY )
636 END_OVERLOAD( Wx::Image::SetAlpha )
639 wxImage::SetAlphaXY( x, y, alpha )
644 THIS->SetAlpha( x, y, alpha );
647 wxImage::SetAlphaData( d )
651 unsigned char* data = (unsigned char*) SvPV( d, len );
652 STRLEN imglen = THIS->GetWidth() * THIS->GetHeight();
653 unsigned char* data_copy = (unsigned char*) malloc( imglen );
654 memcpy( data_copy, data, len );
655 THIS->SetAlpha( data_copy );
660 wxImage::SetData( d )
664 unsigned char* data = (unsigned char*)SvPV( d, len );
665 STRLEN imglen = THIS->GetWidth() * THIS->GetHeight() * 3;
666 unsigned char* data_copy = (unsigned char*)malloc( imglen );
667 memcpy( data_copy, data, len );
668 THIS->SetData( data_copy );
671 wxImage::SetMask( hasMask = true )
675 wxImage::SetMaskColour( red, green, blue )
681 wxImage::SetOption( name, value )
686 wxImage::SetOptionInt( name, value )
690 THIS->SetOption( name, value );
693 wxImage::SetPalette( palette )
696 THIS->SetPalette( *palette );
698 #if WXPERL_W_VERSION_GE( 2, 8, 0 )
701 wxImage::SetRGB( ... )
704 MATCH_REDISP( wxPliOvl_n_n_n_n_n, SetRGBpixel )
705 MATCH_REDISP( wxPliOvl_wrec_n_n_n, SetRGBrect )
706 END_OVERLOAD( Wx::Image::SetRGB )
709 wxImage::SetRGBpixel( x, y, red, green, blue )
716 THIS->SetRGB( x, y, red, green, blue );
719 wxImage::SetRGBrect( rect, red, green, blue )
725 THIS->SetRGB( *rect, red, green, blue );
730 wxImage::SetRGB( x, y, red, green, blue )
739 #if WXPERL_W_VERSION_GE( 2, 8, 0 )
742 wxImage::Blur( blurradius )
745 RETVAL = new wxImage( THIS->Blur( blurradius ) );
750 wxImage::BlurHorizontal( blurradius )
753 RETVAL = new wxImage( THIS->BlurHorizontal( blurradius ) );
758 wxImage::BlurVertical( blurradius )
761 RETVAL = new wxImage( THIS->BlurVertical( blurradius ) );
766 wxImage::GetOrFindMaskColour( red, green, blue )
773 MODULE=Wx PACKAGE=Wx::ImageHandler
776 wxImageHandler::Destroy()
781 wxImageHandler::GetImageCount( stream )
782 wxPliInputStream stream
785 wxImageHandler::GetName()
788 wxImageHandler::GetExtension()
790 #if WXPERL_W_VERSION_GE( 2, 9, 0 )
793 wxImageHandler::GetType()
798 wxImageHandler::GetType()
803 wxImageHandler::GetMimeType()
806 wxImageHandler::LoadFile( image, stream, verbose = true, index = 0 )
808 wxPliInputStream stream
813 wxImageHandler::SaveFile( image, stream )
815 wxPliOutputStream stream
818 wxImageHandler::SetName( name )
822 wxImageHandler::SetExtension( ext )
826 wxImageHandler::SetMimeType( type )
830 wxImageHandler::SetType( type )
833 MODULE=Wx PACKAGE=Wx::GIFHandler
838 MODULE=Wx PACKAGE=Wx::BMPHandler
843 MODULE=Wx PACKAGE=Wx::PNMHandler
848 MODULE=Wx PACKAGE=Wx::PCXHandler
853 MODULE=Wx PACKAGE=Wx::PNGHandler
858 MODULE=Wx PACKAGE=Wx::JPEGHandler
863 #if wxPERL_USE_LIBTIFF && !defined( __WXWINCE__ )
865 MODULE=Wx PACKAGE=Wx::TIFFHandler
872 MODULE=Wx PACKAGE=Wx::XPMHandler
877 MODULE=Wx PACKAGE=Wx::IFFHandler
886 #if wxPERL_USE_ICO_CUR
888 MODULE=Wx PACKAGE=Wx::ICOHandler
893 MODULE=Wx PACKAGE=Wx::CURHandler
898 MODULE=Wx PACKAGE=Wx::ANIHandler
907 MODULE=Wx PACKAGE=Wx::TGAHandler
914 MODULE=Wx PACKAGE=Wx PREFIX=wx
917 wxInitAllImageHandlers()