From c7e6ff6c71b861bca7123c489fcd1657ab46e9b5 Mon Sep 17 00:00:00 2001 From: cristy Date: Mon, 3 Oct 2011 13:46:11 +0000 Subject: [PATCH] --- Magick++/lib/Image.cpp | 14 +++-- MagickCore/color.c | 3 +- MagickCore/fx.c | 101 ++++++++++++++++++++++++++++++------- MagickCore/fx.h | 2 +- MagickCore/magick-config.h | 22 +++----- MagickCore/version.h | 2 +- MagickWand/magick-image.c | 42 ++++++++++----- MagickWand/mogrify.c | 3 +- PerlMagick/Magick.xs | 7 +-- coders/msl.c | 28 +++++----- 10 files changed, 152 insertions(+), 72 deletions(-) diff --git a/Magick++/lib/Image.cpp b/Magick++/lib/Image.cpp index 18aea6f97..7e64bf072 100644 --- a/Magick++/lib/Image.cpp +++ b/Magick++/lib/Image.cpp @@ -600,14 +600,20 @@ void Magick::Image::colorize ( const unsigned int alphaRed_, "Pen color argument is invalid"); } - char alpha[MaxTextExtent]; - FormatLocaleString(alpha,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_); + char blend[MaxTextExtent]; + FormatLocaleString(blend,MaxTextExtent,"%u/%u/%u",alphaRed_,alphaGreen_,alphaBlue_); ExceptionInfo exceptionInfo; GetExceptionInfo( &exceptionInfo ); + PixelInfo target; + GetPixelInfo(image(),&target); + PixelPacket pixel=static_cast(penColor_); + target.red=pixel.red; + target.green=pixel.green; + target.blue=pixel.blue; + target.alpha=pixel.alpha; MagickCore::Image* newImage = - ColorizeImage ( image(), alpha, - penColor_, &exceptionInfo ); + ColorizeImage ( image(), blend, &target, &exceptionInfo ); replaceImage( newImage ); throwException( exceptionInfo ); (void) DestroyExceptionInfo( &exceptionInfo ); diff --git a/MagickCore/color.c b/MagickCore/color.c index 83d9f1ddd..27d7a86ee 100644 --- a/MagickCore/color.c +++ b/MagickCore/color.c @@ -2256,8 +2256,7 @@ MagickExport MagickBooleanType QueryColorname(const Image *image, % */ MagickExport MagickBooleanType QueryMagickColorCompliance(const char *name, - const ComplianceType compliance,PixelInfo *color, - ExceptionInfo *exception) + const ComplianceType compliance,PixelInfo *color,ExceptionInfo *exception) { GeometryInfo geometry_info; diff --git a/MagickCore/fx.c b/MagickCore/fx.c index 55ab982e2..20eef6582 100644 --- a/MagickCore/fx.c +++ b/MagickCore/fx.c @@ -674,14 +674,14 @@ MagickExport Image *CharcoalImage(const Image *image,const double radius, % % The format of the ColorizeImage method is: % -% Image *ColorizeImage(const Image *image,const char *opacity, -% const PixelPacket colorize,ExceptionInfo *exception) +% Image *ColorizeImage(const Image *image,const char *blend, +% const PixelInfo *colorize,ExceptionInfo *exception) % % A description of each parameter follows: % % o image: the image. % -% o opacity: A character string indicating the level of opacity as a +% o blend: A character string indicating the level of blending as a % percentage. % % o colorize: A color value. @@ -689,8 +689,8 @@ MagickExport Image *CharcoalImage(const Image *image,const double radius, % o exception: return any errors or warnings in this structure. % */ -MagickExport Image *ColorizeImage(const Image *image,const char *opacity, - const PixelPacket colorize,ExceptionInfo *exception) +MagickExport Image *ColorizeImage(const Image *image,const char *blend, + const PixelInfo *colorize,ExceptionInfo *exception) { #define ColorizeImageTag "Colorize/Image" @@ -710,12 +710,12 @@ MagickExport Image *ColorizeImage(const Image *image,const char *opacity, MagickOffsetType progress; - PixelInfo - pixel; - MagickStatusType flags; + PixelInfo + pixel; + ssize_t y; @@ -737,22 +737,31 @@ MagickExport Image *ColorizeImage(const Image *image,const char *opacity, colorize_image=DestroyImage(colorize_image); return((Image *) NULL); } - if (opacity == (const char *) NULL) + if (blend == (const char *) NULL) return(colorize_image); /* Determine RGB values of the pen color. */ - flags=ParseGeometry(opacity,&geometry_info); + flags=ParseGeometry(blend,&geometry_info); + GetPixelInfo(image,&pixel); pixel.red=geometry_info.rho; pixel.green=geometry_info.rho; pixel.blue=geometry_info.rho; - pixel.alpha=(MagickRealType) OpaqueAlpha; + pixel.alpha=100.0; if ((flags & SigmaValue) != 0) pixel.green=geometry_info.sigma; if ((flags & XiValue) != 0) pixel.blue=geometry_info.xi; if ((flags & PsiValue) != 0) pixel.alpha=geometry_info.psi; + if (pixel.colorspace == CMYKColorspace) + { + pixel.black=geometry_info.rho; + if ((flags & PsiValue) != 0) + pixel.black=geometry_info.psi; + if ((flags & ChiValue) != 0) + pixel.alpha=geometry_info.chi; + } /* Colorize DirectClass image. */ @@ -789,14 +798,68 @@ MagickExport Image *ColorizeImage(const Image *image,const char *opacity, } for (x=0; x < (ssize_t) image->columns; x++) { - SetPixelRed(colorize_image,ClampToQuantum((GetPixelRed(image,p)* - (100.0-pixel.red)+colorize.red*pixel.red)/100.0),q); - SetPixelGreen(colorize_image,ClampToQuantum((GetPixelGreen(image,p)* - (100.0-pixel.green)+colorize.green*pixel.green)/100.0),q); - SetPixelBlue(colorize_image,ClampToQuantum((GetPixelBlue(image,p)* - (100.0-pixel.blue)+colorize.blue*pixel.blue)/100.0),q); - SetPixelAlpha(colorize_image,ClampToQuantum((GetPixelAlpha(image,p)* - (100.0-pixel.alpha)+colorize.alpha*pixel.alpha)/100.0),q); + register ssize_t + i; + + for (i=0; i < (ssize_t) GetPixelChannels(image); i++) + { + PixelChannel + channel; + + PixelTrait + colorize_traits, + traits; + + traits=GetPixelChannelMapTraits(image,(PixelChannel) i); + channel=GetPixelChannelMapChannel(image,(PixelChannel) i); + colorize_traits=GetPixelChannelMapTraits(colorize_image,channel); + if ((traits == UndefinedPixelTrait) || + (colorize_traits == UndefinedPixelTrait)) + continue; + if ((colorize_traits & CopyPixelTrait) != 0) + { + SetPixelChannel(colorize_image,channel,p[i],q); + continue; + } + switch (channel) + { + case RedPixelChannel: + { + SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]* + (100.0-pixel.red)+colorize->red*pixel.red)/100.0),q); + break; + } + case GreenPixelChannel: + { + SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]* + (100.0-pixel.green)+colorize->green*pixel.green)/100.0),q); + break; + } + case BluePixelChannel: + { + SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]* + (100.0-pixel.blue)+colorize->blue*pixel.blue)/100.0),q); + break; + } + case BlackPixelChannel: + { + SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]* + (100.0-pixel.black)+colorize->black*pixel.black)/100.0),q); + break; + } + case AlphaPixelChannel: + { + SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]* + (100.0-pixel.alpha)+colorize->alpha*pixel.alpha)/100.0),q); + break; + } + default: + { + SetPixelChannel(colorize_image,channel,p[i],q); + break; + } + } + } p+=GetPixelChannels(image); q+=GetPixelChannels(colorize_image); } diff --git a/MagickCore/fx.h b/MagickCore/fx.h index e3fb10832..c36bd8fa9 100644 --- a/MagickCore/fx.h +++ b/MagickCore/fx.h @@ -41,7 +41,7 @@ extern MagickExport Image *BlueShiftImage(const Image *,const double,ExceptionInfo *), *CharcoalImage(const Image *,const double,const double,const double, ExceptionInfo *), - *ColorizeImage(const Image *,const char *,const PixelPacket,ExceptionInfo *), + *ColorizeImage(const Image *,const char *,const PixelInfo *,ExceptionInfo *), *ColorMatrixImage(const Image *,const KernelInfo *kernel,ExceptionInfo *), *FxImage(const Image *,const char *,ExceptionInfo *), *ImplodeImage(const Image *,const double,const PixelInterpolateMethod, diff --git a/MagickCore/magick-config.h b/MagickCore/magick-config.h index 6fe106710..88c4ce443 100644 --- a/MagickCore/magick-config.h +++ b/MagickCore/magick-config.h @@ -435,15 +435,15 @@ #endif /* Define if you have the header file. */ -/* #undef HAVE_LCMS2_H */ +#ifndef MAGICKCORE_HAVE_LCMS2_H +#define MAGICKCORE_HAVE_LCMS2_H 1 +#endif /* Define if you have the header file. */ /* #undef HAVE_LCMS2_LCMS2_H */ /* Define if you have the header file. */ -#ifndef MAGICKCORE_HAVE_LCMS_H -#define MAGICKCORE_HAVE_LCMS_H 1 -#endif +/* #undef HAVE_LCMS_H */ /* Define if you have the header file. */ /* #undef HAVE_LCMS_LCMS_H */ @@ -1166,9 +1166,7 @@ #endif /* Define if you have JBIG library */ -#ifndef MAGICKCORE_JBIG_DELEGATE -#define MAGICKCORE_JBIG_DELEGATE 1 -#endif +/* #undef JBIG_DELEGATE */ /* Define if you have JPEG version 2 "Jasper" library */ #ifndef MAGICKCORE_JP2_DELEGATE @@ -1197,9 +1195,7 @@ #endif /* Define if you have LQR library */ -#ifndef MAGICKCORE_LQR_DELEGATE -#define MAGICKCORE_LQR_DELEGATE 1 -#endif +/* #undef LQR_DELEGATE */ /* Define if using libltdl to support dynamically loadable modules */ #ifndef MAGICKCORE_LTDL_DELEGATE @@ -1211,7 +1207,7 @@ /* Define to the system default library search path. */ #ifndef MAGICKCORE_LT_DLSEARCH_PATH -#define MAGICKCORE_LT_DLSEARCH_PATH "/lib64:/usr/lib64:/lib:/usr/lib:/usr/lib64/R/lib:/usr/lib64/atlas:/opt/modules/pkg/intel/f77/10.0.025/lib:/opt/intel/lib/intel64:/usr/lib64/llvm:/usr/local/lib:/usr/lib64/mysql:/usr/lib64/nvidia:/usr/lib64/qt-3.3/lib:/usr/lib64/xulrunner-2" +#define MAGICKCORE_LT_DLSEARCH_PATH "/lib64:/usr/lib64:/lib:/usr/lib:/usr/lib64/R/lib:/usr/lib64/alliance/lib:/usr/lib64/atlas:/opt/modules/pkg/intel/f77/10.0.025/lib:/usr/lib64/kicad:/usr/lib/llvm:/usr/lib64/llvm:/usr/local/lib:/usr/lib64/mpich2/lib/:/usr/lib64/mysql:/usr/lib64/nvidia:/usr/lib64/octave/3.4.2:/usr/lib64/openmotif:/usr/lib64/qt-3.3/lib:/usr/lib64/tcl8.5/tclx8.4:/usr/lib/wine/:/usr/lib64/wine/:/usr/lib64/xulrunner-2" #endif /* The archive extension */ @@ -1458,9 +1454,7 @@ /* Define if you have WEBP library */ -#ifndef MAGICKCORE_WEBP_DELEGATE -#define MAGICKCORE_WEBP_DELEGATE 1 -#endif +/* #undef WEBP_DELEGATE */ /* Define to use the Windows GDI32 library */ /* #undef WINGDI32_DELEGATE */ diff --git a/MagickCore/version.h b/MagickCore/version.h index fbaf35522..0e70512a2 100644 --- a/MagickCore/version.h +++ b/MagickCore/version.h @@ -34,7 +34,7 @@ extern "C" { #define MagickLibAddendum "-0" #define MagickLibInterface 7 #define MagickLibMinInterface 7 -#define MagickReleaseDate "2011-10-02" +#define MagickReleaseDate "2011-10-03" #define MagickChangeDate "20110801" #define MagickAuthoritativeURL "http://www.imagemagick.org" #if defined(MAGICKCORE_OPENMP_SUPPORT) diff --git a/MagickWand/magick-image.c b/MagickWand/magick-image.c index afdc4df5e..9cfdd0b47 100644 --- a/MagickWand/magick-image.c +++ b/MagickWand/magick-image.c @@ -1434,7 +1434,7 @@ WandExport MagickBooleanType MagickColorDecisionListImage(MagickWand *wand, % The format of the MagickColorizeImage method is: % % MagickBooleanType MagickColorizeImage(MagickWand *wand, -% const PixelWand *colorize,const PixelWand *alpha) +% const PixelWand *colorize,const PixelWand *blend) % % A description of each parameter follows: % @@ -1446,31 +1446,49 @@ WandExport MagickBooleanType MagickColorDecisionListImage(MagickWand *wand, % */ WandExport MagickBooleanType MagickColorizeImage(MagickWand *wand, - const PixelWand *colorize,const PixelWand *alpha) + const PixelWand *colorize,const PixelWand *blend) { char - percent_opaque[MaxTextExtent]; + percent_blend[MaxTextExtent]; Image *colorize_image; - PixelPacket + PixelInfo target; + Quantum + virtual_pixel[MaxPixelChannels]; + assert(wand != (MagickWand *) NULL); assert(wand->signature == WandSignature); if (wand->debug != MagickFalse) (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name); if (wand->images == (Image *) NULL) ThrowWandException(WandError,"ContainsNoImages",wand->name); - (void) FormatLocaleString(percent_opaque,MaxTextExtent, - "%g,%g,%g,%g",(double) (100.0*QuantumScale* - PixelGetRedQuantum(alpha)),(double) (100.0*QuantumScale* - PixelGetGreenQuantum(alpha)),(double) (100.0*QuantumScale* - PixelGetBlueQuantum(alpha)),(double) (100.0*QuantumScale* - PixelGetAlphaQuantum(alpha))); - PixelGetQuantumPacket(colorize,&target); - colorize_image=ColorizeImage(wand->images,percent_opaque,target, + if (target.colorspace != CMYKColorspace) + (void) FormatLocaleString(percent_blend,MaxTextExtent, + "%g,%g,%g,%g",(double) (100.0*QuantumScale* + PixelGetRedQuantum(blend)),(double) (100.0*QuantumScale* + PixelGetGreenQuantum(blend)),(double) (100.0*QuantumScale* + PixelGetBlueQuantum(blend)),(double) (100.0*QuantumScale* + PixelGetAlphaQuantum(blend))); + else + (void) FormatLocaleString(percent_blend,MaxTextExtent, + "%g,%g,%g,%g,%g",(double) (100.0*QuantumScale* + PixelGetRedQuantum(blend)),(double) (100.0*QuantumScale* + PixelGetGreenQuantum(blend)),(double) (100.0*QuantumScale* + PixelGetBlueQuantum(blend)),(double) (100.0*QuantumScale* + PixelGetBlackQuantum(blend)),(double) (100.0*QuantumScale* + PixelGetAlphaQuantum(blend))); + PixelGetQuantumPixel(wand->images,colorize,virtual_pixel); + GetPixelInfo(wand->images,&target); + target.red=virtual_pixel[RedPixelChannel]; + target.green=virtual_pixel[GreenPixelChannel]; + target.blue=virtual_pixel[BluePixelChannel]; + target.black=virtual_pixel[BlackPixelChannel]; + target.alpha=virtual_pixel[AlphaPixelChannel]; + colorize_image=ColorizeImage(wand->images,percent_blend,&target, wand->exception); if (colorize_image == (Image *) NULL) return(MagickFalse); diff --git a/MagickWand/mogrify.c b/MagickWand/mogrify.c index e23d793c6..abd601459 100644 --- a/MagickWand/mogrify.c +++ b/MagickWand/mogrify.c @@ -1124,8 +1124,7 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc, Colorize the image. */ (void) SyncImageSettings(mogrify_info,*image); - mogrify_image=ColorizeImage(*image,argv[i+1],draw_info->fill, - exception); + mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception); break; } if (LocaleCompare("color-matrix",option+1) == 0) diff --git a/PerlMagick/Magick.xs b/PerlMagick/Magick.xs index c78cb3537..91b0400d1 100644 --- a/PerlMagick/Magick.xs +++ b/PerlMagick/Magick.xs @@ -208,7 +208,7 @@ static struct { "Label", { {"label", StringReference} } }, { "AddNoise", { {"noise", MagickNoiseOptions}, {"channel", MagickChannelOptions} } }, - { "Colorize", { {"fill", StringReference}, {"opacity", StringReference} } }, + { "Colorize", { {"fill", StringReference}, {"blend", StringReference} } }, { "Border", { {"geometry", StringReference}, {"width", IntegerReference}, {"height", IntegerReference}, {"fill", StringReference}, {"bordercolor", StringReference}, {"color", StringReference}, @@ -7509,12 +7509,13 @@ Mogrify(ref,...) } case 4: /* Colorize */ { - PixelPacket + PixelInfo target; Quantum virtual_pixel[MaxPixelChannels]; + GetPixelInfo(image,&target); (void) GetOneVirtualPixel(image,0,0,virtual_pixel,exception); target.red=virtual_pixel[RedPixelChannel]; target.green=virtual_pixel[GreenPixelChannel]; @@ -7525,7 +7526,7 @@ Mogrify(ref,...) AllCompliance,&target,exception); if (attribute_flag[1] == 0) argument_list[1].string_reference="100%"; - image=ColorizeImage(image,argument_list[1].string_reference,target, + image=ColorizeImage(image,argument_list[1].string_reference,&target, exception); break; } diff --git a/coders/msl.c b/coders/msl.c index 6c43ab917..6fea30ea0 100644 --- a/coders/msl.c +++ b/coders/msl.c @@ -1367,12 +1367,12 @@ static void MSLStartElement(void *context,const xmlChar *tag, if (LocaleCompare((const char *) tag,"colorize") == 0) { char - opacity[MaxTextExtent]; + blend[MaxTextExtent]; Image *colorize_image; - PixelPacket + PixelInfo target; /* @@ -1384,8 +1384,8 @@ static void MSLStartElement(void *context,const xmlChar *tag, (const char *) tag); break; } - target=msl_info->image[n]->background_color; - (void) CopyMagickString(opacity,"100",MaxTextExtent); + GetPixelInfo(msl_info->image[n],&target); + (void) CopyMagickString(blend,"100",MaxTextExtent); if (attributes != (const xmlChar **) NULL) for (i=0; (attributes[i] != (const xmlChar *) NULL); i++) { @@ -1396,25 +1396,25 @@ static void MSLStartElement(void *context,const xmlChar *tag, CloneString(&value,attribute); switch (*keyword) { - case 'F': - case 'f': + case 'B': + case 'b': { - if (LocaleCompare(keyword,"fill") == 0) + if (LocaleCompare(keyword,"blend") == 0) { - (void) QueryColorCompliance(value,AllCompliance,&target, - &msl_info->image[n]->exception); + (void) CopyMagickString(blend,value,MaxTextExtent); break; } ThrowMSLException(OptionError,"UnrecognizedAttribute", keyword); break; } - case 'O': - case 'o': + case 'F': + case 'f': { - if (LocaleCompare(keyword,"opacity") == 0) + if (LocaleCompare(keyword,"fill") == 0) { - (void) CopyMagickString(opacity,value,MaxTextExtent); + (void) QueryMagickColorCompliance(value,AllCompliance, + &target,&msl_info->image[n]->exception); break; } ThrowMSLException(OptionError,"UnrecognizedAttribute", @@ -1429,7 +1429,7 @@ static void MSLStartElement(void *context,const xmlChar *tag, } } } - colorize_image=ColorizeImage(msl_info->image[n],opacity,target, + colorize_image=ColorizeImage(msl_info->image[n],blend,&target, &msl_info->image[n]->exception); if (colorize_image == (Image *) NULL) break; -- 2.40.0