Пример #1
0
void 
VImage::call_option_string( const char *operation_name, 
	const char *option_string, VOption *options ) 
	throw( VError )
{
	VipsOperation *operation;

	VIPS_DEBUG_MSG( "vips_call_by_name: starting for %s ...\n", 
		operation_name );

	if( !(operation = vips_operation_new( operation_name )) ) {
		if( options )
			delete options;
		throw( VError() ); 
	}

	/* Set str options before vargs options, so the user can't 
	 * override things we set deliberately.
	 */
	if( option_string &&
		vips_object_set_from_string( VIPS_OBJECT( operation ), 
			option_string ) ) {
		vips_object_unref_outputs( VIPS_OBJECT( operation ) );
		g_object_unref( operation ); 
		delete options; 
		throw( VError() ); 
	}

	if( options )
		options->set_operation( operation );

	/* Build from cache.
	 */
	if( vips_cache_operation_buildp( &operation ) ) {
		vips_object_unref_outputs( VIPS_OBJECT( operation ) );
		delete options; 
		throw( VError() ); 
	}

	/* Walk args again, writing output.
	 */
	if( options )
		options->get_operation( operation );

	/* We're done with options!
	 */
	delete options; 

	/* The operation we have built should now have been reffed by 
	 * one of its arguments or have finished its work. Either 
	 * way, we can unref.
	 */
	g_object_unref( operation );
}
Пример #2
0
/**
 * vips_cache_operation_build:
 * @operation: operation to lookup
 *
 * A binding-friendly version of vips_cache_operation_buildp().
 *
 * After calling this, @operation has the same ref count as when it went in,
 * and the result must be freed with vips_object_unref_outputs() and
 * g_object_unref().
 *
 * Returns: (transfer full): The built operation.
 */
VipsOperation *
vips_cache_operation_build( VipsOperation *operation )
{
	VipsOperation *orig_operation = operation;

	/* Stop it being unreffed for us on hit.
	 */
	g_object_ref( orig_operation );

	if( vips_cache_operation_buildp( &operation ) ) {
		g_object_unref( orig_operation );

		return( NULL );
	}

	return( operation );
}
Пример #3
0
/* Run a VipsOperation. Like vo_object_new(), but we return the output args
 * rather than the operation.
 */
void
vo_call( Reduce *rc, const char *name, 
	PElement *required, PElement *optional, PElement *out )
{
	Vo *vo;
	PElement pe;

	if( !(vo = vo_new( rc, name )) ) 
		reduce_throw( rc );

	if( !vo_args( vo, required, optional ) ) {
		vo_free( vo );
		reduce_throw( rc );
	}

	/* Ask the object to construct. This can update vo->operation with an
	 * old one from the cache.
	 */
	if( vips_cache_operation_buildp( (VipsOperation **) &vo->object ) ) {
		error_top( _( "VIPS library error." ) );
		error_sub( "%s", im_error_buffer() );
		im_error_clear();
		vips_object_unref_outputs( vo->object );
		vo_free( vo );
		reduce_throw( rc );
	}

	/* We can't build the output object directly on out, since it might be
	 * one of our inputs. We use the safe Element in vo for the build,
	 * then copy at the end.
	 */

	/* Empty output list.
	 */
	PEPOINTE( &pe, &vo->out );
	heap_list_init( &pe );

	/* Append required outputs.
	 */
	if( vips_argument_map( VIPS_OBJECT( vo->object ),
		(VipsArgumentMapFn) vo_get_required_output, vo, &pe ) ) {
		vips_object_unref_outputs( vo->object );
		vo_free( vo );
		reduce_throw( rc );
	}

	/* Append optional outputs.
	 */
	if( !vo_get_optional( vo, optional, &pe ) ) {
		vips_object_unref_outputs( vo->object );
		vo_free( vo );
		reduce_throw( rc );
	}

	/* Now write the output object to out.
	 */
	PEPUTE( out, &vo->out );

	vips_object_unref_outputs( vo->object );
	vo_free( vo );
}