From 02bdb8b96c2e6a44001d5671ef745179bff5496e Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 24 May 2019 17:42:10 +0100 Subject: [PATCH] better error message for "unsupported colorspace" we just printed the enum number before --- ChangeLog | 1 + libvips/foreign/magick.c | 54 +++++++++++++++++++++++++++++++++++ libvips/foreign/magick.h | 3 ++ libvips/foreign/magick7load.c | 4 +-- 4 files changed, 60 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b0fce75e..077985ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 24/5/19 started 8.8.1 - improve realpath() use on older libc +- better magickload error messages 21/9/18 started 8.8.0 - much faster smartcrop [lovell] diff --git a/libvips/foreign/magick.c b/libvips/foreign/magick.c index fcbeffa5..b82f24fa 100644 --- a/libvips/foreign/magick.c +++ b/libvips/foreign/magick.c @@ -403,6 +403,60 @@ magick_set_image_option( ImageInfo *image_info, #endif /*HAVE_SETIMAGEOPTION*/ } +typedef struct _MagickColorspaceTypeNames { + ColorspaceType colorspace; + const char *name; +} MagickColorspaceTypeNames; + +static MagickColorspaceTypeNames magick_colorspace_names[] = { + { UndefinedColorspace, "UndefinedColorspace" }, + { CMYColorspace, "CMYColorspace" }, + { CMYKColorspace, "CMYKColorspace" }, + { GRAYColorspace, "GRAYColorspace" }, + { HCLColorspace, "HCLColorspace" }, + { HCLpColorspace, "HCLpColorspace" }, + { HSBColorspace, "HSBColorspace" }, + { HSIColorspace, "HSIColorspace" }, + { HSLColorspace, "HSLColorspace" }, + { HSVColorspace, "HSVColorspace" }, + { HWBColorspace, "HWBColorspace" }, + { LabColorspace, "LabColorspace" }, + { LCHColorspace, "LCHColorspace" }, + { LCHabColorspace, "LCHabColorspace" }, + { LCHuvColorspace, "LCHuvColorspace" }, + { LogColorspace, "LogColorspace" }, + { LMSColorspace, "LMSColorspace" }, + { LuvColorspace, "LuvColorspace" }, + { OHTAColorspace, "OHTAColorspace" }, + { Rec601YCbCrColorspace, "Rec601YCbCrColorspace" }, + { Rec709YCbCrColorspace, "Rec709YCbCrColorspace" }, + { RGBColorspace, "RGBColorspace" }, + { scRGBColorspace, "scRGBColorspace" }, + { sRGBColorspace, "sRGBColorspace" }, + { TransparentColorspace, "TransparentColorspace" }, + { xyYColorspace, "xyYColorspace" }, + { XYZColorspace, "XYZColorspace" }, + { YCbCrColorspace, "YCbCrColorspace" }, + { YCCColorspace, "YCCColorspace" }, + { YDbDrColorspace, "YDbDrColorspace" }, + { YIQColorspace, "YIQColorspace" }, + { YPbPrColorspace, "YPbPrColorspace" }, + { YUVColorspace, "YUVColorspace" }, + { LinearGRAYColorspace, "LinearGRAYColorspace" } +}; + +const char * +magick_ColorspaceType2str( ColorspaceType colorspace ) +{ + int i; + + for( i = 0; i < VIPS_NUMBER( magick_colorspace_names ); i++ ) + if( magick_colorspace_names[i].colorspace == colorspace ) + return( magick_colorspace_names[i].name ); + + return( "" ); +} + /* ImageMagick can't detect some formats, like ICO, by examining the contents -- * ico.c simply does not have a recogniser. * diff --git a/libvips/foreign/magick.h b/libvips/foreign/magick.h index 0c78e3c6..8993a31e 100644 --- a/libvips/foreign/magick.h +++ b/libvips/foreign/magick.h @@ -61,11 +61,14 @@ void *magick_profile_map( Image *image, MagickMapProfileFn fn, void *a ); int magick_set_profile( Image *image, const char *name, const void *data, size_t length, ExceptionInfo *exception ); + void magick_set_image_option( ImageInfo *image_info, const char *name, const char *value ); void magick_set_number_scenes( ImageInfo *image_info, int scene, int number_scenes ); +const char *magick_ColorspaceType2str( ColorspaceType colorspace ); + ExceptionInfo *magick_acquire_exception( void ); void magick_destroy_exception( ExceptionInfo *exception ); void magick_inherit_exception( ExceptionInfo *exception, Image *image ); diff --git a/libvips/foreign/magick7load.c b/libvips/foreign/magick7load.c index 66d394e7..3167f30b 100644 --- a/libvips/foreign/magick7load.c +++ b/libvips/foreign/magick7load.c @@ -497,8 +497,8 @@ vips_foreign_load_magick7_parse( VipsForeignLoadMagick7 *magick7, default: vips_error( class->nickname, - _( "unsupported colorspace %d" ), - (int) image->colorspace ); + _( "unsupported colorspace %s" ), + magick_ColorspaceType2str( image->colorspace ) ); return( -1 ); }