diff options
author | Carl Worth <cworth@cworth.org> | 2006-04-25 01:56:51 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2006-04-25 01:56:51 -0700 |
commit | bef621e870e3d4038e00ed56ad40d726d5a7ca77 (patch) | |
tree | 4a5989793ad3433a1ec6329a001f8bdb390a8fd8 | |
parent | a5afc59d0ad90125c0593ab60c8e1e01f51bdc3c (diff) |
Augment tests to do better testing of paths/images with alpha.
Add a new cairo_test_paint_checkered function so that tests that draw
with alpha can easily put an easy-to-see checkered background in place
first.
Add new tests caps-joins-alpha and paint-source-alpha that do simple
tests of strokes and image painting with source pattern alpha.
Also, add the checkered background to paint-with-alpha for
consistency.
-rw-r--r-- | test/.gitignore | 2 | ||||
-rw-r--r-- | test/Makefile.am | 8 | ||||
-rw-r--r-- | test/cairo-test.c | 45 | ||||
-rw-r--r-- | test/cairo-test.h | 3 | ||||
-rw-r--r-- | test/caps-joins-alpha-ref.png | bin | 0 -> 2434 bytes | |||
-rw-r--r-- | test/caps-joins-alpha-rgb24-ref.png | bin | 0 -> 2283 bytes | |||
-rw-r--r-- | test/caps-joins-alpha.c | 94 | ||||
-rw-r--r-- | test/paint-source-alpha-ref.png | bin | 0 -> 258 bytes | |||
-rw-r--r-- | test/paint-source-alpha-rgb24-ref.png | bin | 0 -> 248 bytes | |||
-rw-r--r-- | test/paint-source-alpha.c | 67 | ||||
-rw-r--r-- | test/paint-with-alpha-ref.png | bin | 164 -> 268 bytes | |||
-rw-r--r-- | test/paint-with-alpha-rgb24-ref.png | bin | 142 -> 255 bytes | |||
-rw-r--r-- | test/paint-with-alpha.c | 9 |
13 files changed, 225 insertions, 3 deletions
diff --git a/test/.gitignore b/test/.gitignore index c124fc60..5ec87986 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -4,6 +4,7 @@ Makefile Makefile.in a8-mask caps-joins +caps-joins-alpha caps-sub-paths clip-all clip-fill-rule @@ -44,6 +45,7 @@ nil-surface operator-clear operator-source paint +paint-source-alpha paint-with-alpha path-data pattern-get-type diff --git a/test/Makefile.am b/test/Makefile.am index 044dc08c..d348ab21 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -2,6 +2,7 @@ TESTS = \ a8-mask \ caps-joins \ +caps-joins-alpha \ caps-sub-paths \ clip-all \ clip-fill-rule \ @@ -36,6 +37,7 @@ nil-surface \ operator-clear \ operator-source \ paint \ +paint-source-alpha \ paint-with-alpha \ path-data \ pattern-get-type \ @@ -113,6 +115,8 @@ a8-mask-rgb24-ref.png \ caps-joins-ps-rgb24-ref.png \ caps-joins-ref.png \ caps-joins-rgb24-ref.png \ +caps-joins-alpha-ref.png \ +caps-joins-alpha-rgb24-ref.png \ caps-sub-paths-ref.png \ caps-sub-paths-rgb24-ref.png \ clip-all-ref.png \ @@ -178,6 +182,8 @@ operator-source-ref.png \ operator-source-rgb24-ref.png \ paint-ref.png \ paint-rgb24-ref.png \ +paint-source-alpha-ref.png \ +paint-source-alpha-rgb24-ref.png \ paint-with-alpha-ref.png \ paint-with-alpha-rgb24-ref.png \ path-data-ref.png \ @@ -309,6 +315,7 @@ endif # from autogen.sh. My, but this is painful... a8_mask_LDADD = $(LDADDS) caps_joins_LDADD = $(LDADDS) +caps_joins_alpha_LDADD = $(LDADDS) caps_sub_paths_LDADD = $(LDADDS) clip_all_LDADD = $(LDADDS) clip_fill_rule_LDADD = $(LDADDS) @@ -345,6 +352,7 @@ nil_surface_LDADD = $(LDADDS) operator_clear_LDADD = $(LDADDS) operator_source_LDADD = $(LDADDS) paint_LDADD = $(LDADDS) +paint_source_alpha_LDADD = $(LDADDS) paint_with_alpha_LDADD = $(LDADDS) path_data_LDADD = $(LDADDS) pattern_get_type_LDADD = $(LDADDS) diff --git a/test/cairo-test.c b/test/cairo-test.c index 00d3fd6c..c61cb0e4 100644 --- a/test/cairo-test.c +++ b/test/cairo-test.c @@ -1803,3 +1803,48 @@ cairo_test_create_pattern_from_png (const char *filename) return pattern; } + +static cairo_status_t +_draw_check (cairo_surface_t *surface, int width, int height) +{ + cairo_t *cr; + cairo_status_t status; + + cr = cairo_create (surface); + cairo_set_source_rgb (cr, 0.75, 0.75, 0.75); /* light gray */ + cairo_paint (cr); + + cairo_set_source_rgb (cr, 0.25, 0.25, 0.25); /* dark gray */ + cairo_rectangle (cr, width / 2, 0, width / 2, height / 2); + cairo_rectangle (cr, 0, height / 2, width / 2, height / 2); + cairo_fill (cr); + + status = cairo_status (cr); + + cairo_destroy (cr); + + return status; +} + +cairo_status_t +cairo_test_paint_checkered (cairo_t *cr) +{ + cairo_status_t status; + cairo_surface_t *check; + + check = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 12, 12); + status = _draw_check (check, 12, 12); + if (status) + return status; + + cairo_save (cr); + cairo_set_source_surface (cr, check, 0, 0); + cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); + cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT); + cairo_paint (cr); + cairo_restore (cr); + + cairo_surface_destroy (check); + + return CAIRO_STATUS_SUCCESS; +} diff --git a/test/cairo-test.h b/test/cairo-test.h index 1ba5e5f4..ea5101d3 100644 --- a/test/cairo-test.h +++ b/test/cairo-test.h @@ -138,6 +138,9 @@ cairo_test_create_surface_from_png (const char *filename); cairo_pattern_t * cairo_test_create_pattern_from_png (const char *filename); +cairo_status_t +cairo_test_paint_checkered (cairo_t *cr); + void xasprintf (char **strp, const char *fmt, ...); diff --git a/test/caps-joins-alpha-ref.png b/test/caps-joins-alpha-ref.png Binary files differnew file mode 100644 index 00000000..85cccf24 --- /dev/null +++ b/test/caps-joins-alpha-ref.png diff --git a/test/caps-joins-alpha-rgb24-ref.png b/test/caps-joins-alpha-rgb24-ref.png Binary files differnew file mode 100644 index 00000000..60163dd4 --- /dev/null +++ b/test/caps-joins-alpha-rgb24-ref.png diff --git a/test/caps-joins-alpha.c b/test/caps-joins-alpha.c new file mode 100644 index 00000000..c28482da --- /dev/null +++ b/test/caps-joins-alpha.c @@ -0,0 +1,94 @@ +/* + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2006 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" + +#define LINE_WIDTH 10. +#define SIZE (5 * LINE_WIDTH) +#define PAD (2 * LINE_WIDTH) + +cairo_test_t test = { + "caps-joins-alpha", + "Test caps and joins with some source alpha", + 3 * (PAD + SIZE) + PAD, + PAD + SIZE + PAD +}; + +static void +make_path (cairo_t *cr) +{ + cairo_move_to (cr, 0., 0.); + cairo_rel_line_to (cr, 0., SIZE); + cairo_rel_line_to (cr, SIZE, 0.); + cairo_close_path (cr); + + cairo_move_to (cr, 2 * LINE_WIDTH, 0.); + cairo_rel_line_to (cr, 3 * LINE_WIDTH, 0.); + cairo_rel_line_to (cr, 0., 3 * LINE_WIDTH); +} + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + /* First draw a checkered background */ + cairo_test_paint_checkered (cr); + + /* Then draw the original caps-joins test but with a bit of alphs thrown in. */ + cairo_set_line_width (cr, LINE_WIDTH); + + cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 0.5); /* 50% red */ + cairo_translate (cr, PAD, PAD); + + make_path (cr); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL); + cairo_stroke (cr); + + cairo_set_source_rgba (cr, 0.0, 1.0, 0.0, 0.5); /* 50% green */ + cairo_translate (cr, SIZE + PAD, 0.); + + make_path (cr); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND); + cairo_stroke (cr); + + cairo_set_source_rgba (cr, 0.0, 0.0, 1.0, 0.5); /* 50% blue */ + + cairo_translate (cr, SIZE + PAD, 0.); + + make_path (cr); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); + cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER); + cairo_stroke (cr); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test, draw); +} diff --git a/test/paint-source-alpha-ref.png b/test/paint-source-alpha-ref.png Binary files differnew file mode 100644 index 00000000..32a3eedf --- /dev/null +++ b/test/paint-source-alpha-ref.png diff --git a/test/paint-source-alpha-rgb24-ref.png b/test/paint-source-alpha-rgb24-ref.png Binary files differnew file mode 100644 index 00000000..49074701 --- /dev/null +++ b/test/paint-source-alpha-rgb24-ref.png diff --git a/test/paint-source-alpha.c b/test/paint-source-alpha.c new file mode 100644 index 00000000..8971939a --- /dev/null +++ b/test/paint-source-alpha.c @@ -0,0 +1,67 @@ +/* + * Copyright © 2005 Red Hat, Inc. + * Copyright © 2006 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 = { + "paint-source-alpha", + "Simple test of cairo_paint with a source surface with non-opaque alpha", + 32, 32 +}; + +static cairo_test_status_t +draw (cairo_t *cr, int width, int height) +{ + cairo_surface_t *surface; + static uint32_t data[16] = { + 0x80808080, 0x80808080, 0x80800000, 0x80800000, + 0x80808080, 0x80808080, 0x80800000, 0x80800000, + + 0x80008000, 0x80008000, 0x80000080, 0x80000080, + 0x80008000, 0x80008000, 0x80000080, 0x80000080 + }; + + surface = cairo_image_surface_create_for_data ((unsigned char *) data, + CAIRO_FORMAT_ARGB32, 4, 4, 16); + + cairo_test_paint_checkered (cr); + + cairo_scale (cr, 4, 4); + + cairo_set_source_surface (cr, surface, 2 , 2); + cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); + cairo_paint (cr); + + cairo_surface_destroy (surface); + + return CAIRO_TEST_SUCCESS; +} + +int +main (void) +{ + return cairo_test (&test, draw); +} diff --git a/test/paint-with-alpha-ref.png b/test/paint-with-alpha-ref.png Binary files differindex d821b5eb..3e3942a0 100644 --- a/test/paint-with-alpha-ref.png +++ b/test/paint-with-alpha-ref.png diff --git a/test/paint-with-alpha-rgb24-ref.png b/test/paint-with-alpha-rgb24-ref.png Binary files differindex b5cf0a70..228a78a2 100644 --- a/test/paint-with-alpha-rgb24-ref.png +++ b/test/paint-with-alpha-rgb24-ref.png diff --git a/test/paint-with-alpha.c b/test/paint-with-alpha.c index 3292d5f9..b204b086 100644 --- a/test/paint-with-alpha.c +++ b/test/paint-with-alpha.c @@ -1,5 +1,6 @@ /* * Copyright © 2005 Red Hat, Inc. + * Copyright © 2006 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without @@ -28,7 +29,7 @@ cairo_test_t test = { "paint-with-alpha", "Simple test of cairo_paint_with_alpha", - 12, 12 + 32, 32 }; static cairo_test_status_t @@ -46,9 +47,11 @@ draw (cairo_t *cr, int width, int height) surface = cairo_image_surface_create_for_data ((unsigned char *) data, CAIRO_FORMAT_RGB24, 4, 4, 16); - cairo_scale (cr, 2, 2); + cairo_test_paint_checkered (cr); - cairo_set_source_surface (cr, surface, 1 , 1); + cairo_scale (cr, 4, 4); + + cairo_set_source_surface (cr, surface, 2 , 2); cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST); cairo_paint_with_alpha (cr, 0.5); |