diff --git a/TODO b/TODO index 261522eb..55510c34 100644 --- a/TODO +++ b/TODO @@ -19,9 +19,6 @@ output imagevec output blob -- new_from_buffer(), new_from_memory(), write_to_memory() etc etc - - - use vips_autorot() in jpegload and vipsthumbnail diff --git a/cplusplus/VImage.cc b/cplusplus/VImage.cc index c3ec06d6..0479060f 100644 --- a/cplusplus/VImage.cc +++ b/cplusplus/VImage.cc @@ -489,6 +489,33 @@ VImage::new_from_file( const char *name, VOption *options ) return( out ); } +VImage +VImage::new_from_buffer( void *buf, size_t len, const char *option_string, + VOption *options ) + throw( VError ) +{ + const char *operation_name; + VipsBlob *blob; + VImage out; + + if( !(operation_name = vips_foreign_find_load_buffer( buf, len )) ) { + delete options; + throw( VError() ); + } + + /* We don't take a copy of the data or free it. + */ + blob = vips_blob_new( NULL, buf, len ); + options = (options ? options : VImage::option())-> + set( "buffer", blob )-> + set( "out", &out ); + vips_area_unref( VIPS_AREA( blob ) ); + + call_option_string( operation_name, option_string, options ); + + return( out ); +} + VImage VImage::new_from_image( std::vector pixel ) throw( VError ) @@ -563,6 +590,39 @@ VImage::write_to_file( const char *name, VOption *options ) set( "filename", filename ) ); } +void +VImage::write_to_buffer( const char *suffix, void **buf, size_t *size, + VOption *options ) + throw( VError ) +{ + char filename[VIPS_PATH_MAX]; + char option_string[VIPS_PATH_MAX]; + const char *operation_name; + VipsBlob *blob; + + vips__filename_split8( suffix, filename, option_string ); + if( !(operation_name = vips_foreign_find_save_buffer( filename )) ) { + delete options; + throw VError(); + } + + call_option_string( operation_name, option_string, + (options ? options : VImage::option())-> + set( "in", *this )-> + set( "buffer", &blob ) ); + + if( blob ) { + if( buf ) { + *buf = VIPS_AREA( blob )->data; + VIPS_AREA( blob )->free_fn = NULL; + } + if( size ) + *size = VIPS_AREA( blob )->length; + + vips_area_unref( VIPS_AREA( blob ) ); + } +} + #include "vips-operators.cc" std::vector diff --git a/cplusplus/include/vips/VImage8.h b/cplusplus/include/vips/VImage8.h index 1c8f72d8..235a9af2 100644 --- a/cplusplus/include/vips/VImage8.h +++ b/cplusplus/include/vips/VImage8.h @@ -433,18 +433,88 @@ public: static void call( const char *operation_name, VOption *options = 0 ) throw( VError ); + static VImage + new_memory() + { + return( VImage( vips_image_new_memory() ) ); + } + + static VImage + new_temp_file( const char *file_format = ".v" ) + throw( VError ) + { + VipsImage *image; + + if( !(image = vips_image_new_temp_file( file_format )) ) + throw( VError() ); + + return( VImage( image ) ); + } + static VImage new_from_file( const char *name, VOption *options = 0 ) throw( VError ); + + static VImage new_from_memory( void *data, size_t size, + int width, int height, int bands, VipsBandFormat format ) + throw( VError ) + { + VipsImage *image; + + if( !(image = vips_image_new_from_memory( data, size, + width, height, bands, format )) ) + throw( VError() ); + + return( VImage( image ) ); + } + + static VImage new_from_buffer( void *buf, size_t len, + const char *option_string, VOption *options = 0 ) + throw( VError ); + + static VImage new_matrix( int width, int height ); + + static VImage new_matrix( int width, int height, + double *array, int size ) + throw( VError ) + { + VipsImage *image; + + if( !(image = vips_image_new_matrix_from_array( width, height, + array, size )) ) + throw( VError() ); + + return( VImage( image ) ); + } + + static VImage new_matrixv( int width, int height, ... ); + VImage new_from_image( std::vector pixel ) throw( VError ); VImage new_from_image( double pixel ) throw( VError ); - VImage new_matrix( int width, int height ) ; - VImage new_matrixv( int width, int height, ... ); + + void write( VImage out ) + throw( VError ); void write_to_file( const char *name, VOption *options = 0 ) throw( VError ); + void write_to_buffer( const char *suffix, void **buf, size_t *size, + VOption *options = 0 ) + throw( VError ); + + void *write_to_memory( size_t *size ) + throw( VError ) + { + void *result; + + if( !(result = vips_image_write_to_memory( this->get_image(), + size )) ) + throw( VError() ); + + return( result ); + } + #include "vips-operators.h" // a few useful things @@ -476,6 +546,7 @@ public: VImage bandjoin( VImage other, VOption *options = 0 ) throw( VError ); + VImage bandjoin( double other, VOption *options = 0 ) throw( VError ) @@ -772,7 +843,7 @@ public: friend VImage operator-( VImage a, std::vector b ) throw( VError ) { - return( a.linear( 1.0, vips8::negate( b ) ) ); + return( a.linear( 1.0, vips::negate( b ) ) ); } friend VImage operator*( VImage a, VImage b ) @@ -832,7 +903,7 @@ public: friend VImage operator/( VImage a, std::vector b ) throw( VError ) { - return( a.linear( vips8::invert( b ), 0.0 ) ); + return( a.linear( vips::invert( b ), 0.0 ) ); } friend VImage operator%( VImage a, VImage b ) diff --git a/cplusplus/include/vips/vips8 b/cplusplus/include/vips/vips8 index 19f5b8f2..4d697f17 100644 --- a/cplusplus/include/vips/vips8 +++ b/cplusplus/include/vips/vips8 @@ -34,7 +34,7 @@ #include -#define VIPS_NAMESPACE_START namespace vips8 { +#define VIPS_NAMESPACE_START namespace vips { #define VIPS_NAMESPACE_END } #include "VError8.h"