~ubuntu-branches/ubuntu/intrepid/gimp/intrepid

« back to all changes in this revision

Viewing changes to app/pdb/gradients-cmds.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20081006133041-axco233xt49jobn7
Tags: 2.6.0-1ubuntu1
* Sync on debian and new version (lp: #276839)
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch:
  - updated some strings for ubuntu
* debian/rules:
  - updated translation templates

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program 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
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
/* NOTE: This file is auto-generated by pdbgen.pl. */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <string.h>
 
24
 
 
25
#include <glib-object.h>
 
26
 
 
27
#include "pdb-types.h"
 
28
 
 
29
#include "core/gimp.h"
 
30
#include "core/gimpcontainer-filter.h"
 
31
#include "core/gimpcontext.h"
 
32
#include "core/gimpdatafactory.h"
 
33
#include "core/gimpgradient.h"
 
34
#include "core/gimpparamspecs.h"
 
35
 
 
36
#include "gimppdb.h"
 
37
#include "gimppdb-utils.h"
 
38
#include "gimpprocedure.h"
 
39
#include "internal-procs.h"
 
40
 
 
41
 
 
42
static GValueArray *
 
43
gradients_refresh_invoker (GimpProcedure      *procedure,
 
44
                           Gimp               *gimp,
 
45
                           GimpContext        *context,
 
46
                           GimpProgress       *progress,
 
47
                           const GValueArray  *args,
 
48
                           GError            **error)
 
49
{
 
50
  gimp_data_factory_data_refresh (gimp->gradient_factory);
 
51
 
 
52
  return gimp_procedure_get_return_values (procedure, TRUE, NULL);
 
53
}
 
54
 
 
55
static GValueArray *
 
56
gradients_get_list_invoker (GimpProcedure      *procedure,
 
57
                            Gimp               *gimp,
 
58
                            GimpContext        *context,
 
59
                            GimpProgress       *progress,
 
60
                            const GValueArray  *args,
 
61
                            GError            **error)
 
62
{
 
63
  gboolean success = TRUE;
 
64
  GValueArray *return_vals;
 
65
  const gchar *filter;
 
66
  gint32 num_gradients = 0;
 
67
  gchar **gradient_list = NULL;
 
68
 
 
69
  filter = g_value_get_string (&args->values[0]);
 
70
 
 
71
  if (success)
 
72
    {
 
73
      gradient_list = gimp_container_get_filtered_name_array (gimp->gradient_factory->container,
 
74
                                                              filter, &num_gradients);
 
75
    }
 
76
 
 
77
  return_vals = gimp_procedure_get_return_values (procedure, success,
 
78
                                                  error ? *error : NULL);
 
79
 
 
80
  if (success)
 
81
    {
 
82
      g_value_set_int (&return_vals->values[1], num_gradients);
 
83
      gimp_value_take_stringarray (&return_vals->values[2], gradient_list, num_gradients);
 
84
    }
 
85
 
 
86
  return return_vals;
 
87
}
 
88
 
 
89
static GValueArray *
 
90
gradients_sample_uniform_invoker (GimpProcedure      *procedure,
 
91
                                  Gimp               *gimp,
 
92
                                  GimpContext        *context,
 
93
                                  GimpProgress       *progress,
 
94
                                  const GValueArray  *args,
 
95
                                  GError            **error)
 
96
{
 
97
  gboolean success = TRUE;
 
98
  GValueArray *return_vals;
 
99
  gint32 num_samples;
 
100
  gboolean reverse;
 
101
  gint32 array_length = 0;
 
102
  gdouble *color_samples = NULL;
 
103
 
 
104
  num_samples = g_value_get_int (&args->values[0]);
 
105
  reverse = g_value_get_boolean (&args->values[1]);
 
106
 
 
107
  if (success)
 
108
    {
 
109
      GimpGradient        *gradient;
 
110
      GimpGradientSegment *seg = NULL;
 
111
      gdouble              pos, delta;
 
112
      GimpRGB              color;
 
113
      gdouble             *pv;
 
114
 
 
115
      pos   = 0.0;
 
116
      delta = 1.0 / (num_samples - 1);
 
117
 
 
118
      array_length = num_samples * 4;
 
119
 
 
120
      pv = color_samples = g_new (gdouble, array_length);
 
121
 
 
122
      gradient = gimp_context_get_gradient (context);
 
123
 
 
124
      while (num_samples--)
 
125
        {
 
126
          seg = gimp_gradient_get_color_at (gradient, context, seg,
 
127
                                            pos, reverse, &color);
 
128
 
 
129
          *pv++ = color.r;
 
130
          *pv++ = color.g;
 
131
          *pv++ = color.b;
 
132
          *pv++ = color.a;
 
133
 
 
134
          pos += delta;
 
135
        }
 
136
    }
 
137
 
 
138
  return_vals = gimp_procedure_get_return_values (procedure, success,
 
139
                                                  error ? *error : NULL);
 
140
 
 
141
  if (success)
 
142
    {
 
143
      g_value_set_int (&return_vals->values[1], array_length);
 
144
      gimp_value_take_floatarray (&return_vals->values[2], color_samples, array_length);
 
145
    }
 
146
 
 
147
  return return_vals;
 
148
}
 
149
 
 
150
static GValueArray *
 
151
gradients_sample_custom_invoker (GimpProcedure      *procedure,
 
152
                                 Gimp               *gimp,
 
153
                                 GimpContext        *context,
 
154
                                 GimpProgress       *progress,
 
155
                                 const GValueArray  *args,
 
156
                                 GError            **error)
 
157
{
 
158
  gboolean success = TRUE;
 
159
  GValueArray *return_vals;
 
160
  gint32 num_samples;
 
161
  const gdouble *positions;
 
162
  gboolean reverse;
 
163
  gint32 array_length = 0;
 
164
  gdouble *color_samples = NULL;
 
165
 
 
166
  num_samples = g_value_get_int (&args->values[0]);
 
167
  positions = gimp_value_get_floatarray (&args->values[1]);
 
168
  reverse = g_value_get_boolean (&args->values[2]);
 
169
 
 
170
  if (success)
 
171
    {
 
172
      GimpGradient        *gradient;
 
173
      GimpGradientSegment *seg = NULL;
 
174
      GimpRGB              color;
 
175
      gdouble             *pv;
 
176
 
 
177
      array_length = num_samples * 4;
 
178
 
 
179
      pv = color_samples = g_new (gdouble, array_length);
 
180
 
 
181
      gradient = gimp_context_get_gradient (context);
 
182
 
 
183
      while (num_samples--)
 
184
        {
 
185
          seg = gimp_gradient_get_color_at (gradient, context, seg,
 
186
                                            *positions, reverse, &color);
 
187
 
 
188
          *pv++ = color.r;
 
189
          *pv++ = color.g;
 
190
          *pv++ = color.b;
 
191
          *pv++ = color.a;
 
192
 
 
193
          positions++;
 
194
        }
 
195
    }
 
196
 
 
197
  return_vals = gimp_procedure_get_return_values (procedure, success,
 
198
                                                  error ? *error : NULL);
 
199
 
 
200
  if (success)
 
201
    {
 
202
      g_value_set_int (&return_vals->values[1], array_length);
 
203
      gimp_value_take_floatarray (&return_vals->values[2], color_samples, array_length);
 
204
    }
 
205
 
 
206
  return return_vals;
 
207
}
 
208
 
 
209
static GValueArray *
 
210
gradients_get_gradient_data_invoker (GimpProcedure      *procedure,
 
211
                                     Gimp               *gimp,
 
212
                                     GimpContext        *context,
 
213
                                     GimpProgress       *progress,
 
214
                                     const GValueArray  *args,
 
215
                                     GError            **error)
 
216
{
 
217
  gboolean success = TRUE;
 
218
  GValueArray *return_vals;
 
219
  const gchar *name;
 
220
  gint32 sample_size;
 
221
  gboolean reverse;
 
222
  gchar *actual_name = NULL;
 
223
  gint32 width = 0;
 
224
  gdouble *grad_data = NULL;
 
225
 
 
226
  name = g_value_get_string (&args->values[0]);
 
227
  sample_size = g_value_get_int (&args->values[1]);
 
228
  reverse = g_value_get_boolean (&args->values[2]);
 
229
 
 
230
  if (success)
 
231
    {
 
232
      GimpGradient *gradient;
 
233
 
 
234
      if (sample_size < 1 || sample_size > 10000)
 
235
        sample_size = GIMP_GRADIENT_DEFAULT_SAMPLE_SIZE;
 
236
 
 
237
      if (name && strlen (name))
 
238
        gradient = gimp_pdb_get_gradient (gimp, name, FALSE, error);
 
239
      else
 
240
        gradient = gimp_context_get_gradient (context);
 
241
 
 
242
      if (gradient)
 
243
        {
 
244
          GimpGradientSegment *seg = NULL;
 
245
          gdouble             *pv;
 
246
          gdouble              pos, delta;
 
247
          GimpRGB              color;
 
248
 
 
249
          pos   = 0.0;
 
250
          delta = 1.0 / (sample_size - 1);
 
251
 
 
252
          actual_name = g_strdup (gimp_object_get_name (GIMP_OBJECT (gradient)));
 
253
          grad_data   = g_new (gdouble, sample_size * 4);
 
254
          width       = sample_size * 4;
 
255
 
 
256
          pv = grad_data;
 
257
 
 
258
          while (sample_size)
 
259
            {
 
260
              seg = gimp_gradient_get_color_at (gradient, context, seg,
 
261
                                                pos, reverse, &color);
 
262
 
 
263
              *pv++ = color.r;
 
264
              *pv++ = color.g;
 
265
              *pv++ = color.b;
 
266
              *pv++ = color.a;
 
267
 
 
268
              pos += delta;
 
269
            }
 
270
        }
 
271
      else
 
272
        success = FALSE;
 
273
    }
 
274
 
 
275
  return_vals = gimp_procedure_get_return_values (procedure, success,
 
276
                                                  error ? *error : NULL);
 
277
 
 
278
  if (success)
 
279
    {
 
280
      g_value_take_string (&return_vals->values[1], actual_name);
 
281
      g_value_set_int (&return_vals->values[2], width);
 
282
      gimp_value_take_floatarray (&return_vals->values[3], grad_data, width);
 
283
    }
 
284
 
 
285
  return return_vals;
 
286
}
 
287
 
 
288
void
 
289
register_gradients_procs (GimpPDB *pdb)
 
290
{
 
291
  GimpProcedure *procedure;
 
292
 
 
293
  /*
 
294
   * gimp-gradients-refresh
 
295
   */
 
296
  procedure = gimp_procedure_new (gradients_refresh_invoker);
 
297
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
 
298
                               "gimp-gradients-refresh");
 
299
  gimp_procedure_set_static_strings (procedure,
 
300
                                     "gimp-gradients-refresh",
 
301
                                     "Refresh current gradients. This function always succeeds.",
 
302
                                     "This procedure retrieves all gradients currently in the user's gradient path and updates the gradient dialogs accordingly.",
 
303
                                     "Michael Natterer <mitch@gimp.org>",
 
304
                                     "Michael Natterer",
 
305
                                     "2002",
 
306
                                     NULL);
 
307
  gimp_pdb_register_procedure (pdb, procedure);
 
308
  g_object_unref (procedure);
 
309
 
 
310
  /*
 
311
   * gimp-gradients-get-list
 
312
   */
 
313
  procedure = gimp_procedure_new (gradients_get_list_invoker);
 
314
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
 
315
                               "gimp-gradients-get-list");
 
316
  gimp_procedure_set_static_strings (procedure,
 
317
                                     "gimp-gradients-get-list",
 
318
                                     "Retrieve the list of loaded gradients.",
 
319
                                     "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.",
 
320
                                     "Federico Mena Quintero",
 
321
                                     "Federico Mena Quintero",
 
322
                                     "1997",
 
323
                                     NULL);
 
324
  gimp_procedure_add_argument (procedure,
 
325
                               gimp_param_spec_string ("filter",
 
326
                                                       "filter",
 
327
                                                       "An optional regular expression used to filter the list",
 
328
                                                       FALSE, TRUE, FALSE,
 
329
                                                       NULL,
 
330
                                                       GIMP_PARAM_READWRITE));
 
331
  gimp_procedure_add_return_value (procedure,
 
332
                                   gimp_param_spec_int32 ("num-gradients",
 
333
                                                          "num gradients",
 
334
                                                          "The number of loaded gradients",
 
335
                                                          0, G_MAXINT32, 0,
 
336
                                                          GIMP_PARAM_READWRITE));
 
337
  gimp_procedure_add_return_value (procedure,
 
338
                                   gimp_param_spec_string_array ("gradient-list",
 
339
                                                                 "gradient list",
 
340
                                                                 "The list of gradient names",
 
341
                                                                 GIMP_PARAM_READWRITE));
 
342
  gimp_pdb_register_procedure (pdb, procedure);
 
343
  g_object_unref (procedure);
 
344
 
 
345
  /*
 
346
   * gimp-gradients-sample-uniform
 
347
   */
 
348
  procedure = gimp_procedure_new (gradients_sample_uniform_invoker);
 
349
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
 
350
                               "gimp-gradients-sample-uniform");
 
351
  gimp_procedure_set_static_strings (procedure,
 
352
                                     "gimp-gradients-sample-uniform",
 
353
                                     "This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead.",
 
354
                                     "This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead.",
 
355
                                     "",
 
356
                                     "",
 
357
                                     "",
 
358
                                     "gimp-gradient-get-uniform-samples");
 
359
  gimp_procedure_add_argument (procedure,
 
360
                               gimp_param_spec_int32 ("num-samples",
 
361
                                                      "num samples",
 
362
                                                      "The number of samples to take",
 
363
                                                      2, G_MAXINT32, 2,
 
364
                                                      GIMP_PARAM_READWRITE));
 
365
  gimp_procedure_add_argument (procedure,
 
366
                               g_param_spec_boolean ("reverse",
 
367
                                                     "reverse",
 
368
                                                     "Use the reverse gradient",
 
369
                                                     FALSE,
 
370
                                                     GIMP_PARAM_READWRITE));
 
371
  gimp_procedure_add_return_value (procedure,
 
372
                                   gimp_param_spec_int32 ("array-length",
 
373
                                                          "array length",
 
374
                                                          "Length of the color_samples array (4 * num_samples)",
 
375
                                                          0, G_MAXINT32, 0,
 
376
                                                          GIMP_PARAM_READWRITE));
 
377
  gimp_procedure_add_return_value (procedure,
 
378
                                   gimp_param_spec_float_array ("color-samples",
 
379
                                                                "color samples",
 
380
                                                                "Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }",
 
381
                                                                GIMP_PARAM_READWRITE));
 
382
  gimp_pdb_register_procedure (pdb, procedure);
 
383
  g_object_unref (procedure);
 
384
 
 
385
  /*
 
386
   * gimp-gradients-sample-custom
 
387
   */
 
388
  procedure = gimp_procedure_new (gradients_sample_custom_invoker);
 
389
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
 
390
                               "gimp-gradients-sample-custom");
 
391
  gimp_procedure_set_static_strings (procedure,
 
392
                                     "gimp-gradients-sample-custom",
 
393
                                     "This procedure is deprecated! Use 'gimp-gradient-get-custom-samples' instead.",
 
394
                                     "This procedure is deprecated! Use 'gimp-gradient-get-custom-samples' instead.",
 
395
                                     "",
 
396
                                     "",
 
397
                                     "",
 
398
                                     "gimp-gradient-get-custom-samples");
 
399
  gimp_procedure_add_argument (procedure,
 
400
                               gimp_param_spec_int32 ("num-samples",
 
401
                                                      "num samples",
 
402
                                                      "The number of samples to take",
 
403
                                                      0, G_MAXINT32, 0,
 
404
                                                      GIMP_PARAM_READWRITE));
 
405
  gimp_procedure_add_argument (procedure,
 
406
                               gimp_param_spec_float_array ("positions",
 
407
                                                            "positions",
 
408
                                                            "The list of positions to sample along the gradient",
 
409
                                                            GIMP_PARAM_READWRITE));
 
410
  gimp_procedure_add_argument (procedure,
 
411
                               g_param_spec_boolean ("reverse",
 
412
                                                     "reverse",
 
413
                                                     "Use the reverse gradient",
 
414
                                                     FALSE,
 
415
                                                     GIMP_PARAM_READWRITE));
 
416
  gimp_procedure_add_return_value (procedure,
 
417
                                   gimp_param_spec_int32 ("array-length",
 
418
                                                          "array length",
 
419
                                                          "Length of the color_samples array (4 * num_samples)",
 
420
                                                          0, G_MAXINT32, 0,
 
421
                                                          GIMP_PARAM_READWRITE));
 
422
  gimp_procedure_add_return_value (procedure,
 
423
                                   gimp_param_spec_float_array ("color-samples",
 
424
                                                                "color samples",
 
425
                                                                "Color samples: { R1, G1, B1, A1, ..., Rn, Gn, Bn, An }",
 
426
                                                                GIMP_PARAM_READWRITE));
 
427
  gimp_pdb_register_procedure (pdb, procedure);
 
428
  g_object_unref (procedure);
 
429
 
 
430
  /*
 
431
   * gimp-gradients-get-gradient-data
 
432
   */
 
433
  procedure = gimp_procedure_new (gradients_get_gradient_data_invoker);
 
434
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
 
435
                               "gimp-gradients-get-gradient-data");
 
436
  gimp_procedure_set_static_strings (procedure,
 
437
                                     "gimp-gradients-get-gradient-data",
 
438
                                     "This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead.",
 
439
                                     "This procedure is deprecated! Use 'gimp-gradient-get-uniform-samples' instead.",
 
440
                                     "",
 
441
                                     "",
 
442
                                     "",
 
443
                                     "gimp-gradient-get-uniform-samples");
 
444
  gimp_procedure_add_argument (procedure,
 
445
                               gimp_param_spec_string ("name",
 
446
                                                       "name",
 
447
                                                       "The gradient name (\"\" means current active gradient)",
 
448
                                                       FALSE, TRUE, FALSE,
 
449
                                                       NULL,
 
450
                                                       GIMP_PARAM_READWRITE));
 
451
  gimp_procedure_add_argument (procedure,
 
452
                               gimp_param_spec_int32 ("sample-size",
 
453
                                                      "sample size",
 
454
                                                      "Size of the sample to return when the gradient is changed",
 
455
                                                      1, 10000, 1,
 
456
                                                      GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
 
457
  gimp_procedure_add_argument (procedure,
 
458
                               g_param_spec_boolean ("reverse",
 
459
                                                     "reverse",
 
460
                                                     "Use the reverse gradient",
 
461
                                                     FALSE,
 
462
                                                     GIMP_PARAM_READWRITE));
 
463
  gimp_procedure_add_return_value (procedure,
 
464
                                   gimp_param_spec_string ("actual-name",
 
465
                                                           "actual name",
 
466
                                                           "The gradient name",
 
467
                                                           FALSE, FALSE, FALSE,
 
468
                                                           NULL,
 
469
                                                           GIMP_PARAM_READWRITE));
 
470
  gimp_procedure_add_return_value (procedure,
 
471
                                   gimp_param_spec_int32 ("width",
 
472
                                                          "width",
 
473
                                                          "The gradient sample width (r,g,b,a)",
 
474
                                                          0, G_MAXINT32, 0,
 
475
                                                          GIMP_PARAM_READWRITE));
 
476
  gimp_procedure_add_return_value (procedure,
 
477
                                   gimp_param_spec_float_array ("grad-data",
 
478
                                                                "grad data",
 
479
                                                                "The gradient sample data",
 
480
                                                                GIMP_PARAM_READWRITE));
 
481
  gimp_pdb_register_procedure (pdb, procedure);
 
482
  g_object_unref (procedure);
 
483
}