loaders: PNG: Handle gamma on 16bpp conversion
[gfxprim.git] / tests / gfx / Polygon.c
blobbfc8ae1a89d3f5a6a5c6f1f160d56faff1d356c7
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #include <string.h>
24 #include <errno.h>
25 #include <sys/stat.h>
27 #include <core/GP_Pixmap.h>
28 #include <gfx/GP_Polygon.h>
30 #include "tst_test.h"
32 #include "common.h"
34 struct testcase {
35 /* polygon description */
36 unsigned int edge_count;
37 GP_Coord edges[20];
39 /* expected result */
40 GP_Size w, h;
41 const char pixmap[];
44 static int test_polygon(struct testcase *t)
46 GP_Pixmap *c;
47 int err;
49 c = GP_PixmapAlloc(t->w, t->h, GP_PIXEL_G8);
51 if (c == NULL) {
52 tst_err("Failed to allocate pixmap");
53 return TST_UNTESTED;
56 /* zero the pixels buffer */
57 memset(c->pixels, 0, c->w * c->h);
59 GP_FillPolygon(c, t->edge_count, t->edges, 1);
61 err = compare_buffers(t->pixmap, c);
63 if (err) {
64 tst_msg("Patterns are different");
65 return TST_FAILED;
68 return TST_SUCCESS;
71 struct testcase testcase_1_edge = {
72 .edge_count = 1,
73 .edges = {
74 1, 1,
76 .w = 3,
77 .h = 3,
78 .pixmap = {
79 0, 0, 0,
80 0, 1, 0,
81 0, 0, 0,
85 struct testcase testcase_5_edges_1px = {
86 .edge_count = 5,
87 .edges = {
88 1, 1,
89 1, 1,
90 1, 1,
91 1, 1,
92 1, 1,
94 .w = 3,
95 .h = 3,
96 .pixmap = {
97 0, 0, 0,
98 0, 1, 0,
99 0, 0, 0,
103 struct testcase testcase_line_vert_3px = {
104 .edge_count = 2,
105 .edges = {
106 1, 1,
107 1, 3,
109 .w = 5,
110 .h = 5,
111 .pixmap = {
112 0, 0, 0, 0, 0,
113 0, 1, 0, 0, 0,
114 0, 1, 0, 0, 0,
115 0, 1, 0, 0, 0,
116 0, 0, 0, 0, 0,
120 struct testcase testcase_line_horiz_3px = {
121 .edge_count = 2,
122 .edges = {
123 3, 1,
124 1, 0,
126 .w = 5,
127 .h = 5,
128 .pixmap = {
129 0, 0, 0, 0, 0,
130 0, 1, 1, 1, 0,
131 0, 0, 0, 0, 0,
132 0, 0, 0, 0, 0,
133 0, 0, 0, 0, 0,
137 struct testcase testcase_line_4px = {
138 .edge_count = 2,
139 .edges = {
140 1, 1,
141 2, 3,
143 .w = 5,
144 .h = 5,
145 .pixmap = {
146 0, 0, 0, 0, 0,
147 0, 1, 0, 0, 0,
148 0, 1, 1, 0, 0,
149 0, 0, 1, 0, 0,
150 0, 0, 0, 0, 0,
154 struct testcase testcase_line_3px = {
155 .edge_count = 2,
156 .edges = {
157 1, 1,
158 3, 3,
160 .w = 5,
161 .h = 5,
162 .pixmap = {
163 0, 0, 0, 0, 0,
164 0, 1, 0, 0, 0,
165 0, 0, 1, 0, 0,
166 0, 0, 0, 1, 0,
167 0, 0, 0, 0, 0,
171 struct testcase testcase_2x2_square = {
172 .edge_count = 4,
173 .edges = {
174 1, 1,
175 2, 1,
176 2, 2,
177 1, 2,
179 .w = 4,
180 .h = 4,
181 .pixmap = {
182 0, 0, 0, 0,
183 0, 1, 1, 0,
184 0, 1, 1, 0,
185 0, 0, 0, 0,
189 struct testcase testcase_3x3_square = {
190 .edge_count = 4,
191 .edges = {
192 1, 1,
193 3, 1,
194 3, 3,
195 1, 3,
197 .w = 5,
198 .h = 5,
199 .pixmap = {
200 0, 0, 0, 0, 0,
201 0, 1, 1, 1, 0,
202 0, 1, 1, 1, 0,
203 0, 1, 1, 1, 0,
204 0, 0, 0, 0, 0,
208 struct testcase testcase_4x4_square = {
209 .edge_count = 4,
210 .edges = {
211 1, 1,
212 4, 1,
213 4, 4,
214 1, 4,
216 .w = 6,
217 .h = 6,
218 .pixmap = {
219 0, 0, 0, 0, 0, 0,
220 0, 1, 1, 1, 1, 0,
221 0, 1, 1, 1, 1, 0,
222 0, 1, 1, 1, 1, 0,
223 0, 1, 1, 1, 1, 0,
224 0, 0, 0, 0, 0, 0,
228 struct testcase testcase_4px_triangle = {
229 .edge_count = 3,
230 .edges = {
231 2, 1,
232 1, 2,
233 3, 2,
235 .w = 5,
236 .h = 4,
237 .pixmap = {
238 0, 0, 0, 0, 0,
239 0, 0, 1, 0, 0,
240 0, 1, 1, 1, 0,
241 0, 0, 0, 0, 0,
245 struct testcase testcase_6px_triangle = {
246 .edge_count = 3,
247 .edges = {
248 1, 1,
249 1, 3,
250 3, 3,
252 .w = 5,
253 .h = 5,
254 .pixmap = {
255 0, 0, 0, 0, 0,
256 0, 1, 0, 0, 0,
257 0, 1, 1, 0, 0,
258 0, 1, 1, 1, 0,
259 0, 0, 0, 0, 0,
263 struct testcase testcase_triangle_1 = {
264 .edge_count = 3,
265 .edges = {
266 1, 4,
267 8, 2,
268 2, 8,
270 .w = 10,
271 .h = 10,
272 .pixmap = {
273 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
274 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
275 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
276 0, 0, 0, 0, 0, 1, 1, 1, 0, 0,
277 0, 0, 1, 1, 1, 1, 1, 1, 0, 0,
278 0, 0, 0, 1, 1, 1, 1, 0, 0, 0,
279 0, 0, 0, 1, 1, 1, 0, 0, 0, 0,
280 0, 0, 0, 1, 1, 0, 0, 0, 0, 0,
281 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
282 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
283 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
287 struct testcase testcase_bow_4edges_7px = {
288 .edge_count = 4,
289 .edges = {
290 1, 1,
291 1, 3,
292 3, 1,
293 3, 3,
295 .w = 5,
296 .h = 5,
297 .pixmap = {
298 0, 0, 0, 0, 0,
299 0, 1, 0, 1, 0,
300 0, 1, 1, 1, 0,
301 0, 1, 0, 1, 0,
302 0, 0, 0, 0, 0,
306 const struct tst_suite tst_suite = {
307 .suite_name = "Polygon Testsuite",
308 .tests = {
309 {.name = "1 Edge Polygon",
310 .tst_fn = test_polygon,
311 .data = &testcase_1_edge},
313 {.name = "5 Edges 1px Polygon",
314 .tst_fn = test_polygon,
315 .data = &testcase_5_edges_1px},
317 {.name = "Vertical Line 3px Polygon",
318 .tst_fn = test_polygon,
319 .data = &testcase_line_vert_3px},
321 {.name = "Horizontal Line 3px Polygon",
322 .tst_fn = test_polygon,
323 .data = &testcase_line_horiz_3px},
325 {.name = "Line 3px Polygon",
326 .tst_fn = test_polygon,
327 .data = &testcase_line_3px},
329 {.name = "Line 4px Polygon",
330 .tst_fn = test_polygon,
331 .data = &testcase_line_4px},
333 {.name = "2x2 Square Polygon",
334 .tst_fn = test_polygon,
335 .data = &testcase_2x2_square},
337 {.name = "3x3 Square Polygon",
338 .tst_fn = test_polygon,
339 .data = &testcase_3x3_square},
341 {.name = "4x4 Square Polygon",
342 .tst_fn = test_polygon,
343 .data = &testcase_4x4_square},
345 {.name = "Triangle 4px Polygon",
346 .tst_fn = test_polygon,
347 .data = &testcase_4px_triangle},
349 {.name = "Triangle 6px Polygon",
350 .tst_fn = test_polygon,
351 .data = &testcase_6px_triangle},
353 {.name = "Triangle 1. Polygon",
354 .tst_fn = test_polygon,
355 .data = &testcase_triangle_1},
357 {.name = "Bow 4edges 7px",
358 .tst_fn = test_polygon,
359 .data = &testcase_bow_4edges_7px},
361 {.name = NULL}