Added support for ImageMagick6.

This commit is contained in:
Dirk Lemstra 2017-12-17 01:03:28 +01:00
parent 7072c85e4e
commit c3f1000215

View File

@ -109,16 +109,10 @@
#if !defined(QuantumRange) #if !defined(QuantumRange)
# define QuantumRange MaxRGB # define QuantumRange MaxRGB
#endif #endif
#define TextExtent MagickTextExtent #define MaxPathExtent MaxTextExtent
#elif HAVE_MAGICK7 #elif HAVE_MAGICK7
#include <MagickCore/MagickCore.h> #include <MagickCore/MagickCore.h>
#define TextExtent MagickPathExtent #define MaxPathExtent MagickPathExtent
#endif
/* And this used to be UseHDRI.
*/
#if MAGICKCORE_HDRI_SUPPORT
# define UseHDRI 1
#endif #endif
/* What we track during a write call. /* What we track during a write call.
@ -137,6 +131,12 @@ typedef struct _Write {
#if HAVE_MAGICK #if HAVE_MAGICK
/* And this used to be UseHDRI.
*/
#if MAGICKCORE_HDRI_SUPPORT
# define UseHDRI 1
#endif
#include "pforeign.h" #include "pforeign.h"
/* What we track during a read call. /* What we track during a read call.
@ -232,7 +232,7 @@ read_new( const char *filename, VipsImage *im,
if( filename ) if( filename )
vips_strncpy( read->image_info->filename, vips_strncpy( read->image_info->filename,
filename, MaxTextExtent ); filename, MaxPathExtent );
/* Canvas resolution for rendering vector formats like SVG. /* Canvas resolution for rendering vector formats like SVG.
*/ */
@ -915,6 +915,101 @@ vips__magick_read_buffer_header( const void *buf, const size_t len,
#endif /*HAVE_MAGICK*/ #endif /*HAVE_MAGICK*/
#ifdef HAVE_MAGICK7
static Image*
magick_acquire_image( const ImageInfo *image_info, ExceptionInfo *exception )
{
return AcquireImage( image_info, exception );
}
static void
magick_acquire_next_image( const ImageInfo *image_info, Image *image,
ExceptionInfo *exception)
{
AcquireNextImage( image_info, image, exception );
}
static int
magick_set_image_size( Image *image, const size_t width, const size_t height,
ExceptionInfo *exception)
{
return SetImageExtent( image, width, height, exception );
}
static int
magick_import_pixels( Image *image, const ssize_t x, const ssize_t y,
const size_t width, const size_t height, const char *map,
const StorageType type,const void *pixels, ExceptionInfo *exception )
{
return ImportImagePixels( image, x, y, width, height, map,
type, pixels, exception );
}
static void
magick_set_property( Image *image, const char *property, const char *value,
ExceptionInfo *exception )
{
(void) SetImageProperty( image, property, value, exception );
}
static void
magick_inherit_exception( Write *write ) {
(void) write;
}
#endif /*HAVE_MAGICK7 */
#ifdef HAVE_MAGICK
static Image*
magick_acquire_image(const ImageInfo *image_info, ExceptionInfo *exception)
{
(void) exception;
return AcquireImage( image_info );
}
static void
magick_acquire_next_image( const ImageInfo *image_info, Image *image,
ExceptionInfo *exception )
{
(void) exception;
AcquireNextImage( image_info, image );
}
static int
magick_set_image_size( Image *image, const size_t width, const size_t height,
ExceptionInfo *exception )
{
(void) exception;
return SetImageExtent( image, width, height );
}
static int
magick_import_pixels( Image *image, const ssize_t x, const ssize_t y,
const size_t width, const size_t height, const char *map,
const StorageType type,const void *pixels, ExceptionInfo *exception )
{
(void) exception;
return ImportImagePixels( image, x, y, width, height, map,
type, pixels );
}
static void
magick_set_property( Image *image, const char *property, const char *value,
ExceptionInfo *exception )
{
(void) exception;
(void) SetImageProperty( image, property, value );
}
static void
magick_inherit_exception( Write *write ) {
InheritException( write->exception, &write->current_image->exception );
}
#endif
/* Can be called many times. /* Can be called many times.
*/ */
static void static void
@ -1009,17 +1104,17 @@ write_new( VipsImage *im, const char *filename, const char *format )
if( format ) { if( format ) {
vips_strncpy( write->image_info->magick, vips_strncpy( write->image_info->magick,
format, TextExtent ); format, MaxPathExtent );
if ( filename ) { if ( filename ) {
va_list ap; va_list ap;
(void) vips_snprintf( write->image_info->filename, (void) vips_snprintf( write->image_info->filename,
TextExtent, "%s:%s", format, filename ); MaxPathExtent, "%s:%s", format, filename );
} }
} }
else if ( filename ) { else if ( filename ) {
vips_strncpy( write->image_info->filename, vips_strncpy( write->image_info->filename,
filename, TextExtent ); filename, MaxPathExtent );
} }
write->exception = AcquireExceptionInfo(); write->exception = AcquireExceptionInfo();
@ -1033,8 +1128,6 @@ write_new( VipsImage *im, const char *filename, const char *format )
return( write ); return( write );
} }
#ifdef HAVE_MAGICK7
static int static int
magick_set_properties( Write *write ) magick_set_properties( Write *write )
{ {
@ -1048,7 +1141,7 @@ magick_set_properties( Write *write )
write->current_image->iterations = (size_t) number; write->current_image->iterations = (size_t) number;
if( !vips_image_get_string( write->im, "gif-comment", &str ) ) if( !vips_image_get_string( write->im, "gif-comment", &str ) )
(void) SetImageProperty( write->current_image, "comment", magick_set_property( write->current_image, "comment",
str, write->exception ); str, write->exception );
} }
@ -1061,7 +1154,7 @@ magick_write_block( VipsRegion *region, VipsRect *area, void *a )
p = VIPS_REGION_ADDR(region, area->left, area->top); p = VIPS_REGION_ADDR(region, area->left, area->top);
status=ImportImagePixels( write->current_image, area->left, area->top, status=magick_import_pixels( write->current_image, area->left, area->top,
area->width, area->height, write->map, write->storageType, p, area->width, area->height, write->map, write->storageType, p,
write->exception ); write->exception );
@ -1072,9 +1165,10 @@ static int
magick_create_image( Write *write, VipsImage *im ) magick_create_image( Write *write, VipsImage *im )
{ {
Image *image; Image *image;
int status;
if( write->images == NULL ) { if( write->images == NULL ) {
image = AcquireImage( write->image_info, write->exception ); image = magick_acquire_image( write->image_info, write->exception );
if( image == NULL ) if( image == NULL )
return( -1 ); return( -1 );
@ -1082,19 +1176,21 @@ magick_create_image( Write *write, VipsImage *im )
} }
else { else {
image=GetLastImageInList( write->images ); image=GetLastImageInList( write->images );
AcquireNextImage( write->image_info, image, write->exception ); magick_acquire_next_image( write->image_info, image, write->exception );
if( GetNextImageInList( image ) == NULL ) if( GetNextImageInList( image ) == NULL )
return( -1 ); return( -1 );
image=SyncNextImageInList( image ); image=SyncNextImageInList( image );
} }
if( !SetImageExtent( image, im->Xsize, im->Ysize, write->exception ) ) if( !magick_set_image_size( image, im->Xsize, im->Ysize, write->exception ) )
return( -1 ); return( -1 );
write->current_image=image; write->current_image=image;
magick_set_properties( write ); magick_set_properties( write );
return( vips_sink_disc( im, magick_write_block, write ) ); status = vips_sink_disc( im, magick_write_block, write );
magick_inherit_exception( write );
return( status );
} }
static int static int
@ -1147,8 +1243,6 @@ magick_write_images_buf( Write *write, void **obuf, size_t *olen )
return( 0 ); return( 0 );
} }
#endif /*HAVE_MAGICK7 */
int int
vips__magick_write( VipsImage *im, const char *filename, vips__magick_write( VipsImage *im, const char *filename,
const char *format ) const char *format )