]> granicus.if.org Git - imagemagick/commitdiff
Exclude "Plus" from using 'over' alpha-blending as per SVG definition
authoranthony <anthony@git.imagemagick.org>
Wed, 5 May 2010 06:16:16 +0000 (06:16 +0000)
committeranthony <anthony@git.imagemagick.org>
Wed, 5 May 2010 06:16:16 +0000 (06:16 +0000)
ChangeLog
magick/composite-private.h
magick/composite.c

index aaf409f6e3ca17baa2e56932a14094e70346c55c..bdf8b44c792e296fdeb5d61f96f3d649c756c314 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,12 +2,22 @@
   * Rename of "Add" and "Subtract" compositions to "ModulusAdd" and
     "ModulusSubtract" for more clarity of there functions. Old names
     will continue to work as expected.
-  * Fix "Plus", "Minus", "ModulusAdd", and "ModulusSubtract" to follow
+  * Fix "Minus", "ModulusAdd", and "ModulusSubtract" to follow
     normal SVG 'Over' blending specifications, (see next for override)
-  * Allow the "-channel sync" flag to allow mathematical compositions to work
-    for SVG specified handling, or if turned off, to perform image mathematics
-    on specific individual channels.  You can now use math compose methods
-    with the alpha channels of images, or with just one channel of an image.
+    Note that this does NOT include the "Plus" composition method which has
+    SVG defintion for it to use a 'Plus' blending rather than 'Over' blending.
+
+  * By default mathematical compositions work as per SVG definition. That is
+    the results are syncronized with 'Over' alpha-blending (except "Plus"
+    which uses 'plus' alpha-blending).
+
+    By removing the default 'sync' flag from the -channel setting however
+    Break this inter-channel syncronization and do the mathematical operations
+    only on the individual channels as specified by the -channel setting.
+    That is do 'channel' math rather than 'SVG' composition.
+
+    With this change you can then use mathematical composition methods on
+    individual channels or even with the alpha channel of images.
 
 2010-04-28  6.6.1-6 Anthony Thyssen <A.Thyssen@griffith...>
   * Special case handling in Barrel distortion (pixel at image center)
index 29e2ecf1c6c329538d7432e2878d9c526dd03ef9..9b8b455f1fc6446ceecb65fc7b6ac752238f83c7 100644 (file)
@@ -105,15 +105,14 @@ static inline void MagickPixelCompositeOver(const MagickPixelPacket *p,
     composite->index=gamma*MagickOver_(p->index,alpha,q->index,beta);
 }
 
-#if 0
 static inline void MagickPixelCompositePlus(const MagickPixelPacket *p,
   const MagickRealType alpha,const MagickPixelPacket *q,
   const MagickRealType beta,MagickPixelPacket *composite)
 {
   MagickRealType
-    Sa,
     Da,
-    gamma;
+    gamma,
+    Sa;
 
   /*
     Add two pixels with the given opacities.
@@ -129,7 +128,6 @@ static inline void MagickPixelCompositePlus(const MagickPixelPacket *p,
   if (q->colorspace == CMYKColorspace)
     composite->index=gamma*(Sa*p->index+Da*q->index);
 }
-#endif
 
 /*
   Blend pixel colors p and q by the amount given.
@@ -138,27 +136,9 @@ static inline void MagickPixelCompositeBlend(const MagickPixelPacket *p,
   const MagickRealType alpha,const MagickPixelPacket *q,
   const MagickRealType beta,MagickPixelPacket *composite)
 {
-#if 0
   MagickPixelCompositePlus(p,(MagickRealType) (QuantumRange-alpha*
     (QuantumRange-p->opacity)),q,(MagickRealType) (QuantumRange-beta*
     GetAlphaPixelComponent(q)),composite);
-#else
-  MagickRealType
-    Sa,
-    Da,
-    gamma;
-
-  Sa=alpha*(1.0-QuantumScale*p->opacity);
-  Da=beta*(1.0-QuantumScale*q->opacity);
-  gamma=RoundToUnity(Sa+Da);  /* 'Plus' blending -- not 'Over' blending */
-  composite->opacity=(MagickRealType) QuantumRange*(1.0-gamma);
-  gamma=1.0/(fabs(gamma) <= MagickEpsilon ? 1.0 : 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);
-#endif
 }
 
 /*
@@ -169,28 +149,9 @@ static inline void MagickPixelCompositeAreaBlend(const MagickPixelPacket *p,
   const MagickRealType beta,const MagickRealType area,
   MagickPixelPacket *composite)
 {
-#if 0
   MagickPixelCompositePlus(p,(MagickRealType) QuantumRange-(1.0-area)*
     (QuantumRange-alpha),q,(MagickRealType) (QuantumRange-area*(QuantumRange-
     beta)),composite);
-#else
-  MagickRealType
-    Sa,
-    Da,
-    gamma;
-
-  Sa=(1.0-area)*(1.0-QuantumScale*alpha);
-  Da=area*(1.0-QuantumScale*beta);
-  gamma=RoundToUnity(Sa+Da);  /* 'Plus' blending -- not 'Over' blending */
-  composite->opacity=(MagickRealType) QuantumRange*(1.0-gamma);
-  gamma=1.0/(fabs(gamma) <= MagickEpsilon ? 1.0 : 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);
-#endif
-
 }
 
 #if defined(__cplusplus) || defined(c_plusplus)
index e328f574d9540a77b7a5d57beb2c9a40369fc140..0200d324aebe162f9e4eea78ae3f915ebba057e7 100644 (file)
@@ -891,27 +891,22 @@ static inline void CompositePlus(const MagickPixelPacket *p,
   MagickPixelPacket *composite)
 {
   if ( (channel & SyncChannels) != 0 ) {
-#if 0
-    MagickRealType
-      Sa,
-      Da,
-      gamma;
+    /*
+      NOTE: "Plus" does not use 'over' alpha-blending but uses a
+      special 'plus' form of alph-blending. It is the ONLY mathematical
+      operator to do this. this is what makes it different to the
+      otherwise equivelent "LinearDodge" composition method.
 
-    Sa=1.0-QuantumScale*p->opacity;  /* simplify and speed up equations */
-    Da=1.0-QuantumScale*q->opacity;
-    /* gamma=RoundToUnity(Sa+Da);  ** is this correct?  - I do not think so! */
-    gamma=RoundToUnity(Sa+Da-Sa*Da); /* over blend, as per SVG doc */
-    composite->opacity=(MagickRealType) QuantumRange*(1.0-gamma);
-    gamma=1.0/(fabs(gamma) <= MagickEpsilon ? 1.0 : gamma);
-    composite->red=gamma*(p->red*Sa+q->red*Da);
-    composite->green=gamma*(p->green*Sa+q->green*Da);
-    composite->blue=gamma*(p->blue*Sa+q->blue*Da);
-    if (q->colorspace == CMYKColorspace)
-      composite->index=gamma*(p->index*Sa+q->index*Da);
-#else
-    /* Actually this is just LinearDodge! */
-    CompositeLinearDodge(p,q,composite);
-#endif
+      Note however that color channels are still effected by the alpha channel
+      as a result of the blending, making it just as useless for independant
+      channel maths, just like all other mathematical composition methods.
+
+      As such the removal of the 'sync' flag, is still a usful convention.
+
+      The MagickPixelCompositePlus() function is defined in
+      "composite-private.h" so it can also be used for Image Blending.
+    */
+    MagickPixelCompositePlus(p,p->opacity,q,q->opacity,composite);
   }
   else { /* handle channels as separate grayscale channels */
     if ( (channel | AlphaChannel) != 0 )