Initialize Tizen 2.3
[framework/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 #include <stdio.h>
33 #include <stdlib.h>
34 #include <math.h>
35
36 #include <cairo.h>
37 #include <cairo-gl.h>
38
39 #include "cairo-test.h"
40
41 static cairo_test_status_t
42 draw (cairo_t *cr, int width, int height)
43 {
44     const cairo_test_context_t *ctx = cairo_test_get_context (cr);
45
46     int line_width = 20;
47     int x = width / 2;
48     int y = height / 2;
49     int radius = width / 4;
50
51     cairo_save (cr);
52     cairo_set_source_rgb (cr, 1, 1, 1);
53     cairo_paint (cr);
54     cairo_restore (cr);
55
56     cairo_save (cr);
57
58     /* drop shadow */
59     cairo_arc (cr, x, y, radius, 0, 2 * M_PI);
60     cairo_set_line_width (cr, line_width);
61     cairo_set_draw_shadow_only (cr, 1);
62     cairo_set_shadow (cr, CAIRO_SHADOW_DROP);
63     cairo_set_shadow_rgba (cr, 0, 0, 0, 0.8);
64     cairo_set_shadow_blur (cr, 10, 10);
65     cairo_set_shadow_offset (cr, -42, -7);
66     cairo_stroke (cr);
67
68     /* ring with inset shadow */
69     cairo_arc (cr, x, y, radius, 0, 2 * M_PI);
70     cairo_set_line_width (cr, line_width);
71     cairo_set_source_rgb (cr, 0, 0.5, 0);
72     cairo_set_draw_shadow_only (cr, 0);
73     cairo_set_shadow (cr, CAIRO_SHADOW_INSET);
74     cairo_set_shadow_rgba (cr, 0, 0, 0, 1);
75     cairo_set_shadow_blur (cr, 5, 2);
76     cairo_set_shadow_offset (cr, 6, 1);
77     cairo_stroke (cr);
78
79     /* draw spread */
80     cairo_set_draw_shadow_only (cr, 1);
81     cairo_set_shadow (cr, CAIRO_SHADOW_DROP);
82     cairo_set_shadow_rgba (cr, 1, 1, 1, 1);
83     cairo_set_shadow_blur (cr, 5, 2);
84     cairo_set_line_width (cr, line_width/5);
85     cairo_set_source_rgb (cr, 0, 0.5, 0);
86     cairo_set_shadow_offset (cr, 6, 1);
87     cairo_arc (cr, x, y, radius, 0, 2 * M_PI);
88     cairo_stroke (cr);
89
90     cairo_restore (cr);
91
92     return CAIRO_TEST_SUCCESS;
93 }
94
95 CAIRO_TEST (blur,
96             "Tests gaussian blur of a drawn image",
97             "gl, blur, operator", /* keywords */
98             NULL, /* requirements */
99             256, 256,
100             NULL, draw)