add all new() and write() methods

VImage::new_from_buffer() etc.
This commit is contained in:
John Cupitt 2014-10-31 19:15:29 +00:00
parent 2a992375fe
commit 5694bf6f4c
4 changed files with 136 additions and 8 deletions

3
TODO
View File

@ -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

View File

@ -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<double> 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<VImage>

View File

@ -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<double> 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<double> 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<double> 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 )

View File

@ -34,7 +34,7 @@
#include <glib-object.h>
#define VIPS_NAMESPACE_START namespace vips8 {
#define VIPS_NAMESPACE_START namespace vips {
#define VIPS_NAMESPACE_END }
#include "VError8.h"