Color Modes

MagickCore, C API: Add a Special Effect

Fx



pfx->exception, GetMagickModule

pfx->exception, GetMagickModule(), OptionError, "ImgNum", "lu bad for ImgListLen lu", (unsigned long) i, (unsigned long) pfx->ImgListLen); i = -1; } return i; }

#define WHICH_ATTR_CHAN \ (pel->channel_qual == NO_CHAN_QUAL) ? CompositePixelChannel : \ (pel->channel_qual == THIS_CHANNEL) ? channel : pel->channel_qual

#define WHICH_NON_ATTR_CHAN \ (pel->channel_qual == NO_CHAN_QUAL || \ pel->channel_qual == THIS_CHANNEL || \ pel->channel_qual == CompositePixelChannel \ ) ? (channel == CompositePixelChannel ? RedPixelChannel: channel) \ : pel->channel_qual

static fxFltType GetHslFlt (FxInfo * pfx, ssize_t ImgNum, const fxFltType fx, const fxFltType fy, PixelChannel channel) { Image * img = pfx->Images[ImgNum];

double red, green, blue; double hue=0, saturation=0, lightness=0;

MagickBooleanType okay = MagickTrue; if(!InterpolatePixelChannel (img, pfx->Imgs[ImgNum].View, RedPixelChannel, img->interpolate, (double) fx, (double) fy, &red, pfx->exception)) okay = MagickFalse; if(!InterpolatePixelChannel (img, pfx->Imgs[ImgNum].View, GreenPixelChannel, img->interpolate, (double) fx, (double) fy, &green, pfx->exception)) okay = MagickFalse; if(!InterpolatePixelChannel (img, pfx->Imgs[ImgNum].View, BluePixelChannel, img->interpolate, (double) fx, (double) fy, &blue, pfx->exception)) okay = MagickFalse;

if (!okay) (void) ThrowMagickException ( pfx->exception, GetMagickModule(), OptionError, "GetHslFlt failure", "lu g,g i", (unsigned long) ImgNum, (double) fx, (double) fy, channel);

ConvertRGBToHSL ( red, green, blue, &hue, &saturation, &lightness);

if (channel == HUE_CHANNEL) return hue; if (channel == SAT_CHANNEL) return saturation; if (channel == LIGHT_CHANNEL) return lightness;

return 0.0; }

static fxFltType GetHslInt (FxInfo * pfx, ssize_t ImgNum, const ssize_t imgx, const ssize_t imgy, PixelChannel channel) { Image * img = pfx->Images[ImgNum];

double hue=0, saturation=0, lightness=0;

const Quantum * p = GetCacheViewVirtualPixels (pfx->Imgs[ImgNum].View, imgx, imgy, 1, 1, pfx->exception); if (p == (const Quantum *) NULL) { (void) ThrowMagickException (pfx->exception,GetMagickModule(), OptionError,"GetHslInt failure","lu li,li i",(unsigned long) ImgNum, (long) imgx,(long) imgy,channel); return(0.0); }

ConvertRGBToHSL ( GetPixelRed (img, p), GetPixelGreen (img, p), GetPixelBlue (img, p), &hue, &saturation, &lightness);

if (channel == HUE_CHANNEL) return hue; if (channel == SAT_CHANNEL) return saturation; if (channel == LIGHT_CHANNEL) return lightness;

return 0.0; }

static inline fxFltType GetIntensity (FxInfo * pfx, ssize_t ImgNum, const fxFltType fx, const fxFltType fy) { Quantum quantum_pixel[MaxPixelChannels];

PixelInfo pixelinf;

Image * img = pfx->Images[ImgNum];

(void) GetPixelInfo (img, &pixelinf);

if (!InterpolatePixelInfo (img, pfx->Imgs[pfx->ImgNum].View, img->interpolate, (double) fx, (double) fy, &pixelinf, pfx->exception)) { (void) ThrowMagickException ( pfx->exception, GetMagickModule(), OptionError, "GetIntensity failure", "lu g,g", (unsigned long) ImgNum, (double) fx, (double) fy); }

SetPixelViaPixelInfo (img, &pixelinf, quantum_pixel); return QuantumScale * GetPixelIntensity (img, quantum_pixel); }

static MagickBooleanType ExecuteRPN (FxInfo * pfx, fxRtT * pfxrt, fxFltType *result, const PixelChannel channel, const ssize_t imgx, const ssize_t imgy) { const Quantum * p = pfxrt->thisPixel; fxFltType regA=0, regB=0, regC=0, regD=0, regE=0; Image * img = pfx->image; ChannelStatistics * cs = NULL; MagickBooleanType NeedRelinq = MagickFalse; double hue=0, saturation=0, lightness=0; int i;

/* For -fx, this sets p to ImgNum 0. for [fx:...], this sets p to the current image. Similarly img.