[gimp] app: fix SRC_OVER composite mode



commit 4c3a772cd80d70a171b15141ece2a055e5e61131
Author: Ell <ell_se yahoo com>
Date:   Sun Feb 5 21:31:46 2017 -0500

    app: fix SRC_OVER composite mode
    
    When the source alpha is zero, we don't calculate the blended color,
    so `comp[b]` can be infinite or NaN, in which case the expression
    `in[ALPHA] * (comp[b] - layer[b])` is NaN, rather than the expected
    value of zero.

 .../layer-modes/gimpoperationlayermode.c           |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/app/operations/layer-modes/gimpoperationlayermode.c 
b/app/operations/layer-modes/gimpoperationlayermode.c
index 20de360..39a56f9 100644
--- a/app/operations/layer-modes/gimpoperationlayermode.c
+++ b/app/operations/layer-modes/gimpoperationlayermode.c
@@ -547,12 +547,13 @@ compfun_src_over (gfloat *in,
   while (samples--)
     {
       gfloat new_alpha;
+      gfloat in_alpha    = in[ALPHA];
       gfloat layer_alpha = layer[ALPHA] * opacity;
 
       if (mask)
         layer_alpha *= *mask;
 
-      new_alpha = layer_alpha + (1.0f - layer_alpha) * in[ALPHA];
+      new_alpha = layer_alpha + (1.0f - layer_alpha) * in_alpha;
 
       if (layer_alpha == 0.0f || new_alpha == 0.0f)
         {
@@ -560,13 +561,19 @@ compfun_src_over (gfloat *in,
           out[GREEN] = in[GREEN];
           out[BLUE]  = in[BLUE];
         }
+      else if (in_alpha == 0.0f)
+        {
+          out[RED]   = layer[RED];
+          out[GREEN] = layer[GREEN];
+          out[BLUE]  = layer[BLUE];
+        }
       else
         {
           gfloat ratio = layer_alpha / new_alpha;
           gint   b;
 
           for (b = RED; b < ALPHA; b++)
-            out[b] = ratio * (in[ALPHA] * (comp[b] - layer[b]) + layer[b] - in[b]) + in[b];
+            out[b] = ratio * (in_alpha * (comp[b] - layer[b]) + layer[b] - in[b]) + in[b];
         }
 
       out[ALPHA] = new_alpha;


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