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-2012 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
27 #include <core/GP_Pixmap.h>
28 #include <loaders/GP_Loaders.h>
29 #include <filters/GP_Convolution.h>
33 static int load_resources(const char *path1
, const char *path2
,
34 GP_Pixmap
**c1
, GP_Pixmap
**c2
)
36 *c1
= GP_LoadImage(path1
, NULL
);
37 *c2
= GP_LoadImage(path2
, NULL
);
39 if (*c1
== NULL
|| *c2
== NULL
) {
40 tst_err("Failed to load resource");
47 static int test_lin_conv_box_3x3(void)
52 ret
= load_resources("in.pgm", "out.pgm", &in
, &out
);
54 if (ret
!= TST_SUCCESS
)
57 /* Apply the convolution */
64 GP_FilterKernel2D box_3x3_kernel
= {
71 if (GP_FilterConvolution(in
, in
, &box_3x3_kernel
, NULL
)) {
82 static int test_h_lin_conv_box_3_raw(void)
87 ret
= load_resources("in.pgm", "out.pgm", &in
, &out
);
89 if (ret
!= TST_SUCCESS
)
92 /* Apply the convolution */
93 float kernel
[] = {1, 1, 1};
95 if (GP_FilterHLinearConvolution_Raw(in
, 0, 0, in
->w
, in
->h
, in
, 0, 0,
96 kernel
, 3, 3, NULL
)) {
107 static int test_v_lin_conv_box_3_raw(void)
112 ret
= load_resources("in.pgm", "out.pgm", &in
, &out
);
114 if (ret
!= TST_SUCCESS
)
117 // GP_SetDebugLevel(10);
119 /* Apply the convolution */
120 float kernel
[] = {1, 1, 1};
122 if (GP_FilterVLinearConvolution_Raw(in
, 0, 0, in
->w
, in
->h
, in
, 0, 0,
123 kernel
, 3, 3, NULL
)) {
134 const struct tst_suite tst_suite
= {
135 .suite_name
= "Linear Convolution Testsuite",
137 {.name
= "LinearConvolution Box 3x3",
138 .tst_fn
= test_lin_conv_box_3x3
,
139 .res_path
= "data/conv/box_3x3/",
140 .flags
= TST_TMPDIR
},
141 {.name
= "HLinearConvolution_Raw Kern 3",
142 .tst_fn
= test_h_lin_conv_box_3_raw
,
143 .res_path
= "data/conv/box_3x3/",
144 .flags
= TST_TMPDIR
},
145 {.name
= "VLinearConvolution_Raw Kern 3",
146 .tst_fn
= test_v_lin_conv_box_3_raw
,
147 .res_path
= "data/conv/box_3x3/",
148 .flags
= TST_TMPDIR
},