[librsvg] pixbuf-loader: Add loader test



commit 077c902542d580ca12cbcf9cfce1c0cd0eda17e5
Author: Christian Persch <chpe gnome org>
Date:   Mon Nov 7 14:54:19 2011 +0100

    pixbuf-loader: Add loader test

 gdk-pixbuf-loader/Makefile.am |   29 +++++++++++++
 gdk-pixbuf-loader/test.c      |   89 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 118 insertions(+), 0 deletions(-)
---
diff --git a/gdk-pixbuf-loader/Makefile.am b/gdk-pixbuf-loader/Makefile.am
index ed68a3f..06ce6c8 100644
--- a/gdk-pixbuf-loader/Makefile.am
+++ b/gdk-pixbuf-loader/Makefile.am
@@ -1,5 +1,7 @@
 if ENABLE_PIXBUF_LOADER
 
+NULL =
+
 gdk_pixbuf_module_LTLIBRARIES = libpixbufloader-svg.la
 
 libpixbufloader_svg_la_SOURCES = \
@@ -32,10 +34,37 @@ if PLATFORM_WIN32
 libpixbufloader_svg_la_LDFLAGS += -no-undefined
 endif
 
+noinst_PROGRAMS = rsvg-loader
+
+rsvg_loader_SOURCES = \
+	test.c \
+	(NULL)
+rsvg_loader_CPPFLAGS = \
+	$(AM_CPPFLAGS)
+rsvg_loader_CFLAGS = \
+	$(GDK_PIXBUF_CFLAGS) \
+	$(AM_CFLAGS)
+rsvg_loader_LDFLAGS = \
+	$(AM_LDFLAGS)
+rsvg_loader_LDADD = \
+	$(GDK_PIXBUF_LIBS)
+rsvg_loader_DEPENDENCIES = libpixbufloader-svg.la gdk-pixbuf-loaders
+
+gdk-pixbuf-loaders: Makefile
+	$(AM_V_GEN) ( $(GDK_PIXBUF_QUERYLOADERS) ./libpixbufloader-svg.la && $(GDK_PIXBUF_QUERYLOADERS)) > gdk-pixbuf.loaders 2>/dev/null
+
 install-data-hook:
 	if test -z "$(DESTDIR)"; then \
 		$(mkinstalldirs) $(DESTDIR)$(gdk_pixbuf_binarydir) ; \
 		$(GDK_PIXBUF_QUERYLOADERS) > $(DESTDIR)$(gdk_pixbuf_cache_file) ; \
 	fi
 
+CLEANFILES = \
+	gdk-pixbuf.loaders \
+	$(NULL)
+
+DISTCLEANFILES = \
+	gdk-pixbuf.loaders \
+	$(NULL)
+
 endif # ENABLE_PIXBUF_LOADER
diff --git a/gdk-pixbuf-loader/test.c b/gdk-pixbuf-loader/test.c
new file mode 100644
index 0000000..efb6949
--- /dev/null
+++ b/gdk-pixbuf-loader/test.c
@@ -0,0 +1,89 @@
+/*
+   Copyright  2011 Christian Persch
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public License as
+   published by the Free Software Foundation; either version 2.1 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this program; if not, write to the
+   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.
+*/
+
+#include "config.h"
+
+#include <locale.h>
+
+#include <glib.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+int
+main (int argc, char **argv)
+{
+    GOptionContext *context;
+    int width = -1;
+    int height = -1;
+    char **args = NULL;
+    GdkPixbuf *pixbuf = NULL;
+    GError *error = NULL;
+    int ret = 1;
+
+    GOptionEntry options_table[] = {
+        { "width", 'w', 0, G_OPTION_ARG_INT, &width,
+          "width [optional; defaults to the SVG's width]", "WIDTH" },
+        { "height", 'h', 0, G_OPTION_ARG_INT, &height,
+          "height [optional; defaults to the SVG's height]", "HEIGHT" },
+        { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL, "INPUT-FILE OUTPUT-FILE" },
+        { NULL }
+    };
+
+    setlocale(LC_ALL, "");
+
+    /* Use the locally built rsvg loader, not the system one */
+    g_setenv ("GDK_PIXBUF_MODULE_FILE", "./gdk-pixbuf.loaders", TRUE);
+
+    g_type_init ();
+
+    context = g_option_context_new ("- Pixbuf Test Loader");
+    g_option_context_add_main_entries (context, options_table, NULL);
+    g_option_context_parse (context, &argc, &argv, &error);
+    g_option_context_free (context);
+    if (error)
+      goto done;
+
+    if (args == NULL || g_strv_length (args) != 2) {
+        g_printerr ("Need to specify input and output filenames\n");
+        goto done;
+    }
+
+    pixbuf = gdk_pixbuf_new_from_file_at_size (args[0], width, height, &error);
+    if (pixbuf == NULL)
+      goto done;
+
+    if (!gdk_pixbuf_save (pixbuf, args[1], "png", &error, NULL))
+      goto done;
+
+    /* Success! */
+    ret = 0;
+
+  done:
+
+    if (error) {
+      g_printerr ("Error: %s\n", error->message);
+      g_error_free (error);
+    }
+
+    if (pixbuf)
+      g_object_unref (pixbuf);
+
+    g_strfreev (args);
+
+    return ret;
+}



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