filters: resize NN: Remove forgotten debug print.
[gfxprim.git] / libs / filters / GP_FilterParam.c
blobe6c0f6b310faec6b03bbe60d77ff63b83943fade
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>
25 #include "core/GP_Debug.h"
27 #include "GP_FilterParam.h"
29 GP_FilterParam *GP_FilterParamCreate(GP_PixelType pixel_type)
31 GP_FilterParam *ret;
33 ret = malloc((GP_PixelTypes[pixel_type].numchannels + 1)
34 * sizeof(GP_FilterParam));
36 if (ret == NULL) {
37 GP_WARN("Malloc Failed");
38 return NULL;
41 GP_FilterParamInitChannels(ret, pixel_type);
43 return ret;
46 void GP_FilterParamDestroy(GP_FilterParam *self)
48 free(self);
51 static unsigned int count_channels(GP_FilterParam params[])
53 unsigned int i = 0;
55 while (params[i].channel_name[0] != '\0')
56 i++;
58 return i;
61 GP_FilterParam *GP_FilterParamChannel(GP_FilterParam params[],
62 const char *channel_name)
64 unsigned int i;
66 for (i = 0; params[i].channel_name[0] != '\0'; i++)
67 if (!strcmp(params[i].channel_name, channel_name))
68 return &params[i];
70 return NULL;
73 uint32_t GP_FilterParamChannels(GP_FilterParam params[])
75 return count_channels(params);
78 int GP_FilterParamCheckPixelType(GP_FilterParam params[],
79 GP_PixelType pixel_type)
81 unsigned int i, num_channels;
82 const GP_PixelTypeChannel *channels;
84 num_channels = GP_PixelTypes[pixel_type].numchannels;
85 channels = GP_PixelTypes[pixel_type].channels;
87 i = count_channels(params);
89 if (i != num_channels)
90 return 1;
92 for (i = 0; i < num_channels; i++)
93 if (GP_FilterParamChannel(params, channels[i].name) == NULL)
94 return 1;
96 return 0;
99 int GP_FilterParamCheckChannels(GP_FilterParam params[],
100 const char *channel_names[])
102 unsigned int i;
104 for (i = 0; channel_names[i] != NULL; i++)
105 if (GP_FilterParamChannel(params, channel_names[i]) == NULL)
106 return 1;
108 if (i != count_channels(params))
109 return 1;
111 return 0;
114 void GP_FilterParamInitChannels(GP_FilterParam params[],
115 GP_PixelType pixel_type)
117 unsigned int i, num_channels;
118 const GP_PixelTypeChannel *channels;
120 num_channels = GP_PixelTypes[pixel_type].numchannels;
121 channels = GP_PixelTypes[pixel_type].channels;
123 for (i = 0; i < num_channels; i++) {
124 strcpy(params[i].channel_name, channels[i].name);
125 memset(&params[i].val, 0, sizeof(GP_FilterParamVal));
128 params[i].channel_name[0] = '\0';
131 void GP_FilterParamSetIntAll(GP_FilterParam params[],
132 int32_t val)
134 unsigned int i;
136 for (i = 0; params[i].channel_name[0] != '\0'; i++)
137 params[i].val.i = val;
140 int GP_FilterParamSetInt(GP_FilterParam params[], const char *channel_name,
141 int32_t val)
143 GP_FilterParam *param;
144 param = GP_FilterParamChannel(params, channel_name);
146 if (param == NULL)
147 return 1;
149 param->val.i = val;
150 return 0;
153 void GP_FilterParamSetFloatAll(GP_FilterParam params[],
154 float val)
156 unsigned int i;
158 for (i = 0; params[i].channel_name[0] != '\0'; i++)
159 params[i].val.f = val;
162 int GP_FilterParamSetFloat(GP_FilterParam params[], const char *channel_name,
163 float val)
165 GP_FilterParam *param;
166 param = GP_FilterParamChannel(params, channel_name);
168 if (param == NULL)
169 return 1;
171 param->val.f = val;
172 return 0;
175 void GP_FilterParamSetUIntAll(GP_FilterParam params[],
176 uint32_t val)
178 unsigned int i;
180 for (i = 0; params[i].channel_name[0] != '\0'; i++)
181 params[i].val.ui = val;
184 int GP_FilterParamSetUInt(GP_FilterParam params[], const char *channel_name,
185 uint32_t val)
187 GP_FilterParam *param;
188 param = GP_FilterParamChannel(params, channel_name);
190 if (param == NULL)
191 return 1;
193 param->val.ui = val;
194 return 0;
197 void GP_FilterParamSetPtrAll(GP_FilterParam params[],
198 void *ptr)
200 unsigned int i;
202 for (i = 0; params[i].channel_name[0] != '\0'; i++)
203 params[i].val.ptr = ptr;
206 int GP_FilterParamSetPtr(GP_FilterParam params[], const char *channel_name,
207 void *ptr)
209 GP_FilterParam *param;
210 param = GP_FilterParamChannel(params, channel_name);
212 if (param == NULL)
213 return 1;
215 param->val.ptr = ptr;
216 return 0;
219 void GP_FilterParamFreePtrAll(GP_FilterParam params[])
221 unsigned int i;
223 for (i = 0; params[i].channel_name[0] != '\0'; i++)
224 free(params[i].val.ptr);
227 void GP_FilterParamPrintInt(GP_FilterParam params[])
229 unsigned int i;
231 for (i = 0; params[i].channel_name[0] != '\0'; i++)
232 printf("Chann '%s' = %i\n", params[i].channel_name, params[i].val.i);
235 void GP_FilterParamPrintUInt(GP_FilterParam params[])
237 unsigned int i;
239 for (i = 0; params[i].channel_name[0] != '\0'; i++)
240 printf("Chann '%s' = %u\n", params[i].channel_name, params[i].val.ui);
243 void GP_FilterParamPrintFloat(GP_FilterParam params[])
245 unsigned int i;
247 for (i = 0; params[i].channel_name[0] != '\0'; i++)
248 printf("Chann '%s' = %f\n", params[i].channel_name, params[i].val.f);
251 void GP_FilterParamPrintPtr(GP_FilterParam params[])
253 unsigned int i;
255 for (i = 0; params[i].channel_name[0] != '\0'; i++)
256 printf("Chann '%s' = %p\n", params[i].channel_name, params[i].val.ptr);