doc: Add screenshot to spiv page.
[gfxprim/pasky.git] / tests / gfx / PutPixelAA.c
blob22faee79e5a4f160bafe861c34a428ba9b91addb
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-2013 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #include <string.h>
24 #include <errno.h>
25 #include <sys/stat.h>
27 #include <core/GP_Context.h>
28 #include <gfx/GP_PutPixelAA.h>
30 #include "tst_test.h"
32 #include "common.h"
34 struct testcase {
35 /* pixel description */
36 GP_Coord x;
37 GP_Coord y;
39 /* expected result */
40 GP_Size w, h;
41 const char pixmap[];
44 static int test_pixel(const struct testcase *t)
46 GP_Context *c;
47 int err;
49 c = GP_ContextAlloc(t->w, t->h, GP_PIXEL_G8);
51 if (c == NULL) {
52 tst_err("Failed to allocate context");
53 return TST_UNTESTED;
56 /* zero the pixels buffer */
57 memset(c->pixels, 0, c->w * c->h);
59 GP_PutPixelAA(c, t->x, t->y, 0xff);
61 err = compare_buffers(t->pixmap, c);
63 if (err)
64 return TST_FAILED;
66 return TST_SUCCESS;
69 static struct testcase testcase_pixel_center = {
70 .x = (1<<8),
71 .y = (1<<8),
73 .w = 3,
74 .h = 3,
76 .pixmap = {
77 0x00, 0x00, 0x00,
78 0x00, 0xff, 0x00,
79 0x00, 0x00, 0x00,
83 static struct testcase testcase_pixel_hcenter = {
84 .x = (1<<8),
85 .y = (1<<8) + (1<<7),
87 .w = 3,
88 .h = 4,
90 .pixmap = {
91 0x00, 0x00, 0x00,
92 0x00, 0x80, 0x00,
93 0x00, 0x80, 0x00,
94 0x00, 0x00, 0x00,
98 static struct testcase testcase_pixel_vcenter = {
99 .x = (1<<8) + (1<<7),
100 .y = (1<<8),
102 .w = 4,
103 .h = 3,
105 .pixmap = {
106 0x00, 0x00, 0x00, 0x00,
107 0x00, 0x80, 0x80, 0x00,
108 0x00, 0x00, 0x00, 0x00,
112 static struct testcase testcase_pixel = {
113 .x = (1<<8) + (1<<7),
114 .y = (1<<8) + (1<<7),
116 .w = 4,
117 .h = 4,
119 .pixmap = {
120 0x00, 0x00, 0x00, 0x00,
121 0x00, 0x40, 0x40, 0x00,
122 0x00, 0x40, 0x40, 0x00,
123 0x00, 0x00, 0x00, 0x00,
127 const struct tst_suite tst_suite = {
128 .suite_name = "PutPixelAA Testsuite",
129 .tests = {
130 {.name = "PutPixelAA center",
131 .tst_fn = test_pixel,
132 .data = &testcase_pixel_center},
134 {.name = "PutPixelAA hcenter",
135 .tst_fn = test_pixel,
136 .data = &testcase_pixel_hcenter},
138 {.name = "PutPixelAA vcenter",
139 .tst_fn = test_pixel,
140 .data = &testcase_pixel_vcenter},
142 {.name = "PutPixelAA",
143 .tst_fn = test_pixel,
144 .data = &testcase_pixel},
146 {.name = NULL}