[gimp/goat-invasion: 475/608] app: add gimp_cairo_image_surface_create_buffer()



commit 2168e9fb351240af965d6647d76f8b650116ee5c
Author: Michael Natterer <mitch gimp org>
Date:   Tue Apr 10 13:08:02 2012 +0200

    app: add gimp_cairo_image_surface_create_buffer()
    
    and use it to shrink text layer rendering to even fewer lines.

 app/Makefile.am          |   13 +++++++------
 app/core/gimp-cairo.c    |   28 ++++++++++++++++++++++++++++
 app/core/gimp-cairo.h    |   26 ++++++++++++++------------
 app/text/gimptextlayer.c |   10 +++-------
 4 files changed, 52 insertions(+), 25 deletions(-)
---
diff --git a/app/Makefile.am b/app/Makefile.am
index ee6e66d..15dd262 100644
--- a/app/Makefile.am
+++ b/app/Makefile.am
@@ -135,10 +135,12 @@ workaround_that_file_depends_on_plug_in = \
 # core, vectors and gegl are on the same architectural layer, prevent
 # the linker from panicing
 calm_down_linker = \
-	-u $(SYMPREFIX)gimp_vectors_undo_get_type	\
-	-u $(SYMPREFIX)gimp_vectors_mod_undo_get_type	\
-	-u $(SYMPREFIX)gimp_vectors_prop_undo_get_type	\
-	-u $(SYMPREFIX)gimp_curve_map_pixels
+	-u $(SYMPREFIX)gimp_vectors_undo_get_type		\
+	-u $(SYMPREFIX)gimp_vectors_mod_undo_get_type		\
+	-u $(SYMPREFIX)gimp_vectors_prop_undo_get_type		\
+	-u $(SYMPREFIX)gimp_curve_map_pixels			\
+	-u $(SYMPREFIX)gimp_cairo_image_surface_create_buffer	\
+	-u $(SYMPREFIX)gimp_param_spec_duplicate
 
 AM_LDFLAGS = \
 	$(munix)					\
@@ -147,8 +149,7 @@ AM_LDFLAGS = \
 	$(workaround_that_core_depends_on_xcf)		\
 	$(workaround_that_core_depends_on_pdb)		\
 	$(workaround_that_plug_in_depends_on_pdb)	\
-	$(workaround_that_file_depends_on_plug_in)	\
-	-u $(SYMPREFIX)gimp_param_spec_duplicate
+	$(workaround_that_file_depends_on_plug_in)
 
 gimpconsoleldadd = \
 	xcf/libappxcf.a			\
diff --git a/app/core/gimp-cairo.c b/app/core/gimp-cairo.c
index 3bcdd93..0ecb6c7 100644
--- a/app/core/gimp-cairo.c
+++ b/app/core/gimp-cairo.c
@@ -36,6 +36,34 @@
 static cairo_user_data_key_t surface_data_key = { 0, };
 
 
+GeglBuffer *
+gimp_cairo_image_surface_create_buffer (cairo_surface_t *surface)
+{
+  const Babl *format;
+  gint        width;
+  gint        height;
+
+  g_return_val_if_fail (surface != NULL, NULL);
+  g_return_val_if_fail (cairo_surface_get_type (surface) ==
+                        CAIRO_SURFACE_TYPE_IMAGE, NULL);
+
+  width  = cairo_image_surface_get_width  (surface);
+  height = cairo_image_surface_get_height (surface);
+
+  if (cairo_surface_get_content (surface) == CAIRO_CONTENT_COLOR_ALPHA)
+    format = babl_format ("cairo-ARGB32");
+  else
+    format = babl_format ("cairo-RGB24");
+
+  return
+    gegl_buffer_linear_new_from_data (cairo_image_surface_get_data (surface),
+                                      format,
+                                      GEGL_RECTANGLE (0, 0, width, height),
+                                      cairo_image_surface_get_stride (surface),
+                                      (GDestroyNotify) cairo_surface_destroy,
+                                      cairo_surface_reference (surface));
+}
+
 cairo_pattern_t *
 gimp_cairo_stipple_pattern_create (const GimpRGB *fg,
                                    const GimpRGB *bg,
diff --git a/app/core/gimp-cairo.h b/app/core/gimp-cairo.h
index 140369d..642c8d7 100644
--- a/app/core/gimp-cairo.h
+++ b/app/core/gimp-cairo.h
@@ -25,19 +25,21 @@
 #define __GIMP_CAIRO_H__
 
 
-cairo_pattern_t * gimp_cairo_stipple_pattern_create (const GimpRGB *fg,
-                                                     const GimpRGB *bg,
-                                                     gint           index);
+GeglBuffer      * gimp_cairo_image_surface_create_buffer (cairo_surface_t *surface);
 
-void              gimp_cairo_add_arc                (cairo_t       *cr,
-                                                     gdouble        center_x,
-                                                     gdouble        center_y,
-                                                     gdouble        radius,
-                                                     gdouble        start_angle,
-                                                     gdouble        slice_angle);
-void              gimp_cairo_add_segments           (cairo_t       *cr,
-                                                     GimpSegment   *segs,
-                                                     gint           n_segs);
+cairo_pattern_t * gimp_cairo_stipple_pattern_create      (const GimpRGB   *fg,
+                                                          const GimpRGB   *bg,
+                                                          gint             index);
+
+void              gimp_cairo_add_arc                     (cairo_t         *cr,
+                                                          gdouble          center_x,
+                                                          gdouble          center_y,
+                                                          gdouble          radius,
+                                                          gdouble          start_angle,
+                                                          gdouble          slice_angle);
+void              gimp_cairo_add_segments                (cairo_t         *cr,
+                                                          GimpSegment     *segs,
+                                                          gint             n_segs);
 
 
 #endif /* __GIMP_CAIRO_H__ */
diff --git a/app/text/gimptextlayer.c b/app/text/gimptextlayer.c
index c0aff8d..10299f3 100644
--- a/app/text/gimptextlayer.c
+++ b/app/text/gimptextlayer.c
@@ -36,6 +36,7 @@
 #include "gegl/gimp-gegl-utils.h"
 
 #include "core/gimp.h"
+#include "core/gimp-cairo.h"
 #include "core/gimp-utils.h"
 #include "core/gimpcontext.h"
 #include "core/gimpcontainer.h"
@@ -670,18 +671,13 @@ gimp_text_layer_render_layout (GimpTextLayer  *layer,
 
   cairo_surface_flush (surface);
 
-  buffer =
-    gegl_buffer_linear_new_from_data (cairo_image_surface_get_data (surface),
-                                      babl_format ("cairo-ARGB32"),
-                                      GEGL_RECTANGLE (0, 0, width, height),
-                                      cairo_image_surface_get_stride (surface),
-                                      (GDestroyNotify) cairo_surface_destroy,
-                                      surface);
+  buffer = gimp_cairo_image_surface_create_buffer (surface);
 
   gegl_buffer_copy (buffer, NULL,
                     gimp_drawable_get_buffer (drawable), NULL);
 
   g_object_unref (buffer);
+  cairo_surface_destroy (surface);
 
   gimp_drawable_update (drawable, 0, 0, width, height);
 }



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