diff options
Diffstat (limited to 'test')
25 files changed, 888 insertions, 61 deletions
diff --git a/test/.cvsignore b/test/.cvsignore index 1d037fa05..c1895986a 100644 --- a/test/.cvsignore +++ b/test/.cvsignore @@ -2,7 +2,9 @@ .libs Makefile Makefile.in +a8-mask clip-nesting +clip-operator clip-twice composite-integer-translate-source composite-integer-translate-over @@ -20,6 +22,8 @@ leaky-polygon line-width linear-gradient mask +mask-ctm +mask-surface-ctm move-to-show-surface paint paint-with-alpha @@ -49,6 +53,7 @@ text-rotate transforms translate-show-surface trap-clip +unbounded-operator user-data xlib-surface *-image-out.png diff --git a/test/Makefile.am b/test/Makefile.am index 649c4012b..e630b66b9 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,6 +1,8 @@ # All test cases go here TESTS = \ +a8-mask \ clip-nesting \ +clip-operator \ clip-twice \ composite-integer-translate-source \ composite-integer-translate-over \ @@ -16,6 +18,8 @@ leaky-polygon \ line-width \ linear-gradient \ mask \ +mask-ctm \ +mask-surface-ctm \ move-to-show-surface \ paint \ paint-with-alpha \ @@ -38,6 +42,8 @@ text-rotate \ transforms \ translate-show-surface \ trap-clip \ +unantialiased-shapes \ +unbounded-operator \ user-data \ rel-path @@ -57,7 +63,9 @@ endif # I really don't like having to repeat this list. Anyone know a good # way to avoid it? Can I use a wildcard here? EXTRA_DIST = \ +a8-mask-ref.png \ clip-nesting-ref.png \ +clip-operator-ref.png \ clip-twice-ref.png \ composite-integer-translate-source-ref.png \ composite-integer-translate-over-ref.png \ @@ -72,6 +80,8 @@ leaky-polygon-ref.png \ line-width-ref.png \ linear-gradient-ref.png \ mask-ref.png \ +mask-ctm-ref.png \ +mask-surface-ctm-ref.png \ move-to-show-surface-ref.png \ paint-ref.png \ paint-with-alpha-ref.png \ @@ -90,6 +100,8 @@ text-antialias-none-ref.png \ transforms-ref.png \ translate-show-surface-ref.png \ trap-clip-ref.png \ +unantialiased-shapes-ref.png \ +unbounded-operator-ref.png \ rel-path-ref.png # Any test for which the code committed to CVS is expected to fail @@ -106,10 +118,10 @@ rel-path-ref.png # Also, any test listed here should call cairo_test_expect_failure and # provide an explanation for the expected failure. XFAIL_TESTS = \ +a8-mask \ filter-nearest-offset \ pixman-rotate \ self-intersecting \ -source-surface-scale-paint \ text-antialias-subpixel \ text-rotate @@ -145,7 +157,9 @@ LDADDS = libcairotest.la $(top_builddir)/src/libcairo.la # ARGH! I have to repeat the list of tests a third time. Maybe it's # time to break down and auto-generate the Makefile.am or something # from autogen.sh. My, but this is painful... +a8_mask_LDADD = $(LDADDS) clip_nesting_LDADD = $(LDADDS) +clip_operator_LDADD = $(LDADDS) clip_twice_LDADD = $(LDADDS) composite_integer_translate_source_LDADD = $(LDADDS) composite_integer_translate_over_LDADD = $(LDADDS) @@ -161,6 +175,8 @@ leaky_polygon_LDADD = $(LDADDS) line_width_LDADD = $(LDADDS) linear_gradient_LDADD = $(LDADDS) mask_LDADD = $(LDADDS) +mask_ctm_LDADD = $(LDADDS) +mask_surface_ctm_LDADD = $(LDADDS) move_to_show_surface_LDADD = $(LDADDS) paint_LDADD = $(LDADDS) paint_with_alpha_LDADD = $(LDADDS) @@ -186,6 +202,8 @@ text_rotate_LDADD = $(LDADDS) transforms_LDADD = $(LDADDS) translate_show_surface_LDADD = $(LDADDS) trap_clip_LDADD = $(LDADDS) +unantialiased_shapes_LDADD = $(LDADDS) +unbounded_operator_LDADD = $(LDADDS) user_data_LDADD = $(LDADDS) rel_path_LDADD = $(LDADDS) xlib_surface_LDADD = $(LDADDS) diff --git a/test/a8-mask-ref.png b/test/a8-mask-ref.png Binary files differnew file mode 100644 index 000000000..38556156c --- /dev/null +++ b/test/a8-mask-ref.png diff --git a/test/a8-mask.c b/test/a8-mask.c new file mode 100644 index 000000000..e547ecce2 --- /dev/null +++ b/test/a8-mask.c @@ -0,0 +1,72 @@ +/* + * 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. + * + * Author: Jeff Muizelaar <jeff@infidigm.net> + */ + +#include "cairo-test.h" + +cairo_test_t test = { + "a8-mask", + "test masks of CAIRO_FORMAT_A8", + 8, 8 +}; + +static unsigned char mask[] = { + 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, + 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, + 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, + 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, + 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, + 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, + 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0, + 0x0, 0x0, 0xff, 0x0, 0xff, 0x0, 0x0 +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *surface; + cairo_pattern_t *pattern; + + cairo_set_source_rgb (cr, 0, 0, 1); + cairo_paint (cr); + + surface = cairo_image_surface_create_for_data (mask, CAIRO_FORMAT_A8, + 7, 8, 7); + pattern = cairo_pattern_create_for_surface (surface); + + cairo_set_source_rgb (cr, 1, 0, 0); + cairo_mask (cr, pattern); + + cairo_pattern_destroy (pattern); + cairo_surface_destroy (surface); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test_expect_failure (&test, draw, + "image backend fails because libpixman only handles (stride % sizeof(pixman_bits) == 0)"); +} diff --git a/test/buffer-diff.c b/test/buffer-diff.c index e5ba513ac..78284efcd 100644 --- a/test/buffer-diff.c +++ b/test/buffer-diff.c @@ -23,10 +23,17 @@ * * Author: Richard D. Worth <richard@theworths.org> */ +#if HAVE_CONFIG_H +#include "config.h" +#endif + #include <stdio.h> +#ifdef HAVE_UNISTD_H #include <unistd.h> +#endif #include <errno.h> #include <string.h> +#include <pixman.h> #include "cairo-test.h" @@ -45,18 +52,27 @@ xunlink (const char *pathname) } } -int -buffer_diff (unsigned char *buf_a, - unsigned char *buf_b, - unsigned char *buf_diff, - int width, - int height, - int stride) + +/* This function should be rewritten to compare all formats supported by + * cairo_format_t instead of taking a mask as a parameter. + */ +static int +buffer_diff_core (unsigned char *_buf_a, + unsigned char *_buf_b, + unsigned char *_buf_diff, + int width, + int height, + int stride, + pixman_bits_t mask) { int x, y; - unsigned char *row_a, *row_b, *row; + pixman_bits_t *row_a, *row_b, *row; int pixels_changed = 0; + pixman_bits_t *buf_a = (pixman_bits_t*)_buf_a; + pixman_bits_t *buf_b = (pixman_bits_t*)_buf_b; + pixman_bits_t *buf_diff = (pixman_bits_t*)_buf_diff; + stride /= sizeof(pixman_bits_t); for (y = 0; y < height; y++) { row_a = buf_a + y * stride; @@ -64,33 +80,54 @@ buffer_diff (unsigned char *buf_a, row = buf_diff + y * stride; for (x = 0; x < width; x++) { - int channel; - unsigned char value_a, value_b; - int pixel_differs = 0; - for (channel = 0; channel < 4; channel++) - { - double diff; - value_a = row_a[x * 4 + channel]; - value_b = row_b[x * 4 + channel]; - if (value_a != value_b) - pixel_differs = 1; - diff = value_a - value_b; - row[x * 4 + channel] = 128 + diff / 3.0; - } - if (pixel_differs) { + /* check if the pixels are the same */ + if ((row_a[x] & mask) != (row_b[x] & mask)) { + int channel; + pixman_bits_t diff_pixel = 0; + + /* calculate a difference value for all 4 channels */ + for (channel = 0; channel < 4; channel++) { + unsigned char value_a = (row_a[x] >> (channel*8)); + unsigned char value_b = (row_b[x] >> (channel*8)); + double diff; + diff = value_a - value_b; + diff_pixel |= (unsigned char)(128 + diff / 3.0) << (channel*8); + } + pixels_changed++; + row[x] = diff_pixel; } else { - row[x*4+0] = 0; - row[x*4+1] = 0; - row[x*4+2] = 0; + row[x] = 0; } - row[x * 4 + 3] = 0xff; /* Set ALPHA to 100% (opaque) */ + row[x] |= 0xff000000; /* Set ALPHA to 100% (opaque) */ } } return pixels_changed; } +int +buffer_diff (unsigned char *buf_a, + unsigned char *buf_b, + unsigned char *buf_diff, + int width, + int height, + int stride) +{ + return buffer_diff_core(buf_a, buf_b, buf_diff, width, height, stride, 0xffffffff); +} + +int +buffer_diff_noalpha (unsigned char *buf_a, + unsigned char *buf_b, + unsigned char *buf_diff, + int width, + int height, + int stride) +{ + return buffer_diff_core(buf_a, buf_b, buf_diff, width, height, stride, 0x00ffffff); +} + /* Image comparison code courtesy of Richard Worth <richard@theworths.org> * Returns number of pixels changed, (or -1 on error). * Also saves a "diff" image intended to visually show where the diff --git a/test/buffer-diff.h b/test/buffer-diff.h index a02834f3d..2734713a3 100644 --- a/test/buffer-diff.h +++ b/test/buffer-diff.h @@ -26,7 +26,7 @@ #ifndef BUFFER_DIFF_H #define BUFFER_DIFF_H -/* Returns number of pixels changed, (or -1 on error). +/* Returns number of pixels changed. * Also fills in a "diff" buffer intended to visually show where the * images differ. */ @@ -38,6 +38,18 @@ buffer_diff (unsigned char *buf_a, int height, int stride); +/* Returns number of pixels changed ignoring the alpha channel. + * Also fills in a "diff" buffer intended to visually show where the + * images differ. + */ +int +buffer_diff_noalpha (unsigned char *buf_a, + unsigned char *buf_b, + unsigned char *buf_diff, + int width, + int height, + int stride); + /* Returns number of pixels changed, (or -1 on error). * Also saves a "diff" image intended to visually show where the * images differ. diff --git a/test/cairo-test.c b/test/cairo-test.c index 456d7d85a..6759c849a 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -1,5 +1,5 @@ /* - * Copyright 2004 Red Hat, Inc. + * Copyright © 2004 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without @@ -23,12 +23,19 @@ * Author: Carl D. Worth <cworth@cworth.org> */ +#if HAVE_CONFIG_H +#include "config.h" +#endif + #include <stdio.h> #include <stdlib.h> #include <stdarg.h> +#ifdef HAVE_UNISTD_H #include <unistd.h> +#endif #include <errno.h> #include <string.h> +#include <fontconfig/fontconfig.h> #include "cairo-test.h" @@ -37,6 +44,10 @@ #include "write-png.h" #include "xmalloc.h" +#ifdef _MSC_VER +#define vsnprintf _vsnprintf +#endif + #define CAIRO_TEST_LOG_SUFFIX ".log" #define CAIRO_TEST_PNG_SUFFIX "-out.png" #define CAIRO_TEST_REF_SUFFIX "-ref.png" @@ -469,6 +480,9 @@ cairo_test_for_target (cairo_test_t *test, UNWIND_CAIRO: cairo_destroy (cr); cairo_surface_destroy (surface); + + cairo_debug_reset_static_data (); + target->cleanup_target (target->closure); UNWIND_STRINGS: @@ -557,6 +571,10 @@ cairo_test_expecting (cairo_test_t *test, cairo_test_draw_function_t draw, fclose (cairo_test_log_file); +#if HAVE_FCFINI + FcFini (); +#endif + return ret; } diff --git a/test/cairo-test.h b/test/cairo-test.h index beabc6a5e..d35faab82 100644 --- a/test/cairo-test.h +++ b/test/cairo-test.h @@ -28,6 +28,7 @@ #include <math.h> #include <cairo.h> +#include <cairo-debug.h> typedef enum cairo_test_status { CAIRO_TEST_SUCCESS = 0, diff --git a/test/clip-operator-ref.png b/test/clip-operator-ref.png Binary files differnew file mode 100644 index 000000000..551d13f7d --- /dev/null +++ b/test/clip-operator-ref.png diff --git a/test/clip-operator.c b/test/clip-operator.c new file mode 100644 index 000000000..6cc5216c2 --- /dev/null +++ b/test/clip-operator.c @@ -0,0 +1,205 @@ +/* + * Copyright © 2005 Red Hat, Inc. + * + * 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. + * + * RED HAT, INC. 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. + * + * Author: Kristian Høgsberg <krh@redhat.com> + */ + +#include <math.h> +#include "cairo-test.h" +#include <stdio.h> + +#define WIDTH 64 +#define HEIGHT 64 +#define PAD 10 + +const char png_filename[] = "romedalen.png"; + +static void +draw_mask (cairo_t *cr, int x, int y) +{ + cairo_surface_t *mask_surface; + cairo_t *cr2; + + double width = (int)(0.9 * WIDTH); + double height = (int)(0.9 * HEIGHT); + x += 0.05 * WIDTH; + y += 0.05 * HEIGHT; + + mask_surface = cairo_surface_create_similar (cairo_get_target (cr), + CAIRO_CONTENT_ALPHA, + width, height); + cr2 = cairo_create (mask_surface); + + cairo_save (cr2); + cairo_set_source_rgba (cr2, 0, 0, 0, 0); /* transparent */ + cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE); + cairo_paint (cr2); + cairo_restore (cr2); + + cairo_set_source_rgb (cr2, 1, 1, 1); /* white */ + + cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.45 * height, 0, 2 * M_PI); + cairo_fill (cr2); + + cairo_destroy (cr2); + + cairo_mask_surface (cr, mask_surface, x, y); + + cairo_surface_destroy (mask_surface); +} + +static void +draw_glyphs (cairo_t *cr, int x, int y) +{ + cairo_text_extents_t extents; + + cairo_set_font_size (cr, 0.8 * HEIGHT); + + cairo_text_extents (cr, "FG", &extents); + cairo_move_to (cr, + x + (WIDTH - extents.width) / 2 - extents.x_bearing, + y + (HEIGHT - extents.height) / 2 - extents.y_bearing); + cairo_show_text (cr, "FG"); +} + +static void +draw_polygon (cairo_t *cr, int x, int y) +{ + double width = (int)(0.9 * WIDTH); + double height = (int)(0.9 * HEIGHT); + x += 0.05 * WIDTH; + y += 0.05 * HEIGHT; + + cairo_new_path (cr); + cairo_move_to (cr, x, y); + cairo_line_to (cr, x, y + height); + cairo_line_to (cr, x + width / 2, y + 3 * height / 4); + cairo_line_to (cr, x + width, y + height); + cairo_line_to (cr, x + width, y); + cairo_line_to (cr, x + width / 2, y + height / 4); + cairo_close_path (cr); + cairo_fill (cr); +} + +static void +draw_rects (cairo_t *cr, int x, int y) +{ + double block_width = (int)(0.33 * WIDTH + 0.5); + double block_height = (int)(0.33 * HEIGHT + 0.5); + int i, j; + + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) + if ((i + j) % 2 == 0) + cairo_rectangle (cr, + x + block_width * i, y + block_height * j, + block_width, block_height); + + cairo_fill (cr); +} + +static void (*draw_funcs[])(cairo_t *cr, int x, int y) = { + draw_mask, + draw_glyphs, + draw_polygon, + draw_rects +}; + +#define N_OPERATORS (1 + CAIRO_OPERATOR_SATURATE - CAIRO_OPERATOR_CLEAR) + +#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) +#define IMAGE_WIDTH (N_OPERATORS * (WIDTH + PAD) + PAD) +#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * (HEIGHT + PAD) + PAD) + +static cairo_test_t test = { + "clip-operator", + "Surface clipping with different operators", + IMAGE_WIDTH, IMAGE_HEIGHT +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + int j, x, y; + cairo_operator_t op; + cairo_font_options_t *font_options; + cairo_pattern_t *pattern; + + cairo_select_font_face (cr, "Bitstream Vera Sans", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size (cr, 0.9 * HEIGHT); + + font_options = cairo_font_options_create (); + + cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE); + cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY); + + cairo_set_font_options (cr, font_options); + cairo_font_options_destroy (font_options); + + for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) { + for (op = CAIRO_OPERATOR_CLEAR; op <= CAIRO_OPERATOR_SATURATE; op++) { + x = op * (WIDTH + PAD) + PAD; + y = j * (HEIGHT + PAD) + PAD; + + cairo_save (cr); + + pattern = cairo_pattern_create_linear (x + WIDTH, y, + x, y + HEIGHT); + cairo_pattern_add_color_stop_rgba (pattern, 0.2, + 0.0, 0.0, 1.0, 1.0); /* Solid blue */ + cairo_pattern_add_color_stop_rgba (pattern, 0.8, + 0.0, 0.0, 1.0, 0.0); /* Transparent blue */ + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + + cairo_rectangle (cr, x, y, WIDTH, HEIGHT); + cairo_fill (cr); + + cairo_set_operator (cr, op); + cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); + + cairo_move_to (cr, x, y); + cairo_line_to (cr, x + WIDTH, y); + cairo_line_to (cr, x, y + HEIGHT); + cairo_clip (cr); + + draw_funcs[j] (cr, x, y); + if (cairo_status (cr)) + cairo_test_log ("%d %d HERE!\n", op, j); + + cairo_restore (cr); + } + } + + if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) + cairo_test_log ("%d %d .HERE!\n", op, j); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test, draw); +} diff --git a/test/composite-integer-translate-over-repeat.c b/test/composite-integer-translate-over-repeat.c index ed55f63a6..61a0ea71a 100644 --- a/test/composite-integer-translate-over-repeat.c +++ b/test/composite-integer-translate-over-repeat.c @@ -44,7 +44,7 @@ draw (cairo_t *cr, int width, int height) cairo_fill (cr); cairo_translate (cr, OFFSET, OFFSET); - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_source (cr, pat); cairo_rectangle (cr, 0, 0, SIZE - OFFSET, SIZE - OFFSET); cairo_fill (cr); diff --git a/test/mask-ctm-ref.png b/test/mask-ctm-ref.png Binary files differnew file mode 100644 index 000000000..88a0402ca --- /dev/null +++ b/test/mask-ctm-ref.png diff --git a/test/mask-ctm.c b/test/mask-ctm.c new file mode 100644 index 000000000..1fd48285e --- /dev/null +++ b/test/mask-ctm.c @@ -0,0 +1,82 @@ +/* + * Copyright © 2005 Red Hat, Inc. + * + * 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. + * + * RED HAT, INC. 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. + * + * Author: Carl D. Worth <cworth@cworth.org> + */ + +#include "cairo-test.h" + +cairo_test_t test = { + "mask-ctm", + "Test that cairo_mask is affected properly by the CTM", + 10, 10 +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *mask_surface; + cairo_pattern_t *mask; + unsigned long data[] = { + 0x80000000, 0x80000000, + 0x80000000, 0x80000000, + }; + cairo_matrix_t matrix; + + mask_surface = cairo_image_surface_create_for_data ((unsigned char *) data, + CAIRO_FORMAT_ARGB32, 2, 2, 8); + mask = cairo_pattern_create_for_surface (mask_surface); + cairo_surface_destroy (mask_surface); + + cairo_set_source_rgb (cr, 1.0, 0, 0); + + /* We can translate with the CTM, with the pattern matrix, or with + * both. */ + + /* 1. CTM alone. */ + cairo_save (cr); + { + cairo_translate (cr, 2, 2); + cairo_mask (cr, mask); + } + cairo_restore (cr); + + /* 2. Pattern matrix alone. */ + cairo_matrix_init_translate (&matrix, -4, -4); + cairo_pattern_set_matrix (mask, &matrix); + + cairo_mask (cr, mask); + + /* 3. CTM + pattern matrix */ + cairo_translate (cr, 2, 2); + cairo_mask (cr, mask); + + cairo_pattern_destroy (mask); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test, draw); +} diff --git a/test/mask-surface-ctm-ref.png b/test/mask-surface-ctm-ref.png Binary files differnew file mode 100644 index 000000000..744b1dd37 --- /dev/null +++ b/test/mask-surface-ctm-ref.png diff --git a/test/mask-surface-ctm.c b/test/mask-surface-ctm.c new file mode 100644 index 000000000..6eb2bf26d --- /dev/null +++ b/test/mask-surface-ctm.c @@ -0,0 +1,75 @@ +/* + * Copyright © 2005 Red Hat, Inc. + * + * 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. + * + * RED HAT, INC. 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. + * + * Author: Carl D. Worth <cworth@cworth.org> + */ + +#include "cairo-test.h" + +cairo_test_t test = { + "mask-surface-ctm", + "Test that cairo_mask_surface is affected properly by the CTM", + 10, 10 +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *mask; + unsigned long data[] = { + 0x80000000, 0x80000000, + 0x80000000, 0x80000000, + }; + + mask = cairo_image_surface_create_for_data ((unsigned char *) data, + CAIRO_FORMAT_ARGB32, 2, 2, 8); + + cairo_set_source_rgb (cr, 1.0, 0, 0); + + /* We can translate with the CTM, with the mask_surface offset, or + * with both. */ + + /* 1. CTM alone. */ + cairo_save (cr); + { + cairo_translate (cr, 2, 2); + cairo_mask_surface (cr, mask, 0, 0); + } + cairo_restore (cr); + + /* 2. Offset alone. */ + cairo_mask_surface (cr, mask, 4, 4); + + /* 3. CTM + offset */ + cairo_translate (cr, 2, 2); + cairo_mask_surface (cr, mask, 4, 4); + + cairo_surface_destroy (mask); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test, draw); +} diff --git a/test/read-png.c b/test/read-png.c index 96259dfe8..ff311c283 100644 --- a/test/read-png.c +++ b/test/read-png.c @@ -35,6 +35,18 @@ # include <inttypes.h> #elif HAVE_SYS_INT_TYPES_H # include <sys/int_types.h> +#elif defined(_MSC_VER) + typedef __int8 int8_t; + typedef unsigned __int8 uint8_t; + typedef __int16 int16_t; + typedef unsigned __int16 uint16_t; + typedef __int32 int32_t; + typedef unsigned __int32 uint32_t; + typedef __int64 int64_t; + typedef unsigned __int64 uint64_t; +# ifndef HAVE_UINT64_T +# define HAVE_UINT64_T 1 +# endif #else #error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, etc.) #endif @@ -79,7 +91,7 @@ read_png_argb32 (const char *filename, { int i; FILE *file; - static const int PNG_SIG_SIZE = 8; +#define PNG_SIG_SIZE 8 unsigned char png_sig[PNG_SIG_SIZE]; int sig_bytes; png_struct *png; diff --git a/test/source-surface-scale-paint-ref.png b/test/source-surface-scale-paint-ref.png Binary files differindex ec3c059fd..a81f93d94 100644 --- a/test/source-surface-scale-paint-ref.png +++ b/test/source-surface-scale-paint-ref.png diff --git a/test/source-surface-scale-paint.c b/test/source-surface-scale-paint.c index 9862ba594..1af972f23 100644 --- a/test/source-surface-scale-paint.c +++ b/test/source-surface-scale-paint.c @@ -28,7 +28,7 @@ cairo_test_t test = { "source-surface-scale-paint", "Test call sequence: cairo_set_source_surface; cairo_scale; cairo_paint", - 12, 12 + 8, 8 }; static cairo_test_status_t @@ -59,6 +59,5 @@ draw (cairo_t *cr, int width, int height) int main (void) { - return cairo_test_expect_failure (&test, draw, - "cairo_set_source needs user space locking semantics"); + return cairo_test (&test, draw); } diff --git a/test/surface-finish-twice.c b/test/surface-finish-twice.c index ce4f06595..ad6c0e94b 100644 --- a/test/surface-finish-twice.c +++ b/test/surface-finish-twice.c @@ -52,7 +52,6 @@ static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_surface_t *surface; - cairo_status_t status; surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1); diff --git a/test/text-cache-crash.c b/test/text-cache-crash.c index 547e2a34c..08e857392 100644 --- a/test/text-cache-crash.c +++ b/test/text-cache-crash.c @@ -118,20 +118,6 @@ main (void) ret = cairo_test (&test, draw); - /* It's convenient to be able to free all memory (including - * statically allocated memory). This makes it quite easy to use - * tools such as valgrind to verify that there are no memory leaks - * whatsoever. - * - * But I'm not sure what would be a sensible cairo API function - * for this. The cairo_destroy_caches call below is just something - * I made as a local modification to cairo. - */ - /* - cairo_destroy_caches (); - FcFini (); - */ - return ret; } diff --git a/test/unantialiased-shapes-ref.png b/test/unantialiased-shapes-ref.png Binary files differnew file mode 100644 index 000000000..b94859224 --- /dev/null +++ b/test/unantialiased-shapes-ref.png diff --git a/test/unantialiased-shapes.c b/test/unantialiased-shapes.c new file mode 100644 index 000000000..eaadf417a --- /dev/null +++ b/test/unantialiased-shapes.c @@ -0,0 +1,103 @@ +/* + * Copyright © 2005 Billy Biggs + * + * 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 + * Billy Biggs not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. Billy Biggs makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * BILLY BIGGS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL BILLY BIGGS 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. + * + * Author: Billy Biggs <vektor@dumbterm.net> + */ + +#include "cairo-test.h" + +cairo_test_t test = { + "unantialiased-shapes", + "Test shape drawing without antialiasing", + 320, 240 +}; + +/* The star shape from the SVG test suite, from the fill rule test */ +static void +big_star_path (cairo_t *cr) +{ + cairo_move_to (cr, 40, 0); + cairo_rel_line_to (cr, 25, 80); + cairo_rel_line_to (cr, -65, -50); + cairo_rel_line_to (cr, 80, 0); + cairo_rel_line_to (cr, -65, 50); + cairo_close_path (cr); +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + int i; + + cairo_set_source_rgb (cr, 0, 0, 0); + cairo_paint (cr); + + cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); + + /* Try a circle */ + cairo_arc (cr, 40, 40, 20, 0, 2 * M_PI); + cairo_set_source_rgb (cr, 1, 0, 0); + cairo_fill (cr); + + /* Try using clipping to draw a circle */ + cairo_arc (cr, 100, 40, 20, 0, 2 * M_PI); + cairo_clip (cr); + cairo_rectangle (cr, 80, 20, 40, 40); + cairo_set_source_rgb (cr, 0, 0, 1); + cairo_fill (cr); + + /* Reset the clipping */ + cairo_reset_clip (cr); + + /* Draw a bunch of lines */ + cairo_set_line_width (cr, 1.0); + cairo_set_source_rgb (cr, 0, 1, 0); + for (i = 0; i < 10; i++) { + cairo_move_to (cr, 10, 70 + (i * 4)); + cairo_line_to (cr, 120, 70 + (i * 18)); + cairo_stroke (cr); + } + + /* Try filling a poly */ + cairo_translate (cr, 160, 120); + cairo_set_source_rgb (cr, 1, 1, 0); + big_star_path (cr); + cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD); + cairo_fill (cr); + cairo_translate (cr, -160, -120); + + /* How about some curves? */ + cairo_set_source_rgb (cr, 1, 0, 1); + for (i = 0; i < 10; i++) { + cairo_move_to (cr, 150, 50 + (i * 5)); + cairo_curve_to (cr, 250, 50, 200, (i * 10), 300, 50 + (i * 10)); + cairo_stroke (cr); + } + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test, draw); +} diff --git a/test/unbounded-operator-ref.png b/test/unbounded-operator-ref.png Binary files differnew file mode 100644 index 000000000..7e3b3a07c --- /dev/null +++ b/test/unbounded-operator-ref.png diff --git a/test/unbounded-operator.c b/test/unbounded-operator.c new file mode 100644 index 000000000..45535b976 --- /dev/null +++ b/test/unbounded-operator.c @@ -0,0 +1,201 @@ +/* + * Copyright © 2005 Red Hat, Inc. + * + * 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. + * + * RED HAT, INC. 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: Kristian Høgsberg <krh@redhat.com> + * Owen Taylor <otaylor@redhat.com> + */ + +#include <math.h> +#include "cairo-test.h" +#include <stdio.h> + +#define WIDTH 64 +#define HEIGHT 64 +#define PAD 10 + +static void +draw_mask (cairo_t *cr, int x, int y) +{ + cairo_surface_t *mask_surface; + cairo_t *cr2; + + double width = (int)(0.9 * WIDTH); + double height = (int)(0.9 * HEIGHT); + x += 0.05 * WIDTH; + y += 0.05 * HEIGHT; + + mask_surface = cairo_surface_create_similar (cairo_get_target (cr), + CAIRO_CONTENT_ALPHA, + width, height); + cr2 = cairo_create (mask_surface); + + cairo_save (cr2); + cairo_set_source_rgba (cr2, 0, 0, 0, 0); /* transparent */ + cairo_set_operator (cr2, CAIRO_OPERATOR_SOURCE); + cairo_paint (cr2); + cairo_restore (cr2); + + cairo_set_source_rgb (cr2, 1, 1, 1); /* white */ + + cairo_arc (cr2, 0.5 * width, 0.5 * height, 0.45 * height, 0, 2 * M_PI); + cairo_fill (cr2); + + cairo_destroy (cr2); + + cairo_mask_surface (cr, mask_surface, x, y); + + cairo_surface_destroy (mask_surface); +} + +static void +draw_glyphs (cairo_t *cr, int x, int y) +{ + cairo_text_extents_t extents; + + cairo_set_font_size (cr, 0.8 * HEIGHT); + + cairo_text_extents (cr, "FG", &extents); + cairo_move_to (cr, + x + (WIDTH - extents.width) / 2 - extents.x_bearing, + y + (HEIGHT - extents.height) / 2 - extents.y_bearing); + cairo_show_text (cr, "FG"); +} + +static void +draw_polygon (cairo_t *cr, int x, int y) +{ + double width = (int)(0.9 * WIDTH); + double height = (int)(0.9 * HEIGHT); + x += 0.05 * WIDTH; + y += 0.05 * HEIGHT; + + cairo_new_path (cr); + cairo_move_to (cr, x, y); + cairo_line_to (cr, x, y + height); + cairo_line_to (cr, x + width / 2, y + 3 * height / 4); + cairo_line_to (cr, x + width, y + height); + cairo_line_to (cr, x + width, y); + cairo_line_to (cr, x + width / 2, y + height / 4); + cairo_close_path (cr); + cairo_fill (cr); +} + +static void +draw_rects (cairo_t *cr, int x, int y) +{ + double block_width = (int)(0.33 * WIDTH + 0.5); + double block_height = (int)(0.33 * HEIGHT + 0.5); + int i, j; + + for (i = 0; i < 3; i++) + for (j = 0; j < 3; j++) + if ((i + j) % 2 == 0) + cairo_rectangle (cr, + x + block_width * i, y + block_height * j, + block_width, block_height); + + cairo_fill (cr); +} + +static void (*draw_funcs[])(cairo_t *cr, int x, int y) = { + draw_mask, + draw_glyphs, + draw_polygon, + draw_rects +}; + +static cairo_operator_t operators[] = { + CAIRO_OPERATOR_CLEAR, CAIRO_OPERATOR_SOURCE, CAIRO_OPERATOR_IN, + CAIRO_OPERATOR_OUT, CAIRO_OPERATOR_DEST_IN, CAIRO_OPERATOR_DEST_ATOP +}; + +#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) +#define IMAGE_WIDTH (ARRAY_SIZE (operators) * (WIDTH + PAD) + PAD) +#define IMAGE_HEIGHT (ARRAY_SIZE (draw_funcs) * (HEIGHT + PAD) + PAD) + +static cairo_test_t test = { + "unbounded-operator", + "Operators with an effect for transparent source/mask", + IMAGE_WIDTH, IMAGE_HEIGHT +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + int i, j, x, y; + cairo_font_options_t *font_options; + cairo_pattern_t *pattern; + + cairo_select_font_face (cr, "Bitstream Vera Sans", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); + + font_options = cairo_font_options_create (); + + cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE); + cairo_font_options_set_antialias (font_options, CAIRO_ANTIALIAS_GRAY); + + cairo_set_font_options (cr, font_options); + cairo_font_options_destroy (font_options); + + for (j = 0; j < ARRAY_SIZE (draw_funcs); j++) { + for (i = 0; i < ARRAY_SIZE (operators); i++) { + x = i * (WIDTH + PAD) + PAD; + y = j * (HEIGHT + PAD) + PAD; + + cairo_save (cr); + + pattern = cairo_pattern_create_linear (x + WIDTH, y, + x, y + HEIGHT); + cairo_pattern_add_color_stop_rgba (pattern, 0.2, + 0.0, 0.0, 1.0, 1.0); /* Solid blue */ + cairo_pattern_add_color_stop_rgba (pattern, 0.8, + 0.0, 0.0, 1.0, 0.0); /* Transparent blue */ + cairo_set_source (cr, pattern); + cairo_pattern_destroy (pattern); + + cairo_rectangle (cr, x, y, WIDTH, HEIGHT); + cairo_fill_preserve (cr); + cairo_clip (cr); + + cairo_set_operator (cr, operators[i]); + cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); + + draw_funcs[j] (cr, x, y); + if (cairo_status (cr)) + cairo_test_log ("%d %d HERE!\n", i, j); + + cairo_restore (cr); + } + } + + if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) + cairo_test_log ("%d %d .HERE!\n", i, j); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test, draw); +} diff --git a/test/xlib-surface.c b/test/xlib-surface.c index 2921eb852..0df5514fa 100644 --- a/test/xlib-surface.c +++ b/test/xlib-surface.c @@ -155,19 +155,19 @@ do_test (Display *dpy, if (offscreen) { size_t offset = 4 * (SIZE * OFFSCREEN_OFFSET + OFFSCREEN_OFFSET); - result = !buffer_diff (reference_data + offset, - test_data + offset, - diff_data + offset, - SIZE - OFFSCREEN_OFFSET, - SIZE - OFFSCREEN_OFFSET, - 4 * SIZE); + result = !buffer_diff_noalpha (reference_data + offset, + test_data + offset, + diff_data + offset, + SIZE - OFFSCREEN_OFFSET, + SIZE - OFFSCREEN_OFFSET, + 4 * SIZE); } else { - result = !buffer_diff (reference_data, - test_data, - diff_data, - SIZE, - SIZE, - 4 * SIZE); + result = !buffer_diff_noalpha (reference_data, + test_data, + diff_data, + SIZE, + SIZE, + 4 * SIZE); } fprintf (log_file, "xlib-surface: %s, %s, %s%s: %s\n", @@ -267,6 +267,8 @@ main (void) XCloseDisplay (dpy); + cairo_debug_reset_static_data (); + fclose (log_file); return result; |