[gimp] app: reuse more code



commit 975a0a6943b8e44ba4231256f59c6ee5709d4904
Author: Øyvind Kolås <pippin gimp org>
Date:   Fri Jan 13 18:10:07 2017 +0100

    app: reuse more code

 app/operations/layer-modes/gimpoperationlchcolor.c |   59 ++++++--------------
 app/operations/layer-modes/gimpoperationlchhue.c   |   59 ++++++--------------
 .../layer-modes/gimpoperationlchlightness.c        |   59 ++++++--------------
 3 files changed, 54 insertions(+), 123 deletions(-)
---
diff --git a/app/operations/layer-modes/gimpoperationlchcolor.c 
b/app/operations/layer-modes/gimpoperationlchcolor.c
index 6f4311e..ff3c513 100644
--- a/app/operations/layer-modes/gimpoperationlchcolor.c
+++ b/app/operations/layer-modes/gimpoperationlchcolor.c
@@ -110,45 +110,6 @@ color_pre_process (const Babl   *format,
   babl_process (babl_fish ("CIE Lab alpha float", format), out, out, samples);
 }
 
-static void
-color_post_process (const gfloat *in,
-                    const gfloat *layer,
-                    const gfloat *mask,
-                    gfloat       *out,
-                    gfloat        opacity,
-                    glong         samples)
-{
-  while (samples--)
-    {
-      gfloat comp_alpha = layer[ALPHA] * opacity;
-
-      if (mask)
-        comp_alpha *= *mask++;
-
-      if (comp_alpha != 0.0f)
-        {
-          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
-        {
-          gint b;
-
-          for (b = RED; b < ALPHA; b++)
-            {
-              out[b] = in[b];
-            }
-        }
-
-      out[ALPHA] = in[ALPHA];
-
-      in    += 4;
-      layer += 4;
-      out   += 4;
-    }
-}
-
 gboolean
 gimp_operation_lch_color_process_pixels_linear (gfloat              *in,
                                                 gfloat              *layer,
@@ -159,8 +120,16 @@ gimp_operation_lch_color_process_pixels_linear (gfloat              *in,
                                                 const GeglRectangle *roi,
                                                 gint                 level)
 {
+  static const Babl *from_fish;
+  static const Babl *to_fish;
+  
+  if (!from_fish)
+    from_fish = babl_fish ("RGBA float", "CIE Lab alpha float");
+  if (!to_fish)
+     to_fish = babl_fish ("CIE Lab alpha float", "RGBA float");
+
   color_pre_process (babl_format ("RGBA float"), in, layer, out, samples);
-  color_post_process (in, layer, mask, out, opacity, samples);
+  gimp_operation_layer_composite (in, layer, mask, out, opacity, samples);
 
   return TRUE;
 }
@@ -175,8 +144,16 @@ gimp_operation_lch_color_process_pixels (gfloat              *in,
                                          const GeglRectangle *roi,
                                          gint                 level)
 {
+  static const Babl *from_fish = NULL;
+  static const Babl *to_fish = NULL;
+  
+  if (!from_fish)
+    from_fish = babl_fish ("R'G'B'A float", "CIE Lab alpha float");
+  if (!to_fish)
+     to_fish = babl_fish ("CIE Lab alpha float", "R'G'B'A float");
+
   color_pre_process (babl_format ("R'G'B'A float"), in, layer, out, samples);
-  color_post_process (in, layer, mask, out, opacity, samples);
+  gimp_operation_layer_composite (in, layer, mask, out, opacity, samples);
 
   return TRUE;
 }
diff --git a/app/operations/layer-modes/gimpoperationlchhue.c 
b/app/operations/layer-modes/gimpoperationlchhue.c
index 5f3a3bd..c0575cf 100644
--- a/app/operations/layer-modes/gimpoperationlchhue.c
+++ b/app/operations/layer-modes/gimpoperationlchhue.c
@@ -122,45 +122,6 @@ hue_pre_process (const Babl   *format,
   babl_process (babl_fish ("CIE Lab alpha float", format), out, out, samples);
 }
 
-static void
-hue_post_process (const gfloat *in,
-                  const gfloat *layer,
-                  const gfloat *mask,
-                  gfloat       *out,
-                  gfloat        opacity,
-                  glong         samples)
-{
-  while (samples--)
-    {
-      gfloat comp_alpha = layer[ALPHA] * opacity;
-
-      if (mask)
-        comp_alpha *= *mask++;
-
-      if (comp_alpha != 0.0f)
-        {
-          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
-        {
-          gint b;
-
-          for (b = RED; b < ALPHA; b++)
-            {
-              out[b] = in[b];
-            }
-        }
-
-      out[ALPHA] = in[ALPHA];
-
-      in    += 4;
-      layer += 4;
-      out   += 4;
-    }
-}
-
 gboolean
 gimp_operation_lch_hue_process_pixels_linear (gfloat              *in,
                                               gfloat              *layer,
@@ -171,8 +132,16 @@ gimp_operation_lch_hue_process_pixels_linear (gfloat              *in,
                                               const GeglRectangle *roi,
                                               gint                 level)
 {
+  static const Babl *from_fish = NULL;
+  static const Babl *to_fish = NULL;
+  
+  if (!from_fish)
+    from_fish = babl_fish ("RGBA float", "CIE Lab alpha float");
+  if (!to_fish)
+     to_fish = babl_fish ("CIE Lab alpha float", "RGBA float");
+
   hue_pre_process (babl_format ("RGBA float"), in, layer, out, samples);
-  hue_post_process (in, layer, mask, out, opacity, samples);
+  gimp_operation_layer_composite (in, layer, mask, out, opacity, samples);
 
   return TRUE;
 }
@@ -187,8 +156,16 @@ gimp_operation_lch_hue_process_pixels (gfloat              *in,
                                        const GeglRectangle *roi,
                                        gint                 level)
 {
+  static const Babl *from_fish = NULL;
+  static const Babl *to_fish = NULL;
+  
+  if (!from_fish)
+    from_fish = babl_fish ("R'G'B'A float", "CIE Lab alpha float");
+  if (!to_fish)
+     to_fish = babl_fish ("CIE Lab alpha float", "R'G'B'A float");
+
   hue_pre_process (babl_format ("R'G'B'A float"), in, layer, out, samples);
-  hue_post_process (in, layer, mask, out, opacity, samples);
+  gimp_operation_layer_composite (in, layer, mask, out, opacity, samples);
 
   return TRUE;
 }
diff --git a/app/operations/layer-modes/gimpoperationlchlightness.c 
b/app/operations/layer-modes/gimpoperationlchlightness.c
index f0e7d08..4e9f4a3 100644
--- a/app/operations/layer-modes/gimpoperationlchlightness.c
+++ b/app/operations/layer-modes/gimpoperationlchlightness.c
@@ -106,45 +106,6 @@ lightness_pre_process (const Babl   *format,
   babl_process (babl_fish ("CIE Lab alpha float", format), out, out, samples);
 }
 
-static void
-lightness_post_process (const gfloat *in,
-                        const gfloat *layer,
-                        const gfloat *mask,
-                        gfloat       *out,
-                        gfloat        opacity,
-                        glong         samples)
-{
-  while (samples--)
-    {
-      gfloat comp_alpha = layer[ALPHA] * opacity;
-
-      if (mask)
-        comp_alpha *= *mask++;
-
-      if (comp_alpha != 0.0f)
-        {
-          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
-        {
-          gint b;
-
-          for (b = RED; b < ALPHA; b++)
-            {
-              out[b] = in[b];
-            }
-        }
-
-      out[ALPHA] = in[ALPHA];
-
-      in    += 4;
-      layer += 4;
-      out   += 4;
-    }
-}
-
 gboolean
 gimp_operation_lch_lightness_process_pixels_linear (gfloat              *in,
                                                     gfloat              *layer,
@@ -155,8 +116,16 @@ gimp_operation_lch_lightness_process_pixels_linear (gfloat              *in,
                                                     const GeglRectangle *roi,
                                                     gint                 level)
 {
+  static const Babl *from_fish = NULL;
+  static const Babl *to_fish = NULL;
+  
+  if (!from_fish)
+    from_fish = babl_fish ("RGBA float", "CIE Lab alpha float");
+  if (!to_fish)
+     to_fish = babl_fish ("CIE Lab alpha float", "RGBA float");
+
   lightness_pre_process (babl_format ("RGBA float"), in, layer, out, samples);
-  lightness_post_process (in, layer, mask, out, opacity, samples);
+  gimp_operation_layer_composite (in, layer, mask, out, opacity, samples);
 
   return TRUE;
 }
@@ -171,8 +140,16 @@ gimp_operation_lch_lightness_process_pixels (gfloat              *in,
                                              const GeglRectangle *roi,
                                              gint                 level)
 {
+  static const Babl *from_fish = NULL;
+  static const Babl *to_fish = NULL;
+  
+  if (!from_fish)
+    from_fish = babl_fish ("R'G'B'A float", "CIE Lab alpha float");
+  if (!to_fish)
+     to_fish = babl_fish ("CIE Lab alpha float", "R'G'B'A float");
+
   lightness_pre_process (babl_format ("R'G'B'A float"), in, layer, out, samples);
-  lightness_post_process (in, layer, mask, out, opacity, samples);
+  gimp_operation_layer_composite (in, layer, mask, out, opacity, samples);
 
   return TRUE;
 }


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