1 /*****************************************************************************
2 * This file is part of gfxprim library. *
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. *
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. *
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 *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
27 #include <core/GP_Pixmap.h>
28 #include <core/GP_GetPutPixel.h>
29 #include <loaders/GP_Loaders.h>
33 static int test_load_PNG(const char *path
)
39 img
= GP_LoadPNG(path
, NULL
);
44 tst_msg("Not Implemented");
47 tst_msg("Got %s", strerror(errno
));
53 * TODO: check correct data.
61 struct check_color_test
{
66 static int test_load_PNG_check_color(struct check_color_test
*test
)
72 img
= GP_LoadPNG(test
->path
, NULL
);
77 tst_msg("Not Implemented");
80 tst_msg("Got %s", strerror(errno
));
85 unsigned int x
, y
, fail
= 0;
87 for (x
= 0; x
< img
->w
; x
++) {
88 for (y
= 0; y
< img
->w
; y
++) {
89 GP_Pixel p
= GP_GetPixel(img
, x
, y
);
91 if (p
!= test
->pixel
) {
93 tst_msg("First failed at %u,%u %x %x",
94 x
, y
, p
, test
->pixel
);
101 tst_msg("Pixmap pixels are correct");
111 static struct check_color_test white_adam7
= {
112 .path
= "100x100-white-adam7.png",
116 static struct check_color_test black_grayscale
= {
117 .path
= "100x100-black-grayscale.png",
121 static struct check_color_test red
= {
122 .path
= "100x100-red.png",
126 static int test_save_PNG(GP_PixelType pixel_type
)
131 pixmap
= GP_PixmapAlloc(100, 100, pixel_type
);
133 if (pixmap
== NULL
) {
134 tst_msg("Failed to allocate pixmap");
140 ret
= GP_SavePNG(pixmap
, "/dev/null", NULL
);
143 tst_msg("Saved successfully");
144 GP_PixmapFree(pixmap
);
150 tst_msg("Not Implemented");
151 GP_PixmapFree(pixmap
);
154 tst_msg("Failed and errno is not ENOSYS (%i)", errno
);
155 GP_PixmapFree(pixmap
);
160 const struct tst_suite tst_suite
= {
163 /* PNG loader tests */
164 {.name
= "PNG Load 100x100 RGB",
165 .tst_fn
= test_load_PNG_check_color
,
166 .res_path
= "data/png/valid/100x100-red.png",
168 .flags
= TST_TMPDIR
| TST_CHECK_MALLOC
},
170 {.name
= "PNG Load 100x100 RGB 50\% alpha",
171 .tst_fn
= test_load_PNG
,
172 .res_path
= "data/png/valid/100x100-red-alpha.png",
173 .data
= "100x100-red-alpha.png",
174 .flags
= TST_TMPDIR
| TST_CHECK_MALLOC
},
176 {.name
= "PNG Load 100x100 8 bit Grayscale",
177 .tst_fn
= test_load_PNG_check_color
,
178 .res_path
= "data/png/valid/100x100-black-grayscale.png",
179 .data
= &black_grayscale
,
180 .flags
= TST_TMPDIR
| TST_CHECK_MALLOC
},
182 {.name
= "PNG Load 100x100 8 bit Grayscale + alpha",
183 .tst_fn
= test_load_PNG
,
184 .res_path
= "data/png/valid/100x100-black-grayscale-alpha.png",
185 .data
= "100x100-black-grayscale-alpha.png",
186 .flags
= TST_TMPDIR
| TST_CHECK_MALLOC
},
188 {.name
= "PNG Load 100x100 Palette + alpha",
189 .tst_fn
= test_load_PNG
,
190 .res_path
= "data/png/valid/100x100-palette-alpha.png",
191 .data
= "100x100-palette-alpha.png",
192 .flags
= TST_TMPDIR
| TST_CHECK_MALLOC
},
194 {.name
= "PNG Load 100x100 Palette",
195 .tst_fn
= test_load_PNG
,
196 .res_path
= "data/png/valid/100x100-red-palette.png",
197 .data
= "100x100-red-palette.png",
198 .flags
= TST_TMPDIR
| TST_CHECK_MALLOC
},
200 {.name
= "PNG Load 100x100 RGB Adam7",
201 .tst_fn
= test_load_PNG_check_color
,
202 .res_path
= "data/png/valid/100x100-white-adam7.png",
203 .data
= &white_adam7
,
204 .flags
= TST_TMPDIR
| TST_CHECK_MALLOC
},
206 {.name
= "PNG Save 100x100 G1",
207 .tst_fn
= test_save_PNG
,
208 .data
= (void*)GP_PIXEL_G1
,
209 .flags
= TST_CHECK_MALLOC
},
211 {.name
= "PNG Save 100x100 G2",
212 .tst_fn
= test_save_PNG
,
213 .data
= (void*)GP_PIXEL_G2
,
214 .flags
= TST_CHECK_MALLOC
},
216 {.name
= "PNG Save 100x100 G4",
217 .tst_fn
= test_save_PNG
,
218 .data
= (void*)GP_PIXEL_G4
,
219 .flags
= TST_CHECK_MALLOC
},
221 {.name
= "PNG Save 100x100 G8",
222 .tst_fn
= test_save_PNG
,
223 .data
= (void*)GP_PIXEL_G8
,
224 .flags
= TST_CHECK_MALLOC
},
226 {.name
= "PNG Save 100x100 RGB888",
227 .tst_fn
= test_save_PNG
,
228 .data
= (void*)GP_PIXEL_RGB888
,
229 .flags
= TST_CHECK_MALLOC
},
231 {.name
= "PNG Save 100x100 RGBA8888",
232 .tst_fn
= test_save_PNG
,
233 .data
= (void*)GP_PIXEL_RGBA8888
,
234 .flags
= TST_CHECK_MALLOC
},
236 {.name
= "PNG Save 100x100 BGR888",
237 .tst_fn
= test_save_PNG
,
238 .data
= (void*)GP_PIXEL_BGR888
,
239 .flags
= TST_CHECK_MALLOC
},
241 {.name
= "PNG Save 100x100 G16",
242 .tst_fn
= test_save_PNG
,
243 .data
= (void*)GP_PIXEL_G16
,
244 .flags
= TST_CHECK_MALLOC
},