[cairo-commit] 3 commits - AUTHORS configure.ac src/cairo-pattern.c test/any2ppm.c test/Makefile.am test/ps2png.c
Chris Wilson
ickle at kemper.freedesktop.org
Thu Oct 9 04:28:34 PDT 2008
AUTHORS | 1
configure.ac | 21 +++++++--
src/cairo-pattern.c | 1
test/Makefile.am | 12 ++++-
test/any2ppm.c | 73 ++++++++++++++++++++++++++++++++-
test/ps2png.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 212 insertions(+), 9 deletions(-)
New commits:
commit 8ac8e8c523abaa5db24c5303c671ff3487bf0801
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date: Sun Sep 21 14:29:30 2008 +0200
[test] Add ps2png check program using libspectre
Add a simple program to compliment pdf2png and svg2png.
diff --git a/configure.ac b/configure.ac
index a3daae7..5545fb1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -357,6 +357,7 @@ if test "x$use_ps" = "xyes"; then
fi
AM_CONDITIONAL(CAIRO_CAN_TEST_PS_SURFACE, test "x$test_ps" = "xyes")
+AM_CONDITIONAL(BUILD_PS2PNG, test "x$any2ppm_ps" = "xyes")
AC_SUBST(LIBSPECTRE_CFLAGS)
AC_SUBST(LIBSPECTRE_LIBS)
diff --git a/test/Makefile.am b/test/Makefile.am
index 8790a90..583276e 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1094,6 +1094,14 @@ svg2png_LDFLAGS = $(CAIRO_TEST_UNDEFINED_LDFLAGS)
svg2png_LDADD = $(LDADD) $(LIBRSVG_LIBS)
endif
+if BUILD_PS2PNG
+check_PROGRAMS += ps2png
+ps2png_CFLAGS = $(LIBSPECTRE_CFLAGS)
+# add LDADD, so ps2png uses "our" cairo
+ps2png_LDFLAGS = $(CAIRO_TEST_UNDEFINED_LDFLAGS)
+ps2png_LDADD = $(LDADD) $(LIBSPECTRE_LIBS)
+endif
+
EXTRA_PROGRAMS += $(TESTS) $(DISABLED_TESTS)
# Do a funny transition of CAIRO_TEST_TARGET through TARGETS such that
diff --git a/test/ps2png.c b/test/ps2png.c
new file mode 100644
index 0000000..cf98aed
--- /dev/null
+++ b/test/ps2png.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright © 2008 Carlos Garcia Campos
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Carlos Garcia Campos <carlosgc at gnome.org>
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <cairo.h>
+#include <libspectre/spectre.h>
+
+#define FAIL(msg) \
+ do { fprintf (stderr, "FAIL: %s\n", msg); exit (-1); } while (0)
+
+static const char *
+_spectre_render_page (const char *filename,
+ const char *page_label,
+ cairo_surface_t **surface_out)
+{
+ static const cairo_user_data_key_t key;
+
+ SpectreDocument *document;
+ SpectreStatus status;
+ int width, height, stride;
+ unsigned char *pixels;
+ cairo_surface_t *surface;
+
+ document = spectre_document_new ();
+ spectre_document_load (document, filename);
+ status = spectre_document_status (document);
+ if (status) {
+ spectre_document_free (document);
+ return spectre_status_to_string (status);
+ }
+
+ if (page_label) {
+ SpectrePage *page;
+ SpectreRenderContext *rc;
+
+ page = spectre_document_get_page_by_label (document, page_label);
+ spectre_document_free (document);
+ if (page == NULL)
+ return "page not found";
+
+ spectre_page_get_size (page, &width, &height);
+ rc = spectre_render_context_new ();
+ spectre_render_context_set_page_size (rc, width, height);
+ spectre_page_render (page, rc, &pixels, &stride);
+ spectre_render_context_free (rc);
+ status = spectre_page_status (page);
+ spectre_page_free (page);
+ if (status) {
+ free (pixels);
+ return spectre_status_to_string (status);
+ }
+ } else {
+ spectre_document_get_page_size (document, &width, &height);
+ spectre_document_render (document, &pixels, &stride);
+ spectre_document_free (document);
+ }
+
+ surface = cairo_image_surface_create_for_data (pixels,
+ CAIRO_FORMAT_RGB24,
+ width, height,
+ stride);
+ cairo_surface_set_user_data (surface, &key,
+ pixels, (cairo_destroy_func_t) free);
+ *surface_out = surface;
+ return NULL;
+}
+
+int main
+(int argc, char *argv[])
+{
+ const char *err;
+ cairo_surface_t *surface = NULL; /* silence compiler warning */
+ cairo_status_t status;
+
+ if (argc < 3 || argc > 4)
+ FAIL ("usage: ps2png input_file.ps output_file.png [page]");
+
+ err = _spectre_render_page (argv[1], argv[3], &surface);
+ if (err != NULL)
+ FAIL (err);
+
+ status = cairo_surface_write_to_png (surface, argv[2]);
+ cairo_surface_destroy (surface);
+
+ if (status != CAIRO_STATUS_SUCCESS)
+ FAIL (cairo_status_to_string (status));
+
+ return 0;
+}
commit 3e6afb353da1fee624b519f5a96b3303c7eb91ae
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date: Thu Oct 9 12:11:51 2008 +0100
[test/any2ppm] Enable PS conversion using libspectre.
Complete the vector trilogy using libspectre to provide a similar
interface (to poppler and librsvg) around GhostScript.
diff --git a/AUTHORS b/AUTHORS
index b922060..488f4c0 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -9,6 +9,7 @@ Christian Biesinger <cbiesinger at web.de> BeOS backend
Billy Biggs <vektor at dumbterm.net> Pixman code merge. Optimization. Fixes for subtle rendering bugs.
Hans Breuer <hans at breuer.org> win32 bug fixes, build fixes, and improvements
Brian Cameron <brian.cameron at sun.com> Flag bug in Sun's X server
+Carlos Garcia Campos <carlosgc at gnome.org> libspectre integration into the test-suite
Damien Carbery <damien.carbery at sun.com> Build fixes
Andrew Chant <andrew.chant at utoronto.ca> Adding const where needed
Steve Chaplin <stevech1097 at yahoo.com.au> Bug fixes for PNG reading
diff --git a/configure.ac b/configure.ac
index 2c5c4df..a3daae7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -337,7 +337,9 @@ CAIRO_ENABLE_SURFACE_BACKEND(ps, PostScript, yes, [
dnl ===========================================================================
+SPECTRE_VERSION_REQUIRED=0.2.0
test_ps=no
+any2ppm_ps=no
if test "x$use_ps" = "xyes"; then
AC_CHECK_PROG(GS, gs, gs)
if test "$GS"; then
@@ -347,9 +349,16 @@ if test "x$use_ps" = "xyes"; then
AC_MSG_WARN([PS backend will not be tested since ghostscript is not available])
test_ps="no (requires ghostscript)"
fi
+
+ libspectre_DEPENDENCY="libspectre >= $SPECTRE_VERSION_REQUIRED"
+ PKG_CHECK_MODULES(LIBSPECTRE, $libspectre_DEPENDENCY,
+ [any2ppm_ps=yes],
+ [AC_MSG_RESULT(no)])
fi
AM_CONDITIONAL(CAIRO_CAN_TEST_PS_SURFACE, test "x$test_ps" = "xyes")
+AC_SUBST(LIBSPECTRE_CFLAGS)
+AC_SUBST(LIBSPECTRE_LIBS)
dnl ===========================================================================
@@ -365,11 +374,12 @@ dnl ===========================================================================
# enhancement not to gobble nearly 1GiB of memory during test/large-font.
POPPLER_VERSION_REQUIRED=0.9.2
test_pdf=no
+any2ppm_pdf=no
if test "x$use_pdf" = "xyes"; then
poppler_DEPENDENCY="poppler-glib >= $POPPLER_VERSION_REQUIRED"
PKG_CHECK_MODULES(POPPLER, $poppler_DEPENDENCY pango gtk+-2.0,
[CAIRO_CHECK_FUNCS_WITH_FLAGS(poppler_page_render, [$POPPLER_CFLAGS], [$POPPLER_LIBS],
- [test_pdf=yes],
+ [test_pdf=yes; any2ppm_pdf=yes],
[AC_MSG_RESULT(no); test_pdf="no (requires $poppler_DEPENDENCY)"])],
[AC_MSG_RESULT(no); test_pdf="no (requires $poppler_DEPENDENCY)"])
if test "x$test_pdf" = "xyes"; then
@@ -395,11 +405,12 @@ CAIRO_ENABLE_SURFACE_BACKEND(svg, SVG, yes, [
LIBRSVG_VERSION_REQUIRED=2.15.0
test_svg=no
+any2ppm_svg=no
if test "x$use_svg" = "xyes"; then
librsvg_DEPENDENCY="librsvg-2.0 >= $LIBRSVG_VERSION_REQUIRED"
PKG_CHECK_MODULES(LIBRSVG, $librsvg_DEPENDENCY gdk-2.0,
[CAIRO_CHECK_FUNCS_WITH_FLAGS(rsvg_pixbuf_from_file, [$LIBRSVG_CFLAGS], [$LIBRSVG_LIBS],
- [test_svg=yes],
+ [test_svg=yes; any2ppm_svg=yes],
[AC_MSG_RESULT(no); test_svg="no (requires $librsvg_DEPENDENCY)"])],
[AC_MSG_RESULT(no); test_svg="no (requires $librsvg_DEPENDENCY)"])
if test "x$test_svg" = "xyes"; then
@@ -436,8 +447,9 @@ CAIRO_ENABLE_FONT_BACKEND(user, user, always)
dnl ===========================================================================
dnl Build the external converter if we have any of the test backends
AM_CONDITIONAL(BUILD_ANY2PPM,
- test "x$test_svg" = "xyes" \
- -o "x$test_pdf" = "xyes" ) # -o "x$test_ps" = "xyes")
+ test "x$any2ppm_svg" = "xyes" \
+ -o "x$any2ppm_pdf" = "xyes" \
+ -o "x$any2ppm_ps" = "xyes")
dnl ===========================================================================
diff --git a/test/Makefile.am b/test/Makefile.am
index 339bc18..8790a90 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1072,10 +1072,10 @@ check_PROGRAMS += imagediff png-flatten
if BUILD_ANY2PPM
check_PROGRAMS += any2ppm
-any2ppm_CFLAGS = $(POPPLER_CFLAGS) $(LIBRSVG_CFLAGS)
+any2ppm_CFLAGS = $(POPPLER_CFLAGS) $(LIBRSVG_CFLAGS) $(LIBSPECTRE_CFLAGS)
# add LDADD, so poppler/librsvg uses "our" cairo
any2ppm_LDFLAGS = $(CAIRO_TEST_UNDEFINED_LDFLAGS)
-any2ppm_LDADD = $(LDADD) $(POPPLER_LIBS) $(LIBRSVG_LIBS)
+any2ppm_LDADD = $(LDADD) $(POPPLER_LIBS) $(LIBRSVG_LIBS) $(LIBSPECTRE_LIBS)
endif
if CAIRO_CAN_TEST_PDF_SURFACE
diff --git a/test/any2ppm.c b/test/any2ppm.c
index 412bbb8..36c742f 100644
--- a/test/any2ppm.c
+++ b/test/any2ppm.c
@@ -22,6 +22,9 @@
*
* Author: Chris Wilson <chris at chris-wilson.co.uk>
*
+ * Contributor(s):
+ * Carlos Garcia Campos <carlosgc at gnome.org>
+ *
* Adapted from pdf2png.c:
* Copyright © 2005 Red Hat, Inc.
*
@@ -70,6 +73,7 @@
#endif
#if CAIRO_CAN_TEST_PS_SURFACE
+#include <libspectre/spectre.h>
#endif
#if HAVE_FCNTL_H && HAVE_SIGNAL_H && HAVE_SYS_STAT_H && HAVE_SYS_SOCKET_H && HAVE_SYS_POLL_H && HAVE_SYS_UN_H
@@ -347,11 +351,76 @@ svg_convert (char **argv, int fd)
#if CAIRO_CAN_TEST_PS_SURFACE
static const char *
+_spectre_render_page (const char *filename,
+ const char *page_label,
+ cairo_surface_t **surface_out)
+{
+ static const cairo_user_data_key_t key;
+
+ SpectreDocument *document;
+ SpectreStatus status;
+ int width, height, stride;
+ unsigned char *pixels;
+ cairo_surface_t *surface;
+
+ document = spectre_document_new ();
+ spectre_document_load (document, filename);
+ status = spectre_document_status (document);
+ if (status) {
+ spectre_document_free (document);
+ return spectre_status_to_string (status);
+ }
+
+ if (page_label) {
+ SpectrePage *page;
+ SpectreRenderContext *rc;
+
+ page = spectre_document_get_page_by_label (document, page_label);
+ spectre_document_free (document);
+ if (page == NULL)
+ return "page not found";
+
+ spectre_page_get_size (page, &width, &height);
+ rc = spectre_render_context_new ();
+ spectre_render_context_set_page_size (rc, width, height);
+ spectre_page_render (page, rc, &pixels, &stride);
+ spectre_render_context_free (rc);
+ status = spectre_page_status (page);
+ spectre_page_free (page);
+ if (status) {
+ free (pixels);
+ return spectre_status_to_string (status);
+ }
+ } else {
+ spectre_document_get_page_size (document, &width, &height);
+ spectre_document_render (document, &pixels, &stride);
+ spectre_document_free (document);
+ }
+
+ surface = cairo_image_surface_create_for_data (pixels,
+ CAIRO_FORMAT_RGB24,
+ width, height,
+ stride);
+ cairo_surface_set_user_data (surface, &key,
+ pixels, (cairo_destroy_func_t) free);
+ *surface_out = surface;
+ return NULL;
+}
+
+static const char *
ps_convert (char **argv, int fd)
{
- /* XXX libspectre */
+ const char *err;
+ cairo_surface_t *surface = NULL; /* silence compiler warning */
- return "no method to convert PS";
+ err = _spectre_render_page (argv[0], argv[1], &surface);
+ if (err != NULL)
+ return err;
+
+ err = write_ppm (surface, fd);
+ cairo_surface_destroy (surface);
+
+ return err;
}
#endif
commit ddd1615a1777181c6e8db1dbafacb68535ed163a
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Oct 8 23:13:03 2008 +0100
[pattern] Remove incorrect assert.
It's possible to reach that point without setting the filter to NEAREST,
for example if using FAST or GAUSSIAN.
diff --git a/src/cairo-pattern.c b/src/cairo-pattern.c
index 16c3dc9..b2b1c60 100644
--- a/src/cairo-pattern.c
+++ b/src/cairo-pattern.c
@@ -1745,7 +1745,6 @@ _cairo_pattern_acquire_surface_for_surface (cairo_surface_pattern_t *pattern,
cairo_matrix_init_identity (&attr->matrix);
attr->x_offset = tx;
attr->y_offset = ty;
- assert (attr->filter == CAIRO_FILTER_NEAREST);
}
else
{
More information about the cairo-commit
mailing list