[lasem] build: remove gdk dependency.



commit 6e54523669bd03254c7a053fa7ceeb8887fb82cc
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Tue Mar 1 21:25:13 2011 +0100

    build: remove gdk dependency.
    
    The only function used in gdk was gdk_cairo_set_source_pixbuf. This
    commit imports the corresponding code, renamed lsm_cairo_set_source_pixbuf,
    and removes the dependency on gdk.

 configure.ac     |    1 -
 src/lsmcairo.c   |  107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/lsmcairo.h   |    5 +++
 src/lsmsvgview.c |    4 +-
 4 files changed, 114 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 2de885b..f8468a8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -40,7 +40,6 @@ PKG_CHECK_MODULES(LASEM, [gobject-2.0
 			  glib-2.0
 			  gio-2.0
 			  gdk-pixbuf-2.0 >= 2.16
-			  gdk-2.0 >= 2.16
 			  cairo >= 1.2
 			  pangocairo >= 1.16.0
 			  libxml-2.0])
diff --git a/src/lsmcairo.c b/src/lsmcairo.c
index 3ad34d9..e827db6 100644
--- a/src/lsmcairo.c
+++ b/src/lsmcairo.c
@@ -219,3 +219,110 @@ lsm_filter_fast_blur (LsmFilterSurface *input,
 	g_free (intermediate);
 }
 
+/**
+ * lsm_cairo_set_source_pixbuf:
+ * @cr: a cairo context
+ * @pixbuf: a #GdkPixbuf
+ * @pixbuf_x: X coordinate of location to place upper left corner of @pixbuf
+ * @pixbuf_y: Y coordinate of location to place upper left corner of @pixbuf
+ *
+ * Sets the given pixbuf as the source pattern for @cr.
+ *
+ * The pattern has an extend mode of %CAIRO_EXTEND_NONE and is aligned
+ * so that the origin of @pixbuf is @pixbuf_x, @pixbuf_y.
+ *
+ * Since: 0.4
+ */
+
+void
+lsm_cairo_set_source_pixbuf (cairo_t         *cr,
+                             const GdkPixbuf *pixbuf,
+                             gdouble          pixbuf_x,
+                             gdouble          pixbuf_y)
+{
+	gint width = gdk_pixbuf_get_width (pixbuf);
+	gint height = gdk_pixbuf_get_height (pixbuf);
+	guchar *gdk_pixels = gdk_pixbuf_get_pixels (pixbuf);
+	int gdk_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+	int n_channels = gdk_pixbuf_get_n_channels (pixbuf);
+	int cairo_stride;
+	guchar *cairo_pixels;
+	cairo_format_t format;
+	cairo_surface_t *surface;
+	static const cairo_user_data_key_t key;
+	int j;
+
+	if (n_channels == 3)
+		format = CAIRO_FORMAT_RGB24;
+	else
+		format = CAIRO_FORMAT_ARGB32;
+
+	cairo_stride = cairo_format_stride_for_width (format, width);
+	cairo_pixels = g_malloc (height * cairo_stride);
+	surface = cairo_image_surface_create_for_data ((unsigned char *)cairo_pixels,
+						       format,
+						       width, height, cairo_stride);
+
+	cairo_surface_set_user_data (surface, &key,
+				     cairo_pixels, (cairo_destroy_func_t)g_free);
+
+	for (j = height; j; j--)
+	{
+		guchar *p = gdk_pixels;
+		guchar *q = cairo_pixels;
+
+		if (n_channels == 3)
+		{
+			guchar *end = p + 3 * width;
+
+			while (p < end)
+			{
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+				q[0] = p[2];
+				q[1] = p[1];
+				q[2] = p[0];
+#else
+				q[1] = p[0];
+				q[2] = p[1];
+				q[3] = p[2];
+#endif
+				p += 3;
+				q += 4;
+			}
+		}
+		else
+		{
+			guchar *end = p + 4 * width;
+			guint t1,t2,t3;
+
+#define MULT(d,c,a,t) G_STMT_START { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } G_STMT_END
+
+			while (p < end)
+			{
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+				MULT(q[0], p[2], p[3], t1);
+				MULT(q[1], p[1], p[3], t2);
+				MULT(q[2], p[0], p[3], t3);
+				q[3] = p[3];
+#else
+				q[0] = p[3];
+				MULT(q[1], p[0], p[3], t1);
+				MULT(q[2], p[1], p[3], t2);
+				MULT(q[3], p[2], p[3], t3);
+#endif
+
+				p += 4;
+				q += 4;
+			}
+
+#undef MULT
+		}
+
+		gdk_pixels += gdk_rowstride;
+		cairo_pixels += cairo_stride;
+	}
+
+	cairo_set_source_surface (cr, surface, pixbuf_x, pixbuf_y);
+	cairo_surface_destroy (surface);
+}
+
diff --git a/src/lsmcairo.h b/src/lsmcairo.h
index 4b909db..1c157d9 100644
--- a/src/lsmcairo.h
+++ b/src/lsmcairo.h
@@ -26,6 +26,7 @@
 
 #include <lsmtypes.h>
 #include <cairo.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 
 G_BEGIN_DECLS
 
@@ -42,6 +43,10 @@ void 			lsm_filter_surface_free 		(LsmFilterSurface *filter_surface);
 void 			lsm_filter_fast_blur 			(LsmFilterSurface *input,
 								 LsmFilterSurface *output,
 								 double sx, double sy);
+void 			lsm_cairo_set_source_pixbuf 		(cairo_t         *cr,
+								 const GdkPixbuf *pixbuf,
+								 gdouble          pixbuf_x,
+								 gdouble          pixbuf_y);
 
 G_END_DECLS
 
diff --git a/src/lsmsvgview.c b/src/lsmsvgview.c
index b04441b..d821a6b 100644
--- a/src/lsmsvgview.c
+++ b/src/lsmsvgview.c
@@ -34,7 +34,7 @@
 #include <lsmsvgmaskelement.h>
 #include <lsmcairo.h>
 #include <lsmstr.h>
-#include <gdk/gdk.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 #include <glib/gprintf.h>
 
 #include <math.h>
@@ -1462,7 +1462,7 @@ lsm_svg_view_show_pixbuf (LsmSvgView *view, GdkPixbuf *pixbuf)
 	g_return_if_fail (LSM_IS_SVG_VIEW (view));
 	g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
 
-	gdk_cairo_set_source_pixbuf (view->dom_view.cairo, pixbuf, 0, 0);
+	lsm_cairo_set_source_pixbuf (view->dom_view.cairo, pixbuf, 0, 0);
 	cairo_paint (view->dom_view.cairo);
 }
 



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