This source file includes following definitions.
- RoundToUnity
- MagickOver_
- MagickCompositeOver
- MagickPixelCompositeOver
- MagickPixelCompositePlus
- MagickPixelCompositeBlend
- MagickPixelCompositeAreaBlend
#ifndef _MAGICKCORE_COMPOSITE_PRIVATE_H
#define _MAGICKCORE_COMPOSITE_PRIVATE_H
#include "magick/color.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/pixel-private.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
static inline MagickRealType RoundToUnity(const MagickRealType value)
{
return(value < 0.0 ? 0.0 : (value > 1.0) ? 1.0 : value);
}
static inline MagickRealType MagickOver_(const MagickRealType p,
const MagickRealType alpha,const MagickRealType q,const MagickRealType beta)
{
MagickRealType
Da,
Sa;
Sa=1.0-QuantumScale*alpha;
Da=1.0-QuantumScale*beta;
return(Sa*p+Da*q*(1.0-Sa));
}
static inline void MagickCompositeOver(const PixelPacket *p,
const MagickRealType alpha,const PixelPacket *q,const MagickRealType beta,
PixelPacket *composite)
{
MagickRealType
Da,
gamma,
Sa;
Sa=1.0-QuantumScale*alpha;
Da=1.0-QuantumScale*beta;
gamma=Sa+Da-Sa*Da;
#if !defined(MAGICKCORE_HDRI_SUPPORT)
SetPixelOpacity(composite,ClampToQuantum(QuantumRange*(1.0-
RoundToUnity(gamma))));
gamma=PerceptibleReciprocal(gamma);
SetPixelRed(composite,ClampToQuantum(gamma*MagickOver_((MagickRealType)
GetPixelRed(p),alpha,(MagickRealType) GetPixelRed(q),beta)));
SetPixelGreen(composite,ClampToQuantum(gamma*MagickOver_((MagickRealType)
GetPixelGreen(p),alpha,(MagickRealType) GetPixelGreen(q),beta)));
SetPixelBlue(composite,ClampToQuantum(gamma*MagickOver_((MagickRealType)
GetPixelBlue(p),alpha,(MagickRealType) GetPixelBlue(q),beta)));
#else
SetPixelOpacity(composite,QuantumRange*(1.0-RoundToUnity(gamma)));
gamma=PerceptibleReciprocal(gamma);
SetPixelRed(composite,gamma*MagickOver_((MagickRealType)
GetPixelRed(p),alpha,(MagickRealType) GetPixelRed(q),beta));
SetPixelGreen(composite,gamma*MagickOver_((MagickRealType)
GetPixelGreen(p),alpha,(MagickRealType) GetPixelGreen(q),beta));
SetPixelBlue(composite,gamma*MagickOver_((MagickRealType)
GetPixelBlue(p),alpha,(MagickRealType) GetPixelBlue(q),beta));
#endif
}
static inline void MagickPixelCompositeOver(const MagickPixelPacket *p,
const MagickRealType alpha,const MagickPixelPacket *q,
const MagickRealType beta,MagickPixelPacket *composite)
{
MagickRealType
Da,
gamma,
Sa;
Sa=1.0-QuantumScale*alpha;
Da=1.0-QuantumScale*beta;
gamma=Sa+Da-Sa*Da;
composite->opacity=(MagickRealType) (QuantumRange*(1.0-RoundToUnity(gamma)));
gamma=PerceptibleReciprocal(gamma);
composite->red=gamma*MagickOver_(p->red,alpha,q->red,beta);
composite->green=gamma*MagickOver_(p->green,alpha,q->green,beta);
composite->blue=gamma*MagickOver_(p->blue,alpha,q->blue,beta);
if (q->colorspace == CMYKColorspace)
composite->index=gamma*MagickOver_(p->index,alpha,q->index,beta);
}
static inline void MagickPixelCompositePlus(const MagickPixelPacket *p,
const MagickRealType alpha,const MagickPixelPacket *q,
const MagickRealType beta,MagickPixelPacket *composite)
{
MagickRealType
Da,
gamma,
Sa;
Sa=1.0-QuantumScale*alpha;
Da=1.0-QuantumScale*beta;
gamma=RoundToUnity(Sa+Da);
composite->opacity=(MagickRealType) QuantumRange*(1.0-RoundToUnity(gamma));
gamma=PerceptibleReciprocal(gamma);
composite->red=gamma*(Sa*p->red+Da*q->red);
composite->green=gamma*(Sa*p->green+Da*q->green);
composite->blue=gamma*(Sa*p->blue+Da*q->blue);
if (q->colorspace == CMYKColorspace)
composite->index=gamma*(Sa*p->index+Da*q->index);
}
static inline void MagickPixelCompositeBlend(const MagickPixelPacket *p,
const MagickRealType alpha,const MagickPixelPacket *q,
const MagickRealType beta,MagickPixelPacket *composite)
{
MagickPixelCompositePlus(p,(MagickRealType) (QuantumRange-alpha*
(QuantumRange-p->opacity)),q,(MagickRealType) (QuantumRange-beta*
(QuantumRange-q->opacity)),composite);
}
static inline void MagickPixelCompositeAreaBlend(const MagickPixelPacket *p,
const MagickRealType alpha,const MagickPixelPacket *q,
const MagickRealType beta,const MagickRealType area,
MagickPixelPacket *composite)
{
MagickPixelCompositePlus(p,(MagickRealType) QuantumRange-(1.0-area)*
(QuantumRange-alpha),q,(MagickRealType) (QuantumRange-area*(QuantumRange-
beta)),composite);
}
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
#endif