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 *****************************************************************************/
25 #include "core/GP_Debug.h"
27 #include "GP_FilterParam.h"
29 GP_FilterParam
*GP_FilterParamCreate(GP_PixelType pixel_type
)
33 ret
= malloc((GP_PixelTypes
[pixel_type
].numchannels
+ 1)
34 * sizeof(GP_FilterParam
));
37 GP_WARN("Malloc Failed");
41 GP_FilterParamInitChannels(ret
, pixel_type
);
46 void GP_FilterParamDestroy(GP_FilterParam
*self
)
51 static unsigned int count_channels(GP_FilterParam params
[])
55 while (params
[i
].channel_name
[0] != '\0')
61 GP_FilterParam
*GP_FilterParamChannel(GP_FilterParam params
[],
62 const char *channel_name
)
66 for (i
= 0; params
[i
].channel_name
[0] != '\0'; i
++)
67 if (!strcmp(params
[i
].channel_name
, channel_name
))
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
)
92 for (i
= 0; i
< num_channels
; i
++)
93 if (GP_FilterParamChannel(params
, channels
[i
].name
) == NULL
)
99 int GP_FilterParamCheckChannels(GP_FilterParam params
[],
100 const char *channel_names
[])
104 for (i
= 0; channel_names
[i
] != NULL
; i
++)
105 if (GP_FilterParamChannel(params
, channel_names
[i
]) == NULL
)
108 if (i
!= count_channels(params
))
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(¶ms
[i
].val
, 0, sizeof(GP_FilterParamVal
));
128 params
[i
].channel_name
[0] = '\0';
131 void GP_FilterParamSetIntAll(GP_FilterParam params
[],
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
,
143 GP_FilterParam
*param
;
144 param
= GP_FilterParamChannel(params
, channel_name
);
153 void GP_FilterParamSetFloatAll(GP_FilterParam params
[],
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
,
165 GP_FilterParam
*param
;
166 param
= GP_FilterParamChannel(params
, channel_name
);
175 void GP_FilterParamSetUIntAll(GP_FilterParam params
[],
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
,
187 GP_FilterParam
*param
;
188 param
= GP_FilterParamChannel(params
, channel_name
);
197 void GP_FilterParamSetPtrAll(GP_FilterParam params
[],
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
,
209 GP_FilterParam
*param
;
210 param
= GP_FilterParamChannel(params
, channel_name
);
215 param
->val
.ptr
= ptr
;
219 void GP_FilterParamFreePtrAll(GP_FilterParam params
[])
223 for (i
= 0; params
[i
].channel_name
[0] != '\0'; i
++)
224 free(params
[i
].val
.ptr
);
227 void GP_FilterParamPrintInt(GP_FilterParam params
[])
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
[])
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
[])
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
[])
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
);