34
36
#include "core/gimpgradient.h"
35
37
#include "core/gimplist.h"
37
static ProcRecord gradients_refresh_proc;
38
static ProcRecord gradients_get_list_proc;
39
static ProcRecord gradients_sample_uniform_proc;
40
static ProcRecord gradients_sample_custom_proc;
41
static ProcRecord gradients_get_gradient_data_proc;
44
register_gradients_procs (Gimp *gimp)
46
procedural_db_register (gimp, &gradients_refresh_proc);
47
procedural_db_register (gimp, &gradients_get_list_proc);
48
procedural_db_register (gimp, &gradients_sample_uniform_proc);
49
procedural_db_register (gimp, &gradients_sample_custom_proc);
50
procedural_db_register (gimp, &gradients_get_gradient_data_proc);
54
gradients_refresh_invoker (Gimp *gimp,
56
GimpProgress *progress,
59
gimp_data_factory_data_save (gimp->gradient_factory);
60
gimp_data_factory_data_init (gimp->gradient_factory, FALSE);
61
return procedural_db_return_args (&gradients_refresh_proc, TRUE);
64
static ProcRecord gradients_refresh_proc =
66
"gimp_gradients_refresh",
67
"Refresh current gradients. This function always succeeds.",
68
"This procedure retrieves all gradients currently in the user's gradient path and updates the gradient dialogs accordingly.",
78
{ { gradients_refresh_invoker } }
82
gradients_get_list_invoker (Gimp *gimp,
84
GimpProgress *progress,
39
#include "internal_procs.h"
43
gradients_refresh_invoker (GimpProcedure *procedure,
46
GimpProgress *progress,
47
const GValueArray *args)
49
gimp_data_factory_data_refresh (gimp->gradient_factory);
50
return gimp_procedure_get_return_values (procedure, TRUE);
54
gradients_get_list_invoker (GimpProcedure *procedure,
57
GimpProgress *progress,
58
const GValueArray *args)
87
60
gboolean success = TRUE;
88
Argument *return_args;
61
GValueArray *return_vals;
63
gint32 num_gradients = 0;
91
64
gchar **gradient_list = NULL;
93
filter = (gchar *) args[0].value.pdb_pointer;
94
if (filter && !g_utf8_validate (filter, -1, NULL))
98
gradient_list = gimp_container_get_filtered_name_array (gimp->gradient_factory->container, filter, &num_gradients);
100
return_args = procedural_db_return_args (&gradients_get_list_proc, success);
104
return_args[1].value.pdb_int = num_gradients;
105
return_args[2].value.pdb_pointer = gradient_list;
66
filter = g_value_get_string (&args->values[0]);
70
gradient_list = gimp_container_get_filtered_name_array (gimp->gradient_factory->container,
71
filter, &num_gradients);
74
return_vals = gimp_procedure_get_return_values (procedure, success);
78
g_value_set_int (&return_vals->values[1], num_gradients);
79
gimp_value_take_stringarray (&return_vals->values[2], gradient_list, num_gradients);
111
static ProcArg gradients_get_list_inargs[] =
116
"An optional regular expression used to filter the list"
120
static ProcArg gradients_get_list_outargs[] =
125
"The number of loaded gradients"
128
GIMP_PDB_STRINGARRAY,
130
"The list of gradient names"
134
static ProcRecord gradients_get_list_proc =
136
"gimp_gradients_get_list",
137
"Retrieve the list of loaded gradients.",
138
"This procedure returns a list of the gradients that are currently loaded. You can later use the 'gimp_context_set_gradient' function to set the active gradient.",
139
"Federico Mena Quintero",
140
"Federico Mena Quintero",
145
gradients_get_list_inargs,
147
gradients_get_list_outargs,
148
{ { gradients_get_list_invoker } }
152
gradients_sample_uniform_invoker (Gimp *gimp,
153
GimpContext *context,
154
GimpProgress *progress,
86
gradients_sample_uniform_invoker (GimpProcedure *procedure,
89
GimpProgress *progress,
90
const GValueArray *args)
157
92
gboolean success = TRUE;
158
Argument *return_args;
93
GValueArray *return_vals;
161
96
gint32 array_length = 0;
162
97
gdouble *color_samples = NULL;
163
GimpGradient *gradient;
168
i = args[0].value.pdb_int;
172
reverse = args[1].value.pdb_int ? TRUE : FALSE;
99
num_samples = g_value_get_int (&args->values[0]);
100
reverse = g_value_get_boolean (&args->values[1]);
104
GimpGradient *gradient;
105
GimpGradientSegment *seg = NULL;
177
delta = 1.0 / (i - 1);
111
delta = 1.0 / (num_samples - 1);
179
array_length = i * 4;
113
array_length = num_samples * 4;
181
115
pv = color_samples = g_new (gdouble, array_length);
183
117
gradient = gimp_context_get_gradient (context);
119
while (num_samples--)
187
gimp_gradient_get_color_at (gradient, pos, reverse, &color);
121
seg = gimp_gradient_get_color_at (gradient, context, seg,
122
pos, reverse, &color);
198
return_args = procedural_db_return_args (&gradients_sample_uniform_proc, success);
133
return_vals = gimp_procedure_get_return_values (procedure, success);
202
return_args[1].value.pdb_int = array_length;
203
return_args[2].value.pdb_pointer = color_samples;
137
g_value_set_int (&return_vals->values[1], array_length);
138
gimp_value_take_floatarray (&return_vals->values[2], color_samples, array_length);
209
static ProcArg gradients_sample_uniform_inargs[] =
214
"The number of samples to take"
219
"Use the reverse gradient (TRUE or FALSE)"
223
static ProcArg gradients_sample_uniform_outargs[] =
228
"Length of the color_samples array (4 * num_samples)"
233
"Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }"
237
static ProcRecord gradients_sample_uniform_proc =
239
"gimp_gradients_sample_uniform",
240
"This procedure is deprecated! Use 'gimp_gradient_get_uniform_samples' instead.",
241
"This procedure is deprecated! Use 'gimp_gradient_get_uniform_samples' instead.",
245
"gimp_gradient_get_uniform_samples",
248
gradients_sample_uniform_inargs,
250
gradients_sample_uniform_outargs,
251
{ { gradients_sample_uniform_invoker } }
255
gradients_sample_custom_invoker (Gimp *gimp,
256
GimpContext *context,
257
GimpProgress *progress,
145
gradients_sample_custom_invoker (GimpProcedure *procedure,
147
GimpContext *context,
148
GimpProgress *progress,
149
const GValueArray *args)
260
151
gboolean success = TRUE;
261
Argument *return_args;
152
GValueArray *return_vals;
154
const gdouble *positions;
264
155
gboolean reverse;
265
156
gint32 array_length = 0;
266
157
gdouble *color_samples = NULL;
267
GimpGradient *gradient;
271
i = args[0].value.pdb_int;
275
pos = (gdouble *) args[1].value.pdb_pointer;
277
reverse = args[2].value.pdb_int ? TRUE : FALSE;
159
num_samples = g_value_get_int (&args->values[0]);
160
positions = gimp_value_get_floatarray (&args->values[1]);
161
reverse = g_value_get_boolean (&args->values[2]);
281
array_length = i * 4;
165
GimpGradient *gradient;
166
GimpGradientSegment *seg = NULL;
170
array_length = num_samples * 4;
283
172
pv = color_samples = g_new (gdouble, array_length);
285
174
gradient = gimp_context_get_gradient (context);
176
while (num_samples--)
289
gimp_gradient_get_color_at (gradient, *pos, reverse, &color);
178
seg = gimp_gradient_get_color_at (gradient, context, seg,
179
*positions, reverse, &color);
300
return_args = procedural_db_return_args (&gradients_sample_custom_proc, success);
190
return_vals = gimp_procedure_get_return_values (procedure, success);
304
return_args[1].value.pdb_int = array_length;
305
return_args[2].value.pdb_pointer = color_samples;
194
g_value_set_int (&return_vals->values[1], array_length);
195
gimp_value_take_floatarray (&return_vals->values[2], color_samples, array_length);
311
static ProcArg gradients_sample_custom_inargs[] =
316
"The number of samples to take"
321
"The list of positions to sample along the gradient"
326
"Use the reverse gradient (TRUE or FALSE)"
330
static ProcArg gradients_sample_custom_outargs[] =
335
"Length of the color_samples array (4 * num_samples)"
340
"Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }"
344
static ProcRecord gradients_sample_custom_proc =
346
"gimp_gradients_sample_custom",
347
"This procedure is deprecated! Use 'gimp_gradient_get_custom_samples' instead.",
348
"This procedure is deprecated! Use 'gimp_gradient_get_custom_samples' instead.",
352
"gimp_gradient_get_custom_samples",
355
gradients_sample_custom_inargs,
357
gradients_sample_custom_outargs,
358
{ { gradients_sample_custom_invoker } }
362
gradients_get_gradient_data_invoker (Gimp *gimp,
363
GimpContext *context,
364
GimpProgress *progress,
202
gradients_get_gradient_data_invoker (GimpProcedure *procedure,
204
GimpContext *context,
205
GimpProgress *progress,
206
const GValueArray *args)
367
208
gboolean success = TRUE;
368
Argument *return_args;
209
GValueArray *return_vals;
370
211
gint32 sample_size;
371
212
gboolean reverse;
372
gdouble *values = NULL;
373
GimpGradient *gradient = NULL;
375
name = (gchar *) args[0].value.pdb_pointer;
376
if (name && !g_utf8_validate (name, -1, NULL))
379
sample_size = args[1].value.pdb_int;
380
if (sample_size <= 0 || sample_size > 10000)
381
sample_size = GIMP_GRADIENT_DEFAULT_SAMPLE_SIZE;
383
reverse = args[2].value.pdb_int ? TRUE : FALSE;
213
gchar *actual_name = NULL;
215
gdouble *grad_data = NULL;
217
name = g_value_get_string (&args->values[0]);
218
sample_size = g_value_get_int (&args->values[1]);
219
reverse = g_value_get_boolean (&args->values[2]);
223
GimpGradient *gradient;
225
if (sample_size < 1 || sample_size > 10000)
226
sample_size = GIMP_GRADIENT_DEFAULT_SAMPLE_SIZE;
387
228
if (name && strlen (name))
389
230
gradient = (GimpGradient *)
427
return_args = procedural_db_return_args (&gradients_get_gradient_data_proc, success);
272
return_vals = gimp_procedure_get_return_values (procedure, success);
431
return_args[1].value.pdb_pointer = g_strdup (GIMP_OBJECT (gradient)->name);
432
return_args[2].value.pdb_int = sample_size * 4;
433
return_args[3].value.pdb_pointer = values;
276
g_value_take_string (&return_vals->values[1], actual_name);
277
g_value_set_int (&return_vals->values[2], width);
278
gimp_value_take_floatarray (&return_vals->values[3], grad_data, width);
439
static ProcArg gradients_get_gradient_data_inargs[] =
444
"The gradient name (\"\" means current active gradient)"
449
"Size of the sample to return when the gradient is changed (0 < sample_size <= 10000)"
454
"Use the reverse gradient (TRUE or FALSE)"
458
static ProcArg gradients_get_gradient_data_outargs[] =
468
"The gradient sample width (r,g,b,a)"
473
"The gradient sample data"
477
static ProcRecord gradients_get_gradient_data_proc =
479
"gimp_gradients_get_gradient_data",
480
"This procedure is deprecated! Use 'gimp_gradient_get_uniform_samples' instead.",
481
"This procedure is deprecated! Use 'gimp_gradient_get_uniform_samples' instead.",
485
"gimp_gradient_get_uniform_samples",
488
gradients_get_gradient_data_inargs,
490
gradients_get_gradient_data_outargs,
491
{ { gradients_get_gradient_data_invoker } }
285
register_gradients_procs (GimpPDB *pdb)
287
GimpProcedure *procedure;
290
* gimp-gradients-refresh
292
procedure = gimp_procedure_new (gradients_refresh_invoker);
293
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-gradients-refresh");
294
gimp_procedure_set_static_strings (procedure,
295
"gimp-gradients-refresh",
296
"Refresh current gradients. This function always succeeds.",
297
"This procedure retrieves all gradients currently in the user's gradient path and updates the gradient dialogs accordingly.",
298
"Michael Natterer <mitch@gimp.org>",
302
gimp_pdb_register_procedure (pdb, procedure);
303
g_object_unref (procedure);
306
* gimp-gradients-get-list
308
procedure = gimp_procedure_new (gradients_get_list_invoker);
309
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-gradients-get-list");
310
gimp_procedure_set_static_strings (procedure,
311
"gimp-gradients-get-list",
312
"Retrieve the list of loaded gradients.",
313
"This procedure returns a list of the gradients that are currently loaded. You can later use the 'gimp-context-set-gradient' function to set the active gradient.",
314
"Federico Mena Quintero",
315
"Federico Mena Quintero",
318
gimp_procedure_add_argument (procedure,
319
gimp_param_spec_string ("filter",
321
"An optional regular expression used to filter the list",
324
GIMP_PARAM_READWRITE));
325
gimp_procedure_add_return_value (procedure,
326
gimp_param_spec_int32 ("num-gradients",
328
"The number of loaded gradients",
330
GIMP_PARAM_READWRITE));
331
gimp_procedure_add_return_value (procedure,
332
gimp_param_spec_string_array ("gradient-list",
334
"The list of gradient names",
335
GIMP_PARAM_READWRITE));
336
gimp_pdb_register_procedure (pdb, procedure);
337
g_object_unref (procedure);
340
* gimp-gradients-sample-uniform
342
procedure = gimp_procedure_new (gradients_sample_uniform_invoker);
343
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-gradients-sample-uniform");
344
gimp_procedure_set_static_strings (procedure,
345
"gimp-gradients-sample-uniform",
346
"This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead.",
347
"This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead.",
351
"gimp-gradient-get-uniform-samples");
352
gimp_procedure_add_argument (procedure,
353
gimp_param_spec_int32 ("num-samples",
355
"The number of samples to take",
357
GIMP_PARAM_READWRITE));
358
gimp_procedure_add_argument (procedure,
359
g_param_spec_boolean ("reverse",
361
"Use the reverse gradient",
363
GIMP_PARAM_READWRITE));
364
gimp_procedure_add_return_value (procedure,
365
gimp_param_spec_int32 ("array-length",
367
"Length of the color_samples array (4 * num_samples)",
369
GIMP_PARAM_READWRITE));
370
gimp_procedure_add_return_value (procedure,
371
gimp_param_spec_float_array ("color-samples",
373
"Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }",
374
GIMP_PARAM_READWRITE));
375
gimp_pdb_register_procedure (pdb, procedure);
376
g_object_unref (procedure);
379
* gimp-gradients-sample-custom
381
procedure = gimp_procedure_new (gradients_sample_custom_invoker);
382
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-gradients-sample-custom");
383
gimp_procedure_set_static_strings (procedure,
384
"gimp-gradients-sample-custom",
385
"This procedure is deprecated! Use 'gimp-gradient-get-custom-samples' instead.",
386
"This procedure is deprecated! Use 'gimp-gradient-get-custom-samples' instead.",
390
"gimp-gradient-get-custom-samples");
391
gimp_procedure_add_argument (procedure,
392
gimp_param_spec_int32 ("num-samples",
394
"The number of samples to take",
396
GIMP_PARAM_READWRITE));
397
gimp_procedure_add_argument (procedure,
398
gimp_param_spec_float_array ("positions",
400
"The list of positions to sample along the gradient",
401
GIMP_PARAM_READWRITE));
402
gimp_procedure_add_argument (procedure,
403
g_param_spec_boolean ("reverse",
405
"Use the reverse gradient",
407
GIMP_PARAM_READWRITE));
408
gimp_procedure_add_return_value (procedure,
409
gimp_param_spec_int32 ("array-length",
411
"Length of the color_samples array (4 * num_samples)",
413
GIMP_PARAM_READWRITE));
414
gimp_procedure_add_return_value (procedure,
415
gimp_param_spec_float_array ("color-samples",
417
"Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }",
418
GIMP_PARAM_READWRITE));
419
gimp_pdb_register_procedure (pdb, procedure);
420
g_object_unref (procedure);
423
* gimp-gradients-get-gradient-data
425
procedure = gimp_procedure_new (gradients_get_gradient_data_invoker);
426
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-gradients-get-gradient-data");
427
gimp_procedure_set_static_strings (procedure,
428
"gimp-gradients-get-gradient-data",
429
"This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead.",
430
"This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead.",
434
"gimp-gradient-get-uniform-samples");
435
gimp_procedure_add_argument (procedure,
436
gimp_param_spec_string ("name",
438
"The gradient name (\"\" means current active gradient)",
441
GIMP_PARAM_READWRITE));
442
gimp_procedure_add_argument (procedure,
443
gimp_param_spec_int32 ("sample-size",
445
"Size of the sample to return when the gradient is changed",
447
GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
448
gimp_procedure_add_argument (procedure,
449
g_param_spec_boolean ("reverse",
451
"Use the reverse gradient",
453
GIMP_PARAM_READWRITE));
454
gimp_procedure_add_return_value (procedure,
455
gimp_param_spec_string ("actual-name",
460
GIMP_PARAM_READWRITE));
461
gimp_procedure_add_return_value (procedure,
462
gimp_param_spec_int32 ("width",
464
"The gradient sample width (r,g,b,a)",
466
GIMP_PARAM_READWRITE));
467
gimp_procedure_add_return_value (procedure,
468
gimp_param_spec_float_array ("grad-data",
470
"The gradient sample data",
471
GIMP_PARAM_READWRITE));
472
gimp_pdb_register_procedure (pdb, procedure);
473
g_object_unref (procedure);