2 * Copyright © Jeff Muizelaar
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Red Hat, Inc. not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Red Hat, Inc. makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * JEFF MUIZELAAR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Authors: Jeff Muizelaar <jeff@infidigm.net>
24 * Carl Worth <cworth@cworth.org>
25 * Chris Wilson <chris@chris-wilson.co.uk>
28 #include "cairo-test.h"
30 static cairo_test_draw_function_t draw
;
35 #ifdef WORDS_BIGENDIAN
36 #define MASK 0x28, 0x55
38 #define MASK 0x14, 0xAA
40 static unsigned char mask
[(MASK_WIDTH
+ 7) / 8 * MASK_HEIGHT
] = {
53 "test masks of CAIRO_FORMAT_A1",
54 MASK_WIDTH
, MASK_HEIGHT
,
59 static cairo_test_status_t
60 check_status (cairo_status_t status
, cairo_status_t expected
)
62 if (status
== expected
)
63 return CAIRO_TEST_SUCCESS
;
65 cairo_test_log ("Error: Expected status value %d (%s), received %d (%s)\n",
67 cairo_status_to_string (expected
),
69 cairo_status_to_string (status
));
70 return CAIRO_TEST_FAILURE
;
73 static cairo_test_status_t
74 test_surface_with_width_and_stride (int width
, int stride
,
75 cairo_status_t expected
)
77 cairo_test_status_t status
;
78 cairo_surface_t
*surface
;
83 cairo_test_log ("Creating surface with width %d and stride %d\n",
91 surface
= cairo_image_surface_create_for_data (data
, CAIRO_FORMAT_A1
,
93 cr
= cairo_create (surface
);
97 status
= check_status (cairo_surface_status (surface
), expected
);
101 status
= check_status (cairo_status (cr
), expected
);
107 cairo_surface_destroy (surface
);
112 static cairo_test_status_t
113 draw (cairo_t
*cr
, int dst_width
, int dst_height
)
115 unsigned char *mask_aligned
;
116 cairo_surface_t
*surface
;
118 surface
= cairo_image_surface_create (CAIRO_FORMAT_A1
,
122 mask_aligned
= cairo_image_surface_get_data (surface
);
123 if (mask_aligned
!= NULL
) {
124 int stride
= cairo_image_surface_get_stride (surface
), row
;
125 const unsigned char *src
= mask
;
126 unsigned char *dst
= mask_aligned
;
127 for (row
= 0; row
< MASK_HEIGHT
; row
++) {
128 memcpy (dst
, src
, (MASK_WIDTH
+ 7) / 8);
129 src
+= (MASK_WIDTH
+ 7) / 8;
134 /* Paint background blue */
135 cairo_set_source_rgb (cr
, 0, 0, 1); /* blue */
138 /* Then paint red through our mask */
139 cairo_set_source_rgb (cr
, 1, 0, 0); /* red */
140 cairo_mask_surface (cr
, surface
, 0, 0);
141 cairo_surface_destroy (surface
);
143 return CAIRO_TEST_SUCCESS
;
151 cairo_test_init ("a1-mask");
153 /* first check the API strictness */
154 for (test_width
= 0; test_width
< 40; test_width
++) {
155 int test_stride
= (test_width
+ 7) / 8;
156 int stride
= cairo_format_stride_for_width (CAIRO_FORMAT_A1
,
158 cairo_test_status_t status
;
159 cairo_status_t expected
;
161 /* First create a surface using the width as the stride,
162 * (most of these should fail).
164 expected
= (stride
== test_stride
) ?
165 CAIRO_STATUS_SUCCESS
: CAIRO_STATUS_INVALID_STRIDE
;
167 status
= test_surface_with_width_and_stride (test_width
,
173 status
= test_surface_with_width_and_stride (test_width
,
180 /* Then create a surface using the correct stride,
181 * (should always succeed).
183 status
= test_surface_with_width_and_stride (test_width
,
185 CAIRO_STATUS_SUCCESS
);
189 status
= test_surface_with_width_and_stride (test_width
,
191 CAIRO_STATUS_SUCCESS
);
198 return cairo_test (&test
);