[gimp] libgimp: add GEGL branch to gimp_layer_new_from_pixbuf()



commit 48a264ce4b50992d483b9cd71fc08a2d24c6055c
Author: Michael Natterer <mitch gimp org>
Date:   Thu May 3 03:48:49 2012 +0200

    libgimp: add GEGL branch to gimp_layer_new_from_pixbuf()
    
    can't get rid of the legacy impl yet bacause plug-ins need to be able
    to run in compat mode.

 libgimp/gimplayer.c |   99 ++++++++++++++++++++++++++++++---------------------
 1 files changed, 58 insertions(+), 41 deletions(-)
---
diff --git a/libgimp/gimplayer.c b/libgimp/gimplayer.c
index 430d9fe..32b26af 100644
--- a/libgimp/gimplayer.c
+++ b/libgimp/gimplayer.c
@@ -116,18 +116,11 @@ gimp_layer_new_from_pixbuf (gint32                image_ID,
                             gdouble               progress_start,
                             gdouble               progress_end)
 {
-  GimpDrawable *drawable;
-  GimpPixelRgn	rgn;
-  const guchar *pixels;
-  gpointer      pr;
-  gint32        layer;
-  gint          width;
-  gint          height;
-  gint          rowstride;
-  gint          bpp;
-  gdouble       range = progress_end - progress_start;
-  guint         count = 0;
-  guint         done  = 0;
+  gint32  layer;
+  gint    width;
+  gint    height;
+  gint    bpp;
+  gdouble range = progress_end - progress_start;
 
   g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), -1);
 
@@ -143,9 +136,9 @@ gimp_layer_new_from_pixbuf (gint32                image_ID,
       return -1;
     }
 
-  width  = gdk_pixbuf_get_width (pixbuf);
-  height = gdk_pixbuf_get_height (pixbuf);
-  bpp    = gdk_pixbuf_get_n_channels (pixbuf);
+  width     = gdk_pixbuf_get_width (pixbuf);
+  height    = gdk_pixbuf_get_height (pixbuf);
+  bpp       = gdk_pixbuf_get_n_channels (pixbuf);
 
   layer = gimp_layer_new (image_ID, name, width, height,
                           bpp == 3 ? GIMP_RGB_IMAGE : GIMP_RGBA_IMAGE,
@@ -154,46 +147,70 @@ gimp_layer_new_from_pixbuf (gint32                image_ID,
   if (layer == -1)
     return -1;
 
-  drawable = gimp_drawable_get (layer);
-
-  gimp_pixel_rgn_init (&rgn, drawable, 0, 0, width, height, TRUE, FALSE);
+  if (gimp_plugin_precision_enabled ())
+    {
+      GeglBuffer *src_buffer;
+      GeglBuffer *dest_buffer;
 
-  g_assert (bpp == rgn.bpp);
+      src_buffer = gimp_pixbuf_create_buffer (pixbuf);
+      dest_buffer = gimp_drawable_get_buffer (layer);
 
-  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
-  pixels    = gdk_pixbuf_get_pixels (pixbuf);
+      gegl_buffer_copy (src_buffer, NULL, dest_buffer, NULL);
 
-  for (pr = gimp_pixel_rgns_register (1, &rgn);
-       pr != NULL;
-       pr = gimp_pixel_rgns_process (pr))
+      g_object_unref (src_buffer);
+      g_object_unref (dest_buffer);
+    }
+  else
     {
-      const guchar *src  = pixels + rgn.y * rowstride + rgn.x * bpp;
-      guchar       *dest = rgn.data;
-      gint          y;
+      GimpDrawable *drawable;
+      GimpPixelRgn  rgn;
+      gpointer      pr;
+      const guchar *pixels;
+      gint          rowstride;
+      guint         done  = 0;
+      guint         count = 0;
 
-      for (y = 0; y < rgn.h; y++)
-        {
-          memcpy (dest, src, rgn.w * rgn.bpp);
+      drawable = gimp_drawable_get (layer);
 
-          src  += rowstride;
-          dest += rgn.rowstride;
-        }
+      gimp_pixel_rgn_init (&rgn, drawable, 0, 0, width, height, TRUE, FALSE);
 
-      if (range > 0.0)
+      g_assert (bpp == rgn.bpp);
+
+      rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+      pixels    = gdk_pixbuf_get_pixels (pixbuf);
+
+      for (pr = gimp_pixel_rgns_register (1, &rgn);
+           pr != NULL;
+           pr = gimp_pixel_rgns_process (pr))
         {
-          done += rgn.h * rgn.w;
+          const guchar *src  = pixels + rgn.y * rowstride + rgn.x * bpp;
+          guchar       *dest = rgn.data;
+          gint          y;
 
-          if (count++ % 32 == 0)
-            gimp_progress_update (progress_start +
-                                  (gdouble) done / (width * height) * range);
+          for (y = 0; y < rgn.h; y++)
+            {
+              memcpy (dest, src, rgn.w * rgn.bpp);
+
+              src  += rowstride;
+              dest += rgn.rowstride;
+            }
+
+          if (range > 0.0)
+            {
+              done += rgn.h * rgn.w;
+
+              if (count++ % 32 == 0)
+                gimp_progress_update (progress_start +
+                                      (gdouble) done / (width * height) * range);
+            }
         }
+
+      gimp_drawable_detach (drawable);
     }
 
   if (range > 0.0)
     gimp_progress_update (progress_end);
 
-  gimp_drawable_detach (drawable);
-
   return layer;
 }
 



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