[gimp] Bug 766116: Behind mode is not working correctly



commit 3a43478fdadd3fb2285caa3fca94ddc48e6688b6
Author: Massimo Valentini <mvalentini src gnome org>
Date:   Tue May 17 19:56:39 2016 +0200

    Bug 766116: Behind mode is not working correctly
    
    use same var names as gimp-2-8 to make
    it easier to spot unwanted differences

 app/operations/gimpoperationbehindmode.c |   21 ++++++++++++++-------
 1 files changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/app/operations/gimpoperationbehindmode.c b/app/operations/gimpoperationbehindmode.c
index 7a02d6a..719753d 100644
--- a/app/operations/gimpoperationbehindmode.c
+++ b/app/operations/gimpoperationbehindmode.c
@@ -93,29 +93,36 @@ gimp_operation_behind_mode_process_pixels (gfloat              *in,
 
   while (samples--)
     {
-      gfloat value = opacity;
+      gfloat src1_alpha = in[ALPHA];
+      gfloat src2_alpha = layer[ALPHA] * opacity;
+      gfloat new_alpha;
       gint   b;
 
       if (has_mask)
-        value *= *mask;
+        src2_alpha *= *mask;
 
-      out[ALPHA] = in[ALPHA] + (1.0 - in[ALPHA]) * layer[ALPHA] * value;
+      new_alpha = src2_alpha + (1.0 - src2_alpha) * src1_alpha;
 
-      if (out[ALPHA])
+      if (new_alpha)
         {
+          gfloat ratio = in[ALPHA] / new_alpha;
+          gfloat compl_ratio = 1.0f - ratio;
+
           for (b = RED; b < ALPHA; b++)
             {
-              out[b] = (in[b] * in[ALPHA] + layer[b] * value * layer[ALPHA] * value * (1.0 - in[ALPHA])) / 
out[ALPHA];
+              out[b] = in[b] * ratio + layer[b] * compl_ratio;
             }
         }
       else
         {
-          for (b = RED; b <= ALPHA; b++)
+          for (b = RED; b < ALPHA; b++)
             {
-              out[b] = in[b];
+              out[b] = layer[b];
             }
         }
 
+      out[ALPHA] = new_alpha;
+
       in    += 4;
       layer += 4;
       out   += 4;


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