void vips_lib_error() { VALUE vips_error = rb_str_new2(im_error_buffer()); im_error_clear(); rb_raise(eVIPSError, "VIPS error: %s", RSTRING_PTR(vips_error)); }
/* A non-fatal error. Print the vips error buffer and continue. */ static void print_error( const char *fmt, ... ) { va_list ap; va_start( ap, fmt ); vfprintf( stderr, fmt, ap ); va_end( ap ); fprintf( stderr, "\n%s\n", im_error_buffer() ); im_error_clear(); }
static int ismagick( const char *filename ) { IMAGE *im; int result; if( !(im = im_open( "dummy", "p" )) ) return( -1 ); result = magick2vips_header( filename, im ); im_error_clear(); im_close( im ); return( result == 0 ); }
/* Make a VipsObject. */ void vo_object_new( Reduce *rc, const char *name, PElement *required, PElement *optional, PElement *out ) { Vo *vo; Managedgobject *managedgobject; 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. */ if( vips_object_build( vo->object ) ) { error_top( _( "VIPS library error." ) ); error_sub( "%s", im_error_buffer() ); im_error_clear(); vo_free( vo ); reduce_throw( rc ); } /* Return the constructed object. */ if( !(managedgobject = managedgobject_new( vo->rc->heap, G_OBJECT( vo->object ) )) ) { vo_free( vo ); reduce_throw( rc ); } PEPUTP( out, ELEMENT_MANAGED, managedgobject ); #ifdef DEBUG { char txt[1000]; VipsBuf buf = VIPS_BUF_STATIC( txt ); vips_object_to_string( vo->object, &buf ); printf( "vo_object_new: built %s\n", vips_buf_all( &buf ) ); } #endif /*DEBUG*/ vo_free( vo ); }
/* Make a leaf for a file. */ static JoinNode * build_node( SymbolTable *st, char *name ) { JoinNode *node = IM_NEW( st->im, JoinNode ); int n = hash( name ); /* Fill fields. */ if( !node || !(node->name = im_strdup( st->im, name )) ) return( NULL ); node->type = JOIN_LEAF; node->dirty = 0; node->mwidth = -2; node->st = st; im__transform_init( &node->cumtrn ); node->trnim = NULL; node->arg1 = NULL; node->arg2 = NULL; node->overlaps = NULL; node->im = NULL; node->index = 0; if( im_add_close_callback( st->im, (im_callback_fn) junk_node, node, NULL ) ) return( NULL ); /* Try to open. */ if( (node->im = im__global_open_image( st, name )) ) { /* There is a file there - set width and height. */ node->cumtrn.oarea.width = node->im->Xsize; node->cumtrn.oarea.height = node->im->Ysize; } else { /* Clear the error buffer to lessen confusion. */ im_error_clear(); } st->table[n] = g_slist_prepend( st->table[n], node ); return( node ); }
int main( int argc, char **argv ) { GOptionContext *context; GError *error = NULL; int i; if( im_init_world( argv[0] ) ) error_exit( "unable to start VIPS" ); textdomain( GETTEXT_PACKAGE ); setlocale( LC_ALL, "" ); context = g_option_context_new( _( "- thumbnail generator" ) ); g_option_context_add_main_entries( context, options, GETTEXT_PACKAGE ); g_option_context_add_group( context, im_get_option_group() ); if( !g_option_context_parse( context, &argc, &argv, &error ) ) { if( error ) { fprintf( stderr, "%s\n", error->message ); g_error_free( error ); } error_exit( "try \"%s --help\"", g_get_prgname() ); } g_option_context_free( context ); for( i = 1; i < argc; i++ ) if( thumbnail( argv[i] ) ) { fprintf( stderr, "%s: unable to thumbnail %s\n", argv[0], argv[i] ); fprintf( stderr, "%s", im_error_buffer() ); im_error_clear(); } vips_shutdown(); return( 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 ); }
/* A non-fatal error. Print the vips error buffer and continue. */ static void print_error( void ) { fprintf( stderr, "%s: %s", g_get_prgname(), im_error_buffer() ); im_error_clear(); }