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.
This commit is contained in:
Andrea Canciani 2010-12-31 13:01:50 +01:00
parent b4aa01f72f
commit ada6057b8c
41 changed files with 200 additions and 520 deletions

View file

@ -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 \

View file

@ -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 \

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 142 KiB

View file

@ -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)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 KiB

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

View file

@ -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)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 200 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 88 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -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)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 245 KiB

After

Width:  |  Height:  |  Size: 399 KiB

View file

@ -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)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 117 KiB

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 188 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 162 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 258 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 175 KiB

After

Width:  |  Height:  |  Size: 258 KiB

View file

@ -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;
double x0, x1, radius0, radius1, left, right, center;
cairo_save (cr);
x0 = 0;
x1 = 1;
radius0 = radiuses[index];
radius1 = radiuses[NUM_GRADIENTS - index - 1];
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);
/* 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_rectangle (cr, x, y, size, size);
cairo_clip (cr);
/* 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_set_source (cr, pattern);
cairo_paint (cr);
cairo_pattern_destroy (pattern);
cairo_restore (cr);
return cairo_pattern_create_radial (x0, 0, radius0, x1, 0, radius1);
}
static cairo_test_status_t
draw (cairo_t *cr, int width, int height)
static void
pattern_add_stops (cairo_pattern_t *pattern)
{
int i, j, k;
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, add_stops_t add_stops, composite_t composite)
{
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)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 184 KiB

After

Width:  |  Height:  |  Size: 251 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 242 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 257 KiB

After

Width:  |  Height:  |  Size: 373 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 258 KiB