loaders: JPG: Fix bussy loop on corrupted file.
[gfxprim.git] / tests / filters / LinearConvolution.c
blobc786772a08e6894a03351b110da8d7b66394fe62
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 <loaders/GP_Loaders.h>
29 #include <filters/GP_Convolution.h>
31 #include "tst_test.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");
41 return TST_UNTESTED;
44 return TST_SUCCESS;
47 static int test_lin_conv_box_3x3(void)
49 GP_Pixmap *in, *out;
50 int ret;
52 ret = load_resources("in.pgm", "out.pgm", &in, &out);
54 if (ret != TST_SUCCESS)
55 return ret;
57 /* Apply the convolution */
58 float box_3x3[] = {
59 1, 1, 1,
60 1, 1, 1,
61 1, 1, 1,
64 GP_FilterKernel2D box_3x3_kernel = {
65 .w = 3,
66 .h = 3,
67 .div = 9,
68 .kernel = box_3x3,
71 if (GP_FilterConvolution(in, in, &box_3x3_kernel, NULL)) {
72 if (errno == ENOSYS)
73 return TST_SKIPPED;
76 /* Check result */
77 //TODO
79 return TST_SUCCESS;
82 static int test_h_lin_conv_box_3_raw(void)
84 GP_Pixmap *in, *out;
85 int ret;
87 ret = load_resources("in.pgm", "out.pgm", &in, &out);
89 if (ret != TST_SUCCESS)
90 return ret;
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)) {
97 if (errno == ENOSYS)
98 return TST_SKIPPED;
101 /* Check result */
102 //TODO
104 return TST_SUCCESS;
107 static int test_v_lin_conv_box_3_raw(void)
109 GP_Pixmap *in, *out;
110 int ret;
112 ret = load_resources("in.pgm", "out.pgm", &in, &out);
114 if (ret != TST_SUCCESS)
115 return ret;
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)) {
124 if (errno == ENOSYS)
125 return TST_SKIPPED;
128 /* Check result */
129 //TODO
131 return TST_SUCCESS;
134 const struct tst_suite tst_suite = {
135 .suite_name = "Linear Convolution Testsuite",
136 .tests = {
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},
149 {.name = NULL}