try to improve error handling in magicksave
This commit is contained in:
parent
af51114352
commit
140a3b3ed0
@ -96,26 +96,6 @@ magick_inherit_exception( ExceptionInfo *exception, Image *image )
|
||||
(void) image;
|
||||
}
|
||||
|
||||
static void *
|
||||
magick_genesis_cb( void *client )
|
||||
{
|
||||
#ifdef DEBUG
|
||||
printf( "magick_genesis_cb:\n" );
|
||||
#endif /*DEBUG*/
|
||||
|
||||
MagickCoreGenesis( vips_get_argv0(), MagickFalse );
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
void
|
||||
magick_genesis( void )
|
||||
{
|
||||
static GOnce once = G_ONCE_INIT;
|
||||
|
||||
VIPS_ONCE( &once, magick_genesis_cb, NULL );
|
||||
}
|
||||
|
||||
#endif /*HAVE_MAGICK7*/
|
||||
|
||||
#ifdef HAVE_MAGICK
|
||||
@ -175,6 +155,20 @@ magick_inherit_exception( ExceptionInfo *exception, Image *image )
|
||||
InheritException( exception, &image->exception );
|
||||
}
|
||||
|
||||
#endif /*HAVE_MAGICK*/
|
||||
|
||||
#if defined(HAVE_MAGICK) || defined(HAVE_MAGICK7)
|
||||
|
||||
void
|
||||
magick_vips_error( const char *domain, ExceptionInfo *exception )
|
||||
{
|
||||
if( exception &&
|
||||
exception->reason &&
|
||||
exception->description )
|
||||
vips_error( domain, _( "libMagick error: %s %s" ),
|
||||
exception->reason, exception->description );
|
||||
}
|
||||
|
||||
static void *
|
||||
magick_genesis_cb( void *client )
|
||||
{
|
||||
|
@ -53,9 +53,9 @@ int magick_import_pixels( Image *image, const ssize_t x, const ssize_t y,
|
||||
const StorageType type,const void *pixels, ExceptionInfo *exception );
|
||||
void magick_set_property( Image *image, const char *property, const char *value,
|
||||
ExceptionInfo *exception );
|
||||
int magick_set_image_colorspace( Image *image, const ColorspaceType colorspace,
|
||||
ExceptionInfo *exception );
|
||||
|
||||
void magick_inherit_exception( ExceptionInfo *exception, Image *image );
|
||||
void magick_vips_error( const char *domain, ExceptionInfo *exception );
|
||||
|
||||
void magick_genesis( void );
|
||||
|
||||
|
@ -201,6 +201,7 @@ vips_foreign_save_magick_create( VipsForeignSaveMagick *magick, VipsImage *im )
|
||||
static int
|
||||
vips_foreign_save_magick_build( VipsObject *object )
|
||||
{
|
||||
VipsObjectClass *class = VIPS_OBJECT_GET_CLASS( object );
|
||||
VipsForeignSave *save = (VipsForeignSave *) object;
|
||||
VipsForeignSaveMagick *magick = (VipsForeignSaveMagick *) object;
|
||||
|
||||
@ -246,6 +247,8 @@ vips_foreign_save_magick_build( VipsObject *object )
|
||||
break;
|
||||
|
||||
default:
|
||||
vips_error( class->nickname,
|
||||
"%s", _( "unsupported image format" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
@ -275,6 +278,8 @@ vips_foreign_save_magick_build( VipsObject *object )
|
||||
break;
|
||||
|
||||
default:
|
||||
vips_error( class->nickname,
|
||||
"%s", _( "unsupported number of image bands" ) );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
@ -294,8 +299,10 @@ vips_foreign_save_magick_build( VipsObject *object )
|
||||
if( magick->quality > 0 )
|
||||
magick->image_info->quality = magick->quality;
|
||||
|
||||
if( vips_foreign_save_magick_create( magick, im ) )
|
||||
if( vips_foreign_save_magick_create( magick, im ) ) {
|
||||
magick_vips_error( class->nickname, magick->exception );
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
@ -385,12 +392,7 @@ vips_foreign_save_magick_file_build( VipsObject *object )
|
||||
if( !WriteImages( magick->image_info, magick->images,
|
||||
magick->image_info->filename, magick->exception ) ) {
|
||||
magick_inherit_exception( magick->exception, magick->images );
|
||||
vips_error( class->nickname,
|
||||
_( "unable to write file \"%s\"\n"
|
||||
"libMagick error: %s %s" ),
|
||||
file->filename,
|
||||
magick->exception->reason,
|
||||
magick->exception->description );
|
||||
magick_vips_error( class->nickname, magick->exception );
|
||||
|
||||
return( -1 );
|
||||
}
|
||||
@ -459,11 +461,7 @@ vips_foreign_save_magick_buffer_build( VipsObject *object )
|
||||
if( !(obuf = ImagesToBlob( magick->image_info, magick->images,
|
||||
&olen, magick->exception )) ) {
|
||||
magick_inherit_exception( magick->exception, magick->images );
|
||||
vips_error( class->nickname,
|
||||
_( "unable to write buffer\n"
|
||||
"libMagick error: %s %s" ),
|
||||
magick->exception->reason,
|
||||
magick->exception->description );
|
||||
magick_vips_error( class->nickname, magick->exception );
|
||||
|
||||
return( -1 );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user