fix a ref leak in the C++ API
see https://github.com/jcupitt/libvips/issues/290 thanks huskier added a write-to-buffer example as well
This commit is contained in:
parent
dbdcf91171
commit
db4ee8d6b6
|
@ -1,3 +1,7 @@
|
||||||
|
4/5/15 started 8.0.2
|
||||||
|
- fix a refcount error in C++ wrapper, thanks huskier
|
||||||
|
- reomve a couple of stray header decls, thanks benjamin
|
||||||
|
|
||||||
25/4/15 started 8.0.1
|
25/4/15 started 8.0.1
|
||||||
- fix some compiler warnings
|
- fix some compiler warnings
|
||||||
- work around a glib bug that can cause segv under load
|
- work around a glib bug that can cause segv under load
|
||||||
|
|
|
@ -442,8 +442,9 @@ VOption::get_operation( VipsOperation *operation )
|
||||||
(*((*i)->vvector))[j] = array[j];
|
(*((*i)->vvector))[j] = array[j];
|
||||||
}
|
}
|
||||||
else if( type == VIPS_TYPE_BLOB ) {
|
else if( type == VIPS_TYPE_BLOB ) {
|
||||||
|
// our caller gets a reference
|
||||||
*((*i)->vblob) =
|
*((*i)->vblob) =
|
||||||
(VipsBlob *) g_value_get_boxed( value );
|
(VipsBlob *) g_value_dup_boxed( value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -504,7 +505,7 @@ VImage::call_option_string( const char *operation_name,
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
VImage::call( const char *operation_name, VOption *options )
|
VImage::call( const char *operation_name, VOption *options )
|
||||||
throw( VError )
|
throw( VError )
|
||||||
{
|
{
|
||||||
call_option_string( operation_name, NULL, options );
|
call_option_string( operation_name, NULL, options );
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* compile with:
|
||||||
|
*
|
||||||
|
* g++ -g -Wall buffer.cpp `pkg-config vips-cpp --cflags --libs`
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define DEBUG
|
||||||
|
|
||||||
|
#include <vips/vips8>
|
||||||
|
|
||||||
|
using namespace vips;
|
||||||
|
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// load an image from a file
|
||||||
|
VImage im = VImage::new_from_file( argv[1],
|
||||||
|
VImage::option()->set( "access", "sequential-unbuffered" ) );
|
||||||
|
printf( "loaded %d x %d pixel image from %s\n",
|
||||||
|
im.width(), im.height(), argv[1] );
|
||||||
|
|
||||||
|
// write to a formatted memory buffer
|
||||||
|
size_t size;
|
||||||
|
void *buf;
|
||||||
|
im.write_to_buffer( ".png", &buf, &size );
|
||||||
|
printf( "written to memory %p in png format, %zd bytes\n", buf, size );
|
||||||
|
|
||||||
|
// load from the formatted memory area
|
||||||
|
im = VImage::new_from_buffer( buf, size, "" );
|
||||||
|
printf( "loaded from memory, %d x %d pixel image\n",
|
||||||
|
im.width(), im.height() );
|
||||||
|
|
||||||
|
// write back to a file
|
||||||
|
im.write_to_file( argv[2] );
|
||||||
|
printf( "written back to %s\n", argv[2] );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
Loading…
Reference in New Issue