diff --git a/configure.ac b/configure.ac index 1a74e303..bfdeb908 100644 --- a/configure.ac +++ b/configure.ac @@ -744,6 +744,21 @@ AC_ARG_ENABLE([magicksave], AS_HELP_STRING([--disable-magicksave], [disable libMagic save (default: enabled)])) +if test x"$enable_magicksave" != x"yes"; then + # we need ImportImagePixels ... GM is missing this sadly + save_LIBS="$LIBS" + LIBS="$LIBS $MAGICK_LIBS" + AC_CHECK_FUNCS(ImportImagePixels,[ + AC_DEFINE(HAVE_IMPORTIMAGEPIXELS,1, + [define if you have ImportImagePixels.]) + ],[ + AC_MSG_WARN([ImportImagePixels not found; disabling magicksave]) + enable_magicksave=no + ] + ) + LIBS="$save_LIBS" +fi + if test x"$with_magick" != x"no"; then if test x"$enable_magickload" != x"no"; then AC_DEFINE(ENABLE_MAGICKLOAD,1,[define to enable load with libMagick]) diff --git a/libvips/foreign/magick.c b/libvips/foreign/magick.c index 500132b1..6e3fe4ac 100644 --- a/libvips/foreign/magick.c +++ b/libvips/foreign/magick.c @@ -93,10 +93,11 @@ magick_inherit_exception( ExceptionInfo *exception, Image *image ) #ifdef HAVE_MAGICK6 -Image* -magick_acquire_image(const ImageInfo *image_info, ExceptionInfo *exception) +Image * +magick_acquire_image( const ImageInfo *image_info, ExceptionInfo *exception ) { (void) exception; + #ifdef HAVE_ACQUIREIMAGE return( AcquireImage( image_info ) ); #else /*!HAVE_ACQUIREIMAGE*/ @@ -157,8 +158,12 @@ magick_import_pixels( Image *image, const ssize_t x, const ssize_t y, * * then repack pixels into that area using map and storage_type. */ +#ifdef HAVE_IMPORTIMAGEPIXELS return( ImportImagePixels( image, x, y, width, height, map, type, pixels ) ); +#else /*!HAVE_IMPORTIMAGEPIXELS*/ + return( MagickFalse ); +#endif /*HAVE_IMPORTIMAGEPIXELS*/ } void @@ -185,6 +190,38 @@ magick_inherit_exception( ExceptionInfo *exception, Image *image ) #if defined(HAVE_MAGICK6) || defined(HAVE_MAGICK7) +void +magick_set_image_option( ImageInfo *image_info, + const char *name, const char *value ) +{ +#ifdef HAVE_SETIMAGEOPTION + SetImageOption( image_info, name, value ); +#endif /*HAVE_SETIMAGEOPTION*/ +} + +void +magick_set_number_scenes( ImageInfo *image_info, int scene, int number_scenes ) +{ +#ifdef HAVE_NUMBER_SCENES + /* I can't find docs for these fields, but this seems to work. + */ + char page[256]; + + image_info->scene = scene; + image_info->number_scenes = number_scenes; + + /* Some IMs must have the string version set as well. + */ + vips_snprintf( page, 256, "%d-%d", scene, scene + number_scenes ); + image_info->scenes = strdup( page ); +#else /*!HAVE_NUMBER_SCENES*/ + /* This works with GM 1.2.31 and probably others. + */ + image_info->subimage = scene; + image_info->subrange = number_scenes; +#endif +} + void magick_vips_error( const char *domain, ExceptionInfo *exception ) { diff --git a/libvips/foreign/magick.h b/libvips/foreign/magick.h index 507e7e11..1d7539f5 100644 --- a/libvips/foreign/magick.h +++ b/libvips/foreign/magick.h @@ -53,6 +53,10 @@ 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 ); +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 ); void magick_inherit_exception( ExceptionInfo *exception, Image *image ); void magick_vips_error( const char *domain, ExceptionInfo *exception ); diff --git a/libvips/foreign/magick2vips.c b/libvips/foreign/magick2vips.c index c9518ed2..74497a48 100644 --- a/libvips/foreign/magick2vips.c +++ b/libvips/foreign/magick2vips.c @@ -228,7 +228,6 @@ read_new( const char *filename, VipsImage *im, */ VIPS_SETSTR( read->image_info->density, density ); -#ifdef HAVE_SETIMAGEOPTION /* When reading DICOM images, we want to ignore any * window_center/_width setting, since it may put pixels outside the * 0-65535 range and lose data. @@ -236,30 +235,12 @@ read_new( const char *filename, VipsImage *im, * These window settings are attached as vips metadata, so our caller * can interpret them if it wants. */ - SetImageOption( read->image_info, "dcm:display-range", "reset" ); -#endif /*HAVE_SETIMAGEOPTION*/ + magick_set_image_option( read->image_info, + "dcm:display-range", "reset" ); - if( read->page > 0 ) { -#ifdef HAVE_NUMBER_SCENES - /* I can't find docs for these fields, but this seems to work. - */ - char page[256]; - - read->image_info->scene = read->page; - read->image_info->number_scenes = read->n; - - /* Some IMs must have the string version set as well. - */ - vips_snprintf( page, 256, "%d-%d", - read->page, read->page + read->n ); - read->image_info->scenes = strdup( page ); -#else /*!HAVE_NUMBER_SCENES*/ - /* This works with GM 1.2.31 and probably others. - */ - read->image_info->subimage = read->page; - read->image_info->subrange = read->n; -#endif - } + if( read->page > 0 ) + magick_set_number_scenes( read->image_info, + read->page, read->n ); #ifdef DEBUG printf( "magick2vips: read_new: %s\n", read->filename ); @@ -703,7 +684,9 @@ get_pixels( Image *image, int left, int top, int width, int height ) IndexPacket *indexes = (IndexPacket *) GetVirtualIndexQueue( image ); #else - IndexPacket *indexes = GetIndexes( image ); + /* Was GetIndexes(), but that's now deprecated. + */ + IndexPacket *indexes = AccessMutableIndexes( image ); #endif int i; diff --git a/libvips/foreign/magick7load.c b/libvips/foreign/magick7load.c index 35d18864..57cca252 100644 --- a/libvips/foreign/magick7load.c +++ b/libvips/foreign/magick7load.c @@ -325,20 +325,12 @@ vips_foreign_load_magick7_build( VipsObject *object ) * These window settings are attached as vips metadata, so our caller * can interpret them if it wants. */ - SetImageOption( magick7->image_info, "dcm:display-range", "reset" ); + magick_set_image_option( magick7->image_info, + "dcm:display-range", "reset" ); - if( magick7->page > 0 ) { - /* I can't find docs for these fields, but this seems to work. - */ - char page[256]; - - magick7->image_info->scene = magick7->page; - magick7->image_info->number_scenes = magick7->n; - - vips_snprintf( page, 256, "%d-%d", - magick7->page, magick7->page + magick7->n ); - magick7->image_info->scenes = strdup( page ); - } + if( magick7->page > 0 ) + magick_set_number_scenes( magick7->image_info, + magick7->page, magick7->n ); if( VIPS_OBJECT_CLASS( vips_foreign_load_magick7_parent_class )-> build( object ) )