summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2011-06-25 08:41:52 +0200
committerAndrea Canciani <ranma42@gmail.com>2011-06-25 10:19:36 +0200
commitacfc00168571928a882787d3c6622efde22172e0 (patch)
tree15398c03c59aecfda15c7fd14f67e8c4ffe28d83
parent5fffa3fae122da624aa79923ff13c781842e005d (diff)
test: Add extended-blend-solid tests
Unify extended-blend* tests and add a solid pattern version, which crashes on the win32 backend. Bug pointed out by Peter Frentrup <peter_frentrup@gmx.de> in http://lists.cairographics.org/archives/cairo/2011-April/021908.html
-rw-r--r--test/Makefile.refs6
-rw-r--r--test/Makefile.sources1
-rw-r--r--test/extended-blend-alpha.c115
-rw-r--r--test/extended-blend-solid-alpha.argb32.ref.pngbin0 -> 9406 bytes
-rw-r--r--test/extended-blend-solid-alpha.image16.ref.pngbin0 -> 4626 bytes
-rw-r--r--test/extended-blend-solid-alpha.rgb24.ref.pngbin0 -> 5743 bytes
-rw-r--r--test/extended-blend-solid.argb32.ref.pngbin0 -> 4071 bytes
-rw-r--r--test/extended-blend-solid.image16.ref.pngbin0 -> 4145 bytes
-rw-r--r--test/extended-blend-solid.rgb24.ref.pngbin0 -> 3772 bytes
-rw-r--r--test/extended-blend.c170
10 files changed, 138 insertions, 154 deletions
diff --git a/test/Makefile.refs b/test/Makefile.refs
index d1d6c802..10cab7af 100644
--- a/test/Makefile.refs
+++ b/test/Makefile.refs
@@ -391,6 +391,12 @@ REFERENCE_IMAGES = \
extended-blend-alpha.rgb24.ref.png \
extended-blend-alpha.svg12.argb32.xfail.png \
extended-blend-alpha.svg12.rgb24.xfail.png \
+ extended-blend-solid-alpha.argb32.ref.png \
+ extended-blend-solid-alpha.image16.ref.png \
+ extended-blend-solid-alpha.rgb24.ref.png \
+ extended-blend-solid.argb32.ref.png \
+ extended-blend-solid.image16.ref.png \
+ extended-blend-solid.rgb24.ref.png \
extended-blend.argb32.ref.png \
extended-blend.image16.ref.png \
extended-blend.quartz.argb32.ref.png \
diff --git a/test/Makefile.sources b/test/Makefile.sources
index 5a0beb31..c5a949ae 100644
--- a/test/Makefile.sources
+++ b/test/Makefile.sources
@@ -95,7 +95,6 @@ test_sources = \
extend-repeat.c \
extend-repeat-similar.c \
extended-blend.c \
- extended-blend-alpha.c \
fill-alpha.c \
fill-alpha-pattern.c \
fill-and-stroke.c \
diff --git a/test/extended-blend-alpha.c b/test/extended-blend-alpha.c
deleted file mode 100644
index e0316f35..00000000
--- a/test/extended-blend-alpha.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright © 2005 Red Hat, Inc.
- * Copyright © 2007 Emmanuel Pacaud
- * Copyright © 2008 Benjamin Otte
- *
- * 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: Owen Taylor <otaylor@redhat.com>
- * Kristian Høgsberg <krh@redhat.com>
- * Emmanuel Pacaud <emmanuel.pacaud@lapp.in2p3.fr>
- */
-
-#include <math.h>
-#include "cairo-test.h"
-#include <stdio.h>
-
-#define STEPS 16
-#define START_OPERATOR CAIRO_OPERATOR_MULTIPLY
-#define STOP_OPERATOR CAIRO_OPERATOR_HSL_LUMINOSITY
-
-static void
-create_patterns (cairo_t *bg, cairo_t *fg)
-{
- int x;
-
- for (x = 0; x < STEPS; x++) {
- /* draw a yellow background fading in using discrete steps */
- cairo_set_source_rgba (bg, 1, 1, 0, (double) x / (STEPS - 1));
- cairo_rectangle (bg, x, 0, 1, STEPS);
- cairo_fill (bg);
-
- /* draw an orthogonal teal pattern fading in using discrete steps */
- cairo_set_source_rgba (fg, 0, 1, 1, (double) x / (STEPS - 1));
- cairo_rectangle (fg, 0, x, STEPS, 1);
- cairo_fill (fg);
- }
-}
-
-/* expects a STEP*STEP pixel rectangle */
-static void
-do_blend (cairo_t *cr, cairo_operator_t op, cairo_surface_t *bg, cairo_surface_t *fg)
-{
- /* not using CAIRO_OPERATOR_SOURCE here, it triggers a librsvg bug */
- cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
- cairo_set_source_surface (cr, bg, 0, 0);
- cairo_paint (cr);
-
- cairo_set_operator (cr, op);
- cairo_set_source_surface (cr, fg, 0, 0);
- cairo_paint (cr);
-}
-
-#define SIZE 5
-#define COUNT 4
-#define FULL_WIDTH ((STEPS + 1) * COUNT - 1)
-#define FULL_HEIGHT ((COUNT + STOP_OPERATOR - START_OPERATOR) / COUNT) * (STEPS + 1)
-
-static cairo_test_status_t
-draw (cairo_t *cr, int width, int height)
-{
- size_t i = 0;
- cairo_operator_t op;
- cairo_t *bgcr, *fgcr;
- cairo_surface_t *bg, *fg;
-
- bg = cairo_surface_create_similar (cairo_get_target (cr),
- CAIRO_CONTENT_COLOR_ALPHA, SIZE * STEPS, SIZE * STEPS);
- fg = cairo_surface_create_similar (cairo_get_target (cr),
- CAIRO_CONTENT_COLOR_ALPHA, SIZE * STEPS, SIZE * STEPS);
- bgcr = cairo_create (bg);
- fgcr = cairo_create (fg);
- cairo_scale (bgcr, SIZE, SIZE);
- cairo_scale (fgcr, SIZE, SIZE);
- create_patterns (bgcr, fgcr);
- cairo_destroy (bgcr);
- cairo_destroy (fgcr);
-
- for (op = START_OPERATOR; op <= STOP_OPERATOR; op++, i++) {
- cairo_save (cr);
- cairo_translate (cr,
- SIZE * (STEPS + 1) * (i % COUNT),
- SIZE * (STEPS + 1) * (i / COUNT));
- do_blend (cr, op, bg, fg);
- cairo_restore (cr);
- }
-
- cairo_surface_destroy (fg);
- cairo_surface_destroy (bg);
-
- return CAIRO_TEST_SUCCESS;
-}
-
-CAIRO_TEST (extended_blend_alpha,
- "Tests extended blend modes with alpha",
- "operator", /* keywords */
- NULL, /* requirements */
- FULL_WIDTH * SIZE, FULL_HEIGHT * SIZE,
- NULL, draw)
diff --git a/test/extended-blend-solid-alpha.argb32.ref.png b/test/extended-blend-solid-alpha.argb32.ref.png
new file mode 100644
index 00000000..4d56a21f
--- /dev/null
+++ b/test/extended-blend-solid-alpha.argb32.ref.png
Binary files differ
diff --git a/test/extended-blend-solid-alpha.image16.ref.png b/test/extended-blend-solid-alpha.image16.ref.png
new file mode 100644
index 00000000..df964697
--- /dev/null
+++ b/test/extended-blend-solid-alpha.image16.ref.png
Binary files differ
diff --git a/test/extended-blend-solid-alpha.rgb24.ref.png b/test/extended-blend-solid-alpha.rgb24.ref.png
new file mode 100644
index 00000000..f62dda95
--- /dev/null
+++ b/test/extended-blend-solid-alpha.rgb24.ref.png
Binary files differ
diff --git a/test/extended-blend-solid.argb32.ref.png b/test/extended-blend-solid.argb32.ref.png
new file mode 100644
index 00000000..083fe873
--- /dev/null
+++ b/test/extended-blend-solid.argb32.ref.png
Binary files differ
diff --git a/test/extended-blend-solid.image16.ref.png b/test/extended-blend-solid.image16.ref.png
new file mode 100644
index 00000000..2052ea7c
--- /dev/null
+++ b/test/extended-blend-solid.image16.ref.png
Binary files differ
diff --git a/test/extended-blend-solid.rgb24.ref.png b/test/extended-blend-solid.rgb24.ref.png
new file mode 100644
index 00000000..53c1b226
--- /dev/null
+++ b/test/extended-blend-solid.rgb24.ref.png
Binary files differ
diff --git a/test/extended-blend.c b/test/extended-blend.c
index cd2b06b9..45e0e480 100644
--- a/test/extended-blend.c
+++ b/test/extended-blend.c
@@ -35,29 +35,97 @@
#define START_OPERATOR CAIRO_OPERATOR_MULTIPLY
#define STOP_OPERATOR CAIRO_OPERATOR_HSL_LUMINOSITY
+#define SIZE 5
+#define COUNT 4
+#define FULL_WIDTH ((STEPS + 1) * COUNT - 1)
+#define FULL_HEIGHT ((COUNT + STOP_OPERATOR - START_OPERATOR) / COUNT) * (STEPS + 1)
+
+static void
+set_solid_pattern (cairo_t *cr,
+ int step,
+ cairo_bool_t bg,
+ cairo_bool_t alpha)
+{
+ double c, a;
+
+ a = ((double) step) / (STEPS - 1);
+ if (alpha) {
+ c = 1;
+ } else {
+ c = a;
+ a = 1;
+ }
+
+ if (bg) /* draw a yellow background fading in using discrete steps */
+ cairo_set_source_rgba (cr, c, c, 0, a);
+ else /* draw a teal foreground pattern fading in using discrete steps */
+ cairo_set_source_rgba (cr, 0, c, c, a);
+}
+
+/* expects a STEP*STEP pixel rectangle */
static void
-create_patterns (cairo_t *bg, cairo_t *fg)
+do_blend_solid (cairo_t *cr, cairo_operator_t op, cairo_bool_t alpha)
{
int x;
+ cairo_save (cr);
+ cairo_scale (cr, SIZE, SIZE);
+
+ /* not using CAIRO_OPERATOR_SOURCE here, it triggers a librsvg bug */
+ cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
+ for (x = 0; x < STEPS; x++) {
+ /* draw the background using discrete steps */
+ set_solid_pattern (cr, x, TRUE, alpha);
+ cairo_rectangle (cr, x, 0, 1, STEPS);
+ cairo_fill (cr);
+ }
+
+ cairo_set_operator (cr, op);
for (x = 0; x < STEPS; x++) {
- double i = (double) x / (STEPS - 1);
- /* draw a yellow background fading in using discrete steps */
- cairo_set_source_rgba (bg, i, i, 0, 1);
- cairo_rectangle (bg, x, 0, 1, STEPS);
- cairo_fill (bg);
-
- /* draw an orthogonal teal pattern fading in using discrete steps */
- cairo_set_source_rgba (fg, 0, i, i, 1);
- cairo_rectangle (fg, 0, x, STEPS, 1);
- cairo_fill (fg);
+ /* draw an orthogonal foreground pattern using discrete steps */
+ set_solid_pattern (cr, x, FALSE, alpha);
+ cairo_rectangle (cr, 0, x, STEPS, 1);
+ cairo_fill (cr);
}
+
+ cairo_restore (cr);
+}
+
+static void
+create_patterns (cairo_t *cr,
+ cairo_surface_t **bg,
+ cairo_surface_t **fg,
+ cairo_bool_t alpha)
+{
+ cairo_t *bgcr, *fgcr;
+
+ *bg = cairo_surface_create_similar (cairo_get_target (cr),
+ CAIRO_CONTENT_COLOR_ALPHA,
+ SIZE * STEPS,
+ SIZE * STEPS);
+ *fg = cairo_surface_create_similar (cairo_get_target (cr),
+ CAIRO_CONTENT_COLOR_ALPHA,
+ SIZE * STEPS,
+ SIZE * STEPS);
+
+ bgcr = cairo_create (*bg);
+ fgcr = cairo_create (*fg);
+
+ do_blend_solid (bgcr, CAIRO_OPERATOR_DEST, alpha);
+ do_blend_solid (fgcr, CAIRO_OPERATOR_SOURCE, alpha);
+
+ cairo_destroy (bgcr);
+ cairo_destroy (fgcr);
}
/* expects a STEP*STEP pixel rectangle */
static void
-do_blend (cairo_t *cr, cairo_operator_t op, cairo_surface_t *bg, cairo_surface_t *fg)
+do_blend (cairo_t *cr, cairo_operator_t op, cairo_bool_t alpha)
{
+ cairo_surface_t *bg, *fg;
+
+ create_patterns (cr, &bg, &fg, alpha);
+
/* not using CAIRO_OPERATOR_SOURCE here, it triggers a librsvg bug */
cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
cairo_set_source_surface (cr, bg, 0, 0);
@@ -66,52 +134,78 @@ do_blend (cairo_t *cr, cairo_operator_t op, cairo_surface_t *bg, cairo_surface_t
cairo_set_operator (cr, op);
cairo_set_source_surface (cr, fg, 0, 0);
cairo_paint (cr);
-}
-#define SIZE 5
-#define COUNT 4
-#define FULL_WIDTH ((STEPS + 1) * COUNT - 1)
-#define FULL_HEIGHT ((COUNT + STOP_OPERATOR - START_OPERATOR) / COUNT) * (STEPS + 1)
+ cairo_surface_destroy (fg);
+ cairo_surface_destroy (bg);
+}
static cairo_test_status_t
-draw (cairo_t *cr, int width, int height)
+draw (cairo_t *cr, cairo_bool_t alpha,
+ void (*blend)(cairo_t *, cairo_operator_t, cairo_bool_t))
{
size_t i = 0;
cairo_operator_t op;
- cairo_t *bgcr, *fgcr;
- cairo_surface_t *bg, *fg;
-
- bg = cairo_surface_create_similar (cairo_get_target (cr),
- CAIRO_CONTENT_COLOR_ALPHA, SIZE * STEPS, SIZE * STEPS);
- fg = cairo_surface_create_similar (cairo_get_target (cr),
- CAIRO_CONTENT_COLOR_ALPHA, SIZE * STEPS, SIZE * STEPS);
- bgcr = cairo_create (bg);
- fgcr = cairo_create (fg);
- cairo_scale (bgcr, SIZE, SIZE);
- cairo_scale (fgcr, SIZE, SIZE);
- create_patterns (bgcr, fgcr);
- cairo_destroy (bgcr);
- cairo_destroy (fgcr);
for (op = START_OPERATOR; op <= STOP_OPERATOR; op++, i++) {
cairo_save (cr);
- cairo_translate (cr,
+ cairo_translate (cr,
SIZE * (STEPS + 1) * (i % COUNT),
SIZE * (STEPS + 1) * (i / COUNT));
- do_blend (cr, op, bg, fg);
+ blend (cr, op, alpha);
cairo_restore (cr);
}
- cairo_surface_destroy (fg);
- cairo_surface_destroy (bg);
-
return CAIRO_TEST_SUCCESS;
}
+static cairo_test_status_t
+draw_extended_blend (cairo_t *cr, int width, int height)
+{
+ return draw (cr, FALSE, do_blend);
+}
+
+static cairo_test_status_t
+draw_extended_blend_alpha (cairo_t *cr, int width, int height)
+{
+ return draw (cr, TRUE, do_blend);
+}
+
+static cairo_test_status_t
+draw_extended_blend_solid (cairo_t *cr, int width, int height)
+{
+ return draw (cr, FALSE, do_blend_solid);
+}
+
+static cairo_test_status_t
+draw_extended_blend_solid_alpha (cairo_t *cr, int width, int height)
+{
+ return draw (cr, TRUE, do_blend_solid);
+}
+
CAIRO_TEST (extended_blend,
"Tests extended blend modes without alpha",
"operator", /* keywords */
NULL, /* requirements */
FULL_WIDTH * SIZE, FULL_HEIGHT * SIZE,
- NULL, draw)
+ NULL, draw_extended_blend)
+CAIRO_TEST (extended_blend_alpha,
+ "Tests extended blend modes with alpha",
+ "operator", /* keywords */
+ NULL, /* requirements */
+ FULL_WIDTH * SIZE, FULL_HEIGHT * SIZE,
+ NULL, draw_extended_blend_alpha)
+
+CAIRO_TEST (extended_blend_solid,
+ "Tests extended blend modes on solid patterns without alpha",
+ "operator", /* keywords */
+ NULL, /* requirements */
+ FULL_WIDTH * SIZE, FULL_HEIGHT * SIZE,
+ NULL, draw_extended_blend_solid)
+
+CAIRO_TEST (extended_blend_solid_alpha,
+ "Tests extended blend modes on solid patterns with alpha",
+ "operator", /* keywords */
+ NULL, /* requirements */
+ FULL_WIDTH * SIZE, FULL_HEIGHT * SIZE,
+ NULL, draw_extended_blend_solid_alpha)