[cairo-commit] 4 commits - src/cairo-font-face.c src/cairo-pdf-surface.c test/a1-mask.c test/a1-mask-ref.png test/.gitignore test/Makefile.am
Chris Wilson
ickle at kemper.freedesktop.org
Thu Apr 3 07:41:50 PDT 2008
src/cairo-font-face.c | 1
src/cairo-pdf-surface.c | 30 +------
test/.gitignore | 2
test/Makefile.am | 2
test/a1-mask-ref.png |binary
test/a1-mask.c | 198 ++++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 210 insertions(+), 23 deletions(-)
New commits:
commit 6101dc3e93b20294c75734d7f29e55694ed58e74
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Apr 3 14:53:17 2008 +0100
[cairo-pdf-surface] Do not bitswap big-endian A1 masks.
Pixman stores the bits A1 surfaces in native byte order, PDF stores
A1 masks in MSb - so only perform swapping for little-endian machines.
Note this also removes the extraneous packing as per the PDF spec 4.8.2:
"Byte boundaries are ignored, except that each row of sample data must
begin on a byte boundary. If the number of data bits per row is not a
multiple of 8, the end of the row is padded with extra bits to fill out
the last byte."
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 53af765..ce6d8c4 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -1250,7 +1250,6 @@ _cairo_pdf_surface_emit_smask (cairo_pdf_surface_t *surface,
int i, x, y;
cairo_bool_t opaque;
uint8_t a;
- int src_bit, dst_bit;
/* This is the only image format we support, which simplifies things. */
assert (image->format == CAIRO_FORMAT_ARGB32 ||
@@ -1260,11 +1259,7 @@ _cairo_pdf_surface_emit_smask (cairo_pdf_surface_t *surface,
stream_ret->id = 0;
if (image->format == CAIRO_FORMAT_A1) {
- /* We allocate using slightly different math so that we can get
- * the overflow checking from _cairo_malloc_ab, but alpha_size
- * needs to be the correct size for emitting the data in the PDF.
- */
- alpha_size = (image->width*image->height + 7) / 8;
+ alpha_size = (image->width + 7) / 8 * image->height;
alpha = _cairo_malloc_ab ((image->width+7) / 8, image->height);
} else {
alpha_size = image->height * image->width;
@@ -1278,8 +1273,6 @@ _cairo_pdf_surface_emit_smask (cairo_pdf_surface_t *surface,
opaque = TRUE;
i = 0;
- src_bit = 0;
- dst_bit = 7;
for (y = 0; y < image->height; y++) {
if (image->format == CAIRO_FORMAT_ARGB32) {
pixel32 = (uint32_t *) (image->data + y * image->stride);
@@ -1302,21 +1295,12 @@ _cairo_pdf_surface_emit_smask (cairo_pdf_surface_t *surface,
} else { /* image->format == CAIRO_FORMAT_A1 */
pixel8 = (uint8_t *) (image->data + y * image->stride);
- for (x = 0; x < image->width; x++, pixel8++) {
- if (dst_bit == 7)
- alpha[i] = 0;
- if ((*pixel8 >> src_bit) & 1) {
- opaque = FALSE;
- alpha[i] |= (1 << dst_bit);
- }
- if (++src_bit > 7) {
- src_bit = 0;
- pixel8++;
- }
- if (--dst_bit < 0) {
- dst_bit = 7;
- i++;
- }
+ for (x = 0; x < (image->width + 7) / 8; x++, pixel8++) {
+ a = *pixel8;
+ a = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (a);
+ alpha[i++] = a;
+ if (a != 0xff)
+ opaque = FALSE;
}
}
}
commit 7901eb29efb04e469f4bf94e2da6fd6b79b140b0
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Apr 3 12:12:25 2008 +0100
[test] Add a1-mask.
Add a variant of the a8-mask test case that exercises the FORMAT_A1 code
paths instead.
diff --git a/test/.gitignore b/test/.gitignore
index f9b3121..e153c7a 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -5,6 +5,7 @@ Makefile.in
index.html
ref.hash
a1-image-sample
+a1-mask
a1-traps-sample
a8-mask
big-line
diff --git a/test/Makefile.am b/test/Makefile.am
index c23a097..ef1d757 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -3,6 +3,7 @@ SUBDIRS=pdiff .
# Here are all the tests that are run unconditionally
TESTS = \
a1-image-sample$(EXEEXT) \
+a1-mask$(EXEEXT) \
a1-traps-sample$(EXEEXT) \
a8-mask$(EXEEXT) \
big-line$(EXEEXT) \
@@ -249,6 +250,7 @@ endif
# All tests which have a reference image go here.
REFERENCE_IMAGES = \
a1-image-sample-ref.png \
+ a1-mask-ref.png \
a1-traps-sample-ref.png \
a8-mask-ref.png \
big-line-ref.png \
diff --git a/test/a1-mask-ref.png b/test/a1-mask-ref.png
new file mode 100644
index 0000000..ac4d97a
Binary files /dev/null and b/test/a1-mask-ref.png differ
diff --git a/test/a1-mask.c b/test/a1-mask.c
new file mode 100644
index 0000000..cbc64b0
--- /dev/null
+++ b/test/a1-mask.c
@@ -0,0 +1,198 @@
+/*
+ * Copyright © Jeff Muizelaar
+ *
+ * Permission to use, copy, modify, distribute, and sell this software
+ * and its documentation for any purpose is hereby granted without
+ * fee, provided that the above copyright notice appear in all copies
+ * and that both that copyright notice and this permission notice
+ * appear in supporting documentation, and that the name of
+ * Red Hat, Inc. not be used in advertising or publicity pertaining to
+ * distribution of the software without specific, written prior
+ * permission. Red Hat, Inc. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * JEFF MUIZELAAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+ * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Authors: Jeff Muizelaar <jeff at infidigm.net>
+ * Carl Worth <cworth at cworth.org>
+ * Chris Wilson <chris at chris-wilson.co.uk>
+ */
+
+#include "cairo-test.h"
+
+static cairo_test_draw_function_t draw;
+
+#define MASK_WIDTH 10
+#define MASK_HEIGHT 8
+
+#ifdef WORDS_BIGENDIAN
+#define MASK 0x28, 0x55
+#else
+#define MASK 0x14, 0xAA
+#endif
+static unsigned char mask[(MASK_WIDTH + 7) / 8 * MASK_HEIGHT] = {
+ MASK,
+ MASK,
+ MASK,
+ MASK,
+ MASK,
+ MASK,
+ MASK,
+ MASK,
+};
+
+cairo_test_t test = {
+ "a1-mask",
+ "test masks of CAIRO_FORMAT_A1",
+ MASK_WIDTH, MASK_HEIGHT,
+ draw
+};
+
+
+static cairo_test_status_t
+check_status (cairo_status_t status, cairo_status_t expected)
+{
+ if (status == expected)
+ return CAIRO_TEST_SUCCESS;
+
+ cairo_test_log ("Error: Expected status value %d (%s), received %d (%s)\n",
+ expected,
+ cairo_status_to_string (expected),
+ status,
+ cairo_status_to_string (status));
+ return CAIRO_TEST_FAILURE;
+}
+
+static cairo_test_status_t
+test_surface_with_width_and_stride (int width, int stride,
+ cairo_status_t expected)
+{
+ cairo_test_status_t status;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ int len;
+ unsigned char *data;
+
+ cairo_test_log ("Creating surface with width %d and stride %d\n",
+ width, stride);
+
+ len = stride;
+ if (len < 0)
+ len = -len;
+ data = xmalloc (len);
+
+ surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_A1,
+ width, 1, stride);
+ cr = cairo_create (surface);
+
+ cairo_paint (cr);
+
+ status = check_status (cairo_surface_status (surface), expected);
+ if (status)
+ goto BAIL;
+
+ status = check_status (cairo_status (cr), expected);
+ if (status)
+ goto BAIL;
+
+ BAIL:
+ cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+ free (data);
+ return status;
+}
+
+static cairo_test_status_t
+draw (cairo_t *cr, int dst_width, int dst_height)
+{
+ int test_width, test_stride, stride, row;
+ unsigned char *src, *dst, *mask_aligned;
+ cairo_surface_t *surface;
+ cairo_pattern_t *pattern;
+ cairo_test_status_t status;
+ cairo_status_t expected;
+
+ for (test_width = 0; test_width < 40; test_width++) {
+ test_stride = (test_width + 7) / 8;
+ stride = cairo_format_stride_for_width (CAIRO_FORMAT_A1,
+ test_width);
+
+ /* First create a surface using the width as the stride, (most
+ * of these should fail). */
+ expected = (stride == test_stride) ?
+ CAIRO_STATUS_SUCCESS : CAIRO_STATUS_INVALID_STRIDE;
+
+ status = test_surface_with_width_and_stride (test_width,
+ test_stride,
+ expected);
+ if (status)
+ return status;
+
+ status = test_surface_with_width_and_stride (test_width,
+ -test_stride,
+ expected);
+ if (status)
+ return status;
+
+
+ /* Then create a surface using the correct stride, (should
+ always succeed).*/
+ status = test_surface_with_width_and_stride (test_width,
+ stride,
+ CAIRO_STATUS_SUCCESS);
+ if (status)
+ return status;
+
+ status = test_surface_with_width_and_stride (test_width,
+ -stride,
+ CAIRO_STATUS_SUCCESS);
+ if (status)
+ return status;
+ }
+
+ /* Now test actually drawing through our mask data, allocating and
+ * copying with the proper stride. */
+ surface = cairo_image_surface_create (CAIRO_FORMAT_A1,
+ MASK_WIDTH,
+ MASK_HEIGHT);
+
+ mask_aligned = cairo_image_surface_get_data (surface);
+ if (mask_aligned != NULL) {
+ stride = cairo_image_surface_get_stride (surface);
+ src = mask;
+ dst = mask_aligned;
+ for (row = 0; row < MASK_HEIGHT; row++) {
+ memcpy (dst, src, (MASK_WIDTH + 7) / 8);
+ src += (MASK_WIDTH + 7) / 8;
+ dst += stride;
+ }
+ }
+
+ /* Paint background blue */
+ cairo_set_source_rgb (cr, 0, 0, 1); /* blue */
+ cairo_paint (cr);
+
+ /* Then paint red through our mask */
+ pattern = cairo_pattern_create_for_surface (surface);
+
+ cairo_set_source_rgb (cr, 1, 0, 0); /* red */
+ cairo_mask (cr, pattern);
+
+ cairo_pattern_destroy (pattern);
+ cairo_surface_destroy (surface);
+
+ return CAIRO_TEST_SUCCESS;
+}
+
+int
+main (void)
+{
+ return cairo_test (&test);
+}
commit 5aa5aeb1f56493cf7a6bafd22c6921d8415db64e
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Apr 3 12:09:03 2008 +0100
[cairo-font-face] Cleanup up the font_face on the error path.
A missing _cairo_toy_font_face_fini() was leaking the strdup(family).
diff --git a/src/cairo-font-face.c b/src/cairo-font-face.c
index c7f0a44..49c8cdf 100644
--- a/src/cairo-font-face.c
+++ b/src/cairo-font-face.c
@@ -433,6 +433,7 @@ _cairo_toy_font_face_create (const char *family,
return &font_face->base;
UNWIND_FONT_FACE_INIT:
+ _cairo_toy_font_face_fini (font_face);
UNWIND_FONT_FACE_MALLOC:
free (font_face);
UNWIND_HASH_TABLE_LOCK:
commit 048160d44c564b0265b2e740b13d6ed3b367661d
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Thu Apr 3 12:11:44 2008 +0100
[.gitignore] Add test/stroke-image
diff --git a/test/.gitignore b/test/.gitignore
index ab211ee..f9b3121 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -164,6 +164,7 @@ solid-pattern-cache-stress
source-clip
source-clip-scale
source-surface-scale-paint
+stroke-image
stroke-ctm-caps
surface-finish-twice
surface-pattern
More information about the cairo-commit
mailing list