From 1d473ef5cc20600b852bf2a47d1a03966a766a00 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Fri, 30 Apr 2010 19:16:39 +0000 Subject: [PATCH] stuff --- ChangeLog | 1 + TODO | 2 - configure.in | 53 ++++++++++++++++----- libvips/format/im_magick2vips.c | 83 ++++++++++++++++++++++++--------- libvips/include/vips/image.h | 1 + libvips/iofuncs/im_init_world.c | 22 +++++++++ 6 files changed, 126 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 560b7068..1ffb1872 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,7 @@ - add --enable-debug=xxx flag - im_iterate() -> vips_sink() - better number-of-bands detection for im_magick2vips() +- added im_get_argv0() 16/1/10 started 7.21.2 - "invalidate" is careful to keep images alive, so invalidate callbacks can do diff --git a/TODO b/TODO index 3fea017a..781a00e1 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ -- im_magick2vips() needs rewriting, argh - - add support for PFM files, portable float maps diff --git a/configure.in b/configure.in index 1f513fd5..a8ed07d1 100644 --- a/configure.in +++ b/configure.in @@ -323,18 +323,6 @@ if test x"$with_magick" != "xno"; then ]) fi -if test x"$with_magick" != "xno"; then - # we need ResetImageAttributeIterator() / GetNextImageAttribute() to loop - # over attrs, but that's 6.2+ I think ... test for them - # graphicsmagick only has GetImageAttribute(), test for that as a fallback - save_LIBS=$LIBS - LIBS="$LIBS $MAGICK_LIBS" - AC_CHECK_FUNCS(GetNextImageAttribute GetImageAttribute, - AC_DEFINE(HAVE_MAGICK_ATTR,1, - [define if your magick has attribute support.])) - LIBS=$save_LIBS -fi - if test x"$with_magick" != "xno"; then # we SetImageOption to disable some DICOM read processing, but that's only # in more recent imagemagicks and not in graphicsmagick @@ -346,6 +334,47 @@ if test x"$with_magick" != "xno"; then LIBS=$save_LIBS fi +if test x"$with_magick" != "xno"; then + # newer ImageMagicks use MagickCoreGenesis instead of InitializeMagick argh + save_LIBS=$LIBS + LIBS="$LIBS $MAGICK_LIBS" + AC_CHECK_FUNCS(MagickCoreGenesis, + AC_DEFINE(HAVE_MAGICKCOREGENESIS,1, + [define if your magick has MagickCoreGenesis.])) + LIBS=$save_LIBS +fi + +if test x"$with_magick" != "xno"; then + # newer ImageMagicks use ResetImagePropertyIterator instead of + # ResetImageAttributeIterator argh + save_LIBS=$LIBS + LIBS="$LIBS $MAGICK_LIBS" + AC_CHECK_FUNCS(ResetImagePropertyIterator, + AC_DEFINE(HAVE_RESETIMAGEPROPERTYITERATOR,1, + [define if your magick has ResetImagePropertyIterator.])) + LIBS=$save_LIBS +fi + +if test x"$with_magick" != "xno"; then + # so ... do we have ResetImageAttributeIterator()? GM does not + save_LIBS=$LIBS + LIBS="$LIBS $MAGICK_LIBS" + AC_CHECK_FUNCS(ResetImageAttributeIterator, + AC_DEFINE(HAVE_RESETIMAGEATTRIBUTEITERATOR,1, + [define if your magick has ResetImageAttributeIterator.])) + LIBS=$save_LIBS +fi + +if test x"$with_magick" != "xno"; then + # more recent magicks have GetVirtualPixels rather than GetImagePixels + save_LIBS=$LIBS + LIBS="$LIBS $MAGICK_LIBS" + AC_CHECK_FUNCS(GetVirtualPixels, + AC_DEFINE(HAVE_GETVIRTUALPIXELS,1, + [define if your magick has GetVirtualPixels.])) + LIBS=$save_LIBS +fi + # liboil AC_ARG_WITH([liboil], AS_HELP_STRING([--without-liboil], [build without liboil (default: test)])) diff --git a/libvips/format/im_magick2vips.c b/libvips/format/im_magick2vips.c index 5f0e728c..c289f4db 100644 --- a/libvips/format/im_magick2vips.c +++ b/libvips/format/im_magick2vips.c @@ -35,6 +35,7 @@ * - gtkdoc * 30/4/10 * - better number of bands detection with GetImageType() + * - use new API stuff, argh */ /* @@ -158,7 +159,11 @@ read_new( const char *filename, IMAGE *im ) static int inited = 0; if( !inited ) { +#ifdef HAVE_MAGICKCOREGENESIS + MagickCoreGenesis( im_get_argv0(), MagickFalse ); +#else /*!HAVE_MAGICKCOREGENESIS*/ InitializeMagick( "" ); +#endif /*HAVE_MAGICKCOREGENESIS*/ inited = 1; } @@ -241,9 +246,6 @@ parse_header( Read *read ) IMAGE *im = read->im; Image *image = read->image; -#ifdef HAVE_MAGICK_ATTR - const ImageAttribute *attr; -#endif /*HAVE_MAGICK_ATTR*/ Image *p; int i; @@ -353,34 +355,60 @@ parse_header( Read *read ) */ im->Coding = IM_CODING_NONE; -#ifdef HAVE_MAGICK_ATTR -#ifdef HAVE_GETNEXTIMAGEATTRIBUTE - /* Gah, magick6.something and later only. Attach any attributes. + /* Three ways to loop over attributes / properties :-( + */ + +#ifdef HAVE_RESETIMAGEPROPERTYITERATOR +{ + char *key; + + /* This is the most recent imagemagick API, test for this first. + */ + ResetImagePropertyIterator( image ); + while( (key = GetNextImageProperty( image )) ) { + char name_text[256]; + VipsBuf name; + + vips_buf_init_static( &name, name_text, 256 ); + vips_buf_appendf( &name, "magick-%s", key ); + im_meta_set_string( im, + vips_buf_all( &name ), GetImageProperty( image, key ) ); + } +} +#elif defined(HAVE_RESETIMAGEATTRIBUTEITERATOR) +{ + const ImageAttribute *attr; + + /* magick6.1-ish and later, deprecated in 6.5ish. */ ResetImageAttributeIterator( image ); while( (attr = GetNextImageAttribute( image )) ) { -#elif defined(HAVE_GETIMAGEATTRIBUTE) - /* GraphicsMagick is missing the iterator: we have to loop ourselves. - * ->attributes is marked as private in the header, but there's no - * getter so we have to access it directly. - */ - for( attr = image->attributes; attr; attr = attr->next ) { -#else /*stuff*/ - #error attributes enabled, but no access funcs found -#endif char name_text[256]; VipsBuf name; vips_buf_init_static( &name, name_text, 256 ); vips_buf_appendf( &name, "magick-%s", attr->key ); im_meta_set_string( im, vips_buf_all( &name ), attr->value ); - -#ifdef DEBUG - printf( "key = \"%s\", value = \"%s\"\n", - attr->key, attr->value ); -#endif /*DEBUG*/ } -#endif /*HAVE_MAGICK_ATTR*/ +} +#else +{ + const ImageAttribute *attr; + + /* GraphicsMagick is missing the iterator: we have to loop ourselves. + * ->attributes is marked as private in the header, but there's no + * getter so we have to access it directly. + */ + for( attr = image->attributes; attr; attr = attr->next ) { + char name_text[256]; + VipsBuf name; + + vips_buf_init_static( &name, name_text, 256 ); + vips_buf_appendf( &name, "magick-%s", attr->key ); + im_meta_set_string( im, vips_buf_all( &name ), attr->value ); + } +} +#endif /* Do we have a set of equal-sized frames? Append them. @@ -556,8 +584,13 @@ static PixelPacket * get_pixels( Image *image, int left, int top, int width, int height ) { PixelPacket *pixels; - + +#ifdef HAVE_GETVIRTUALPIXELS + if( !(pixels = (PixelPacket *) GetVirtualPixels( image, + left, top, width, height, &image->exception )) ) +#else if( !(pixels = GetImagePixels( image, left, top, width, height )) ) +#endif return( NULL ); /* Can't happen if red/green/blue are doubles. @@ -566,7 +599,13 @@ get_pixels( Image *image, int left, int top, int width, int height ) /* Unpack palette. */ if( image->storage_class == PseudoClass ) { +#ifdef HAVE_GETVIRTUALPIXELS + IndexPacket *indexes = (IndexPacket *) + GetVirtualIndexQueue( image ); +#else IndexPacket *indexes = GetIndexes( image ); +#endif + int i; for( i = 0; i < width * height; i++ ) { diff --git a/libvips/include/vips/image.h b/libvips/include/vips/image.h index bf246493..0316ed55 100644 --- a/libvips/include/vips/image.h +++ b/libvips/include/vips/image.h @@ -291,6 +291,7 @@ extern const size_t im__sizeof_bandfmt[]; (X) * IM_IMAGE_SIZEOF_PEL(I)) #endif /*DEBUG*/ +const char *im_get_argv0( void ); int im_init_world( const char *argv0 ); GOptionGroup *im_get_option_group( void ); diff --git a/libvips/iofuncs/im_init_world.c b/libvips/iofuncs/im_init_world.c index 2eb59cc0..65ecfb33 100644 --- a/libvips/iofuncs/im_init_world.c +++ b/libvips/iofuncs/im_init_world.c @@ -58,6 +58,8 @@ #endif /*HAVE_CONFIG_H*/ #include +#include + #include #include #include @@ -75,6 +77,24 @@ */ GMutex *im__global_lock = NULL; +/* Keep a copy of the argv0 here. + */ +static char *im__argv0 = NULL; + +/** + * im_get_argv0: + * + * See also: im_init_world(). + * + * Returns: a pointer to an internal copy of the argv0 string passed to + * im_init_world(). Do not free this value + */ +const char * +im_get_argv0( void ) +{ + return( im__argv0 ); +} + /** * im_init_world: * @argv0: name of application @@ -147,6 +167,8 @@ im_init_world( const char *argv0 ) return( 0 ); started = TRUE; + IM_SETSTR( im__argv0, argv0 ); + /* Need gobject etc. */ g_type_init();