[gimp] libgimp: add gimp_layer_new_from_surface()



commit 374dd50c43cca559a4888224f8fd6322fb26115d
Author: Michael Natterer <mitch gimp org>
Date:   Wed Apr 20 23:58:00 2011 +0200

    libgimp: add gimp_layer_new_from_surface()
    
    and to enable that, make libgimp depend on Cairo.

 configure.ac                            |    6 +-
 devel-docs/libgimp/libgimp-sections.txt |    1 +
 gimp.pc.in                              |    2 +-
 libgimp/Makefile.am                     |    1 +
 libgimp/gimp.def                        |    1 +
 libgimp/gimp.h                          |    1 +
 libgimp/gimplayer.c                     |  157 +++++++++++++++++++++++++++++++
 libgimp/gimplayer.h                     |    7 ++
 plug-ins/common/Makefile.am             |   20 ++++
 plug-ins/common/mkgen.pl                |    2 +-
 plug-ins/file-faxg3/Makefile.am         |    2 +
 plug-ins/help/Makefile.am               |    2 +
 12 files changed, 198 insertions(+), 4 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5c355cd..7f2ab87 100644
--- a/configure.ac
+++ b/configure.ac
@@ -117,11 +117,13 @@ AC_SUBST(GIMP_FULL_NAME)
 
 # These are used in the .pc files
 GLIB_REQUIRED_VERSION=glib_required_version
-GTK_REQUIRED_VERSION=gtk_required_version
 GDK_PIXBUF_REQUIRED_VERSION=gdk_pixbuf_required_version
+GTK_REQUIRED_VERSION=gtk_required_version
+CAIRO_REQUIRED_VERSION=cairo_required_version
 AC_SUBST(GLIB_REQUIRED_VERSION)
-AC_SUBST(GTK_REQUIRED_VERSION)
 AC_SUBST(GDK_PIXBUF_REQUIRED_VERSION)
+AC_SUBST(GTK_REQUIRED_VERSION)
+AC_SUBST(CAIRO_REQUIRED_VERSION)
 
 # The symbol GIMP_UNSTABLE is defined above for substitution in
 # Makefiles and conditionally defined here as a preprocessor symbol
diff --git a/devel-docs/libgimp/libgimp-sections.txt b/devel-docs/libgimp/libgimp-sections.txt
index dc49ad2..f756e6d 100644
--- a/devel-docs/libgimp/libgimp-sections.txt
+++ b/devel-docs/libgimp/libgimp-sections.txt
@@ -696,6 +696,7 @@ gimp_layer_new
 gimp_layer_new_from_drawable
 gimp_layer_new_from_visible
 gimp_layer_new_from_pixbuf
+gimp_layer_new_from_surface
 gimp_layer_group_new
 gimp_layer_copy
 gimp_layer_scale
diff --git a/gimp.pc.in b/gimp.pc.in
index e2765a4..8609a77 100644
--- a/gimp.pc.in
+++ b/gimp.pc.in
@@ -12,6 +12,6 @@ gimplocaledir= gimplocaledir@
 Name: GIMP
 Description: GIMP Library
 Version: @GIMP_REAL_VERSION@
-Requires: gdk-pixbuf-2.0 >= @GDK_PIXBUF_REQUIRED_VERSION@
+Requires: gdk-pixbuf-2.0 >= @GDK_PIXBUF_REQUIRED_VERSION@ cairo >= @CAIRO_REQUIRED_VERSION@
 Libs: -L${libdir} -lgimp- GIMP_API_VERSION@ -lgimpmath- GIMP_API_VERSION@  -lgimpconfig- GIMP_API_VERSION@ -lgimpcolor- GIMP_API_VERSION@ -lgimpbase- GIMP_API_VERSION@ @RT_LIBS@
 Cflags: -I${includedir}/gimp- GIMP_API_VERSION@
diff --git a/libgimp/Makefile.am b/libgimp/Makefile.am
index c613ae1..86f45ac 100644
--- a/libgimp/Makefile.am
+++ b/libgimp/Makefile.am
@@ -364,6 +364,7 @@ libgimp_2_0_la_LIBADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)
 
diff --git a/libgimp/gimp.def b/libgimp/gimp.def
index 3f11785..8894eb5 100644
--- a/libgimp/gimp.def
+++ b/libgimp/gimp.def
@@ -516,6 +516,7 @@ EXPORTS
 	gimp_layer_new
 	gimp_layer_new_from_drawable
 	gimp_layer_new_from_pixbuf
+	gimp_layer_new_from_surface
 	gimp_layer_new_from_visible
 	gimp_layer_remove_mask
 	gimp_layer_resize
diff --git a/libgimp/gimp.h b/libgimp/gimp.h
index 0814502..f97d7fc 100644
--- a/libgimp/gimp.h
+++ b/libgimp/gimp.h
@@ -21,6 +21,7 @@
 #ifndef __GIMP_H__
 #define __GIMP_H__
 
+#include <cairo.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
 #include <libgimpbase/gimpbase.h>
diff --git a/libgimp/gimplayer.c b/libgimp/gimplayer.c
index ded7e93..7b5f40c 100644
--- a/libgimp/gimplayer.c
+++ b/libgimp/gimplayer.c
@@ -27,6 +27,9 @@
 #undef __GIMP_LAYER_H__
 #include "gimplayer.h"
 
+#include "libgimpwidgets/gimpcairo-utils.h" /* eek */
+
+
 /**
  * gimp_layer_new:
  * @image_ID: The image to which to add the layer.
@@ -199,6 +202,160 @@ gimp_layer_new_from_pixbuf (gint32                image_ID,
 }
 
 /**
+ * gimp_layer_new_from_surface:
+ * @image_ID:        The RGB image to which to add the layer.
+ * @name:            The layer name.
+ * @cairo_surface_t: A Cairo image surface.
+ * @opacity:         The layer opacity.
+ * @mode:            The layer combination mode.
+ * @progress_start:  start of progress
+ * @progress_end:    end of progress
+ *
+ * Create a new layer from a #cairo_surface_t.
+ *
+ * This procedure creates a new layer from the given
+ * #cairo_surface_t. The image has to be an RGB image and just like
+ * with gimp_layer_new() you will still need to add the layer to it.
+ *
+ * If you pass @progress_end > @progress_start to this function,
+ * gimp_progress_update() will be called for. You have to call
+ * gimp_progress_init() beforehand then.
+ *
+ * Returns: The newly created layer.
+ *
+ * Since: GIMP 2.8
+ */
+gint32
+gimp_layer_new_from_surface (gint32                image_ID,
+                             const gchar          *name,
+                             cairo_surface_t      *surface,
+                             gdouble               opacity,
+                             GimpLayerModeEffects  mode,
+                             gdouble               progress_start,
+                             gdouble               progress_end)
+{
+  GimpDrawable    *drawable;
+  GimpPixelRgn	   rgn;
+  const guchar    *pixels;
+  gpointer         pr;
+  gint32           layer;
+  cairo_format_t   format;
+  gint             width;
+  gint             height;
+  gint             rowstride;
+  gdouble          range = progress_end - progress_start;
+  guint            count = 0;
+  guint            done  = 0;
+
+  g_return_val_if_fail (surface != NULL, -1);
+  g_return_val_if_fail (cairo_surface_get_type (surface) ==
+                        CAIRO_SURFACE_TYPE_IMAGE, -1);
+
+  if (gimp_image_base_type (image_ID) != GIMP_RGB)
+    {
+      g_warning ("gimp_layer_new_from_surface() needs an RGB image");
+      return -1;
+    }
+
+  width  = cairo_image_surface_get_width (surface);
+  height = cairo_image_surface_get_height (surface);
+  format = cairo_image_surface_get_format (surface);
+
+  if (format != CAIRO_FORMAT_ARGB32 &&
+      format != CAIRO_FORMAT_RGB24)
+    {
+      g_warning ("gimp_layer_new_from_surface() assumes that surface is RGB");
+      return -1;
+    }
+
+  layer = gimp_layer_new (image_ID, name, width, height,
+                          format == CAIRO_FORMAT_RGB24 ?
+                          GIMP_RGB_IMAGE : GIMP_RGBA_IMAGE,
+                          opacity, mode);
+
+  if (layer == -1)
+    return -1;
+
+  drawable = gimp_drawable_get (layer);
+
+  gimp_pixel_rgn_init (&rgn, drawable, 0, 0, width, height, TRUE, FALSE);
+
+  rowstride = cairo_image_surface_get_stride (surface);
+  pixels    = cairo_image_surface_get_data (surface);
+
+  for (pr = gimp_pixel_rgns_register (1, &rgn);
+       pr != NULL;
+       pr = gimp_pixel_rgns_process (pr))
+    {
+      const guchar *src  = pixels + rgn.y * rowstride + rgn.x * 4;
+      guchar       *dest = rgn.data;
+      gint          y;
+
+      switch (format)
+        {
+        case CAIRO_FORMAT_RGB24:
+          for (y = 0; y < rgn.h; y++)
+            {
+              const guchar *s = src;
+              guchar       *d = dest;
+              gint          w = rgn.w;
+
+              while (w--)
+                {
+                  GIMP_CAIRO_RGB24_GET_PIXEL (s, d[0], d[1], d[2]);
+
+                  s += 4;
+                  d += 3;
+                }
+
+              src  += rowstride;
+              dest += rgn.rowstride;
+            }
+          break;
+
+        case CAIRO_FORMAT_ARGB32:
+          for (y = 0; y < rgn.h; y++)
+            {
+              const guchar *s = src;
+              guchar       *d = dest;
+              gint          w = rgn.w;
+
+              while (w--)
+                {
+                  GIMP_CAIRO_ARGB32_GET_PIXEL (s, d[0], d[1], d[2], d[3]);
+
+                  s += 4;
+                  d += 4;
+                }
+
+              src  += rowstride;
+              dest += rgn.rowstride;
+            }
+          break;
+
+        default:
+          break;
+        }
+
+     if (range > 0.0)
+        {
+          done += rgn.h * rgn.w;
+
+          if (count++ % 32 == 0)
+            gimp_progress_update (progress_start +
+                                  (gdouble) done / (width * height) * range);
+        }
+    }
+
+  if (range > 0.0)
+    gimp_progress_update (progress_end);
+
+  gimp_drawable_detach (drawable);
+
+  return layer;
+}
+
+/**
  * gimp_layer_get_preserve_trans:
  * @layer_ID: The layer.
  *
diff --git a/libgimp/gimplayer.h b/libgimp/gimplayer.h
index fb1dcb4..22d4ad3 100644
--- a/libgimp/gimplayer.h
+++ b/libgimp/gimplayer.h
@@ -42,6 +42,13 @@ gint32   gimp_layer_new_from_pixbuf    (gint32                image_ID,
                                         GimpLayerModeEffects  mode,
                                         gdouble               progress_start,
                                         gdouble               progress_end);
+gint32   gimp_layer_new_from_surface   (gint32                image_ID,
+                                        const gchar          *name,
+                                        cairo_surface_t      *surface,
+                                        gdouble               opacity,
+                                        GimpLayerModeEffects  mode,
+                                        gdouble               progress_start,
+                                        gdouble               progress_end);
 
 
 #ifndef GIMP_DISABLE_DEPRECATED
diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am
index 22a392a..656d099 100644
--- a/plug-ins/common/Makefile.am
+++ b/plug-ins/common/Makefile.am
@@ -264,6 +264,7 @@ animation_optimize_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -295,6 +296,7 @@ antialias_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -343,6 +345,7 @@ blur_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -631,6 +634,7 @@ contrast_normalize_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -662,6 +666,7 @@ contrast_stretch_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -676,6 +681,7 @@ contrast_stretch_hsv_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -707,6 +713,7 @@ crop_auto_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -721,6 +728,7 @@ crop_zealous_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -922,6 +930,7 @@ edge_laplace_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -1039,6 +1048,7 @@ file_compressor_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -1070,6 +1080,7 @@ file_desktop_link_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -1120,6 +1131,7 @@ file_gif_load_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -1168,6 +1180,7 @@ file_glob_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -1216,6 +1229,7 @@ file_jp2_load_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(JP2_LIBS)		\
 	$(RT_LIBS)		\
@@ -1660,6 +1674,7 @@ gradient_map_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -1691,6 +1706,7 @@ guillotine_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -2201,6 +2217,7 @@ rotate_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -2252,6 +2269,7 @@ semi_flatten_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -2453,6 +2471,7 @@ tile_seamless_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
@@ -2518,6 +2537,7 @@ value_invert_LDADD = \
 	$(libgimpconfig)	\
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
diff --git a/plug-ins/common/mkgen.pl b/plug-ins/common/mkgen.pl
index 2cbd43b..060e741 100755
--- a/plug-ins/common/mkgen.pl
+++ b/plug-ins/common/mkgen.pl
@@ -139,7 +139,7 @@ foreach (sort keys %plugins) {
     if (exists $plugins{$_}->{ui}) {
 	$glib = "\$(GTK_LIBS)\t\t\\"
     } else {
-	$glib = "\$(GDK_PIXBUF_LIBS)\t\\"
+	$glib = "\$(CAIRO_LIBS)\t\t\\\n\t\$(GDK_PIXBUF_LIBS)\t\\"
     }
 
     my $optlib = "";
diff --git a/plug-ins/file-faxg3/Makefile.am b/plug-ins/file-faxg3/Makefile.am
index 7153ff4..cb9a919 100644
--- a/plug-ins/file-faxg3/Makefile.am
+++ b/plug-ins/file-faxg3/Makefile.am
@@ -30,6 +30,7 @@ file_faxg3_SOURCES = \
 
 INCLUDES = \
 	-I$(top_srcdir)		\
+	$(CAIRO_CFLAGS)		\
 	$(GDK_PIXBUF_CFLAGS)	\
 	-I$(includedir)
 
@@ -39,6 +40,7 @@ LDADD = \
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
 	$(libgimpmath)		\
+	$(CAIRO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\
 	$(INTLLIBS)		\
diff --git a/plug-ins/help/Makefile.am b/plug-ins/help/Makefile.am
index c81e290..c83d7e6 100644
--- a/plug-ins/help/Makefile.am
+++ b/plug-ins/help/Makefile.am
@@ -44,6 +44,7 @@ help_SOURCES = help.c
 
 INCLUDES = \
 	-I$(top_srcdir)		\
+	$(CAIRO_CFLAGS)		\
 	$(GIO_CFLAGS)		\
 	$(GDK_PIXBUF_CFLAGS)	\
 	-I$(includedir)
@@ -55,6 +56,7 @@ LDADD = \
 	$(libgimpcolor)		\
 	$(libgimpbase)		\
 	$(libgimpmath)		\
+	$(CAIRO_LIBS)		\
 	$(GIO_LIBS)		\
 	$(GDK_PIXBUF_LIBS)	\
 	$(RT_LIBS)		\



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