diff --git a/cplusplus/VImage.cc b/cplusplus/VImage.cc index 8f44df6c..c4909984 100644 --- a/cplusplus/VImage.cc +++ b/cplusplus/VImage.cc @@ -43,7 +43,8 @@ VIPS_NAMESPACE_START -std::vector to_vectorv( int n, ... ) +std::vector +to_vectorv( int n, ... ) { std::vector vector( n ); va_list ap; @@ -56,12 +57,14 @@ std::vector to_vectorv( int n, ... ) return( vector ); } -std::vector to_vector( double value ) +std::vector +to_vector( double value ) { return( to_vectorv( 1, value ) ); } -std::vector to_vector( int n, double array[] ) +std::vector +to_vector( int n, double array[] ) { std::vector vector( n ); @@ -71,7 +74,8 @@ std::vector to_vector( int n, double array[] ) return( vector ); } -std::vector negate( std::vector vector ) +std::vector +negate( std::vector vector ) { std::vector new_vector( vector.size() ); @@ -81,7 +85,8 @@ std::vector negate( std::vector vector ) return( new_vector ); } -std::vector invert( std::vector vector ) +std::vector +invert( std::vector vector ) { std::vector new_vector( vector.size() ); @@ -100,7 +105,8 @@ VOption::~VOption() } // input bool -VOption *VOption::set( const char *name, bool value ) +VOption * +VOption::set( const char *name, bool value ) { Pair *pair = new Pair( name ); @@ -113,7 +119,8 @@ VOption *VOption::set( const char *name, bool value ) } // input int ... this path is used for enums as well -VOption *VOption::set( const char *name, int value ) +VOption * +VOption::set( const char *name, int value ) { Pair *pair = new Pair( name ); @@ -126,7 +133,8 @@ VOption *VOption::set( const char *name, int value ) } // input double -VOption *VOption::set( const char *name, double value ) +VOption * +VOption::set( const char *name, double value ) { Pair *pair = new Pair( name ); @@ -138,7 +146,8 @@ VOption *VOption::set( const char *name, double value ) return( this ); } -VOption *VOption::set( const char *name, const char *value ) +VOption * +VOption::set( const char *name, const char *value ) { Pair *pair = new Pair( name ); @@ -151,7 +160,8 @@ VOption *VOption::set( const char *name, const char *value ) } // input image -VOption *VOption::set( const char *name, VImage value ) +VOption * +VOption::set( const char *name, VImage value ) { Pair *pair = new Pair( name ); @@ -165,7 +175,8 @@ VOption *VOption::set( const char *name, VImage value ) } // input double array -VOption *VOption::set( const char *name, std::vector value ) +VOption * +VOption::set( const char *name, std::vector value ) { Pair *pair = new Pair( name ); @@ -186,7 +197,8 @@ VOption *VOption::set( const char *name, std::vector value ) } // input image array -VOption *VOption::set( const char *name, std::vector value ) +VOption * +VOption::set( const char *name, std::vector value ) { Pair *pair = new Pair( name ); @@ -211,7 +223,8 @@ VOption *VOption::set( const char *name, std::vector value ) } // input blob -VOption *VOption::set( const char *name, VipsBlob *value ) +VOption * +VOption::set( const char *name, VipsBlob *value ) { Pair *pair = new Pair( name ); @@ -224,7 +237,8 @@ VOption *VOption::set( const char *name, VipsBlob *value ) } // output bool -VOption *VOption::set( const char *name, bool *value ) +VOption * +VOption::set( const char *name, bool *value ) { Pair *pair = new Pair( name ); @@ -239,7 +253,8 @@ VOption *VOption::set( const char *name, bool *value ) } // output int -VOption *VOption::set( const char *name, int *value ) +VOption * +VOption::set( const char *name, int *value ) { Pair *pair = new Pair( name ); @@ -254,7 +269,8 @@ VOption *VOption::set( const char *name, int *value ) } // output double -VOption *VOption::set( const char *name, double *value ) +VOption * +VOption::set( const char *name, double *value ) { Pair *pair = new Pair( name ); @@ -269,7 +285,8 @@ VOption *VOption::set( const char *name, double *value ) } // output image -VOption *VOption::set( const char *name, VImage *value ) +VOption * +VOption::set( const char *name, VImage *value ) { Pair *pair = new Pair( name ); @@ -284,7 +301,8 @@ VOption *VOption::set( const char *name, VImage *value ) } // output doublearray -VOption *VOption::set( const char *name, std::vector *value ) +VOption * +VOption::set( const char *name, std::vector *value ) { Pair *pair = new Pair( name ); @@ -298,7 +316,8 @@ VOption *VOption::set( const char *name, std::vector *value ) } // output blob -VOption *VOption::set( const char *name, VipsBlob **value ) +VOption * +VOption::set( const char *name, VipsBlob **value ) { Pair *pair = new Pair( name ); @@ -311,7 +330,8 @@ VOption *VOption::set( const char *name, VipsBlob **value ) } // walk the options and set props on the operation -void VOption::set_operation( VipsOperation *operation ) +void +VOption::set_operation( VipsOperation *operation ) { std::list::iterator i; @@ -332,7 +352,8 @@ void VOption::set_operation( VipsOperation *operation ) } // walk the options and do any processing needed for output objects -void VOption::get_operation( VipsOperation *operation ) +void +VOption::get_operation( VipsOperation *operation ) { std::list::iterator i; @@ -383,7 +404,8 @@ void VOption::get_operation( VipsOperation *operation ) } } -void VImage::call_option_string( const char *operation_name, +void +VImage::call_option_string( const char *operation_name, const char *option_string, VOption *options ) throw( VError ) { @@ -437,13 +459,15 @@ void VImage::call_option_string( const char *operation_name, g_object_unref( operation ); } -void VImage::call( const char *operation_name, VOption *options ) +void + VImage::call( const char *operation_name, VOption *options ) throw( VError ) { call_option_string( operation_name, NULL, options ); } -VImage VImage::new_from_file( const char *name, VOption *options ) +VImage +VImage::new_from_file( const char *name, VOption *options ) throw( VError ) { char filename[VIPS_PATH_MAX]; @@ -466,7 +490,8 @@ VImage VImage::new_from_file( const char *name, VOption *options ) return( out ); } -VImage VImage::new_from_image( std::vector pixel ) +VImage +VImage::new_from_image( std::vector pixel ) throw( VError ) { VImage onepx = VImage::black( 1, 1, @@ -488,18 +513,21 @@ VImage VImage::new_from_image( std::vector pixel ) return( big ); } -VImage VImage::new_from_image( double pixel ) +VImage +VImage::new_from_image( double pixel ) throw( VError ) { return( new_from_image( to_vectorv( 1, pixel ) ) ); } -VImage VImage::new_matrix( int width, int height ) +VImage +VImage::new_matrix( int width, int height ) { return( VImage( vips_image_new_matrix( width, height ) ) ); } -VImage VImage::new_matrixv( int width, int height, ... ) +VImage +VImage::new_matrixv( int width, int height, ... ) { VImage matrix = new_matrix( width, height ); VipsImage *vips_matrix = matrix.get_image(); @@ -516,7 +544,8 @@ VImage VImage::new_matrixv( int width, int height, ... ) return( matrix ); } -void VImage::write_to_file( const char *name, VOption *options ) +void +VImage::write_to_file( const char *name, VOption *options ) throw( VError ) { char filename[VIPS_PATH_MAX]; @@ -537,7 +566,8 @@ void VImage::write_to_file( const char *name, VOption *options ) #include "vips-operators.cc" -std::vector VImage::bandsplit( VOption *options ) +std::vector +VImage::bandsplit( VOption *options ) throw( VError ) { std::vector b; @@ -548,7 +578,8 @@ std::vector VImage::bandsplit( VOption *options ) return( b ); } -VImage VImage::bandjoin( VImage other, VOption *options ) +VImage +VImage::bandjoin( VImage other, VOption *options ) throw( VError ) { VImage v[2] = { *this, other }; @@ -557,7 +588,8 @@ VImage VImage::bandjoin( VImage other, VOption *options ) return( bandjoin( vec, options ) ); } -std::complex VImage::minpos( VOption *options ) +std::complex +VImage::minpos( VOption *options ) throw( VError ) { double x, y; @@ -570,7 +602,8 @@ std::complex VImage::minpos( VOption *options ) return( std::complex( x, y ) ); } -std::complex VImage::maxpos( VOption *options ) +std::complex +VImage::maxpos( VOption *options ) throw( VError ) { double x, y; diff --git a/cplusplus/examples/test_overloads.cc b/cplusplus/examples/test_overloads.cc new file mode 100644 index 00000000..ed108601 --- /dev/null +++ b/cplusplus/examples/test_overloads.cc @@ -0,0 +1,92 @@ +/* + * compile with: + * + * g++ -g -Wall try.cc `pkg-config vips-cc --cflags --libs` + * + */ + +#define DEBUG + +#include + +using namespace vips8; + +int +main( int argc, char **argv ) +{ + GOptionContext *context; + GOptionGroup *main_group; + GError *error = NULL; + + if( vips_init( argv[0] ) ) + vips_error_exit( NULL ); + + context = g_option_context_new( "" ); + + main_group = g_option_group_new( NULL, NULL, NULL, NULL, NULL ); + g_option_context_set_main_group( context, main_group ); + g_option_context_add_group( context, vips_get_option_group() ); + + if( !g_option_context_parse( context, &argc, &argv, &error ) ) { + if( error ) { + fprintf( stderr, "%s\n", error->message ); + g_error_free( error ); + } + + vips_error_exit( NULL ); + } + + +{ + VImage in = VImage::new_from_file( argv[1], + VImage::option()->set( "access", VIPS_ACCESS_SEQUENTIAL_UNBUFFERED ) ); + double avg; + + avg = in.avg(); + + printf( "avg = %g\n", avg ); +} + +{ + VImage in = VImage::new_from_file( argv[1], + VImage::option()->set( "access", VIPS_ACCESS_SEQUENTIAL_UNBUFFERED ) ); + + VImage out = in.embed( 10, 10, 1000, 1000, + VImage::option()->set( "extend", VIPS_EXTEND_COPY ) ); + + out.write_to_file( "embed.jpg" ); +} + +{ + VImage in = VImage::new_from_file( argv[1], + VImage::option()->set( "access", VIPS_ACCESS_SEQUENTIAL_UNBUFFERED ) ); + double a[] = { 1.0, 2.0, 3.0 }; + double b[] = { 4.0, 5.0, 6.0 }; + + std::vector avec( a, a + VIPS_NUMBER( a ) ); + std::vector bvec( b, b + VIPS_NUMBER( b ) ); + + VImage out = in.linear( avec, bvec ); + + out.write_to_file( "linear.jpg" ); +} + +{ + VImage in = VImage::new_from_file( argv[1], + VImage::option()->set( "access", VIPS_ACCESS_SEQUENTIAL_UNBUFFERED ) ); + VImage out = in.linear( 1, 2 ); + + out.write_to_file( "linear1.jpg" ); +} + +{ + VImage in = VImage::new_from_file( argv[1] ); + VImage out = in.new_from_image( 128 ); + + out.write_to_file( "const.jpg" ); +} + + vips_shutdown(); + + return( 0 ); +} diff --git a/cplusplus/include/vips/VImage8.h b/cplusplus/include/vips/VImage8.h index c2fc2309..fb400833 100644 --- a/cplusplus/include/vips/VImage8.h +++ b/cplusplus/include/vips/VImage8.h @@ -253,114 +253,136 @@ public: { } - VipsImage *get_image() + VipsImage * + get_image() { return( (VipsImage *) VObject::get_object() ); } - int width() + int + width() { return( vips_image_get_width( get_image() ) ); } - int height() + int + height() { return( vips_image_get_height( get_image() ) ); } - int bands() + int + bands() { return( vips_image_get_bands( get_image() ) ); } - VipsBandFormat format() + VipsBandFormat + format() { return( vips_image_get_format( get_image() ) ); } - VipsCoding coding() + VipsCoding + coding() { return( vips_image_get_coding( get_image() ) ); } - VipsInterpretation interpretation() + VipsInterpretation + interpretation() { return( vips_image_get_interpretation( get_image() ) ); } - VipsInterpretation guess_interpretation() + VipsInterpretation + guess_interpretation() { return( vips_image_guess_interpretation( get_image() ) ); } - double xres() + double + xres() { return( vips_image_get_xres( get_image() ) ); } - double yres() + double + yres() { return( vips_image_get_yres( get_image() ) ); } - double xoffset() + double + xoffset() { return( vips_image_get_xoffset( get_image() ) ); } - double yoffset() + double + yoffset() { return( vips_image_get_yoffset( get_image() ) ); } - const char *filename() + const char * + filename() { return( vips_image_get_filename( get_image() ) ); } - double scale() + double + scale() { return( vips_image_get_scale( get_image() ) ); } - double offset() + double + offset() { return( vips_image_get_offset( get_image() ) ); } - const void *data() + const void * + data() { return( vips_image_get_data( get_image() ) ); } - void set( const char *field, int value ) + void + set( const char *field, int value ) { vips_image_set_int( this->get_image(), field, value ); } - void set( const char *field, double value ) + void + set( const char *field, double value ) { vips_image_set_double( this->get_image(), field, value ); } - void set( const char *field, const char *value ) + void + set( const char *field, const char *value ) { vips_image_set_string( this->get_image(), field, value ); } - void set( const char *field, + void + set( const char *field, VipsCallbackFn free_fn, void *data, size_t length ) { vips_image_set_blob( this->get_image(), field, free_fn, data, length ); } - int get_typeof( const char *field ) + int + get_typeof( const char *field ) { return( vips_image_get_typeof( this->get_image(), field ) ); } - int get_int( const char *field ) + int + get_int( const char *field ) throw( VError ) { int value; @@ -371,7 +393,8 @@ public: return( value ); } - double get_double( const char *field ) + double + get_double( const char *field ) throw( VError ) { double value; @@ -382,7 +405,8 @@ public: return( value ); } - const char *get_string( const char *field ) + const char * + get_string( const char *field ) throw( VError ) { const char *value; @@ -393,7 +417,8 @@ public: return( value ); } - const void *get_blob( const char *field, size_t *length ) + const void * + get_blob( const char *field, size_t *length ) { void *value; @@ -404,7 +429,8 @@ public: return( value ); } - static VOption *option() + static VOption * + option() { return( new VOption() ); } @@ -431,20 +457,23 @@ public: // a few useful things - VImage linear( double a, double b, VOption *options = 0 ) + VImage + linear( double a, double b, VOption *options = 0 ) throw( VError ) { return( this->linear( to_vector( a ), to_vector( b ), options ) ); } - VImage linear( std::vector a, double b, VOption *options = 0 ) + VImage + linear( std::vector a, double b, VOption *options = 0 ) throw( VError ) { return( this->linear( a, to_vector( b ), options ) ); } - VImage linear( double a, std::vector b, VOption *options = 0 ) + VImage + linear( double a, std::vector b, VOption *options = 0 ) throw( VError ) { return( this->linear( to_vector( a ), b, options ) ); @@ -455,12 +484,15 @@ public: VImage bandjoin( VImage other, VOption *options = 0 ) throw( VError ); - VImage bandjoin( double other, VOption *options = 0 ) + VImage + bandjoin( double other, VOption *options = 0 ) throw( VError ) { return( bandjoin( this->new_from_image( other ), options ) ); } - VImage bandjoin( std::vector other, VOption *options = 0 ) + + VImage + bandjoin( std::vector other, VOption *options = 0 ) throw( VError ) { return( bandjoin( this->new_from_image( other ), options ) ); @@ -472,169 +504,194 @@ public: std::complex maxpos( VOption *options = 0 ) throw( VError ); - VImage floor( VOption *options = 0 ) + VImage + floor( VOption *options = 0 ) throw( VError ) { return( round( VIPS_OPERATION_ROUND_FLOOR, options ) ); } - VImage ceil( VOption *options = 0 ) + VImage + ceil( VOption *options = 0 ) throw( VError ) { return( round( VIPS_OPERATION_ROUND_CEIL, options ) ); } - VImage rint( VOption *options = 0 ) + VImage + rint( VOption *options = 0 ) throw( VError ) { return( round( VIPS_OPERATION_ROUND_RINT, options ) ); } - VImage real( VOption *options = 0 ) + VImage + real( VOption *options = 0 ) throw( VError ) { return( complexget( VIPS_OPERATION_COMPLEXGET_REAL, options ) ); } - VImage imag( VOption *options = 0 ) + VImage + imag( VOption *options = 0 ) throw( VError ) { return( complexget( VIPS_OPERATION_COMPLEXGET_IMAG, options ) ); } - VImage polar( VOption *options = 0 ) + VImage + polar( VOption *options = 0 ) throw( VError ) { return( complex( VIPS_OPERATION_COMPLEX_POLAR, options ) ); } - VImage rect( VOption *options = 0 ) + VImage + rect( VOption *options = 0 ) throw( VError ) { return( complex( VIPS_OPERATION_COMPLEX_RECT, options ) ); } - VImage conj( VOption *options = 0 ) + VImage + conj( VOption *options = 0 ) throw( VError ) { return( complex( VIPS_OPERATION_COMPLEX_CONJ, options ) ); } - VImage sin( VOption *options = 0 ) + VImage + sin( VOption *options = 0 ) throw( VError ) { return( math( VIPS_OPERATION_MATH_SIN, options ) ); } - VImage cos( VOption *options = 0 ) + VImage + cos( VOption *options = 0 ) throw( VError ) { return( math( VIPS_OPERATION_MATH_COS, options ) ); } - VImage tan( VOption *options = 0 ) + VImage + tan( VOption *options = 0 ) throw( VError ) { return( math( VIPS_OPERATION_MATH_TAN, options ) ); } - VImage asin( VOption *options = 0 ) + VImage + asin( VOption *options = 0 ) throw( VError ) { return( math( VIPS_OPERATION_MATH_ASIN, options ) ); } - VImage acos( VOption *options = 0 ) + VImage + acos( VOption *options = 0 ) throw( VError ) { return( math( VIPS_OPERATION_MATH_ACOS, options ) ); } - VImage atan( VOption *options = 0 ) + VImage + atan( VOption *options = 0 ) throw( VError ) { return( math( VIPS_OPERATION_MATH_ATAN, options ) ); } - VImage log( VOption *options = 0 ) + VImage + log( VOption *options = 0 ) throw( VError ) { return( math( VIPS_OPERATION_MATH_LOG, options ) ); } - VImage log10( VOption *options = 0 ) + VImage + log10( VOption *options = 0 ) throw( VError ) { return( math( VIPS_OPERATION_MATH_LOG10, options ) ); } - VImage exp( VOption *options = 0 ) + VImage + exp( VOption *options = 0 ) throw( VError ) { return( math( VIPS_OPERATION_MATH_EXP, options ) ); } - VImage exp10( VOption *options = 0 ) + VImage + exp10( VOption *options = 0 ) throw( VError ) { return( math( VIPS_OPERATION_MATH_EXP10, options ) ); } - VImage pow( VImage other, VOption *options = 0 ) + VImage + pow( VImage other, VOption *options = 0 ) throw( VError ) { return( math2( other, VIPS_OPERATION_MATH2_POW, options ) ); } - VImage pow( double other, VOption *options = 0 ) + VImage + pow( double other, VOption *options = 0 ) throw( VError ) { return( math2_const( to_vector( other ), VIPS_OPERATION_MATH2_POW, options ) ); } - VImage pow( std::vector other, VOption *options = 0 ) + VImage + pow( std::vector other, VOption *options = 0 ) throw( VError ) { return( math2_const( other, VIPS_OPERATION_MATH2_POW, options ) ); } - VImage wop( VImage other, VOption *options = 0 ) + VImage + wop( VImage other, VOption *options = 0 ) throw( VError ) { return( math2( other, VIPS_OPERATION_MATH2_WOP, options ) ); } - VImage wop( double other, VOption *options = 0 ) + VImage + wop( double other, VOption *options = 0 ) throw( VError ) { return( math2_const( to_vector( other ), VIPS_OPERATION_MATH2_WOP, options ) ); } - VImage wop( std::vector other, VOption *options = 0 ) + VImage + wop( std::vector other, VOption *options = 0 ) throw( VError ) { return( math2_const( other, VIPS_OPERATION_MATH2_WOP, options ) ); } - VImage ifthenelse( std::vector th, VImage el, - VOption *options = 0 ) + VImage + ifthenelse( std::vector th, VImage el, VOption *options = 0 ) throw( VError ) { return( ifthenelse( el.new_from_image( th ), el, options ) ); } - VImage ifthenelse( VImage th, std::vector el, - VOption *options = 0 ) + VImage + ifthenelse( VImage th, std::vector el, VOption *options = 0 ) throw( VError ) { return( ifthenelse( th, th.new_from_image( el ), options ) ); } - VImage ifthenelse( std::vector th, std::vector el, + VImage + ifthenelse( std::vector th, std::vector el, VOption *options = 0 ) throw( VError ) { @@ -642,19 +699,22 @@ public: options ) ); } - VImage ifthenelse( double th, VImage el, VOption *options ) + VImage + ifthenelse( double th, VImage el, VOption *options ) throw( VError ) { return( ifthenelse( to_vector( th ), el, options ) ); } - VImage ifthenelse( VImage th, double el, VOption *options ) + VImage + ifthenelse( VImage th, double el, VOption *options ) throw( VError ) { return( ifthenelse( th, to_vector( el ), options ) ); } - VImage ifthenelse( double th, double el, VOption *options ) + VImage + ifthenelse( double th, double el, VOption *options ) throw( VError ) { return( ifthenelse( to_vector( th ), to_vector( el ),