[gimp/gimp-2-10] plug-ins: port cml-explorer to GEGL, stupid 8-bit port only



commit 0fdf11bfbbea6cd11b54506a753e756ff40e0de8
Author: Michael Natterer <mitch gimp org>
Date:   Sat Jul 13 00:23:45 2019 +0200

    plug-ins: port cml-explorer to GEGL, stupid 8-bit port only
    
    (cherry picked from commit f9e149dc1e3b7b745024d14f7298123aa1eea64a)

 plug-ins/common/Makefile.am    |   1 +
 plug-ins/common/cml-explorer.c | 155 ++++++++++++++++++++++++++---------------
 plug-ins/common/plugin-defs.pl |   2 +-
 3 files changed, 99 insertions(+), 59 deletions(-)
---
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 8a8a6c161e..a44451e7d3 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -428,6 +428,7 @@ cml_explorer_LDADD = \
        $(libgimpcolor)         \
        $(libgimpbase)          \
        $(GTK_LIBS)             \
+       $(GEGL_LIBS)            \
        $(RT_LIBS)              \
        $(INTLLIBS)             \
        $(cml_explorer_RC)
diff --git a/plug-ins/common/cml-explorer.c b/plug-ins/common/cml-explorer.c
index dae62166e1..e7346667d2 100644
--- a/plug-ins/common/cml-explorer.c
+++ b/plug-ins/common/cml-explorer.c
@@ -519,7 +519,6 @@ run (const gchar      *name,
       break;
     }
 
-  gimp_tile_cache_ntiles (TILE_CACHE_SIZE);
   status = CML_main_function (FALSE);
 
   if (run_mode != GIMP_RUN_NONINTERACTIVE)
@@ -538,28 +537,27 @@ run (const gchar      *name,
 static GimpPDBStatusType
 CML_main_function (gboolean preview_p)
 {
-  GimpDrawable *drawable = NULL;
-  GimpPixelRgn  dest_rgn, src_rgn;
-  guchar    *dest_buffer = NULL;
-  guchar    *src_buffer  = NULL;
-  gint       x, y;
-  gint       dx, dy;
-  gboolean   dest_has_alpha = FALSE;
-  gboolean   dest_is_gray   = FALSE;
-  gboolean   src_has_alpha  = FALSE;
-  gboolean   src_is_gray    = FALSE;
-  gint       total, processed = 0;
-  gint       keep_height = 1;
-  gint       cell_num, width_by_pixel, height_by_pixel;
-  gint       index;
-  gint       src_bpp, src_bpl;
-  gint       dest_bpp, dest_bpl;
-  gdouble   *hues, *sats, *vals;
-  gdouble   *newh, *news, *newv;
-  gdouble   *haux, *saux, *vaux;
-
-  /* open THE drawable */
-  drawable = gimp_drawable_get (drawable_id);
+  GeglBuffer *src_buffer;
+  GeglBuffer *dest_buffer;
+  const Babl *src_format;
+  const Babl *dest_format;
+  guchar     *dest_buf = NULL;
+  guchar     *src_buf  = NULL;
+  gint        x, y;
+  gint        dx, dy;
+  gboolean    dest_has_alpha = FALSE;
+  gboolean    dest_is_gray   = FALSE;
+  gboolean    src_has_alpha  = FALSE;
+  gboolean    src_is_gray    = FALSE;
+  gint        total, processed = 0;
+  gint        keep_height = 1;
+  gint        cell_num, width_by_pixel, height_by_pixel;
+  gint        index;
+  gint        src_bpp, src_bpl;
+  gint        dest_bpp, dest_bpl;
+  gdouble    *hues, *sats, *vals;
+  gdouble    *newh, *news, *newv;
+  gdouble    *haux, *saux, *vaux;
 
   if (! gimp_drawable_mask_intersect (drawable_id,
                                       &x, &y,
@@ -567,11 +565,31 @@ CML_main_function (gboolean preview_p)
     return GIMP_PDB_SUCCESS;
 
   src_has_alpha = dest_has_alpha = gimp_drawable_has_alpha (drawable_id);
-  src_is_gray = dest_is_gray = gimp_drawable_is_gray (drawable_id);
-  src_bpp = dest_bpp = (src_is_gray ? 1 : 3) + (src_has_alpha ? 1 : 0);
+  src_is_gray   = dest_is_gray   = gimp_drawable_is_gray (drawable_id);
+
+  if (src_is_gray)
+    {
+      if (src_has_alpha)
+        src_format = babl_format ("Y'A u8");
+      else
+        src_format = babl_format ("Y' u8");
+    }
+  else
+    {
+      if (src_has_alpha)
+        src_format = babl_format ("R'G'B'A u8");
+      else
+        src_format = babl_format ("R'G'B' u8");
+    }
+
+  dest_format = src_format;
+
+  src_bpp = dest_bpp = babl_format_get_bytes_per_pixel (src_format);
 
   if (preview_p)
     {
+      dest_format = babl_format ("R'G'B' u8");
+
       dest_has_alpha = FALSE;
       dest_bpp       = 3;
 
@@ -580,12 +598,15 @@ CML_main_function (gboolean preview_p)
       if (height_by_pixel > PREVIEW_HEIGHT)
         height_by_pixel = PREVIEW_HEIGHT;
     }
+
   dest_bpl = width_by_pixel * dest_bpp;
   src_bpl = width_by_pixel * src_bpp;
   cell_num = (width_by_pixel - 1)/ VALS.scale + 1;
   total = height_by_pixel * width_by_pixel;
+
   if (total < 1)
     return GIMP_PDB_EXECUTION_ERROR;
+
   keep_height = VALS.scale;
 
   /* configure reusable memories */
@@ -595,6 +616,7 @@ CML_main_function (gboolean preview_p)
       mem_chank0_size = 9 * cell_num * sizeof (gdouble);
       mem_chank0 = (gdouble *) g_malloc (mem_chank0_size);
     }
+
   hues = mem_chank0;
   sats = mem_chank0 + cell_num;
   vals = mem_chank0 + 2 * cell_num;
@@ -611,7 +633,7 @@ CML_main_function (gboolean preview_p)
       mem_chank1_size = src_bpl * keep_height;
       mem_chank1 = (guchar *) g_malloc (mem_chank1_size);
     }
-  src_buffer = mem_chank1;
+  src_buf = mem_chank1;
 
   if (mem_chank2_size < dest_bpl * keep_height)
     {
@@ -619,16 +641,12 @@ CML_main_function (gboolean preview_p)
       mem_chank2_size = dest_bpl * keep_height;
       mem_chank2 = (guchar *) g_malloc (mem_chank2_size);
     }
-  dest_buffer = mem_chank2;
+  dest_buf = mem_chank2;
 
   if (! preview_p)
-    gimp_pixel_rgn_init (&dest_rgn, drawable, x, y,
-                         width_by_pixel, height_by_pixel,
-                         TRUE, TRUE);
+    dest_buffer = gimp_drawable_get_shadow_buffer (drawable_id);
 
-  gimp_pixel_rgn_init (&src_rgn, drawable, x, y,
-                       width_by_pixel, height_by_pixel,
-                       FALSE, FALSE);
+  src_buffer = gimp_drawable_get_buffer (drawable_id);
 
   gr = g_rand_new ();
   if (VALS.initial_value == CML_INITIAL_RANDOM_FROM_SEED)
@@ -660,6 +678,7 @@ CML_main_function (gboolean preview_p)
           haux [index] = VALS.hue.power;
           break;
         }
+
       switch (VALS.sat.arrange)
         {
         case RAND_POWER0:
@@ -684,6 +703,7 @@ CML_main_function (gboolean preview_p)
           saux [index] = VALS.sat.power;
           break;
         }
+
       switch (VALS.val.arrange)
         {
         case RAND_POWER0:
@@ -708,6 +728,7 @@ CML_main_function (gboolean preview_p)
           vaux [index] = VALS.val.power;
           break;
         }
+
       switch (VALS.initial_value)
         {
         case 0:
@@ -750,8 +771,10 @@ CML_main_function (gboolean preview_p)
           int   rgbi[3];
           int   i;
 
-          gimp_pixel_rgn_get_pixel (&src_rgn, buffer,
-                                    x + (index * VALS.scale), y);
+          gegl_buffer_sample (src_buffer, x + (index * VALS.scale), y, NULL,
+                              buffer, src_format,
+                              GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
+
           for (i = 0; i < 3; i++) rgbi[i] = buffer[i];
           gimp_rgb_to_hsv_int (rgbi, rgbi + 1, rgbi + 2);
           hues[index] = (gdouble) rgbi[0] / (gdouble) 255;
@@ -780,8 +803,13 @@ CML_main_function (gboolean preview_p)
       if ((VALS.hue.function == CML_KEEP_VALUES) ||
           (VALS.sat.function == CML_KEEP_VALUES) ||
           (VALS.val.function == CML_KEEP_VALUES))
-        gimp_pixel_rgn_get_rect (&src_rgn, src_buffer,
-                                 x, y + dy, width_by_pixel, keep_height);
+        {
+          gegl_buffer_get (src_buffer,
+                           GEGL_RECTANGLE (x, y + dy,
+                                           width_by_pixel, keep_height), 1.0,
+                           src_format, src_buf,
+                           GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
+        }
 
       CML_compute_next_step (cell_num,
                              &hues, &sats, &vals,
@@ -813,8 +841,8 @@ CML_main_function (gboolean preview_p)
                     int i;
 
                     for (i = 0; i < src_bpp; i++)
-                      rgbi[i] = src_buffer[offset_y * src_bpl
-                                           + (dx * VALS.scale + offset_x) * src_bpp + i];
+                      rgbi[i] = src_buf[offset_y * src_bpl
+                                        + (dx * VALS.scale + offset_x) * src_bpp + i];
                     if (src_is_gray && (VALS.val.function == CML_KEEP_VALUES))
                       {
                         b = rgbi[0];
@@ -835,21 +863,21 @@ CML_main_function (gboolean preview_p)
 
                 if (dest_is_gray)
                   {
-                    dest_buffer[dest_offset++] = b;
+                    dest_buf[dest_offset++] = b;
                     if (preview_p)
                       {
-                        dest_buffer[dest_offset++] = b;
-                        dest_buffer[dest_offset++] = b;
+                        dest_buf[dest_offset++] = b;
+                        dest_buf[dest_offset++] = b;
                       }
                   }
                 else
                   {
-                    dest_buffer[dest_offset++] = r;
-                    dest_buffer[dest_offset++] = g;
-                    dest_buffer[dest_offset++] = b;
+                    dest_buf[dest_offset++] = r;
+                    dest_buf[dest_offset++] = g;
+                    dest_buf[dest_offset++] = b;
                   }
                 if (dest_has_alpha)
-                  dest_buffer[dest_offset] = 255;
+                  dest_buf[dest_offset] = 255;
 
                 if ((!preview_p) &&
                     (++processed % (total / PROGRESS_UPDATE_NUM + 1)) == 0)
@@ -858,16 +886,26 @@ CML_main_function (gboolean preview_p)
         }
 
       if (preview_p)
-        gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
-                                0, dy,
-                                width_by_pixel, keep_height,
-                                GIMP_RGB_IMAGE,
-                                dest_buffer,
-                                dest_bpl);
+        {
+          gimp_preview_area_draw (GIMP_PREVIEW_AREA (preview),
+                                  0, dy,
+                                  width_by_pixel, keep_height,
+                                  GIMP_RGB_IMAGE,
+                                  dest_buf,
+                                  dest_bpl);
+        }
       else
-        gimp_pixel_rgn_set_rect (&dest_rgn, dest_buffer, x, y + dy,
-                                 width_by_pixel, keep_height);
+        {
+          gegl_buffer_set (dest_buffer,
+                           GEGL_RECTANGLE (x, y + dy,
+                                           width_by_pixel, keep_height), 0,
+                           dest_format, dest_buf,
+                           GEGL_AUTO_ROWSTRIDE);
+        }
     }
+
+  g_object_unref (src_buffer);
+
   if (preview_p)
     {
       gtk_widget_queue_draw (preview);
@@ -875,11 +913,12 @@ CML_main_function (gboolean preview_p)
   else
     {
       gimp_progress_update (1.0);
-      gimp_drawable_flush (drawable);
-      gimp_drawable_merge_shadow (drawable->drawable_id, TRUE);
-      gimp_drawable_update (drawable->drawable_id,
+
+      g_object_unref (dest_buffer);
+
+      gimp_drawable_merge_shadow (drawable_id, TRUE);
+      gimp_drawable_update (drawable_id,
                             x, y, width_by_pixel, height_by_pixel);
-      gimp_drawable_detach (drawable);
     }
 
   g_rand_free (gr);
diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl
index b9c5ac7a63..bc65c64624 100644
--- a/plug-ins/common/plugin-defs.pl
+++ b/plug-ins/common/plugin-defs.pl
@@ -8,7 +8,7 @@
     'busy-dialog' => { ui => 1, gegl => 1 },
     'cartoon' => { ui => 1 },
     'checkerboard' => { ui => 1, gegl => 1 },
-    'cml-explorer' => { ui => 1 },
+    'cml-explorer' => { ui => 1, gegl => 1 },
     'color-cube-analyze' => { ui => 1 },
     'color-enhance' => { ui => 1 },
     'colorify' => { ui => 1 },


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