From a7d56f20e34f4d8ff05f9a3cbcce8789e27667cc Mon Sep 17 00:00:00 2001 From: dirk Date: Thu, 7 Jul 2016 23:16:32 +0200 Subject: [PATCH] The source pixels need to be copied when a channel mask is set otherwise the values will be uninitialized. --- MagickCore/accelerate.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/MagickCore/accelerate.c b/MagickCore/accelerate.c index 35cc3938a..3c8b72953 100644 --- a/MagickCore/accelerate.c +++ b/MagickCore/accelerate.c @@ -226,6 +226,28 @@ static MagickCLEnv getOpenCLEnvironment(ExceptionInfo* exception) return(clEnv); } +static inline void copyPixels(const Image *source,Image *destination, + ExceptionInfo *exception) +{ + RectangleInfo + geometry; + + OffsetInfo + offset; + + /* The pixels only need to be copied when a channel mask has been set */ + if (((source->channel_mask & RedChannel) != 0) && + ((source->channel_mask & GreenChannel) != 0) && + ((source->channel_mask & BlueChannel) != 0) && + ((source->channel_mask & AlphaChannel) != 0)) + return; + + geometry.width=source->columns; + geometry.height=source->rows; + geometry.x=geometry.y=offset.x=offset.y=0; + CopyImagePixels(destination,source,&geometry,&offset,exception); +} + /* pad the global workgroup size to the next multiple of the local workgroup size */ inline static unsigned int padGlobalWorkgroupSizeToLocalWorkgroupSize( @@ -435,6 +457,7 @@ static Image *ComputeAddNoiseImage(const Image *image,MagickCLEnv clEnv, goto cleanup; if (filteredImage->number_channels != image->number_channels) goto cleanup; + copyPixels(image,filteredImage,exception); imageBuffer=GetAuthenticOpenCLBuffer(image,device,exception); if (imageBuffer == (cl_mem) NULL) goto cleanup; @@ -628,6 +651,7 @@ static Image *ComputeBlurImage(const Image* image,MagickCLEnv clEnv, goto cleanup; if (filteredImage->number_channels != image->number_channels) goto cleanup; + copyPixels(image,filteredImage,exception); imageBuffer=GetAuthenticOpenCLBuffer(image,device,exception); if (imageBuffer == (cl_mem) NULL) goto cleanup; @@ -4609,6 +4633,7 @@ static Image* ComputeRotationalBlurImage(const Image *image,MagickCLEnv clEnv, goto cleanup; if (filteredImage->number_channels != image->number_channels) goto cleanup; + copyPixels(image,filteredImage,exception); imageBuffer=GetAuthenticOpenCLBuffer(image,device,exception); if (imageBuffer == (cl_mem) NULL) goto cleanup; @@ -4809,6 +4834,7 @@ static Image *ComputeUnsharpMaskImage(const Image *image,MagickCLEnv clEnv, goto cleanup; if (filteredImage->number_channels != image->number_channels) goto cleanup; + copyPixels(image,filteredImage,exception); imageBuffer=GetAuthenticOpenCLBuffer(image,device,exception); if (imageBuffer == (cl_mem) NULL) goto cleanup; @@ -4983,6 +5009,7 @@ static Image *ComputeUnsharpMaskImageSingle(const Image *image, goto cleanup; if (filteredImage->number_channels != image->number_channels) goto cleanup; + copyPixels(image,filteredImage,exception); imageBuffer=GetAuthenticOpenCLBuffer(image,device,exception); if (imageBuffer == (cl_mem) NULL) goto cleanup; -- 2.40.0