diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2008-11-04 10:45:34 +0000 |
---|---|---|
committer | Chris Wilson <chris@chris-wilson.co.uk> | 2008-11-13 11:36:54 +0000 |
commit | a856371bef496da0e84226f4fd2fc3cb72e955ac (patch) | |
tree | 95f1f503c692a03aae722a28a44eb44c96143106 /test | |
parent | 47a56e08501ec9375f75c15e35a68c77b313ada4 (diff) |
Add CairoScript backend.
A new meta-surface backend for serialising drawing operations to a
CairoScript file. The principal use (as currently envisaged) is to provide
a round-trip testing mechanism for CairoScript - i.e. we can generate
script files for every test in the suite and check that we can replay them
with perfect fidelity. (Obviously this does not provide complete coverage
of CairoScript's syntax, but should give reasonable coverage over the
operators.)
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 4 | ||||
-rw-r--r-- | test/any2ppm.c | 87 | ||||
-rw-r--r-- | test/mime-data.script.ref.png | bin | 0 -> 1982 bytes |
3 files changed, 84 insertions, 7 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 131ed603..498f6161 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1170,10 +1170,10 @@ png_flatten_LDADD = $(top_builddir)/src/libcairo.la $(CAIRO_LDADD) if BUILD_ANY2PPM check_PROGRAMS += any2ppm -any2ppm_CFLAGS = $(POPPLER_CFLAGS) $(LIBRSVG_CFLAGS) $(LIBSPECTRE_CFLAGS) +any2ppm_CFLAGS = $(POPPLER_CFLAGS) $(LIBRSVG_CFLAGS) $(LIBSPECTRE_CFLAGS) $(csi_CFLAGS) # add LDADD, so poppler/librsvg uses "our" cairo any2ppm_LDFLAGS = $(CAIRO_TEST_UNDEFINED_LDFLAGS) -any2ppm_LDADD = $(top_builddir)/src/libcairo.la $(CAIRO_LDADD) $(POPPLER_LIBS) $(LIBRSVG_LIBS) $(LIBSPECTRE_LIBS) +any2ppm_LDADD = $(top_builddir)/src/libcairo.la $(CAIRO_LDADD) $(POPPLER_LIBS) $(LIBRSVG_LIBS) $(LIBSPECTRE_LIBS) $(csi_LIBS) endif if CAIRO_CAN_TEST_PDF_SURFACE diff --git a/test/any2ppm.c b/test/any2ppm.c index 85c1bdbb..1bd42858 100644 --- a/test/any2ppm.c +++ b/test/any2ppm.c @@ -63,6 +63,10 @@ #include <cairo.h> +#if CAIRO_CAN_TEST_SCRIPT_SURFACE +#include <cairo-script-interpreter.h> +#endif + #if CAIRO_CAN_TEST_PDF_SURFACE #include <poppler.h> #endif @@ -160,7 +164,21 @@ write_ppm (cairo_surface_t *surface, int fd) int width, height, stride; int i, j; + data = cairo_image_surface_get_data (surface); + height = cairo_image_surface_get_height (surface); + width = cairo_image_surface_get_width (surface); + stride = cairo_image_surface_get_stride (surface); format = cairo_image_surface_get_format (surface); + if (format == CAIRO_FORMAT_ARGB32) { + /* see if we can convert to a standard ppm type and trim a few bytes */ + cairo_bool_t uses_alpha = FALSE; + const unsigned char *alpha = data; + for (j = height * stride; j-- && uses_alpha == FALSE; alpha += 4) + uses_alpha = *alpha != 0xff; + if (! uses_alpha) + format = CAIRO_FORMAT_RGB24; + } + switch (format) { case CAIRO_FORMAT_ARGB32: /* XXX need true alpha for svg */ @@ -177,11 +195,6 @@ write_ppm (cairo_surface_t *surface, int fd) return "unhandled image format"; } - data = cairo_image_surface_get_data (surface); - height = cairo_image_surface_get_height (surface); - width = cairo_image_surface_get_width (surface); - stride = cairo_image_surface_get_stride (surface); - len = sprintf (buf, "%s %d %d 255\n", format_str, width, height); for (j = 0; j < height; j++) { const unsigned int *row = (unsigned int *) (data + stride * j); @@ -220,6 +233,69 @@ write_ppm (cairo_surface_t *surface, int fd) return NULL; } +#if CAIRO_CAN_TEST_SCRIPT_SURFACE +static cairo_surface_t * +_create_image (void *closure, + double width, double height, + csi_object_t *dictionary) +{ + cairo_surface_t **out = closure; + cairo_surface_t *surface; + + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); + return *out = cairo_surface_reference (surface); +} + +static const char * +_cairo_script_render_page (const char *filename, + cairo_surface_t **surface_out) +{ + cairo_script_interpreter_t *csi; + cairo_surface_t *surface = NULL; + cairo_status_t status; + + csi = csi_create (); + csi_set_surface_create_function (csi, _create_image, &surface); + csi_run (csi, filename); + status = csi_destroy (csi); + if (status || surface == NULL) { + cairo_surface_destroy (surface); + return "cairo-script interpreter failed"; + } + + status = cairo_surface_status (surface); + if (status) { + cairo_surface_destroy (surface); + return cairo_status_to_string (status); + } + + *surface_out = surface; + return NULL; +} + +static const char * +cs_convert (char **argv, int fd) +{ + const char *err; + cairo_surface_t *surface = NULL; /* silence compiler warning */ + + err = _cairo_script_render_page (argv[0], &surface); + if (err != NULL) + return err; + + err = write_ppm (surface, fd); + cairo_surface_destroy (surface); + + return err; +} +#else +static const char * +cs_convert (char **argv, int fd) +{ + return "compiled without CairoScript support."; +} +#endif + #if CAIRO_CAN_TEST_PDF_SURFACE /* adapted from pdf2png.c */ static const char * @@ -453,6 +529,7 @@ convert (char **argv, int fd) const char *type; const char *(*func) (char **, int); } converters[] = { + { "cs", cs_convert }, { "pdf", pdf_convert }, { "ps", ps_convert }, { "svg", svg_convert }, diff --git a/test/mime-data.script.ref.png b/test/mime-data.script.ref.png Binary files differnew file mode 100644 index 00000000..a236b044 --- /dev/null +++ b/test/mime-data.script.ref.png |