Opensource Compliance Issue.
[platform/core/graphics/cairo.git] / test / blur.c
1 /*
2  * Copyright © 2013 Samsung Electronics
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  *
24  * Authors:
25  *   Bryce Harrington <b.harrington@samsung.com>
26  *   Henry Song <henry.song@samsung.com>
27  */
28
29 /* This test exercises gaussian blur rendering
30  */
31
32 /* When we build only for backends other than gl,
33    include <cairo-gl.h> in blur.c will give errors.
34 */
35 #if 0
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <math.h>
39
40 #include <cairo.h>
41 #include <cairo-gl.h>
42 #endif
43
44 #include "cairo-test.h"
45
46 static cairo_test_status_t
47 draw (cairo_t *cr, int width, int height)
48 {
49     const cairo_test_context_t *ctx = cairo_test_get_context (cr);
50
51     int line_width = 20;
52     int x = width / 2;
53     int y = height / 2;
54     int radius = width / 4;
55
56     cairo_save (cr);
57     cairo_set_source_rgb (cr, 1, 1, 1);
58     cairo_paint (cr);
59     cairo_restore (cr);
60
61     cairo_save (cr);
62
63     /* drop shadow */
64     cairo_arc (cr, x, y, radius, 0, 2 * M_PI);
65     cairo_set_line_width (cr, line_width);
66     cairo_set_draw_shadow_only (cr, 1);
67     cairo_set_shadow (cr, CAIRO_SHADOW_DROP);
68     cairo_set_shadow_rgba (cr, 0, 0, 0, 0.8);
69     cairo_set_shadow_blur (cr, 10, 10);
70     cairo_set_shadow_offset (cr, -42, -7);
71     cairo_stroke (cr);
72
73     /* ring with inset shadow */
74     cairo_arc (cr, x, y, radius, 0, 2 * M_PI);
75     cairo_set_line_width (cr, line_width);
76     cairo_set_source_rgb (cr, 0, 0.5, 0);
77     cairo_set_draw_shadow_only (cr, 0);
78     cairo_set_shadow (cr, CAIRO_SHADOW_INSET);
79     cairo_set_shadow_rgba (cr, 0, 0, 0, 1);
80     cairo_set_shadow_blur (cr, 5, 2);
81     cairo_set_shadow_offset (cr, 6, 1);
82     cairo_stroke (cr);
83
84     /* draw spread */
85     cairo_set_draw_shadow_only (cr, 1);
86     cairo_set_shadow (cr, CAIRO_SHADOW_DROP);
87     cairo_set_shadow_rgba (cr, 1, 1, 1, 1);
88     cairo_set_shadow_blur (cr, 5, 2);
89     cairo_set_line_width (cr, line_width/5);
90     cairo_set_source_rgb (cr, 0, 0.5, 0);
91     cairo_set_shadow_offset (cr, 6, 1);
92     cairo_arc (cr, x, y, radius, 0, 2 * M_PI);
93     cairo_stroke (cr);
94
95     cairo_restore (cr);
96
97     return CAIRO_TEST_SUCCESS;
98 }
99
100 CAIRO_TEST (blur,
101             "Tests gaussian blur of a drawn image",
102             "gl, blur, operator", /* keywords */
103             NULL, /* requirements */
104             256, 256,
105             NULL, draw)