[gimp/goat-invasion] app: fix GimpOperationReplaceMode to not do two things different than legacy



commit e02a119a28ff6f5f2e8d214b22464efaf85565ff
Author: Michael Natterer <mitch gimp org>
Date:   Tue May 1 04:11:16 2012 +0200

    app: fix GimpOperationReplaceMode to not do two things different than legacy

 app/gegl/gimpoperationreplacemode.c |   45 ++++++++++++++++++++--------------
 1 files changed, 26 insertions(+), 19 deletions(-)
---
diff --git a/app/gegl/gimpoperationreplacemode.c b/app/gegl/gimpoperationreplacemode.c
index caeb7cb..1ab480d 100644
--- a/app/gegl/gimpoperationreplacemode.c
+++ b/app/gegl/gimpoperationreplacemode.c
@@ -174,39 +174,46 @@ gimp_operation_replace_mode_process (GeglOperation       *operation,
   gfloat *mask                   = aux2_buf;
   gfloat *out                    = out_buf;
 
-
   while (samples--)
     {
       gint   b;
       gfloat new_alpha;
-      gfloat ratio;
 
       if (mask)
-        {
-          new_alpha = (layer[ALPHA] - in[ALPHA]) * (*mask) * opacity + in[ALPHA];
-          ratio = *mask * opacity / layer[ALPHA] / new_alpha;
-        }
+        new_alpha = (layer[ALPHA] - in[ALPHA]) * (*mask) * opacity + in[ALPHA];
       else
-        {
-          new_alpha = (layer[ALPHA] - in[ALPHA]) * opacity + in[ALPHA];
-          ratio = opacity / layer[ALPHA] / new_alpha;
-        }
+        new_alpha = (layer[ALPHA] - in[ALPHA]) * opacity + in[ALPHA];
 
-      for (b = RED; b < ALPHA; b++)
+      if (new_alpha)
         {
-          gfloat t;
+          gfloat ratio;
 
-          if (layer[b] > in[b])
-            {
-              t = (layer[b] - in[b]) * ratio;
-              out[b] = in[b] + t;
-            }
+          if (mask)
+            ratio = *mask * opacity * layer[ALPHA] / new_alpha;
           else
+            ratio = opacity * layer[ALPHA] / new_alpha;
+
+          for (b = RED; b < ALPHA; b++)
             {
-              t = (in[b] - layer[b]) * ratio;
-              out[b] = in[b] - t;
+              gfloat t;
+
+              if (layer[b] > in[b])
+                {
+                  t = (layer[b] - in[b]) * ratio;
+                  out[b] = in[b] + t;
+                }
+              else
+                {
+                  t = (in[b] - layer[b]) * ratio;
+                  out[b] = in[b] - t;
+                }
             }
         }
+      else
+        {
+          for (b = RED; b < ALPHA; b++)
+            out[b] = in[b];
+        }
 
       out[ALPHA] = new_alpha;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]