[cairo-commit] 4 commits - boilerplate/cairo-boilerplate.c src/cairo-script-surface.c test/any2ppm.c test/mime-data.script.ref.png test/scale-offset-image.c test/scale-offset-similar.c util/cairo-script
Chris Wilson
ickle at kemper.freedesktop.org
Sat Jul 4 10:47:30 PDT 2009
boilerplate/cairo-boilerplate.c | 13 ++++----
src/cairo-script-surface.c | 45 +++++++++++++++++++------------
test/any2ppm.c | 15 +++++++++-
test/mime-data.script.ref.png |binary
test/scale-offset-image.c | 2 -
test/scale-offset-similar.c | 2 -
util/cairo-script/cairo-script-scanner.c | 6 ++--
7 files changed, 56 insertions(+), 27 deletions(-)
New commits:
commit 8a10ab1c04298d6c22ae8aabec5d762141a8e98f
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sat Jul 4 18:46:21 2009 +0100
[script] Tidy dict construction for glyphs
Replace dict with '<< ... >>' similar to surface definitions as it is
easier to read in scripts.
diff --git a/src/cairo-script-surface.c b/src/cairo-script-surface.c
index 8212e17..d232767 100644
--- a/src/cairo-script-surface.c
+++ b/src/cairo-script-surface.c
@@ -2185,8 +2185,8 @@ _emit_scaled_glyph_vector (cairo_script_surface_t *surface,
scaled_glyph->surface_private = (void *) index;
_cairo_output_stream_printf (surface->ctx->stream,
- "%lu dict\n"
- " /metrics [%f %f %f %f %f %f] set\n"
+ "%lu <<\n"
+ " /metrics [%f %f %f %f %f %f]\n"
" /render {\n",
index,
scaled_glyph->fs_metrics.x_bearing,
@@ -2213,7 +2213,7 @@ _emit_scaled_glyph_vector (cairo_script_surface_t *surface,
&surface->base);
surface->cr = old_cr;
- _cairo_output_stream_puts (surface->ctx->stream, "} set set\n");
+ _cairo_output_stream_puts (surface->ctx->stream, "} >> set\n");
return status;
}
@@ -2232,8 +2232,8 @@ _emit_scaled_glyph_bitmap (cairo_script_surface_t *surface,
scaled_glyph->surface_private = (void *) index;
_cairo_output_stream_printf (surface->ctx->stream,
- "%lu dict\n"
- " /metrics [%f %f %f %f %f %f] set\n"
+ "%lu <<\n"
+ " /metrics [%f %f %f %f %f %f]\n"
" /render {\n"
"%f %f translate\n",
index,
@@ -2261,7 +2261,7 @@ _emit_scaled_glyph_bitmap (cairo_script_surface_t *surface,
scaled_font->font_matrix.y0);
}
_cairo_output_stream_puts (surface->ctx->stream,
- "mask\n} set set\n");
+ "mask\n} >> set\n");
return CAIRO_STATUS_SUCCESS;
}
commit fef3649953a3dcc3a17d9d5858f56690a8782501
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sat Jul 4 18:32:57 2009 +0100
[script] Fix the trivial errors running the test suite
A few typos crept in breaking the script output and various refreshes of
the expected results.
diff --git a/src/cairo-script-surface.c b/src/cairo-script-surface.c
index b2388d9..8212e17 100644
--- a/src/cairo-script-surface.c
+++ b/src/cairo-script-surface.c
@@ -363,7 +363,7 @@ _get_target (cairo_script_surface_t *surface)
_cairo_output_stream_printf (ctx->stream, "s%ld ", surface->id);
} else {
_cairo_output_stream_printf (ctx->stream, "%d index ", depth);
- _cairo_output_stream_puts (ctx->stream, "get-target exch pop ");
+ _cairo_output_stream_puts (ctx->stream, "/target get exch pop ");
}
} else {
if (depth == 1) {
@@ -374,11 +374,11 @@ _get_target (cairo_script_surface_t *surface)
"%d -1 roll\n",
depth);
}
- _cairo_output_stream_puts (ctx->stream, "get-target ");
+ _cairo_output_stream_puts (ctx->stream, "/target get ");
target_push (surface);
}
} else
- _cairo_output_stream_puts (ctx->stream, "get-target ");
+ _cairo_output_stream_puts (ctx->stream, "/target get ");
}
static cairo_status_t
@@ -1028,7 +1028,7 @@ _emit_png_surface (cairo_script_surface_t *surface,
if (unlikely (status))
return status;
- _cairo_output_stream_puts (surface->ctx->stream, " >> image");
+ _cairo_output_stream_puts (surface->ctx->stream, " >> image ");
return CAIRO_STATUS_SUCCESS;
}
@@ -1046,20 +1046,31 @@ _emit_image_surface (cairo_script_surface_t *surface,
if (_cairo_status_is_error (status)) {
return status;
} else if (status == CAIRO_INT_STATUS_UNSUPPORTED) {
+ cairo_image_surface_t *clone;
+
+ if (image->format == CAIRO_FORMAT_INVALID) {
+ clone =
+ _cairo_image_surface_coerce (image,
+ _cairo_format_from_content (image->base.content));
+ } else {
+ clone = (cairo_image_surface_t *)
+ cairo_surface_reference (&image->base);
+ }
+
_cairo_output_stream_printf (surface->ctx->stream,
"<< "
"/width %d "
"/height %d "
"/format //%s "
"/source <~",
- image->width, image->height,
- _format_to_string (image->format));
+ clone->width, clone->height,
+ _format_to_string (clone->format));
- if (image->width * image->height > 8) {
+ if (clone->width * clone->height > 8) {
base85_stream = _cairo_base85_stream_create (surface->ctx->stream);
zlib_stream = _cairo_deflate_stream_create (base85_stream);
- status = _write_image_surface (zlib_stream, image);
+ status = _write_image_surface (zlib_stream, clone);
status2 = _cairo_output_stream_destroy (zlib_stream);
if (status == CAIRO_STATUS_SUCCESS)
@@ -1071,10 +1082,10 @@ _emit_image_surface (cairo_script_surface_t *surface,
return status;
_cairo_output_stream_puts (surface->ctx->stream,
- " /deflate filter>> image ");
+ " /deflate filter >> image ");
} else {
base85_stream = _cairo_base85_stream_create (surface->ctx->stream);
- status = _write_image_surface (base85_stream, image);
+ status = _write_image_surface (base85_stream, clone);
status2 = _cairo_output_stream_destroy (base85_stream);
if (status == CAIRO_STATUS_SUCCESS)
status = status2;
@@ -1082,6 +1093,8 @@ _emit_image_surface (cairo_script_surface_t *surface,
_cairo_output_stream_puts (surface->ctx->stream,
" >> image ");
}
+
+ cairo_surface_destroy (&clone->base);
}
cairo_surface_get_mime_data (&image->base, CAIRO_MIME_TYPE_JPEG,
diff --git a/test/mime-data.script.ref.png b/test/mime-data.script.ref.png
index a236b04..64d7bf3 100644
Binary files a/test/mime-data.script.ref.png and b/test/mime-data.script.ref.png differ
diff --git a/test/scale-offset-image.c b/test/scale-offset-image.c
index 5a4ac7d..4c6894a 100644
--- a/test/scale-offset-image.c
+++ b/test/scale-offset-image.c
@@ -135,7 +135,7 @@ draw (cairo_t *cr, int width, int height)
CAIRO_TEST (scale_offset_image,
"Tests drawing surfaces under various scales and transforms",
- "XFAIL=!ps,image,xlib-fallback surface scale-offset", /* keywords */
+ "XFAIL=!ps,image,xlib-fallback,script surface scale-offset", /* keywords */
NULL, /* requirements */
320, 320,
NULL, draw)
diff --git a/test/scale-offset-similar.c b/test/scale-offset-similar.c
index 379e761..5b92f1a 100644
--- a/test/scale-offset-similar.c
+++ b/test/scale-offset-similar.c
@@ -136,7 +136,7 @@ draw (cairo_t *cr, int width, int height)
CAIRO_TEST (scale_offset_similar,
"Tests drawing surfaces under various scales and transforms",
- "XFAIL=!ps,image,xlib-fallback surface scale-offset", /* keywords */
+ "XFAIL=!ps,image,xlib-fallback,script surface scale-offset", /* keywords */
NULL, /* requirements */
320, 320,
NULL, draw)
diff --git a/util/cairo-script/cairo-script-scanner.c b/util/cairo-script/cairo-script-scanner.c
index dd89826..b3217cd 100644
--- a/util/cairo-script/cairo-script-scanner.c
+++ b/util/cairo-script/cairo-script-scanner.c
@@ -40,6 +40,8 @@
#include <string.h> /* memset */
#include <assert.h>
+#define DEBUG_SCAN 0
+
/*
* whitespace:
* 0 - nul
@@ -1181,7 +1183,7 @@ scan_base85:
static csi_status_t
_scan_push (csi_t *ctx, csi_object_t *obj)
{
- if (0) {
+ if (DEBUG_SCAN) {
fprintf (stderr, "push ");
fprintf_obj (stderr, ctx, obj);
}
@@ -1191,7 +1193,7 @@ _scan_push (csi_t *ctx, csi_object_t *obj)
static csi_status_t
_scan_execute (csi_t *ctx, csi_object_t *obj)
{
- if (0) {
+ if (DEBUG_SCAN) {
fprintf (stderr, "exec ");
fprintf_obj (stderr, ctx, obj);
}
commit 2395bba1e66a2623cb288e13effc206f86e5e62e
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sat Jul 4 18:31:49 2009 +0100
[any2ppm] Choose a more appropriate format for the replay content
Actually select a format that matches the request content when replaying
the script to an image.
diff --git a/test/any2ppm.c b/test/any2ppm.c
index 31dd0eb..f35891f 100644
--- a/test/any2ppm.c
+++ b/test/any2ppm.c
@@ -240,7 +240,20 @@ _create_image (void *closure,
//csi_object_t *dictionary)
{
cairo_surface_t **out = closure;
- *out = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
+ cairo_format_t format;
+ switch (content) {
+ case CAIRO_CONTENT_ALPHA:
+ format = CAIRO_FORMAT_A8;
+ break;
+ case CAIRO_CONTENT_COLOR:
+ format = CAIRO_FORMAT_RGB24;
+ break;
+ default:
+ case CAIRO_CONTENT_COLOR_ALPHA:
+ format = CAIRO_FORMAT_ARGB32;
+ break;
+ }
+ *out = cairo_image_surface_create (format, width, height);
return cairo_surface_reference (*out);
}
commit 9942a89870f7754e28ff334010c4432553cf7d91
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Sat Jul 4 18:30:24 2009 +0100
[boilerplate] Read whole RGB lines at a time
Rather than read+unpack each pixel, read in a whole RGB packed line and
unpack the whole line in a single pass.
diff --git a/boilerplate/cairo-boilerplate.c b/boilerplate/cairo-boilerplate.c
index af6f9fa..f3e574c 100644
--- a/boilerplate/cairo-boilerplate.c
+++ b/boilerplate/cairo-boilerplate.c
@@ -1102,19 +1102,20 @@ cairo_boilerplate_image_surface_create_from_ppm_stream (FILE *file)
data = cairo_image_surface_get_data (image);
stride = cairo_image_surface_get_stride (image);
for (y = 0; y < height; y++) {
- unsigned char *buf = data + y *stride;
+ unsigned char *buf = data + y*stride;
switch (format) {
case '7':
if (! freadn (buf, 4 * width, file))
goto FAIL;
break;
case '6':
- for (x = 0; x < width; x++) {
- if (! freadn (buf, 3, file))
- goto FAIL;
- *(uint32_t *) buf =
+ if (! freadn (buf, 3*width, file))
+ goto FAIL;
+ buf += 3*width;
+ for (x = width; x--; ) {
+ buf -= 3;
+ ((uint32_t *) (data + y*stride))[x] =
(buf[0] << 16) | (buf[1] << 8) | (buf[2] << 0);
- buf += 4;
}
break;
case '5':
More information about the cairo-commit
mailing list