]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/composite-private.h
Update web pages
[imagemagick] / MagickCore / composite-private.h
index 37ae0bd947a61dedaa65518c3b9c58a528c8683e..d963a7f7c01e76d9358dc62f43563cddd7e0dd00 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization
+  Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization
   dedicated to making software imaging solutions freely available.
 
   You may not use this file except in compliance with the License.
 #ifndef _MAGICKCORE_COMPOSITE_PRIVATE_H
 #define _MAGICKCORE_COMPOSITE_PRIVATE_H
 
-#if defined(__cplusplus) || defined(c_plusplus)
-extern "C" {
-#endif
-
-/*
-  ImageMagick Alpha Composite Inline Methods (special export)
-*/
 
 #include "MagickCore/color.h"
 #include "MagickCore/image.h"
@@ -32,8 +25,15 @@ extern "C" {
 #include "MagickCore/pixel-accessor.h"
 #include "MagickCore/pixel-private.h"
 
-static inline double MagickOver_(const double p,
-  const double alpha,const double q,const double beta)
+#if defined(__cplusplus) || defined(c_plusplus)
+extern "C" {
+#endif
+
+/*
+  ImageMagick Alpha Composite Inline Methods (special export)
+*/
+static inline double MagickOver_(const double p,const double alpha,
+  const double q,const double beta)
 {
   double
     Da,
@@ -41,7 +41,12 @@ static inline double MagickOver_(const double p,
 
   Sa=QuantumScale*alpha;
   Da=QuantumScale*beta;
-  return(Sa*p-Sa*Da*q+Da*q);
+  return(Sa*p+Da*q*(1.0-Sa));
+}
+
+static inline double RoundToUnity(const double value)
+{
+  return(value < 0.0 ? 0.0 : (value > 1.0) ? 1.0 : value);
 }
 
 static inline void CompositePixelOver(const Image *image,const PixelInfo *p,
@@ -59,8 +64,8 @@ static inline void CompositePixelOver(const Image *image,const PixelInfo *p,
     Compose pixel p over pixel q with the given alpha.
   */
   Sa=QuantumScale*alpha;
-  Da=QuantumScale*beta,
-  gamma=Sa*(-Da)+Sa+Da;
+  Da=QuantumScale*beta;
+  gamma=Sa+Da-Sa*Da;
   gamma=PerceptibleReciprocal(gamma);
   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
   {
@@ -74,11 +79,6 @@ static inline void CompositePixelOver(const Image *image,const PixelInfo *p,
     traits=GetPixelChannelTraits(image,channel);
     if (traits == UndefinedPixelTrait)
       continue;
-    if (fabs(alpha-TransparentAlpha) < MagickEpsilon)
-      {
-        composite[i]=q[i];
-        continue;
-      }
     switch (channel)
     {
       case RedPixelChannel:
@@ -107,7 +107,7 @@ static inline void CompositePixelOver(const Image *image,const PixelInfo *p,
       }
       case AlphaPixelChannel:
       {
-        composite[i]=ClampToQuantum(QuantumRange*(Sa*(-Da)+Sa+Da));
+        composite[i]=ClampToQuantum(QuantumRange*RoundToUnity(Sa+Da-Sa*Da));
         break;
       }
       default:
@@ -130,15 +130,10 @@ static inline void CompositePixelInfoOver(const PixelInfo *p,
   /*
     Compose pixel p over pixel q with the given opacities.
   */
-  if (fabs(alpha-TransparentAlpha) < MagickEpsilon)
-    {
-      *composite=(*p);
-      return;
-    }
   Sa=QuantumScale*alpha;
   Da=QuantumScale*beta,
-  gamma=Sa*(-Da)+Sa+Da;
-  composite->alpha=(double) QuantumRange*gamma;
+  gamma=Sa+Da-Sa*Da;
+  composite->alpha=(double) QuantumRange*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);
@@ -147,11 +142,6 @@ static inline void CompositePixelInfoOver(const PixelInfo *p,
     composite->black=gamma*MagickOver_(p->black,alpha,q->black,beta);
 }
 
-static inline double RoundToUnity(const double value)
-{
-  return(value < 0.0 ? 0.0 : (value > 1.0) ? 1.0 : value);
-}
-
 static inline void CompositePixelInfoPlus(const PixelInfo *p,
   const double alpha,const PixelInfo *q,const double beta,PixelInfo *composite)
 {
@@ -166,7 +156,7 @@ static inline void CompositePixelInfoPlus(const PixelInfo *p,
   Sa=QuantumScale*alpha;
   Da=QuantumScale*beta;
   gamma=RoundToUnity(Sa+Da);  /* 'Plus' blending -- not 'Over' blending */
-  composite->alpha=(double) QuantumRange*gamma;
+  composite->alpha=(double) QuantumRange*RoundToUnity(gamma);
   gamma=PerceptibleReciprocal(gamma);
   composite->red=gamma*(Sa*p->red+Da*q->red);
   composite->green=gamma*(Sa*p->green+Da*q->green);