~ubuntu-branches/ubuntu/vivid/rawstudio/vivid

« back to all changes in this revision

Viewing changes to librawstudio/rs-filter-param.c

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2011-07-28 17:36:32 UTC
  • mfrom: (2.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20110728173632-5czluz9ye3c83zc5
Tags: 2.0-1
* [3750b2cf] Merge commit 'upstream/2.0'
* [63637468] Removing Patch, not necessary anymore.
* [2fb580dc] Add new build-dependencies.
* [c57d953b] Run dh_autoreconf due to patches in configure.in
* [13febe39] Add patch to remove the libssl requirement.
* [5ae773fe] Replace libjpeg62-dev by libjpeg8-dev :)
* [1969d755] Don't build static libraries.
* [7cfe0a2e] Add a patch to fix the plugin directory path.
  As plugins are shared libraries, they need to go into /usr/lib,
  not into /usr/share.
  Thanks to Andrew McMillan
* [c1d0d9dd] Don't install .la files for all plugins and libraries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * * Copyright (C) 2006-2011 Anders Brander <anders@brander.dk>, 
 
3
 * * Anders Kvist <akv@lnxbx.dk> and Klaus Post <klauspost@gmail.com>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
 
 
20
#include "rs-filter-param.h"
 
21
 
 
22
#define RS_TYPE_FLOAT4 rs_float4_get_type()
 
23
 
 
24
gpointer
 
25
float4_copy(const gpointer boxed)
 
26
{
 
27
        return g_memdup(boxed, sizeof(gfloat)*4);
 
28
}
 
29
 
 
30
GType
 
31
rs_float4_get_type(void)
 
32
{
 
33
        static GType type = 0;
 
34
        if (!type)
 
35
                type = g_boxed_type_register_static(g_intern_static_string("RSFloat4"), float4_copy, g_free);
 
36
        return type;
 
37
}
 
38
 
 
39
G_DEFINE_TYPE(RSFilterParam, rs_filter_param, G_TYPE_OBJECT)
 
40
 
 
41
static void
 
42
rs_filter_param_dispose(GObject *object)
 
43
{
 
44
        RSFilterParam *filter_param = RS_FILTER_PARAM(object);
 
45
 
 
46
        if (!filter_param->dispose_has_run)
 
47
        {
 
48
                filter_param->dispose_has_run = TRUE;
 
49
 
 
50
                g_hash_table_destroy(filter_param->properties);
 
51
        }
 
52
 
 
53
        G_OBJECT_CLASS(rs_filter_param_parent_class)->dispose (object);
 
54
}
 
55
 
 
56
static void
 
57
rs_filter_param_finalize(GObject *object)
 
58
{
 
59
        G_OBJECT_CLASS(rs_filter_param_parent_class)->finalize (object);
 
60
}
 
61
 
 
62
static void
 
63
rs_filter_param_class_init(RSFilterParamClass *klass)
 
64
{
 
65
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
66
 
 
67
        object_class->dispose = rs_filter_param_dispose;
 
68
        object_class->finalize = rs_filter_param_finalize;
 
69
}
 
70
 
 
71
static inline GValue *
 
72
new_value(GType type)
 
73
{
 
74
        GValue *value  = g_slice_new0(GValue);
 
75
        g_value_init(value, type);
 
76
 
 
77
        return value;
 
78
}
 
79
 
 
80
static void
 
81
free_value(gpointer data)
 
82
{
 
83
        GValue *value = (GValue *) data;
 
84
 
 
85
        g_value_unset(value);
 
86
        g_slice_free(GValue, value);
 
87
}
 
88
 
 
89
static inline GValue *
 
90
clone_value(const GValue *value)
 
91
{
 
92
        GType type = G_VALUE_TYPE(value);
 
93
        GValue *ret = new_value(type);
 
94
        g_value_copy(value, ret);
 
95
 
 
96
        return ret;
 
97
}
 
98
 
 
99
static void
 
100
rs_filter_param_init(RSFilterParam *param)
 
101
{
 
102
        param->properties = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, free_value);
 
103
}
 
104
 
 
105
RSFilterParam *
 
106
rs_filter_param_new(void)
 
107
{
 
108
        return g_object_new (RS_TYPE_FILTER_PARAM, NULL);
 
109
}
 
110
 
 
111
void
 
112
rs_filter_param_clone(RSFilterParam *destination, const RSFilterParam *source)
 
113
{
 
114
        g_assert(RS_IS_FILTER_PARAM(destination));
 
115
        g_assert(RS_IS_FILTER_PARAM(source));
 
116
 
 
117
        /* Clone the properties table */
 
118
        GHashTableIter iter;
 
119
        gpointer key, value;
 
120
 
 
121
        g_hash_table_iter_init (&iter, source->properties);
 
122
        while (g_hash_table_iter_next (&iter, &key, &value))
 
123
                g_hash_table_insert(destination->properties, (gpointer) g_strdup(key), clone_value(value));
 
124
}
 
125
 
 
126
static void
 
127
rs_filter_param_set_gvalue(RSFilterParam *filter_param, const gchar *name, GValue * value)
 
128
{
 
129
        g_assert(RS_IS_FILTER_PARAM(filter_param));
 
130
        g_assert(name != NULL);
 
131
        g_assert(name[0] != '\0');
 
132
 
 
133
        g_hash_table_insert(filter_param->properties, (gpointer) g_strdup(name), value);
 
134
}
 
135
 
 
136
static GValue *
 
137
rs_filter_param_get_gvalue(const RSFilterParam *filter_param, const gchar *name)
 
138
{
 
139
        g_assert(RS_IS_FILTER_PARAM(filter_param));
 
140
 
 
141
        GValue *value = g_hash_table_lookup(filter_param->properties, name);
 
142
 
 
143
        return value;
 
144
}
 
145
 
 
146
/**
 
147
 * Delete a property from a RSFilterParam
 
148
 * @param filter_param A RSFilterParam
 
149
 * @param name The name of the property
 
150
 * @return TRUE if the property was found, FALSE otherwise
 
151
 */
 
152
gboolean
 
153
rs_filter_param_delete(RSFilterParam *filter_param, const gchar *name)
 
154
{
 
155
        g_assert(RS_IS_FILTER_PARAM(filter_param));
 
156
 
 
157
        return g_hash_table_remove(filter_param->properties, name);
 
158
}
 
159
 
 
160
/**
 
161
 * Set a string property
 
162
 * @param filter_param A RSFilterParam
 
163
 * @param name The name of the property
 
164
 * @param str NULL-terminated string to set (will be copied)
 
165
 */
 
166
void
 
167
rs_filter_param_set_string(RSFilterParam *filter_param, const gchar *name, const gchar *str)
 
168
{
 
169
        GValue *val = new_value(G_TYPE_STRING);
 
170
        g_value_set_string(val, str);
 
171
 
 
172
        rs_filter_param_set_gvalue(filter_param, name, val);
 
173
}
 
174
 
 
175
/**
 
176
 * Get a string property
 
177
 * @param filter_param A RSFilterParam
 
178
 * @param name The name of the property
 
179
 * @param str A pointer to a string pointer where the value of the property can be saved. Should not be freed
 
180
 * @return TRUE if the property was found, FALSE otherwise
 
181
 */
 
182
gboolean
 
183
rs_filter_param_get_string(const RSFilterParam *filter_param, const gchar *name, const gchar ** const str)
 
184
{
 
185
        GValue *val = rs_filter_param_get_gvalue(filter_param, name);
 
186
 
 
187
        if (val && G_VALUE_HOLDS_STRING(val))
 
188
                *str = g_value_get_string(val);
 
189
 
 
190
        return (val != NULL);
 
191
}
 
192
 
 
193
/**
 
194
 * Set a boolean property
 
195
 * @param filter_param A RSFilterParam
 
196
 * @param name The name of the property
 
197
 * @param value A value to store
 
198
 */
 
199
void
 
200
rs_filter_param_set_boolean(RSFilterParam *filter_param, const gchar *name, const gboolean value)
 
201
{
 
202
        GValue *val = new_value(G_TYPE_BOOLEAN);
 
203
        g_value_set_boolean(val, value);
 
204
 
 
205
        rs_filter_param_set_gvalue(filter_param, name, val);
 
206
}
 
207
 
 
208
/**
 
209
 * Get a gboolean property
 
210
 * @param filter_param A RSFilterParam
 
211
 * @param name The name of the property
 
212
 * @param value A pointer to a gboolean where the value will be stored
 
213
 * @return TRUE if the property was found, FALSE otherwise
 
214
 */
 
215
gboolean
 
216
rs_filter_param_get_boolean(const RSFilterParam *filter_param, const gchar *name, gboolean *value)
 
217
{
 
218
        GValue *val = rs_filter_param_get_gvalue(filter_param, name);
 
219
 
 
220
        if (val && G_VALUE_HOLDS_BOOLEAN(val))
 
221
                *value = g_value_get_boolean(val);
 
222
 
 
223
        return (val != NULL);
 
224
}
 
225
 
 
226
/**
 
227
 * Set a integer property
 
228
 * @param filter_param A RSFilterParam
 
229
 * @param name The name of the property
 
230
 * @param value A value to store
 
231
 */
 
232
void
 
233
rs_filter_param_set_integer(RSFilterParam *filter_param, const gchar *name, const gint value)
 
234
{
 
235
        GValue *val = new_value(G_TYPE_INT);
 
236
        g_value_set_int(val, value);
 
237
 
 
238
        rs_filter_param_set_gvalue(filter_param, name, val);
 
239
}
 
240
 
 
241
/**
 
242
 * Get a integer property
 
243
 * @param filter_param A RSFilterParam
 
244
 * @param name The name of the property
 
245
 * @param value A pointer to a gint where the value will be stored
 
246
 * @return TRUE if the property was found, FALSE otherwise
 
247
 */
 
248
gboolean
 
249
rs_filter_param_get_integer(const RSFilterParam *filter_param, const gchar *name, gint *value)
 
250
{
 
251
        GValue *val = rs_filter_param_get_gvalue(filter_param, name);
 
252
 
 
253
        if (val && G_VALUE_HOLDS_INT(val))
 
254
                *value = g_value_get_int(val);
 
255
 
 
256
        return (val != NULL);
 
257
}
 
258
 
 
259
/**
 
260
 * Set a float property
 
261
 * @param filter_param A RSFilterParam
 
262
 * @param name The name of the property
 
263
 * @param value A value to store
 
264
 */
 
265
void
 
266
rs_filter_param_set_float(RSFilterParam *filter_param, const gchar *name, const gfloat value)
 
267
{
 
268
        GValue *val = new_value(G_TYPE_FLOAT);
 
269
        g_value_set_float(val, value);
 
270
 
 
271
        rs_filter_param_set_gvalue(filter_param, name, val);
 
272
}
 
273
 
 
274
/**
 
275
 * Get a float property
 
276
 * @param filter_param A RSFilterParam
 
277
 * @param name The name of the property
 
278
 * @param value A pointer to a gfloat where the value will be stored
 
279
 * @return TRUE if the property was found, FALSE otherwise
 
280
 */
 
281
gboolean
 
282
rs_filter_param_get_float(const RSFilterParam *filter_param, const gchar *name, gfloat *value)
 
283
{
 
284
        GValue *val = rs_filter_param_get_gvalue(filter_param, name);
 
285
 
 
286
        if (val && G_VALUE_HOLDS_FLOAT(val))
 
287
                *value = g_value_get_float(val);
 
288
 
 
289
        return (val != NULL);
 
290
}
 
291
 
 
292
/**
 
293
 * Set a float[4] property
 
294
 * @param filter_param A RSFilterParam
 
295
 * @param name The name of the property
 
296
 * @param value A value to store
 
297
 */
 
298
void
 
299
rs_filter_param_set_float4(RSFilterParam *filter_param, const gchar *name, const gfloat value[4])
 
300
{
 
301
        GValue *val = new_value(RS_TYPE_FLOAT4);
 
302
        g_value_set_boxed(val, value);
 
303
 
 
304
        rs_filter_param_set_gvalue(filter_param, name, val);
 
305
}
 
306
 
 
307
/**
 
308
 * Get a float property
 
309
 * @param filter_param A RSFilterParam
 
310
 * @param name The name of the property
 
311
 * @param value A pointer to a gfloat [4] where the values will be stored
 
312
 * @return TRUE if the property was found, FALSE otherwise
 
313
 */
 
314
gboolean
 
315
rs_filter_param_get_float4(const RSFilterParam *filter_param, const gchar *name, gfloat value[4])
 
316
{
 
317
        typedef gfloat buh[4];
 
318
        GValue *val = rs_filter_param_get_gvalue(filter_param, name);
 
319
 
 
320
        if (val && G_TYPE_CHECK_VALUE_TYPE(val, RS_TYPE_FLOAT4))
 
321
        {
 
322
                gfloat *boxed = g_value_get_boxed(val);
 
323
 
 
324
                value[0] = boxed[0];
 
325
                value[1] = boxed[1];
 
326
                value[2] = boxed[2];
 
327
                value[3] = boxed[3];
 
328
        }
 
329
 
 
330
        return (val != NULL);
 
331
}
 
332
 
 
333
/**
 
334
 * Set an object property
 
335
 * @param filter_param A RSFilterParam
 
336
 * @param name The name of the property
 
337
 * @param value An object to store. Refcount will be incremented by one
 
338
 */
 
339
void
 
340
rs_filter_param_set_object(RSFilterParam *filter_param, const gchar *name, gpointer object)
 
341
{
 
342
        g_return_if_fail(G_IS_OBJECT(object));
 
343
 
 
344
        GValue *val = new_value(G_OBJECT_TYPE(object));
 
345
        g_value_set_object(val, object);
 
346
 
 
347
        rs_filter_param_set_gvalue(filter_param, name, val);
 
348
}
 
349
 
 
350
/**
 
351
 * Get an object property
 
352
 * @param filter_param A RSFilterParam
 
353
 * @param name The name of the property
 
354
 * @return The object if found, NULL otherwise
 
355
 */
 
356
gpointer
 
357
rs_filter_param_get_object(const RSFilterParam *filter_param, const gchar *name)
 
358
{
 
359
        gpointer object = NULL;
 
360
        GValue *val = rs_filter_param_get_gvalue(filter_param, name);
 
361
 
 
362
        if (val && G_VALUE_HOLDS_OBJECT(val))
 
363
                object = g_value_dup_object(val);
 
364
 
 
365
        return object;
 
366
}
 
367
 
 
368
/**
 
369
 * Get an object property
 
370
 * @param filter_param A RSFilterParam
 
371
 * @param name The name of the property
 
372
 * @param type A desired GType, if the type doesn't match, the result is treated as non-existent
 
373
 * @return The object if found, NULL otherwise
 
374
 */
 
375
gpointer
 
376
rs_filter_param_get_object_with_type(const RSFilterParam *filter_param, const gchar *name, GType type)
 
377
{
 
378
        gpointer object = NULL;
 
379
        GValue *val = rs_filter_param_get_gvalue(filter_param, name);
 
380
 
 
381
        if (val && G_TYPE_CHECK_VALUE_TYPE(val, type))
 
382
                object = g_value_dup_object(val);
 
383
 
 
384
        return object;
 
385
}