From 6b0f676a5e7ece6a046016fe5c0c3acb915f34c8 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Fri, 22 Dec 2017 22:06:11 +0100 Subject: [PATCH] Fixed issue with grayscale images. --- libvips/foreign/magicksave.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libvips/foreign/magicksave.c b/libvips/foreign/magicksave.c index a9a3c8cc..c057c49f 100644 --- a/libvips/foreign/magicksave.c +++ b/libvips/foreign/magicksave.c @@ -94,6 +94,13 @@ magick_set_image_size( Image *image, const size_t width, const size_t height, return SetImageExtent( image, width, height, exception ); } +static int +magick_set_image_colorspace( Image *image, const ColorspaceType colorspace, + ExceptionInfo *exception) +{ + return SetImageColorspace( image, colorspace, 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, @@ -143,6 +150,14 @@ magick_set_image_size( Image *image, const size_t width, const size_t height, return SetImageExtent( image, width, height ); } +static int +magick_set_image_colorspace( Image *image, const ColorspaceType colorspace, + ExceptionInfo *exception) +{ + (void) exception; + return SetImageColorspace( image, colorspace ); +} + 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, @@ -350,6 +365,11 @@ magick_create_image( Write *write, VipsImage *im ) if( !magick_set_image_size( image, im->Xsize, im->Ysize, write->exception ) ) return( -1 ); + if( im->Bands < 3) { + if (! magick_set_image_colorspace( image, GRAYColorspace, write->exception ) ) + return( -1 ); + } + write->current_image=image; magick_set_properties( write ); status = vips_sink_disc( im, magick_write_block, write );