filters: Cleanup GP_FilterParams API a little.
[gfxprim.git] / include / filters / GP_FilterParam.h
blob6520354d5485f94797feae0d46e8546192fd77d2
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 *****************************************************************************/
25 Filter per channel parameter passing code.
29 #ifndef FILTERS_GP_FILTER_PARAM_H
30 #define FILTERS_GP_FILTER_PARAM_H
32 #include "core/GP_Pixel.h"
34 #include <stdint.h>
36 typedef union GP_FilterParamVal {
37 float f;
38 uint32_t ui;
39 int32_t i;
40 void *ptr;
41 } GP_FilterParamVal;
44 * Filter parameter structure for one channel.
46 * Filter takes, empty channel name terminated, arrray of these as parameter.
48 typedef struct GP_FilterParam {
49 //TODO: this must be > than maximal channel name (now it's 2)
50 char channel_name[2];
51 union GP_FilterParamVal val;
52 } GP_FilterParam;
55 * Creates filter param structure large enough for given pixel_type.
57 * The returned structure has initalized channel_names and terminator.
59 GP_FilterParam *GP_FilterParamCreate(GP_PixelType pixel_type);
62 * Destroys filter param structure.
64 void GP_FilterParamDestroy(GP_FilterParam *self);
67 * Takes array of filter parameters and returns filter parameter by a channel
68 * name.
70 * Returns NULL if channel wasn't found.
72 GP_FilterParam *GP_FilterParamChannel(GP_FilterParam params[],
73 const char *channel_name);
76 * Returns number of filter channels.
78 uint32_t GP_FilterParamChannels(GP_FilterParam params[]);
81 * Compares param channels and pixel type channels. Returns zero if channels
82 * match.
84 int GP_FilterParamCheckPixelType(GP_FilterParam params[],
85 GP_PixelType pixel_type);
88 * Returns zero only if params have exactly same channels as array of
89 * channel_names.
91 int GP_FilterParamCheckChannels(GP_FilterParam params[],
92 const char *channel_names[]);
95 * Create and initalize the structure on the stack
97 #define GP_FILTER_PARAMS(pixel_type, name) \
98 GP_FilterParam name[GP_PixelTypes[pixel_type].numchannels + 1]; \
99 GP_FilterParamInitChannels(name, pixel_type);
102 * Initalize param names and terminator.
104 * Sets all values to 0.
106 void GP_FilterParamInitChannels(GP_FilterParam params[],
107 GP_PixelType pixel_type);
110 * Sets all values to integer value.
112 void GP_FilterParamSetIntAll(GP_FilterParam params[], int32_t val);
115 * Sets integer value. Returns 0 if such value was found, non-zero otherwise.
117 int GP_FilterParamSetInt(GP_FilterParam params[], const char *channel_name,
118 int32_t val);
121 * Sets all values to float value.
123 void GP_FilterParamSetFloatAll(GP_FilterParam params[], float val);
126 * Sets float value. Returns 0 if such value was found, non-zero otherwise.
128 int GP_FilterParamSetFloat(GP_FilterParam params[], const char *channel_name,
129 float val);
132 * Sets all values to unsigned integer value.
134 void GP_FilterParamSetUIntAll(GP_FilterParam params[], uint32_t val);
137 * Sets unsigned integer value. Returns 0 if such value was found, non-zero
138 * otherwise.
140 int GP_FilterParamSetUInt(GP_FilterParam params[], const char *channel_name,
141 uint32_t val);
144 * Sets all values to pointer value.
146 void GP_FilterParamSetPtrAll(GP_FilterParam params[], void *ptr);
149 * Sets pointer value. Returns 0 if such value was found, non-zero otherwise.
151 int GP_FilterParamSetPtr(GP_FilterParam params[], const char *channel_name,
152 void *ptr);
155 * Call free on all pointer values.
157 void GP_FilterParamFreePtrAll(GP_FilterParam params[]);
160 * Functions to print the array.
162 void GP_FilterParamPrintInt(GP_FilterParam params[]);
163 void GP_FilterParamPrintUInt(GP_FilterParam params[]);
164 void GP_FilterParamPrintFloat(GP_FilterParam params[]);
165 void GP_FilterParamPrintPtr(GP_FilterParam params[]);
167 #endif /* FILTERS_GP_FILTER_PARAM_H */