[gimp/gimp-2-10] plug-ins: replace calls to GimpRegionIterator functions



commit f4b836c68d63493f995552062541729f33b5d39c
Author: Michael Natterer <mitch gimp org>
Date:   Sun Jul 7 17:09:17 2019 +0200

    plug-ins: replace calls to GimpRegionIterator functions
    
    by plain pixel region code, copied right out of gimpregioniterator.c.
    Makes porting to GEGL easier and GimpRegionIterator unused.
    
    (cherry picked from commit 775abb03f3d7a66afd46de372e08f95f4f36624e)

 plug-ins/common/colorify.c           |  58 +++++++++++++++++++-
 plug-ins/common/contrast-normalize.c | 103 +++++++++++++++++++++++++++++++++--
 plug-ins/common/filter-pack.c        |  60 +++++++++++++++++++-
 plug-ins/common/max-rgb.c            |  59 +++++++++++++++++++-
 plug-ins/common/sample-colorize.c    |  61 ++++++++++++++++++++-
 5 files changed, 332 insertions(+), 9 deletions(-)
---
diff --git a/plug-ins/common/colorify.c b/plug-ins/common/colorify.c
index c5dd220cff..5bd0a883d8 100644
--- a/plug-ins/common/colorify.c
+++ b/plug-ins/common/colorify.c
@@ -231,7 +231,63 @@ colorify (GimpDrawable *drawable,
     }
   else
     {
-      gimp_rgn_iterate2 (drawable, 0 /* unused */, colorify_func, NULL);
+      GimpPixelRgn  srcPR, destPR;
+      gint          x1, y1, x2, y2;
+      gpointer      pr;
+      gint          total_area;
+      gint          area_so_far;
+      gint          count;
+
+      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
+
+      total_area  = (x2 - x1) * (y2 - y1);
+      area_so_far = 0;
+
+      if (total_area <= 0)
+        return;
+
+      /* Initialize the pixel regions. */
+      gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
+                           FALSE, FALSE);
+      gimp_pixel_rgn_init (&destPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
+                           TRUE, TRUE);
+
+      for (pr = gimp_pixel_rgns_register (2, &srcPR, &destPR), count = 0;
+           pr != NULL;
+           pr = gimp_pixel_rgns_process (pr), count++)
+        {
+          const guchar *src  = srcPR.data;
+          guchar       *dest = destPR.data;
+          gint          row;
+
+          for (row = 0; row < srcPR.h; row++)
+            {
+              const guchar *s      = src;
+              guchar       *d      = dest;
+              gint          pixels = srcPR.w;
+
+              while (pixels--)
+                {
+                  colorify_func (s, d, srcPR.bpp, NULL);
+
+                  s += srcPR.bpp;
+                  d += destPR.bpp;
+                }
+
+              src  += srcPR.rowstride;
+              dest += destPR.rowstride;
+            }
+
+          area_so_far += srcPR.w * srcPR.h;
+
+          if ((count % 16) == 0)
+            gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
+        }
+
+      /*  update the processed region  */
+      gimp_drawable_flush (drawable);
+      gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
+      gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
     }
 }
 
diff --git a/plug-ins/common/contrast-normalize.c b/plug-ins/common/contrast-normalize.c
index 7a9f3c579c..3fb921f307 100644
--- a/plug-ins/common/contrast-normalize.c
+++ b/plug-ins/common/contrast-normalize.c
@@ -235,15 +235,60 @@ static void
 normalize (GimpDrawable *drawable)
 {
   NormalizeParam_t param;
-  gint x;
-  guchar  range;
+  gint             x1, y1, x2, y2;
+  gint             x;
+  guchar           range;
+  gint             total_area;
 
   param.min = 255;
   param.max = 0;
   param.has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
   param.alpha = (param.has_alpha) ? drawable->bpp - 1 : drawable->bpp;
 
-  gimp_rgn_iterate1 (drawable, 0 /* unused */, find_min_max, &param);
+  gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
+
+  total_area  = (x2 - x1) * (y2 - y1);
+  if (total_area <= 0)
+    return;
+
+  {
+    GimpPixelRgn  srcPR;
+    gpointer      pr;
+    gint          area_so_far;
+    gint          count;
+
+    area_so_far = 0;
+
+    gimp_pixel_rgn_init (&srcPR, drawable,
+                         x1, y1, (x2 - x1), (y2 - y1), FALSE, FALSE);
+
+    for (pr = gimp_pixel_rgns_register (1, &srcPR), count = 0;
+         pr != NULL;
+         pr = gimp_pixel_rgns_process (pr), count++)
+      {
+        const guchar *src = srcPR.data;
+        gint          y;
+
+        for (y = 0; y < srcPR.h; y++)
+          {
+            const guchar *s = src;
+            gint          x;
+
+            for (x = 0; x < srcPR.w; x++)
+              {
+                find_min_max (s, srcPR.bpp, &param);
+                s += srcPR.bpp;
+              }
+
+            src += srcPR.rowstride;
+          }
+
+        area_so_far += srcPR.w * srcPR.h;
+
+        if ((count % 16) == 0)
+          gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
+      }
+  }
 
   /* Calculate LUT */
 
@@ -255,5 +300,55 @@ normalize (GimpDrawable *drawable)
   else
     param.lut[(gint)param.min] = param.min;
 
-  gimp_rgn_iterate2 (drawable, 0 /* unused */, normalize_func, &param);
+  {
+    GimpPixelRgn  srcPR, destPR;
+    gpointer      pr;
+    gint          area_so_far;
+    gint          count;
+
+    area_so_far = 0;
+
+    /* Initialize the pixel regions. */
+    gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
+                         FALSE, FALSE);
+    gimp_pixel_rgn_init (&destPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
+                         TRUE, TRUE);
+
+    for (pr = gimp_pixel_rgns_register (2, &srcPR, &destPR), count = 0;
+         pr != NULL;
+         pr = gimp_pixel_rgns_process (pr), count++)
+      {
+        const guchar *src  = srcPR.data;
+        guchar       *dest = destPR.data;
+        gint          row;
+
+        for (row = 0; row < srcPR.h; row++)
+          {
+            const guchar *s      = src;
+            guchar       *d      = dest;
+            gint          pixels = srcPR.w;
+
+            while (pixels--)
+              {
+                normalize_func (s, d, srcPR.bpp, &param);
+
+                s += srcPR.bpp;
+                d += destPR.bpp;
+              }
+
+            src  += srcPR.rowstride;
+            dest += destPR.rowstride;
+          }
+
+        area_so_far += srcPR.w * srcPR.h;
+
+        if ((count % 16) == 0)
+          gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
+      }
+  }
+
+  /*  update the processed region  */
+  gimp_drawable_flush (drawable);
+  gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
+  gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
 }
diff --git a/plug-ins/common/filter-pack.c b/plug-ins/common/filter-pack.c
index e39a7b2d91..96645962d6 100644
--- a/plug-ins/common/filter-pack.c
+++ b/plug-ins/common/filter-pack.c
@@ -498,7 +498,65 @@ fp_func (const guchar *src,
 static void
 fp (GimpDrawable *drawable)
 {
-  gimp_rgn_iterate2 (drawable, 0 /* unused */, fp_func, NULL);
+  GimpPixelRgn  srcPR, destPR;
+  gint          x1, y1, x2, y2;
+  gpointer      pr;
+  gint          total_area;
+  gint          area_so_far;
+  gint          count;
+
+  g_return_if_fail (drawable != NULL);
+
+  gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
+
+  total_area  = (x2 - x1) * (y2 - y1);
+  area_so_far = 0;
+
+  if (total_area <= 0)
+    return;
+
+  /* Initialize the pixel regions. */
+  gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
+                       FALSE, FALSE);
+  gimp_pixel_rgn_init (&destPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
+                       TRUE, TRUE);
+
+  for (pr = gimp_pixel_rgns_register (2, &srcPR, &destPR), count = 0;
+       pr != NULL;
+       pr = gimp_pixel_rgns_process (pr), count++)
+    {
+      const guchar *src  = srcPR.data;
+      guchar       *dest = destPR.data;
+      gint          row;
+
+      for (row = 0; row < srcPR.h; row++)
+        {
+          const guchar *s      = src;
+          guchar       *d      = dest;
+          gint          pixels = srcPR.w;
+
+          while (pixels--)
+            {
+              fp_func (s, d, srcPR.bpp, NULL);
+
+              s += srcPR.bpp;
+              d += destPR.bpp;
+            }
+
+          src  += srcPR.rowstride;
+          dest += destPR.rowstride;
+        }
+
+      area_so_far += srcPR.w * srcPR.h;
+
+      if ((count % 16) == 0)
+        gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
+    }
+
+  /*  update the processed region  */
+  gimp_drawable_flush (drawable);
+  gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
+  gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
 }
 
 /***********************************************************/
diff --git a/plug-ins/common/max-rgb.c b/plug-ins/common/max-rgb.c
index f1b49cebfd..1261548cf5 100644
--- a/plug-ins/common/max-rgb.c
+++ b/plug-ins/common/max-rgb.c
@@ -229,10 +229,67 @@ main_function (GimpDrawable *drawable,
     }
   else
     {
+      GimpPixelRgn  srcPR, destPR;
+      gint          x1, y1, x2, y2;
+      gpointer      pr;
+      gint          total_area;
+      gint          area_so_far;
+      gint          count;
+
       gimp_progress_init (_("Max RGB"));
 
-      gimp_rgn_iterate2 (drawable, 0 /* unused */, max_rgb_func, &param);
+      gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
+
+      total_area  = (x2 - x1) * (y2 - y1);
+      area_so_far = 0;
+
+      if (total_area <= 0)
+        goto out;
+
+      /* Initialize the pixel regions. */
+      gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
+                           FALSE, FALSE);
+      gimp_pixel_rgn_init (&destPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
+                           TRUE, TRUE);
+
+      for (pr = gimp_pixel_rgns_register (2, &srcPR, &destPR), count = 0;
+           pr != NULL;
+           pr = gimp_pixel_rgns_process (pr), count++)
+        {
+          const guchar *src  = srcPR.data;
+          guchar       *dest = destPR.data;
+          gint          row;
+
+          for (row = 0; row < srcPR.h; row++)
+            {
+              const guchar *s      = src;
+              guchar       *d      = dest;
+              gint          pixels = srcPR.w;
+
+              while (pixels--)
+                {
+                  max_rgb_func (s, d, srcPR.bpp, &param);
+
+                  s += srcPR.bpp;
+                  d += destPR.bpp;
+                }
+
+              src  += srcPR.rowstride;
+              dest += destPR.rowstride;
+            }
+
+          area_so_far += srcPR.w * srcPR.h;
+
+          if ((count % 16) == 0)
+            gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
+        }
+
+      /*  update the processed region  */
+      gimp_drawable_flush (drawable);
+      gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
+      gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
 
+    out:
       gimp_drawable_detach (drawable);
     }
 
diff --git a/plug-ins/common/sample-colorize.c b/plug-ins/common/sample-colorize.c
index 989d720875..7a1bac035c 100644
--- a/plug-ins/common/sample-colorize.c
+++ b/plug-ins/common/sample-colorize.c
@@ -3043,6 +3043,12 @@ colorize_drawable (gint32 drawable_id)
 {
   GimpDrawable *drawable;
   gboolean      has_alpha;
+  GimpPixelRgn  srcPR, destPR;
+  gint          x1, y1, x2, y2;
+  gpointer      pr;
+  gint          total_area;
+  gint          area_so_far;
+  gint          count;
 
   drawable = gimp_drawable_get (drawable_id);
   has_alpha = gimp_drawable_has_alpha (drawable->drawable_id);
@@ -3050,8 +3056,59 @@ colorize_drawable (gint32 drawable_id)
   if (g_show_progress)
     gimp_progress_init (_("Remap colorized"));
 
-  gimp_rgn_iterate2 (drawable, 0 /* unused */, colorize_func,
-                     GINT_TO_POINTER (has_alpha));
+  gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
+
+  total_area  = (x2 - x1) * (y2 - y1);
+  area_so_far = 0;
+
+  if (total_area <= 0)
+    goto out;
+
+  /* Initialize the pixel regions. */
+  gimp_pixel_rgn_init (&srcPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
+                       FALSE, FALSE);
+  gimp_pixel_rgn_init (&destPR, drawable, x1, y1, (x2 - x1), (y2 - y1),
+                       TRUE, TRUE);
+
+  for (pr = gimp_pixel_rgns_register (2, &srcPR, &destPR), count = 0;
+       pr != NULL;
+       pr = gimp_pixel_rgns_process (pr), count++)
+    {
+      const guchar *src  = srcPR.data;
+      guchar       *dest = destPR.data;
+      gint          row;
+
+      for (row = 0; row < srcPR.h; row++)
+        {
+          const guchar *s      = src;
+          guchar       *d      = dest;
+          gint          pixels = srcPR.w;
+
+          while (pixels--)
+            {
+              colorize_func (s, d, srcPR.bpp, GINT_TO_POINTER (has_alpha));
+
+              s += srcPR.bpp;
+              d += destPR.bpp;
+            }
+
+          src  += srcPR.rowstride;
+          dest += destPR.rowstride;
+        }
+
+      area_so_far += srcPR.w * srcPR.h;
+
+      if ((count % 16) == 0)
+        gimp_progress_update ((gdouble) area_so_far / (gdouble) total_area);
+    }
+
+  /*  update the processed region  */
+  gimp_drawable_flush (drawable);
+  gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
+  gimp_drawable_update (drawable->drawable_id, x1, y1, (x2 - x1), (y2 - y1));
+
+ out:
+  gimp_drawable_detach (drawable);
 
   if (g_show_progress)
     gimp_progress_update (0.0);


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