move C API back to int operations

always return results through params
This commit is contained in:
John Cupitt 2011-09-05 21:28:35 +01:00
parent b28cda68a7
commit b5cadc1815
6 changed files with 33 additions and 64 deletions

View File

@ -8,6 +8,7 @@
- in im_vips2tiff, enable YCbCr compression for jpeg write
- VipsMin stops search early if it can
- C API supports optional output args
- switch back to int-valued operations
10/8/11 started 7.26.3
- don't use G_VALUE_COLLECT_INIT(), many platforms do not have a glib this

23
TODO
View File

@ -1,25 +1,4 @@
- is our C API too awkward? we'll need
if( !(c = vips_add( a, b )) ||
!(d = vips_add( a, c )) )
return NULL;
seems wordy compared to
if( vips_add( a, b, &c ) ||
vips_add( a, c, &d ) )
return -1;
plus VipsPool will be more natural with #2, I think, and things like
vips_avg() have to be form #2
also, we have
if( vips_call( "add", a, b, &c ) ||
vips_call( "add", a, c, &d ) )
return( -1 );
which is much closer to #2
- revise vipspool, write a test prog

View File

@ -321,19 +321,15 @@ vips_add_init( VipsAdd *add )
{
}
VipsImage *
vips_add( VipsImage *in1, VipsImage *in2, ... )
int
vips_add( VipsImage *in1, VipsImage *in2, VipsImage **out, ... )
{
va_list ap;
int result;
VipsImage *out;
va_start( ap, in2 );
result = vips_call_split( "add", ap, in1, in2, &out );
va_start( ap, out );
result = vips_call_split( "add", ap, in1, in2, out );
va_end( ap );
if( result )
return( NULL );
return( out );
return( result );
}

View File

@ -254,24 +254,20 @@ vips_subtract_class_init( VipsSubtractClass *class )
bclass->process_line = subtract_buffer;
}
VipsImage *
vips_subtract( VipsImage *in1, VipsImage *in2, ... )
{
va_list ap;
int result;
VipsImage *out;
va_start( ap, in2 );
result = vips_call_split( "subtract", ap, in1, in2, &out );
va_end( ap );
if( result )
return( NULL );
return( out );
}
static void
vips_subtract_init( VipsSubtract *subtract )
{
}
int
vips_subtract( VipsImage *in1, VipsImage *in2, VipsImage **out, ... )
{
va_list ap;
int result;
va_start( ap, in2 );
result = vips_call_split( "subtract", ap, in1, in2, out );
va_end( ap );
return( result );
}

View File

@ -37,8 +37,8 @@
extern "C" {
#endif /*__cplusplus*/
VipsImage *vips_add( VipsImage *in1, VipsImage *in2, ... );
VipsImage *vips_subtract( VipsImage *in1, VipsImage *in2, ... );
int vips_add( VipsImage *in1, VipsImage *in2, VipsImage **out, ... );
int vips_subtract( VipsImage *in1, VipsImage *in2, VipsImage **out, ... );
int vips_avg( VipsImage *in, double *out, ... );
int vips_min( VipsImage *in, double *out, ... );

View File

@ -53,21 +53,20 @@
Here's how to handle ref counts when calling vips operations:
VipsImage *
thing( VipsImage *in1, VipsImage *in2 )
int
thing( VipsImage *in1, VipsImage *in2, VipsImage **out )
{
VipsImage *t;
VipsImage *out;
if( vips_add( in1, in2, &t, NULL ) )
return( NULL );
if( vips_add( in1, t, &out, NULL ) ) {
return( -1 );
if( vips_add( in1, t, out, NULL ) ) {
g_object_unref( t );
return( NULL );
return( -1 );
}
g_object_unref( t );
return( out );
return( 0 );
}
The first vips_add() call returns (via the reference argument) a new
@ -79,18 +78,16 @@
VipsPool provides a nicer way to track the objects that you create and free
them safely. The above function would become:
VipsImage *
thing( VipsPool *pool, VipsImage *in1, VipsImage *in2 )
int
thing( VipsPool *pool, VipsImage *in1, VipsImage *in2, VipsImage **out )
{
VipsPoolContext *context = vips_pool_context_new( pool );
VipsImage *out;
if( vips_add( in1, in2, VIPS_VAR_IMAGE_REF( 1 ), NULL ) ||
vips_add( in1, VIPS_VAR_IMAGE( 1 ), &out, NULL ) )
return( NULL );
vips_add( in1, VIPS_VAR_IMAGE( 1 ), out, NULL ) )
return( -1 );
return( out );
return( 0 );
}
vips_pool_context_new() creates a new context to hold a set of temporary