diff options
author | Andrea Canciani <ranma42@gmail.com> | 2010-12-31 13:01:50 +0100 |
---|---|---|
committer | Andrea Canciani <ranma42@gmail.com> | 2011-01-02 18:31:35 +0100 |
commit | ada6057b8ccab133909b127850c41abb3216a842 (patch) | |
tree | 267517ab8c8ac2552ee4dbcc6d3b2c72db6bec94 | |
parent | b4aa01f72f98d71bded5f6fa3eaf3d12ad30eb2c (diff) |
test: New radial-gradient tests
The old radial gradient tests were actually drawing the same gradients
with different operators (OVER/SOURCE) and operations (paint/mask).
It is possible to refactor them to share the gradient construction
code. This makes it easy to change the gradient shape in all of them
to test more interesting combinations.
Instead of testing 16 generic positions we are now testing just 7
cases, which correspond to every possible combination of the relative
size and position of the two circles defining the gradient. In
particular we are now testing a constant radius gradient and gradients
with tangent circles.
41 files changed, 200 insertions, 520 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 993511603..b33e4f9d9 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1045,37 +1045,20 @@ REFERENCE_IMAGES = \ quartz-surface-source.ps2.ref.png \ quartz-surface-source.ps3.ref.png \ radial-gradient.image16.ref.png \ - radial-gradient.pdf.xfail.png \ - radial-gradient.quartz.ref.png \ radial-gradient.ref.png \ - radial-gradient.svg.xfail.png \ radial-gradient-extend.ps3.ref.png \ radial-gradient-extend.ref.png \ radial-gradient-source.image16.ref.png \ radial-gradient-source.argb32.ref.png \ radial-gradient-source.rgb24.ref.png \ - radial-gradient-source.pdf.argb32.xfail.png \ - radial-gradient-source.pdf.rgb24.xfail.png \ - radial-gradient-source.quartz.argb32.ref.png \ - radial-gradient-source.quartz.rgb24.ref.png \ - radial-gradient-mask.argb32.ref.png \ - radial-gradient-mask.rgb24.ref.png \ + radial-gradient-mask.ref.png \ radial-gradient-mask.image16.ref.png \ - radial-gradient-mask.pdf.argb32.xfail.png \ - radial-gradient-mask.pdf.rgb24.xfail.png \ - radial-gradient-mask.quartz.argb32.ref.png \ - radial-gradient-mask.quartz.rgb24.ref.png \ radial-gradient-mask-source.argb32.ref.png \ radial-gradient-mask-source.rgb24.ref.png \ radial-gradient-mask-source.image16.ref.png \ - radial-gradient-mask-source.pdf.argb32.xfail.png \ - radial-gradient-mask-source.pdf.rgb24.xfail.png \ - radial-gradient-mask-source.quartz.argb32.ref.png \ - radial-gradient-mask-source.quartz.rgb24.ref.png \ - radial-gradient-one-stop.argb32.ref.png \ - radial-gradient-one-stop.rgb24.ref.png \ - radial-gradient-one-stop.ps3.argb32.ref.png \ - radial-gradient-one-stop.ps3.rgb24.ref.png \ + radial-gradient-mask-source.xlib.argb32.ref.png \ + radial-gradient-mask-source.xlib.rgb24.ref.png \ + radial-gradient-one-stop.ref.png \ random-intersections-eo.image16.ref.png \ random-intersections-eo.ps.ref.png \ random-intersections-eo.quartz.ref.png \ diff --git a/test/Makefile.sources b/test/Makefile.sources index 27b8a2764..9e5e4d2bb 100644 --- a/test/Makefile.sources +++ b/test/Makefile.sources @@ -206,10 +206,6 @@ test_sources = \ push-group-path-offset.c \ radial-gradient.c \ radial-gradient-extend.c \ - radial-gradient-mask.c \ - radial-gradient-mask-source.c \ - radial-gradient-one-stop.c \ - radial-gradient-source.c \ random-intersections-eo.c \ random-intersections-nonzero.c \ random-intersections-curves-eo.c \ diff --git a/test/radial-gradient-mask-source.argb32.ref.png b/test/radial-gradient-mask-source.argb32.ref.png Binary files differindex c1613467f..2bf65b3d6 100644 --- a/test/radial-gradient-mask-source.argb32.ref.png +++ b/test/radial-gradient-mask-source.argb32.ref.png diff --git a/test/radial-gradient-mask-source.c b/test/radial-gradient-mask-source.c deleted file mode 100644 index 27b527051..000000000 --- a/test/radial-gradient-mask-source.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright © 2005, 2007 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Author: Carl D. Worth <cworth@cworth.org> - */ - -#include "cairo-test.h" - -#define NUM_GRADIENTS 4 -#define NUM_EXTEND 4 -#define SIZE 60 -#define WIDTH (SIZE * NUM_GRADIENTS * NUM_GRADIENTS) -#define HEIGHT (SIZE * NUM_EXTEND) - -static void -draw_gradient (cairo_t *cr, - int x, - int y, - int size, - double r1_offset, - double r1_radius, - double r2_offset, - double r2_radius, - cairo_extend_t extend) -{ - cairo_pattern_t *pattern; - - cairo_save (cr); - - pattern = cairo_pattern_create_radial (x + size/2.0 + r1_offset, - y + size/2.0 + r1_offset, - r1_radius, - x + size/2.0 + r2_offset, - y + size/2.0 + r2_offset, - r2_radius); - cairo_pattern_add_color_stop_rgba (pattern, 0.0, - 1.0, 0.0, 0.0, 1.0); - cairo_pattern_add_color_stop_rgba (pattern, sqrt (1.0 / 2.0), - 0.0, 1.0, 0.0, 0.0); - cairo_pattern_add_color_stop_rgba (pattern, 1.0, - 0.0, 0.0, 1.0, 0.5); - cairo_pattern_set_extend (pattern, extend); - - cairo_rectangle (cr, x, y, size, size); - cairo_clip (cr); - - cairo_set_source_rgb (cr, 1, 0, 1); - cairo_mask (cr, pattern); - - cairo_pattern_destroy (pattern); - - cairo_restore (cr); -} - -static cairo_test_status_t -draw (cairo_t *cr, int width, int height) -{ - int i, j, k; - cairo_extend_t extend[NUM_EXTEND] = { - CAIRO_EXTEND_NONE, - CAIRO_EXTEND_REPEAT, - CAIRO_EXTEND_REFLECT, - CAIRO_EXTEND_PAD - }; - - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - for (j = 0; j < NUM_EXTEND; j++) { - for (i = 0; i < NUM_GRADIENTS; i++) { - double r1_offset = i % 2 ? SIZE / 12.0 : 0.0; - double r1_radius = i >= NUM_GRADIENTS / 2 ? SIZE / 6.0 : 0.0; - for (k = 0; k < NUM_GRADIENTS; k++) { - double r2_offset = k % 2 ? SIZE / 12.0 : 0.0; - double r2_radius = k >= NUM_GRADIENTS / 2 ? SIZE / 3.0 : SIZE / 12.; - draw_gradient (cr, - i * SIZE * NUM_GRADIENTS + k * SIZE, j * SIZE, SIZE, - r1_offset, r1_radius, - r2_offset, r2_radius, - extend[j]); - } - } - } - - return CAIRO_TEST_SUCCESS; -} - -CAIRO_TEST (radial_gradient_mask_source, - "Simple test of radial gradients using a MASK with a SOURCE operator", - "gradient,mask,source", /* keywords */ - NULL, /* requirements */ - WIDTH, HEIGHT, - NULL, draw) diff --git a/test/radial-gradient-mask-source.image16.ref.png b/test/radial-gradient-mask-source.image16.ref.png Binary files differindex 0a1456366..edb93a986 100644 --- a/test/radial-gradient-mask-source.image16.ref.png +++ b/test/radial-gradient-mask-source.image16.ref.png diff --git a/test/radial-gradient-mask-source.pdf.argb32.xfail.png b/test/radial-gradient-mask-source.pdf.argb32.xfail.png Binary files differdeleted file mode 100644 index 0cb433068..000000000 --- a/test/radial-gradient-mask-source.pdf.argb32.xfail.png +++ /dev/null diff --git a/test/radial-gradient-mask-source.pdf.rgb24.xfail.png b/test/radial-gradient-mask-source.pdf.rgb24.xfail.png Binary files differdeleted file mode 100644 index 8c096b61a..000000000 --- a/test/radial-gradient-mask-source.pdf.rgb24.xfail.png +++ /dev/null diff --git a/test/radial-gradient-mask-source.quartz.argb32.ref.png b/test/radial-gradient-mask-source.quartz.argb32.ref.png Binary files differdeleted file mode 100644 index 9cb1caa55..000000000 --- a/test/radial-gradient-mask-source.quartz.argb32.ref.png +++ /dev/null diff --git a/test/radial-gradient-mask-source.quartz.rgb24.ref.png b/test/radial-gradient-mask-source.quartz.rgb24.ref.png Binary files differdeleted file mode 100644 index 303033b33..000000000 --- a/test/radial-gradient-mask-source.quartz.rgb24.ref.png +++ /dev/null diff --git a/test/radial-gradient-mask-source.rgb24.ref.png b/test/radial-gradient-mask-source.rgb24.ref.png Binary files differindex 884ebb495..55335196a 100644 --- a/test/radial-gradient-mask-source.rgb24.ref.png +++ b/test/radial-gradient-mask-source.rgb24.ref.png diff --git a/test/radial-gradient-mask-source.xlib.argb32.ref.png b/test/radial-gradient-mask-source.xlib.argb32.ref.png Binary files differnew file mode 100644 index 000000000..1c901c905 --- /dev/null +++ b/test/radial-gradient-mask-source.xlib.argb32.ref.png diff --git a/test/radial-gradient-mask-source.xlib.rgb24.ref.png b/test/radial-gradient-mask-source.xlib.rgb24.ref.png Binary files differnew file mode 100644 index 000000000..e50fe8f2a --- /dev/null +++ b/test/radial-gradient-mask-source.xlib.rgb24.ref.png diff --git a/test/radial-gradient-mask.argb32.ref.png b/test/radial-gradient-mask.argb32.ref.png Binary files differdeleted file mode 100644 index c1613467f..000000000 --- a/test/radial-gradient-mask.argb32.ref.png +++ /dev/null diff --git a/test/radial-gradient-mask.c b/test/radial-gradient-mask.c deleted file mode 100644 index ba03a12df..000000000 --- a/test/radial-gradient-mask.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright © 2005, 2007 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Author: Carl D. Worth <cworth@cworth.org> - */ - -#include "cairo-test.h" - -#define NUM_GRADIENTS 4 -#define NUM_EXTEND 4 -#define SIZE 60 -#define WIDTH (SIZE * NUM_GRADIENTS * NUM_GRADIENTS) -#define HEIGHT (SIZE * NUM_EXTEND) - -static void -draw_gradient (cairo_t *cr, - int x, - int y, - int size, - double r1_offset, - double r1_radius, - double r2_offset, - double r2_radius, - cairo_extend_t extend) -{ - cairo_pattern_t *pattern; - - cairo_save (cr); - - pattern = cairo_pattern_create_radial (x + size/2.0 + r1_offset, - y + size/2.0 + r1_offset, - r1_radius, - x + size/2.0 + r2_offset, - y + size/2.0 + r2_offset, - r2_radius); - cairo_pattern_add_color_stop_rgba (pattern, 0.0, - 1.0, 0.0, 0.0, 1.0); - cairo_pattern_add_color_stop_rgba (pattern, sqrt (1.0 / 2.0), - 0.0, 1.0, 0.0, 0.0); - cairo_pattern_add_color_stop_rgba (pattern, 1.0, - 0.0, 0.0, 1.0, 0.5); - cairo_pattern_set_extend (pattern, extend); - - cairo_rectangle (cr, x, y, size, size); - cairo_clip (cr); - - cairo_set_source_rgb (cr, 1, 0, 1); - cairo_mask (cr, pattern); - - cairo_pattern_destroy (pattern); - - cairo_restore (cr); -} - -static cairo_test_status_t -draw (cairo_t *cr, int width, int height) -{ - int i, j, k; - cairo_extend_t extend[NUM_EXTEND] = { - CAIRO_EXTEND_NONE, - CAIRO_EXTEND_REPEAT, - CAIRO_EXTEND_REFLECT, - CAIRO_EXTEND_PAD - }; - - for (j = 0; j < NUM_EXTEND; j++) { - for (i = 0; i < NUM_GRADIENTS; i++) { - double r1_offset = i % 2 ? SIZE / 12.0 : 0.0; - double r1_radius = i >= NUM_GRADIENTS / 2 ? SIZE / 6.0 : 0.0; - for (k = 0; k < NUM_GRADIENTS; k++) { - double r2_offset = k % 2 ? SIZE / 12.0 : 0.0; - double r2_radius = k >= NUM_GRADIENTS / 2 ? SIZE / 3.0 : SIZE / 12.; - draw_gradient (cr, - i * SIZE * NUM_GRADIENTS + k * SIZE, j * SIZE, SIZE, - r1_offset, r1_radius, - r2_offset, r2_radius, - extend[j]); - } - } - } - - return CAIRO_TEST_SUCCESS; -} - -CAIRO_TEST (radial_gradient_mask, - "Simple test of radial gradients using a MASK", - "gradient,mask", /* keywords */ - NULL, /* requirements */ - WIDTH, HEIGHT, - NULL, draw) diff --git a/test/radial-gradient-mask.image16.ref.png b/test/radial-gradient-mask.image16.ref.png Binary files differindex 0a1456366..78712ca52 100644 --- a/test/radial-gradient-mask.image16.ref.png +++ b/test/radial-gradient-mask.image16.ref.png diff --git a/test/radial-gradient-mask.pdf.argb32.xfail.png b/test/radial-gradient-mask.pdf.argb32.xfail.png Binary files differdeleted file mode 100644 index 0cb433068..000000000 --- a/test/radial-gradient-mask.pdf.argb32.xfail.png +++ /dev/null diff --git a/test/radial-gradient-mask.pdf.rgb24.xfail.png b/test/radial-gradient-mask.pdf.rgb24.xfail.png Binary files differdeleted file mode 100644 index 8c096b61a..000000000 --- a/test/radial-gradient-mask.pdf.rgb24.xfail.png +++ /dev/null diff --git a/test/radial-gradient-mask.quartz.argb32.ref.png b/test/radial-gradient-mask.quartz.argb32.ref.png Binary files differdeleted file mode 100644 index 9cb1caa55..000000000 --- a/test/radial-gradient-mask.quartz.argb32.ref.png +++ /dev/null diff --git a/test/radial-gradient-mask.quartz.rgb24.ref.png b/test/radial-gradient-mask.quartz.rgb24.ref.png Binary files differdeleted file mode 100644 index 303033b33..000000000 --- a/test/radial-gradient-mask.quartz.rgb24.ref.png +++ /dev/null diff --git a/test/radial-gradient-mask.ref.png b/test/radial-gradient-mask.ref.png Binary files differnew file mode 100644 index 000000000..4db39aa3f --- /dev/null +++ b/test/radial-gradient-mask.ref.png diff --git a/test/radial-gradient-mask.rgb24.ref.png b/test/radial-gradient-mask.rgb24.ref.png Binary files differdeleted file mode 100644 index 884ebb495..000000000 --- a/test/radial-gradient-mask.rgb24.ref.png +++ /dev/null diff --git a/test/radial-gradient-one-stop.argb32.ref.png b/test/radial-gradient-one-stop.argb32.ref.png Binary files differdeleted file mode 100644 index 0aa45108f..000000000 --- a/test/radial-gradient-one-stop.argb32.ref.png +++ /dev/null diff --git a/test/radial-gradient-one-stop.c b/test/radial-gradient-one-stop.c deleted file mode 100644 index 552de2382..000000000 --- a/test/radial-gradient-one-stop.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright © 2005, 2007 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Author: Carl D. Worth <cworth@cworth.org> - */ - -#include "cairo-test.h" - -#define NUM_GRADIENTS 4 -#define NUM_EXTEND 4 -#define SIZE 60 -#define WIDTH (SIZE * NUM_GRADIENTS * NUM_GRADIENTS) -#define HEIGHT (SIZE * NUM_EXTEND) - -static void -draw_gradient (cairo_t *cr, - int x, - int y, - int size, - double r1_offset, - double r1_radius, - double r2_offset, - double r2_radius, - cairo_extend_t extend) -{ - cairo_pattern_t *pattern; - - cairo_save (cr); - - pattern = cairo_pattern_create_radial (x + size/2.0 + r1_offset, - y + size/2.0 + r1_offset, - r1_radius, - x + size/2.0 + r2_offset, - y + size/2.0 + r2_offset, - r2_radius); - cairo_pattern_add_color_stop_rgb (pattern, 0.25, 1, 0, 0); - cairo_pattern_set_extend (pattern, extend); - - cairo_rectangle (cr, x, y, size, size); - cairo_clip (cr); - - cairo_set_source (cr, pattern); - cairo_paint (cr); - - cairo_pattern_destroy (pattern); - - cairo_restore (cr); -} - -static cairo_test_status_t -draw (cairo_t *cr, int width, int height) -{ - int i, j, k; - cairo_extend_t extend[NUM_EXTEND] = { - CAIRO_EXTEND_NONE, - CAIRO_EXTEND_REPEAT, - CAIRO_EXTEND_REFLECT, - CAIRO_EXTEND_PAD - }; - - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - - for (j = 0; j < NUM_EXTEND; j++) { - for (i = 0; i < NUM_GRADIENTS; i++) { - double r1_offset = i % 2 ? SIZE / 12.0 : 0.0; - double r1_radius = i >= NUM_GRADIENTS / 2 ? SIZE / 6.0 : 0.0; - for (k = 0; k < NUM_GRADIENTS; k++) { - double r2_offset = k % 2 ? SIZE / 12.0 : 0.0; - double r2_radius = k >= NUM_GRADIENTS / 2 ? SIZE / 3.0 : SIZE / 12.; - draw_gradient (cr, - i * SIZE * NUM_GRADIENTS + k * SIZE, j * SIZE, SIZE, - r1_offset, r1_radius, - r2_offset, r2_radius, - extend[j]); - } - } - } - - return CAIRO_TEST_SUCCESS; -} - -CAIRO_TEST (radial_gradient_one_stop, - "Tests radial gradients with a single stop", - "gradient,radial", /* keywords */ - NULL, /* requirements */ - WIDTH, HEIGHT, - NULL, draw) diff --git a/test/radial-gradient-one-stop.ps3.argb32.ref.png b/test/radial-gradient-one-stop.ps3.argb32.ref.png Binary files differdeleted file mode 100644 index 0d2150851..000000000 --- a/test/radial-gradient-one-stop.ps3.argb32.ref.png +++ /dev/null diff --git a/test/radial-gradient-one-stop.ps3.rgb24.ref.png b/test/radial-gradient-one-stop.ps3.rgb24.ref.png Binary files differdeleted file mode 100644 index 0d965ccc6..000000000 --- a/test/radial-gradient-one-stop.ps3.rgb24.ref.png +++ /dev/null diff --git a/test/radial-gradient-one-stop.ref.png b/test/radial-gradient-one-stop.ref.png Binary files differnew file mode 100644 index 000000000..fb35be61d --- /dev/null +++ b/test/radial-gradient-one-stop.ref.png diff --git a/test/radial-gradient-one-stop.rgb24.ref.png b/test/radial-gradient-one-stop.rgb24.ref.png Binary files differdeleted file mode 100644 index 74c848bee..000000000 --- a/test/radial-gradient-one-stop.rgb24.ref.png +++ /dev/null diff --git a/test/radial-gradient-source.argb32.ref.png b/test/radial-gradient-source.argb32.ref.png Binary files differindex d915579be..4ab4796fa 100644 --- a/test/radial-gradient-source.argb32.ref.png +++ b/test/radial-gradient-source.argb32.ref.png diff --git a/test/radial-gradient-source.c b/test/radial-gradient-source.c deleted file mode 100644 index b546157a4..000000000 --- a/test/radial-gradient-source.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright © 2005, 2007 Red Hat, Inc. - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, copy, - * modify, merge, publish, distribute, sublicense, and/or sell copies - * of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Author: Carl D. Worth <cworth@cworth.org> - */ - -/* 20091017: A simple variant on radial-gradient, using the SOURCE operator - * instead as a potential bug was found in pixman under those conditions. - */ - -#include "cairo-test.h" - -#define NUM_GRADIENTS 4 -#define NUM_EXTEND 4 -#define SIZE 60 -#define WIDTH (SIZE * NUM_GRADIENTS * NUM_GRADIENTS) -#define HEIGHT (SIZE * NUM_EXTEND) - -static void -draw_gradient (cairo_t *cr, - int x, - int y, - int size, - double r1_offset, - double r1_radius, - double r2_offset, - double r2_radius, - cairo_extend_t extend) -{ - cairo_pattern_t *pattern; - - cairo_save (cr); - - pattern = cairo_pattern_create_radial (x + size/2.0 + r1_offset, - y + size/2.0 + r1_offset, - r1_radius, - x + size/2.0 + r2_offset, - y + size/2.0 + r2_offset, - r2_radius); - cairo_pattern_add_color_stop_rgba (pattern, 0.0, - 1.0, 0.0, 0.0, 1.0); - cairo_pattern_add_color_stop_rgba (pattern, sqrt (1.0 / 2.0), - 0.0, 1.0, 0.0, 0.0); - cairo_pattern_add_color_stop_rgba (pattern, 1.0, - 0.0, 0.0, 1.0, 0.5); - cairo_pattern_set_extend (pattern, extend); - - cairo_rectangle (cr, x, y, size, size); - cairo_clip (cr); - - cairo_set_source (cr, pattern); - cairo_paint (cr); - - cairo_pattern_destroy (pattern); - - cairo_restore (cr); -} - -static cairo_test_status_t -draw (cairo_t *cr, int width, int height) -{ - int i, j, k; - cairo_extend_t extend[NUM_EXTEND] = { - CAIRO_EXTEND_NONE, - CAIRO_EXTEND_REPEAT, - CAIRO_EXTEND_REFLECT, - CAIRO_EXTEND_PAD - }; - - cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); - for (j = 0; j < NUM_EXTEND; j++) { - for (i = 0; i < NUM_GRADIENTS; i++) { - double r1_offset = i % 2 ? SIZE / 12.0 : 0.0; - double r1_radius = i >= NUM_GRADIENTS / 2 ? SIZE / 6.0 : 0.0; - for (k = 0; k < NUM_GRADIENTS; k++) { - double r2_offset = k % 2 ? SIZE / 12.0 : 0.0; - double r2_radius = k >= NUM_GRADIENTS / 2 ? SIZE / 3.0 : SIZE / 12.; - draw_gradient (cr, - i * SIZE * NUM_GRADIENTS + k * SIZE, j * SIZE, SIZE, - r1_offset, r1_radius, - r2_offset, r2_radius, - extend[j]); - } - } - } - - return CAIRO_TEST_SUCCESS; -} - -CAIRO_TEST (radial_gradient_source, - "Simple test of radial gradients using the SOURCE operator", - "gradient,source", /* keywords */ - NULL, /* requirements */ - WIDTH, HEIGHT, - NULL, draw) diff --git a/test/radial-gradient-source.image16.ref.png b/test/radial-gradient-source.image16.ref.png Binary files differindex 8c815df33..f992b6f39 100644 --- a/test/radial-gradient-source.image16.ref.png +++ b/test/radial-gradient-source.image16.ref.png diff --git a/test/radial-gradient-source.pdf.argb32.xfail.png b/test/radial-gradient-source.pdf.argb32.xfail.png Binary files differdeleted file mode 100644 index e4504489b..000000000 --- a/test/radial-gradient-source.pdf.argb32.xfail.png +++ /dev/null diff --git a/test/radial-gradient-source.pdf.rgb24.xfail.png b/test/radial-gradient-source.pdf.rgb24.xfail.png Binary files differdeleted file mode 100644 index fc0174d4e..000000000 --- a/test/radial-gradient-source.pdf.rgb24.xfail.png +++ /dev/null diff --git a/test/radial-gradient-source.quartz.argb32.ref.png b/test/radial-gradient-source.quartz.argb32.ref.png Binary files differdeleted file mode 100644 index 77caab8f6..000000000 --- a/test/radial-gradient-source.quartz.argb32.ref.png +++ /dev/null diff --git a/test/radial-gradient-source.quartz.rgb24.ref.png b/test/radial-gradient-source.quartz.rgb24.ref.png Binary files differdeleted file mode 100644 index 2870f5e9c..000000000 --- a/test/radial-gradient-source.quartz.rgb24.ref.png +++ /dev/null diff --git a/test/radial-gradient-source.rgb24.ref.png b/test/radial-gradient-source.rgb24.ref.png Binary files differindex 09c2edc30..afaa24118 100644 --- a/test/radial-gradient-source.rgb24.ref.png +++ b/test/radial-gradient-source.rgb24.ref.png diff --git a/test/radial-gradient.c b/test/radial-gradient.c index a6d145c63..3ad4bb9da 100644 --- a/test/radial-gradient.c +++ b/test/radial-gradient.c @@ -26,56 +26,113 @@ #include "cairo-test.h" -#define NUM_GRADIENTS 4 +#define NUM_GRADIENTS 7 #define NUM_EXTEND 4 -#define SIZE 60 -#define WIDTH (SIZE * NUM_GRADIENTS * NUM_GRADIENTS) +#define SIZE 120 +#define WIDTH (SIZE * NUM_GRADIENTS) #define HEIGHT (SIZE * NUM_EXTEND) -static void -draw_gradient (cairo_t *cr, - int x, - int y, - int size, - double r1_offset, - double r1_radius, - double r2_offset, - double r2_radius, - cairo_extend_t extend) +typedef void (*composite_t)(cairo_t *cr, cairo_pattern_t *pattern); +typedef void (*add_stops_t)(cairo_pattern_t *pattern); + +/* + * We want to test all the possible relative positions of the start + * and end circle: + * + * - The start circle can be smaller/equal/bigger than the end + * circle. A radial gradient can be classified in one of these + * three cases depending on the sign of dr. + * + * - The smaller circle can be completely inside/internally + * tangent/outside (at least in part) of the bigger circle. This + * classification is the same as the one which can be computed by + * examining the sign of a = (dx^2 + dy^2 - dr^2). + * + * - If the two circles have the same size, neither can be inside or + * internally tangent + * + * This test draws radial gradients whose circles always have the same + * centers (0, 0) and (1, 0), but with different radiuses. From left + * to right: + * + * - Small start circle completely inside the end circle + * 0.25 -> 1.75; dr = 1.5 > 0; a = 1 - 1.50^2 < 0 + * + * - Small start circle internally tangent to the end circle + * 0.50 -> 1.50; dr = 1.0 > 0; a = 1 - 1.00^2 = 0 + * + * - Small start circle outside of the end circle + * 0.50 -> 1.00; dr = 0.5 > 0; a = 1 - 0.50^2 > 0 + * + * - Start circle with the same size as the end circle + * 1.00 -> 1.00; dr = 0.0 = 0; a = 1 - 0.00^2 > 0 + * + * - Small end circle outside of the start circle + * 1.00 -> 0.50; dr = -0.5 > 0; a = 1 - 0.50^2 > 0 + * + * - Small end circle internally tangent to the start circle + * 1.50 -> 0.50; dr = -1.0 > 0; a = 1 - 1.00^2 = 0 + * + * - Small end circle completely inside the start circle + * 1.75 -> 0.25; dr = -1.5 > 0; a = 1 - 1.50^2 < 0 + * + */ + +const static double radiuses[NUM_GRADIENTS] = { + 0.25, + 0.50, + 0.50, + 1.00, + 1.00, + 1.50, + 1.75 +}; + +static cairo_pattern_t * +create_pattern (int index) { - cairo_pattern_t *pattern; - - cairo_save (cr); - - pattern = cairo_pattern_create_radial (x + size/2.0 + r1_offset, - y + size/2.0 + r1_offset, - r1_radius, - x + size/2.0 + r2_offset, - y + size/2.0 + r2_offset, - r2_radius); - cairo_pattern_add_color_stop_rgba (pattern, 0.0, - 1.0, 0.0, 0.0, 1.0); - cairo_pattern_add_color_stop_rgba (pattern, sqrt (1.0 / 2.0), - 0.0, 1.0, 0.0, 0.0); - cairo_pattern_add_color_stop_rgba (pattern, 1.0, - 0.0, 0.0, 1.0, 0.5); - cairo_pattern_set_extend (pattern, extend); - - cairo_rectangle (cr, x, y, size, size); - cairo_clip (cr); + double x0, x1, radius0, radius1, left, right, center; - cairo_set_source (cr, pattern); - cairo_paint (cr); + x0 = 0; + x1 = 1; + radius0 = radiuses[index]; + radius1 = radiuses[NUM_GRADIENTS - index - 1]; + + /* center the gradient */ + left = fmin (x0 - radius0, x1 - radius1); + right = fmax (x0 + radius0, x1 + radius1); + center = (left + right) * 0.5; + x0 -= center; + x1 -= center; - cairo_pattern_destroy (pattern); + /* scale to make it fit within a 1x1 rect centered in (0,0) */ + x0 *= 0.25; + x1 *= 0.25; + radius0 *= 0.25; + radius1 *= 0.25; - cairo_restore (cr); + return cairo_pattern_create_radial (x0, 0, radius0, x1, 0, radius1); } +static void +pattern_add_stops (cairo_pattern_t *pattern) +{ + cairo_pattern_add_color_stop_rgba (pattern, 0.0, 1, 0, 0, 0.75); + cairo_pattern_add_color_stop_rgba (pattern, sqrt (0.5), 0, 1, 0, 0); + cairo_pattern_add_color_stop_rgba (pattern, 1.0, 0, 0, 1, 1); +} + +static void +pattern_add_single_stop (cairo_pattern_t *pattern) +{ + cairo_pattern_add_color_stop_rgba (pattern, 0.25, 1, 0, 0, 1); +} + + static cairo_test_status_t -draw (cairo_t *cr, int width, int height) +draw (cairo_t *cr, add_stops_t add_stops, composite_t composite) { - int i, j, k; + int i, j; cairo_extend_t extend[NUM_EXTEND] = { CAIRO_EXTEND_NONE, CAIRO_EXTEND_REPEAT, @@ -83,30 +140,117 @@ draw (cairo_t *cr, int width, int height) CAIRO_EXTEND_PAD }; - cairo_test_paint_checkered (cr); + cairo_scale (cr, SIZE, SIZE); + cairo_translate (cr, 0.5, 0.5); for (j = 0; j < NUM_EXTEND; j++) { + cairo_save (cr); for (i = 0; i < NUM_GRADIENTS; i++) { - double r1_offset = i % 2 ? SIZE / 12.0 : 0.0; - double r1_radius = i >= NUM_GRADIENTS / 2 ? SIZE / 6.0 : 0.0; - for (k = 0; k < NUM_GRADIENTS; k++) { - double r2_offset = k % 2 ? SIZE / 12.0 : 0.0; - double r2_radius = k >= NUM_GRADIENTS / 2 ? SIZE / 3.0 : SIZE / 12.; - draw_gradient (cr, - i * SIZE * NUM_GRADIENTS + k * SIZE, j * SIZE, SIZE, - r1_offset, r1_radius, - r2_offset, r2_radius, - extend[j]); - } + cairo_pattern_t *pattern; + + pattern = create_pattern (i); + add_stops (pattern); + cairo_pattern_set_extend (pattern, extend[j]); + + cairo_save (cr); + cairo_rectangle (cr, -0.5, -0.5, 1, 1); + cairo_clip (cr); + composite (cr, pattern); + cairo_restore (cr); + cairo_pattern_destroy (pattern); + + cairo_translate (cr, 1, 0); } + cairo_restore (cr); + cairo_translate (cr, 0, 1); } return CAIRO_TEST_SUCCESS; } + +static void +composite_simple (cairo_t *cr, cairo_pattern_t *pattern) +{ + cairo_set_source (cr, pattern); + cairo_paint (cr); +} + +static void +composite_mask (cairo_t *cr, cairo_pattern_t *pattern) +{ + cairo_set_source_rgb (cr, 1, 0, 1); + cairo_mask (cr, pattern); +} + + +static cairo_test_status_t +draw_simple (cairo_t *cr, int width, int height) +{ + cairo_test_paint_checkered (cr); + return draw (cr, pattern_add_stops, composite_simple); +} + +static cairo_test_status_t +draw_mask (cairo_t *cr, int width, int height) +{ + cairo_test_paint_checkered (cr); + return draw (cr, pattern_add_stops, composite_mask); +} + +static cairo_test_status_t +draw_source (cairo_t *cr, int width, int height) +{ + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + return draw (cr, pattern_add_stops, composite_simple); +} + + +static cairo_test_status_t +draw_mask_source (cairo_t *cr, int width, int height) +{ + cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE); + return draw (cr, pattern_add_stops, composite_mask); +} + +static cairo_test_status_t +draw_one_stop (cairo_t *cr, int width, int height) +{ + cairo_test_paint_checkered (cr); + return draw (cr, pattern_add_single_stop, composite_simple); +} + CAIRO_TEST (radial_gradient, "Simple test of radial gradients", "gradient", /* keywords */ NULL, /* requirements */ WIDTH, HEIGHT, - NULL, draw) + NULL, draw_simple) + +CAIRO_TEST (radial_gradient_mask, + "Simple test of radial gradients using a MASK", + "gradient,mask", /* keywords */ + NULL, /* requirements */ + WIDTH, HEIGHT, + NULL, draw_mask) + +CAIRO_TEST (radial_gradient_source, + "Simple test of radial gradients using the SOURCE operator", + "gradient,source", /* keywords */ + NULL, /* requirements */ + WIDTH, HEIGHT, + NULL, draw_source) + +CAIRO_TEST (radial_gradient_mask_source, + "Simple test of radial gradients using a MASK with a SOURCE operator", + "gradient,mask,source", /* keywords */ + NULL, /* requirements */ + WIDTH, HEIGHT, + NULL, draw_mask_source) + +CAIRO_TEST (radial_gradient_one_stop, + "Tests radial gradients with a single stop", + "gradient,radial", /* keywords */ + NULL, /* requirements */ + WIDTH, HEIGHT, + NULL, draw_one_stop) diff --git a/test/radial-gradient.image16.ref.png b/test/radial-gradient.image16.ref.png Binary files differindex 737f51874..91202d3c4 100644 --- a/test/radial-gradient.image16.ref.png +++ b/test/radial-gradient.image16.ref.png diff --git a/test/radial-gradient.pdf.xfail.png b/test/radial-gradient.pdf.xfail.png Binary files differdeleted file mode 100644 index f7e68fb00..000000000 --- a/test/radial-gradient.pdf.xfail.png +++ /dev/null diff --git a/test/radial-gradient.quartz.ref.png b/test/radial-gradient.quartz.ref.png Binary files differdeleted file mode 100644 index 21b6b46b2..000000000 --- a/test/radial-gradient.quartz.ref.png +++ /dev/null diff --git a/test/radial-gradient.ref.png b/test/radial-gradient.ref.png Binary files differindex 91eda5658..a2cbbc82e 100644 --- a/test/radial-gradient.ref.png +++ b/test/radial-gradient.ref.png diff --git a/test/radial-gradient.svg.xfail.png b/test/radial-gradient.svg.xfail.png Binary files differdeleted file mode 100644 index ab54a3da1..000000000 --- a/test/radial-gradient.svg.xfail.png +++ /dev/null |