[gimp/goat-invasion: 72/526] app: use GEGL to extract an image's component into a channel



commit fb4697c08e5abee7fdbfb01aaf9ef37a48e13007
Author: Michael Natterer <mitch gimp org>
Date:   Fri Mar 16 13:47:38 2012 +0100

    app: use GEGL to extract an image's component into a channel
    
    Add gimp_image_get_component_format() for that purpose.

 app/core/gimpchannel.c       |   30 +++++++++++++++---------------
 app/core/gimpimage.c         |   19 +++++++++++++++++++
 app/core/gimpimage.h         |    2 ++
 app/gegl/gimp-gegl.c         |   15 +++++++++++++++
 app/pdb/channel-cmds.c       |    2 +-
 tools/pdbgen/pdb/channel.pdb |    2 +-
 6 files changed, 53 insertions(+), 17 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index 78f1ea4..44cadb8 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -1695,36 +1695,36 @@ gimp_channel_new_from_component (GimpImage       *image,
 {
   GimpProjection *projection;
   GimpChannel    *channel;
-  TileManager    *proj_tiles;
-  PixelRegion     src;
-  PixelRegion     dest;
+  GeglBuffer     *src_buffer;
+  TileManager    *dest_tiles;
+  GeglBuffer     *dest_buffer;
   gint            width;
   gint            height;
-  gint            pixel;
+  const Babl     *format;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
-  pixel = gimp_image_get_component_index (image, type);
+  format = gimp_image_get_component_format (image, type);
 
-  g_return_val_if_fail (pixel != -1, NULL);
+  g_return_val_if_fail (format != NULL, NULL);
 
   projection = gimp_image_get_projection (image);
 
   gimp_pickable_flush (GIMP_PICKABLE (projection));
 
-  proj_tiles = gimp_pickable_get_tiles (GIMP_PICKABLE (projection));
-  width  = tile_manager_width  (proj_tiles);
-  height = tile_manager_height (proj_tiles);
+  src_buffer = gimp_pickable_get_buffer (GIMP_PICKABLE (projection));
+  width  = gegl_buffer_get_width  (src_buffer);
+  height = gegl_buffer_get_height (src_buffer);
 
   channel = gimp_channel_new (image, width, height, name, color);
 
-  pixel_region_init (&src, proj_tiles,
-                     0, 0, width, height, FALSE);
-  pixel_region_init (&dest,
-                     gimp_drawable_get_tiles (GIMP_DRAWABLE (channel)),
-                     0, 0, width, height, TRUE);
+  dest_tiles = gimp_drawable_get_tiles (GIMP_DRAWABLE (channel));
+  dest_buffer = gimp_tile_manager_create_buffer_with_format (dest_tiles,
+                                                             format, TRUE);
 
-  copy_component (&src, &dest, pixel);
+  gegl_buffer_copy (src_buffer, NULL, dest_buffer, NULL);
+
+  g_object_unref (dest_buffer);
 
   return channel;
 }
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index cc435b2..6105bdc 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -1974,6 +1974,25 @@ gimp_image_mask_changed (GimpImage *image)
 
 /*  image components  */
 
+const Babl *
+gimp_image_get_component_format (const GimpImage *image,
+                                 GimpChannelType  channel)
+{
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+
+  switch (channel)
+    {
+    case GIMP_RED_CHANNEL:     return babl_format ("R u8");
+    case GIMP_GREEN_CHANNEL:   return babl_format ("G u8");
+    case GIMP_BLUE_CHANNEL:    return babl_format ("B u8");
+    case GIMP_GRAY_CHANNEL:    return babl_format ("Y u8");
+    case GIMP_INDEXED_CHANNEL: return babl_format ("Y u8");
+    case GIMP_ALPHA_CHANNEL:   return babl_format ("A u8");
+    }
+
+  return NULL;
+}
+
 gint
 gimp_image_get_component_index (const GimpImage *image,
                                 GimpChannelType  channel)
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index 2c9bf9d..30f7e0e 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -237,6 +237,8 @@ void            gimp_image_mask_changed          (GimpImage          *image);
 
 /*  image components  */
 
+const Babl    * gimp_image_get_component_format  (const GimpImage    *image,
+                                                  GimpChannelType     channel);
 gint            gimp_image_get_component_index   (const GimpImage    *image,
                                                   GimpChannelType     channel);
 
diff --git a/app/gegl/gimp-gegl.c b/app/gegl/gimp-gegl.c
index 5c415db..9d8d978 100644
--- a/app/gegl/gimp-gegl.c
+++ b/app/gegl/gimp-gegl.c
@@ -93,6 +93,21 @@ gimp_gegl_init (Gimp *gimp)
                     G_CALLBACK (gimp_gegl_notify_tile_cache_size),
                     NULL);
 
+  babl_format_new ("name", "R u8",
+                   babl_model ("RGBA"),
+                   babl_type ("u8"),
+                   babl_component ("R"),
+                   NULL);
+  babl_format_new ("name", "G u8",
+                   babl_model ("RGBA"),
+                   babl_type ("u8"),
+                   babl_component ("G"),
+                   NULL);
+  babl_format_new ("name", "B u8",
+                   babl_model ("RGBA"),
+                   babl_type ("u8"),
+                   babl_component ("B"),
+                   NULL);
   babl_format_new ("name", "A u8",
                    babl_model ("RGBA"),
                    babl_type ("u8"),
diff --git a/app/pdb/channel-cmds.c b/app/pdb/channel-cmds.c
index 59b2102c..515a70c 100644
--- a/app/pdb/channel-cmds.c
+++ b/app/pdb/channel-cmds.c
@@ -106,7 +106,7 @@ channel_new_from_component_invoker (GimpProcedure      *procedure,
 
   if (success)
     {
-      if (gimp_image_get_component_index (image, component) != -1)
+      if (gimp_image_get_component_format (image, component) != NULL)
         channel = gimp_channel_new_from_component (image,
                                                    component, name, NULL);
 
diff --git a/tools/pdbgen/pdb/channel.pdb b/tools/pdbgen/pdb/channel.pdb
index 6c0d8f5..0916770 100644
--- a/tools/pdbgen/pdb/channel.pdb
+++ b/tools/pdbgen/pdb/channel.pdb
@@ -161,7 +161,7 @@ HELP
     %invoke = (
 	code => <<'CODE'
 {
-  if (gimp_image_get_component_index (image, component) != -1)
+  if (gimp_image_get_component_format (image, component) != NULL)
     channel = gimp_channel_new_from_component (image,
                                                component, name, NULL);
 



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