[gimp] app: improve and simplify alpha handling of LCH blending modes



commit 13eab78ecc4c3d6422577aa934e4387393f1ae41
Author: Øyvind Kolås <pippin gimp org>
Date:   Fri Jan 13 14:15:35 2017 +0100

    app: improve and simplify alpha handling of LCH blending modes

 .../layer-modes/gimpoperationlchchroma.c           |   15 +++++----------
 app/operations/layer-modes/gimpoperationlchcolor.c |   15 +++++----------
 app/operations/layer-modes/gimpoperationlchhue.c   |   15 +++++----------
 .../layer-modes/gimpoperationlchlightness.c        |   15 +++++----------
 4 files changed, 20 insertions(+), 40 deletions(-)
---
diff --git a/app/operations/layer-modes/gimpoperationlchchroma.c 
b/app/operations/layer-modes/gimpoperationlchchroma.c
index 26d5be1..88f6010 100644
--- a/app/operations/layer-modes/gimpoperationlchchroma.c
+++ b/app/operations/layer-modes/gimpoperationlchchroma.c
@@ -131,21 +131,16 @@ chroma_post_process (const gfloat *in,
 {
   while (samples--)
     {
-      gfloat comp_alpha, new_alpha;
+      gfloat comp_alpha = layer[ALPHA] * opacity;
 
-      comp_alpha = layer[ALPHA] * opacity;
       if (mask)
         comp_alpha *= *mask++;
 
-      new_alpha = in[ALPHA] + (1.0f - in[ALPHA]) * comp_alpha;
-
-      if (comp_alpha && new_alpha)
+      if (comp_alpha != 0.0f)
         {
-          gfloat ratio = comp_alpha / new_alpha;
-
-          out[RED]   = out[RED]   * ratio + in[RED]   * (1.0f - ratio);
-          out[GREEN] = out[GREEN] * ratio + in[GREEN] * (1.0f - ratio);
-          out[BLUE]  = out[BLUE]  * ratio + in[BLUE]  * (1.0f - ratio);
+          out[RED]   = out[RED]   * comp_alpha + in[RED]   * (1.0f - comp_alpha);
+          out[GREEN] = out[GREEN] * comp_alpha + in[GREEN] * (1.0f - comp_alpha);
+          out[BLUE]  = out[BLUE]  * comp_alpha + in[BLUE]  * (1.0f - comp_alpha);
         }
       else
         {
diff --git a/app/operations/layer-modes/gimpoperationlchcolor.c 
b/app/operations/layer-modes/gimpoperationlchcolor.c
index 76ef0b9..6f4311e 100644
--- a/app/operations/layer-modes/gimpoperationlchcolor.c
+++ b/app/operations/layer-modes/gimpoperationlchcolor.c
@@ -120,21 +120,16 @@ color_post_process (const gfloat *in,
 {
   while (samples--)
     {
-      gfloat comp_alpha, new_alpha;
+      gfloat comp_alpha = layer[ALPHA] * opacity;
 
-      comp_alpha = layer[ALPHA] * opacity;
       if (mask)
         comp_alpha *= *mask++;
 
-      new_alpha = in[ALPHA] + (1.0f - in[ALPHA]) * comp_alpha;
-
-      if (comp_alpha && new_alpha)
+      if (comp_alpha != 0.0f)
         {
-          gfloat ratio = comp_alpha / new_alpha;
-
-          out[RED]   = out[RED]   * ratio + in[RED]   * (1.0f - ratio);
-          out[GREEN] = out[GREEN] * ratio + in[GREEN] * (1.0f - ratio);
-          out[BLUE]  = out[BLUE]  * ratio + in[BLUE]  * (1.0f - ratio);
+          out[RED]   = out[RED]   * comp_alpha + in[RED]   * (1.0f - comp_alpha);
+          out[GREEN] = out[GREEN] * comp_alpha + in[GREEN] * (1.0f - comp_alpha);
+          out[BLUE]  = out[BLUE]  * comp_alpha + in[BLUE]  * (1.0f - comp_alpha);
         }
       else
         {
diff --git a/app/operations/layer-modes/gimpoperationlchhue.c 
b/app/operations/layer-modes/gimpoperationlchhue.c
index 88c6433..5f3a3bd 100644
--- a/app/operations/layer-modes/gimpoperationlchhue.c
+++ b/app/operations/layer-modes/gimpoperationlchhue.c
@@ -132,21 +132,16 @@ hue_post_process (const gfloat *in,
 {
   while (samples--)
     {
-      gfloat comp_alpha, new_alpha;
+      gfloat comp_alpha = layer[ALPHA] * opacity;
 
-      comp_alpha = layer[ALPHA] * opacity;
       if (mask)
         comp_alpha *= *mask++;
 
-      new_alpha = in[ALPHA] + (1.0f - in[ALPHA]) * comp_alpha;
-
-      if (comp_alpha && new_alpha)
+      if (comp_alpha != 0.0f)
         {
-          gfloat ratio = comp_alpha / new_alpha;
-
-          out[RED]   = out[RED]   * ratio + in[RED]   * (1.0f - ratio);
-          out[GREEN] = out[GREEN] * ratio + in[GREEN] * (1.0f - ratio);
-          out[BLUE]  = out[BLUE]  * ratio + in[BLUE]  * (1.0f - ratio);
+          out[RED]   = out[RED]   * comp_alpha + in[RED]   * (1.0f - comp_alpha);
+          out[GREEN] = out[GREEN] * comp_alpha + in[GREEN] * (1.0f - comp_alpha);
+          out[BLUE]  = out[BLUE]  * comp_alpha + in[BLUE]  * (1.0f - comp_alpha);
         }
       else
         {
diff --git a/app/operations/layer-modes/gimpoperationlchlightness.c 
b/app/operations/layer-modes/gimpoperationlchlightness.c
index e54b48d..f0e7d08 100644
--- a/app/operations/layer-modes/gimpoperationlchlightness.c
+++ b/app/operations/layer-modes/gimpoperationlchlightness.c
@@ -116,21 +116,16 @@ lightness_post_process (const gfloat *in,
 {
   while (samples--)
     {
-      gfloat comp_alpha, new_alpha;
+      gfloat comp_alpha = layer[ALPHA] * opacity;
 
-      comp_alpha = layer[ALPHA] * opacity;
       if (mask)
         comp_alpha *= *mask++;
 
-      new_alpha = in[ALPHA] + (1.0f - in[ALPHA]) * comp_alpha;
-
-      if (comp_alpha && new_alpha)
+      if (comp_alpha != 0.0f)
         {
-          gfloat ratio = comp_alpha / new_alpha;
-
-          out[RED]   = out[RED]   * ratio + in[RED]   * (1.0f - ratio);
-          out[GREEN] = out[GREEN] * ratio + in[GREEN] * (1.0f - ratio);
-          out[BLUE]  = out[BLUE]  * ratio + in[BLUE]  * (1.0f - ratio);
+          out[RED]   = out[RED]   * comp_alpha + in[RED]   * (1.0f - comp_alpha);
+          out[GREEN] = out[GREEN] * comp_alpha + in[GREEN] * (1.0f - comp_alpha);
+          out[BLUE]  = out[BLUE]  * comp_alpha + in[BLUE]  * (1.0f - comp_alpha);
         }
       else
         {


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