From 1f07555d1773dac3acebfce4ba017128246923c2 Mon Sep 17 00:00:00 2001 From: cristy Date: Tue, 4 Nov 2014 00:03:27 +0000 Subject: [PATCH] --- MagickCore/colorspace-private.h | 12 ++++++- MagickCore/colorspace.c | 10 ------ MagickCore/paint.c | 21 ++++++----- MagickCore/pixel.c | 64 ++++++++++++++++++++++++++++++--- MagickCore/pixel.h | 3 +- 5 files changed, 85 insertions(+), 25 deletions(-) diff --git a/MagickCore/colorspace-private.h b/MagickCore/colorspace-private.h index 53bc6a680..20bb0a5c8 100644 --- a/MagickCore/colorspace-private.h +++ b/MagickCore/colorspace-private.h @@ -27,6 +27,16 @@ extern "C" { #endif +static inline void ConvertCMYKToRGB(PixelInfo *pixel) +{ + pixel->red=((QuantumRange-(QuantumScale*pixel->red*(QuantumRange- + pixel->black)+pixel->black))); + pixel->green=((QuantumRange-(QuantumScale*pixel->green*(QuantumRange- + pixel->black)+pixel->black))); + pixel->blue=((QuantumRange-(QuantumScale*pixel->blue*(QuantumRange- + pixel->black)+pixel->black))); +} + static inline void ConvertRGBToCMYK(PixelInfo *pixel) { MagickRealType @@ -37,7 +47,7 @@ static inline void ConvertRGBToCMYK(PixelInfo *pixel) magenta, red, yellow; - + if (pixel->colorspace != sRGBColorspace) { red=QuantumScale*pixel->red; diff --git a/MagickCore/colorspace.c b/MagickCore/colorspace.c index 3eb3941cd..f7e9e9e67 100644 --- a/MagickCore/colorspace.c +++ b/MagickCore/colorspace.c @@ -1259,16 +1259,6 @@ static inline ssize_t RoundToYCC(const double value) return((ssize_t) (value+0.5)); } -static inline void ConvertCMYKToRGB(PixelInfo *pixel) -{ - pixel->red=((QuantumRange-(QuantumScale*pixel->red* - (QuantumRange-pixel->black)+pixel->black))); - pixel->green=((QuantumRange-(QuantumScale*pixel->green* - (QuantumRange-pixel->black)+pixel->black))); - pixel->blue=((QuantumRange-(QuantumScale*pixel->blue* - (QuantumRange-pixel->black)+pixel->black))); -} - static inline void ConvertLabToRGB(const double L,const double a, const double b,double *red,double *green,double *blue) { diff --git a/MagickCore/paint.c b/MagickCore/paint.c index 7b7e024e2..9ce61d74e 100644 --- a/MagickCore/paint.c +++ b/MagickCore/paint.c @@ -728,7 +728,7 @@ MagickExport Image *OilPaintImage(const Image *image,const double radius, %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % OpaquePaintImage() changes any pixel that matches color with the color -% defined by fill. +% defined by fill argument. % % By default color must match a particular pixel color exactly. However, in % many cases two colors may differ by a small amount. Fuzz defines how much @@ -738,9 +738,9 @@ MagickExport Image *OilPaintImage(const Image *image,const double radius, % % The format of the OpaquePaintImage method is: % -% MagickBooleanType OpaquePaintImage(Image *image, -% const PixelInfo *target,const PixelInfo *fill, -% const MagickBooleanType invert,ExceptionInfo *exception) +% MagickBooleanType OpaquePaintImage(Image *image,const PixelInfo *target, +% const PixelInfo *fill,const MagickBooleanType invert, +% ExceptionInfo *exception) % % A description of each parameter follows: % @@ -771,6 +771,8 @@ MagickExport MagickBooleanType OpaquePaintImage(Image *image, progress; PixelInfo + conform_fill, + conform_target, zero; ssize_t @@ -787,9 +789,10 @@ MagickExport MagickBooleanType OpaquePaintImage(Image *image, if ((IsGrayColorspace(image->colorspace) != MagickFalse) && (IsPixelInfoGray(fill) == MagickFalse)) (void) SetImageColorspace(image,sRGBColorspace,exception); - if ((fill->alpha_trait == BlendPixelTrait) && - (image->alpha_trait != BlendPixelTrait)) - (void) SetImageAlpha(image,OpaqueAlpha,exception); + conform_fill=(*fill); + ConformPixelInfo(image,&conform_fill,exception); + conform_target=(*target); + ConformPixelInfo(image,&conform_target,exception); /* Make image color opaque. */ @@ -824,8 +827,8 @@ MagickExport MagickBooleanType OpaquePaintImage(Image *image, for (x=0; x < (ssize_t) image->columns; x++) { GetPixelInfoPixel(image,q,&pixel); - if (IsFuzzyEquivalencePixelInfo(&pixel,target) != invert) - SetPixelInfoPixel(image,fill,q); + if (IsFuzzyEquivalencePixelInfo(&pixel,&conform_target) != invert) + SetPixelInfoPixel(image,&conform_fill,q); q+=GetPixelChannels(image); } if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) diff --git a/MagickCore/pixel.c b/MagickCore/pixel.c index a2a652f50..a3be57ee7 100644 --- a/MagickCore/pixel.c +++ b/MagickCore/pixel.c @@ -44,6 +44,7 @@ #include "MagickCore/blob-private.h" #include "MagickCore/cache-private.h" #include "MagickCore/color-private.h" +#include "MagickCore/colorspace-private.h" #include "MagickCore/draw.h" #include "MagickCore/exception.h" #include "MagickCore/exception-private.h" @@ -158,11 +159,11 @@ MagickExport PixelChannelMap *ClonePixelChannelMap(PixelChannelMap *channel_map) % % The format of the ClonePixelInfo method is: % -% PixelInfo *ClonePixelInfo(const PixelInfo *pixel_info) +% PixelInfo *ClonePixelInfo(const PixelInfo *pixel) % % A description of each parameter follows: % -% o pixel_info: the pixel info. +% o pixel: the pixel info. % */ MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel) @@ -182,6 +183,63 @@ MagickExport PixelInfo *ClonePixelInfo(const PixelInfo *pixel) % % % % % % ++ C o n f o r m P i x e l I n f o % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% ConformPixelInfo() ensures the pixel conforms with the colorspace and alpha +% attribute of the image. +% +% The format of the ConformPixelInfo method is: +% +% void *ConformPixelInfo((Image *image,PixelInfo *pixel, +% ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o pixel: the pixel info. +% +% o image: the image. +% +% o exception: return any errors or warnings in this structure. +% +*/ +MagickExport void ConformPixelInfo(Image *image,PixelInfo *pixel, + ExceptionInfo *exception) +{ + assert(image != (Image *) NULL); + assert(image->signature == MagickSignature); + assert(pixel != (const PixelInfo *) NULL); + + if (image->colorspace == CMYKColorspace) + { + if (IssRGBCompatibleColorspace(pixel->colorspace)) + ConvertRGBToCMYK(pixel); + } + else + if (pixel->colorspace == CMYKColorspace) + { + if (IssRGBCompatibleColorspace(image->colorspace)) + ConvertCMYKToRGB(pixel); + } +#if 0 + if ((IsGrayColorspace(image->colorspace) != MagickFalse) && + (IsPixelInfoGray(pixel) == MagickFalse)) + /* TODO: Add this method. */ + SetPixelInfoGray(pixel); +#endif + if ((pixel->alpha_trait == BlendPixelTrait) && + (image->alpha_trait != BlendPixelTrait)) + (void) SetImageAlpha(image,OpaqueAlpha,exception); +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % % D e c o d e P i x e l G a m m a % % % % % @@ -4419,7 +4477,6 @@ MagickExport MagickBooleanType InterpolatePixelChannel(const Image *image, x_offset, y_offset; - assert(image != (Image *) NULL); assert(image != (Image *) NULL); assert(image->signature == MagickSignature); assert(image_view != (CacheView *) NULL); @@ -4841,7 +4898,6 @@ MagickExport MagickBooleanType InterpolatePixelChannels(const Image *source, PixelInterpolateMethod interpolate; - assert(source != (Image *) NULL); assert(source != (Image *) NULL); assert(source->signature == MagickSignature); assert(source_view != (CacheView *) NULL); diff --git a/MagickCore/pixel.h b/MagickCore/pixel.h index 444994838..ad8cbbfe7 100644 --- a/MagickCore/pixel.h +++ b/MagickCore/pixel.h @@ -244,8 +244,9 @@ extern MagickExport MagickRealType EncodePixelGamma(const MagickRealType) magick_hot_spot; extern MagickExport void - InitializePixelChannelMap(Image *), + ConformPixelInfo(Image *,PixelInfo *,ExceptionInfo *), GetPixelInfo(const Image *,PixelInfo *), + InitializePixelChannelMap(Image *), SetPixelChannelMask(Image *,const ChannelType); #if defined(__cplusplus) || defined(c_plusplus) -- 2.40.0