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 3 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, see <https://www.gnu.org/licenses/>.
16  */
17 
18 /* NOTE: This file is auto-generated by pdbgen.pl. */
19 
20 #include "config.h"
21 
22 #include <gegl.h>
23 
24 #include <gdk-pixbuf/gdk-pixbuf.h>
25 
26 #include "libgimpmath/gimpmath.h"
27 
28 #include "libgimpbase/gimpbase.h"
29 
30 #include "pdb-types.h"
31 
32 #include "core/gimp.h"
33 #include "core/gimpdrawable-equalize.h"
34 #include "core/gimpdrawable-histogram.h"
35 #include "core/gimpdrawable-levels.h"
36 #include "core/gimpdrawable-operation.h"
37 #include "core/gimpdrawable.h"
38 #include "core/gimphistogram.h"
39 #include "core/gimpparamspecs.h"
40 #include "operations/gimpbrightnesscontrastconfig.h"
41 #include "operations/gimpcolorbalanceconfig.h"
42 #include "operations/gimpcurvesconfig.h"
43 #include "operations/gimphuesaturationconfig.h"
44 #include "operations/gimplevelsconfig.h"
45 #include "plug-in/gimpplugin.h"
46 #include "plug-in/gimppluginmanager.h"
47 
48 #include "gimppdb.h"
49 #include "gimppdb-utils.h"
50 #include "gimpprocedure.h"
51 #include "internal-procs.h"
52 
53 #include "gimp-intl.h"
54 
55 
56 static GimpValueArray *
brightness_contrast_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)57 brightness_contrast_invoker (GimpProcedure         *procedure,
58                              Gimp                  *gimp,
59                              GimpContext           *context,
60                              GimpProgress          *progress,
61                              const GimpValueArray  *args,
62                              GError               **error)
63 {
64   gboolean success = TRUE;
65   GimpDrawable *drawable;
66   gint32 brightness;
67   gint32 contrast;
68 
69   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
70   brightness = g_value_get_int (gimp_value_array_index (args, 1));
71   contrast = g_value_get_int (gimp_value_array_index (args, 2));
72 
73   if (success)
74     {
75       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
76                                      GIMP_PDB_ITEM_CONTENT, error) &&
77           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
78         {
79           GObject *config = g_object_new (GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG,
80                                           "brightness", brightness / 127.0,
81                                           "contrast",   contrast   / 127.0,
82                                           NULL);
83 
84           gimp_drawable_apply_operation_by_name (drawable, progress,
85                                                  C_("undo-type", "Brightness-Contrast"),
86                                                  "gimp:brightness-contrast",
87                                                  config);
88           g_object_unref (config);
89         }
90       else
91         success = FALSE;
92     }
93 
94   return gimp_procedure_get_return_values (procedure, success,
95                                            error ? *error : NULL);
96 }
97 
98 static GimpValueArray *
levels_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)99 levels_invoker (GimpProcedure         *procedure,
100                 Gimp                  *gimp,
101                 GimpContext           *context,
102                 GimpProgress          *progress,
103                 const GimpValueArray  *args,
104                 GError               **error)
105 {
106   gboolean success = TRUE;
107   GimpDrawable *drawable;
108   gint32 channel;
109   gint32 low_input;
110   gint32 high_input;
111   gdouble gamma;
112   gint32 low_output;
113   gint32 high_output;
114 
115   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
116   channel = g_value_get_enum (gimp_value_array_index (args, 1));
117   low_input = g_value_get_int (gimp_value_array_index (args, 2));
118   high_input = g_value_get_int (gimp_value_array_index (args, 3));
119   gamma = g_value_get_double (gimp_value_array_index (args, 4));
120   low_output = g_value_get_int (gimp_value_array_index (args, 5));
121   high_output = g_value_get_int (gimp_value_array_index (args, 6));
122 
123   if (success)
124     {
125       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
126                                      GIMP_PDB_ITEM_CONTENT, error) &&
127           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
128           channel != GIMP_HISTOGRAM_LUMINANCE &&
129           (gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
130           (! gimp_drawable_is_gray (drawable) ||
131            channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA))
132         {
133           GObject *config = g_object_new (GIMP_TYPE_LEVELS_CONFIG,
134                                           "channel", channel,
135                                           NULL);
136 
137           g_object_set (config,
138                         "low-input",    low_input   / 255.0,
139                         "high-input",   high_input  / 255.0,
140                         "clamp-input",  TRUE,
141                         "gamma",        gamma,
142                         "low-output",   low_output  / 255.0,
143                         "high-output",  high_output / 255.0,
144                         "clamp-input",  TRUE,
145                         NULL);
146 
147           gimp_drawable_apply_operation_by_name (drawable, progress,
148                                                  C_("undo-type", "Levels"),
149                                                  "gimp:levels",
150                                                  config);
151           g_object_unref (config);
152         }
153       else
154         success = TRUE;
155     }
156 
157   return gimp_procedure_get_return_values (procedure, success,
158                                            error ? *error : NULL);
159 }
160 
161 static GimpValueArray *
levels_auto_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)162 levels_auto_invoker (GimpProcedure         *procedure,
163                      Gimp                  *gimp,
164                      GimpContext           *context,
165                      GimpProgress          *progress,
166                      const GimpValueArray  *args,
167                      GError               **error)
168 {
169   gboolean success = TRUE;
170   GimpDrawable *drawable;
171 
172   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
173 
174   if (success)
175     {
176       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
177                                      GIMP_PDB_ITEM_CONTENT, error) &&
178           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
179         {
180           gimp_drawable_levels_stretch (drawable, progress);
181         }
182       else
183         success = FALSE;
184     }
185 
186   return gimp_procedure_get_return_values (procedure, success,
187                                            error ? *error : NULL);
188 }
189 
190 static GimpValueArray *
levels_stretch_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)191 levels_stretch_invoker (GimpProcedure         *procedure,
192                         Gimp                  *gimp,
193                         GimpContext           *context,
194                         GimpProgress          *progress,
195                         const GimpValueArray  *args,
196                         GError               **error)
197 {
198   gboolean success = TRUE;
199   GimpDrawable *drawable;
200 
201   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
202 
203   if (success)
204     {
205       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
206                                      GIMP_PDB_ITEM_CONTENT, error) &&
207           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
208         {
209           gimp_drawable_levels_stretch (drawable, progress);
210         }
211       else
212         success = FALSE;
213     }
214 
215   return gimp_procedure_get_return_values (procedure, success,
216                                            error ? *error : NULL);
217 }
218 
219 static GimpValueArray *
posterize_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)220 posterize_invoker (GimpProcedure         *procedure,
221                    Gimp                  *gimp,
222                    GimpContext           *context,
223                    GimpProgress          *progress,
224                    const GimpValueArray  *args,
225                    GError               **error)
226 {
227   gboolean success = TRUE;
228   GimpDrawable *drawable;
229   gint32 levels;
230 
231   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
232   levels = g_value_get_int (gimp_value_array_index (args, 1));
233 
234   if (success)
235     {
236       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
237                                      GIMP_PDB_ITEM_CONTENT, error) &&
238           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
239         {
240           GeglNode *node =
241             gegl_node_new_child (NULL,
242                                  "operation", "gimp:posterize",
243                                  "levels",    levels,
244                                  NULL);
245 
246           gimp_drawable_apply_operation (drawable, progress,
247                                          C_("undo-type", "Posterize"),
248                                          node);
249           g_object_unref (node);
250         }
251       else
252         success = FALSE;
253     }
254 
255   return gimp_procedure_get_return_values (procedure, success,
256                                            error ? *error : NULL);
257 }
258 
259 static GimpValueArray *
desaturate_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)260 desaturate_invoker (GimpProcedure         *procedure,
261                     Gimp                  *gimp,
262                     GimpContext           *context,
263                     GimpProgress          *progress,
264                     const GimpValueArray  *args,
265                     GError               **error)
266 {
267   gboolean success = TRUE;
268   GimpDrawable *drawable;
269 
270   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
271 
272   if (success)
273     {
274       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
275                                      GIMP_PDB_ITEM_CONTENT, error) &&
276           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
277           gimp_drawable_is_rgb (drawable))
278         {
279           GeglNode *node =
280             gegl_node_new_child (NULL,
281                                  "operation", "gimp:desaturate",
282                                  "mode",      GIMP_DESATURATE_LIGHTNESS,
283                                  NULL);
284 
285           gimp_drawable_apply_operation (drawable, progress,
286                                          C_("undo-type", "Desaturate"),
287                                          node);
288           g_object_unref (node);
289         }
290       else
291         success = FALSE;
292     }
293 
294   return gimp_procedure_get_return_values (procedure, success,
295                                            error ? *error : NULL);
296 }
297 
298 static GimpValueArray *
desaturate_full_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)299 desaturate_full_invoker (GimpProcedure         *procedure,
300                          Gimp                  *gimp,
301                          GimpContext           *context,
302                          GimpProgress          *progress,
303                          const GimpValueArray  *args,
304                          GError               **error)
305 {
306   gboolean success = TRUE;
307   GimpDrawable *drawable;
308   gint32 desaturate_mode;
309 
310   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
311   desaturate_mode = g_value_get_enum (gimp_value_array_index (args, 1));
312 
313   if (success)
314     {
315       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
316                                      GIMP_PDB_ITEM_CONTENT, error) &&
317           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
318           gimp_drawable_is_rgb (drawable))
319         {
320           GeglNode *node =
321             gegl_node_new_child (NULL,
322                                  "operation", "gimp:desaturate",
323                                  "mode",      desaturate_mode,
324                                  NULL);
325 
326           gimp_drawable_apply_operation (drawable, progress,
327                                          C_("undo-type", "Desaturate"),
328                                          node);
329           g_object_unref (node);
330         }
331       else
332         success = FALSE;
333     }
334 
335   return gimp_procedure_get_return_values (procedure, success,
336                                            error ? *error : NULL);
337 }
338 
339 static GimpValueArray *
equalize_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)340 equalize_invoker (GimpProcedure         *procedure,
341                   Gimp                  *gimp,
342                   GimpContext           *context,
343                   GimpProgress          *progress,
344                   const GimpValueArray  *args,
345                   GError               **error)
346 {
347   gboolean success = TRUE;
348   GimpDrawable *drawable;
349   gboolean mask_only;
350 
351   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
352   mask_only = g_value_get_boolean (gimp_value_array_index (args, 1));
353 
354   if (success)
355     {
356       if (! gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
357                                        GIMP_PDB_ITEM_CONTENT, error) ||
358           ! gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
359         success = FALSE;
360 
361       if (success)
362         gimp_drawable_equalize (drawable, mask_only);
363     }
364 
365   return gimp_procedure_get_return_values (procedure, success,
366                                            error ? *error : NULL);
367 }
368 
369 static GimpValueArray *
invert_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)370 invert_invoker (GimpProcedure         *procedure,
371                 Gimp                  *gimp,
372                 GimpContext           *context,
373                 GimpProgress          *progress,
374                 const GimpValueArray  *args,
375                 GError               **error)
376 {
377   gboolean success = TRUE;
378   GimpDrawable *drawable;
379 
380   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
381 
382   if (success)
383     {
384       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
385                                      GIMP_PDB_ITEM_CONTENT, error) &&
386           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
387         {
388           gimp_drawable_apply_operation_by_name (drawable, progress,
389                                                  _("Invert"),
390                                                  "gegl:invert-gamma",
391                                                  NULL);
392         }
393       else
394         success = FALSE;
395     }
396 
397   return gimp_procedure_get_return_values (procedure, success,
398                                            error ? *error : NULL);
399 }
400 
401 static GimpValueArray *
curves_spline_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)402 curves_spline_invoker (GimpProcedure         *procedure,
403                        Gimp                  *gimp,
404                        GimpContext           *context,
405                        GimpProgress          *progress,
406                        const GimpValueArray  *args,
407                        GError               **error)
408 {
409   gboolean success = TRUE;
410   GimpDrawable *drawable;
411   gint32 channel;
412   gint32 num_points;
413   const guint8 *control_pts;
414 
415   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
416   channel = g_value_get_enum (gimp_value_array_index (args, 1));
417   num_points = g_value_get_int (gimp_value_array_index (args, 2));
418   control_pts = gimp_value_get_int8array (gimp_value_array_index (args, 3));
419 
420   if (success)
421     {
422       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
423                                      GIMP_PDB_ITEM_CONTENT, error) &&
424           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
425           ! (num_points & 1) &&
426           (gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
427           (! gimp_drawable_is_gray (drawable) ||
428            channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA)  &&
429            channel != GIMP_HISTOGRAM_LUMINANCE)
430         {
431           GObject *config = gimp_curves_config_new_spline_cruft (channel,
432                                                                  control_pts,
433                                                                  num_points / 2);
434 
435           gimp_drawable_apply_operation_by_name (drawable, progress,
436                                                  C_("undo-type", "Curves"),
437                                                  "gimp:curves",
438                                                  config);
439           g_object_unref (config);
440         }
441       else
442         success = FALSE;
443     }
444 
445   return gimp_procedure_get_return_values (procedure, success,
446                                            error ? *error : NULL);
447 }
448 
449 static GimpValueArray *
curves_explicit_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)450 curves_explicit_invoker (GimpProcedure         *procedure,
451                          Gimp                  *gimp,
452                          GimpContext           *context,
453                          GimpProgress          *progress,
454                          const GimpValueArray  *args,
455                          GError               **error)
456 {
457   gboolean success = TRUE;
458   GimpDrawable *drawable;
459   gint32 channel;
460   gint32 num_bytes;
461   const guint8 *curve;
462 
463   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
464   channel = g_value_get_enum (gimp_value_array_index (args, 1));
465   num_bytes = g_value_get_int (gimp_value_array_index (args, 2));
466   curve = gimp_value_get_int8array (gimp_value_array_index (args, 3));
467 
468   if (success)
469     {
470       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
471                                      GIMP_PDB_ITEM_CONTENT, error) &&
472           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
473           (num_bytes == 256) &&
474           (gimp_drawable_has_alpha (drawable) || channel != GIMP_HISTOGRAM_ALPHA) &&
475           (! gimp_drawable_is_gray (drawable) ||
476            channel == GIMP_HISTOGRAM_VALUE || channel == GIMP_HISTOGRAM_ALPHA) &&
477            channel != GIMP_HISTOGRAM_LUMINANCE)
478         {
479           GObject *config = gimp_curves_config_new_explicit_cruft (channel,
480                                                                    curve,
481                                                                    num_bytes);
482 
483           gimp_drawable_apply_operation_by_name (drawable, progress,
484                                                  C_("undo-type", "Curves"),
485                                                  "gimp:curves",
486                                                  config);
487           g_object_unref (config);
488         }
489       else
490         success = FALSE;
491     }
492 
493   return gimp_procedure_get_return_values (procedure, success,
494                                            error ? *error : NULL);
495 }
496 
497 static GimpValueArray *
color_balance_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)498 color_balance_invoker (GimpProcedure         *procedure,
499                        Gimp                  *gimp,
500                        GimpContext           *context,
501                        GimpProgress          *progress,
502                        const GimpValueArray  *args,
503                        GError               **error)
504 {
505   gboolean success = TRUE;
506   GimpDrawable *drawable;
507   gint32 transfer_mode;
508   gboolean preserve_lum;
509   gdouble cyan_red;
510   gdouble magenta_green;
511   gdouble yellow_blue;
512 
513   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
514   transfer_mode = g_value_get_enum (gimp_value_array_index (args, 1));
515   preserve_lum = g_value_get_boolean (gimp_value_array_index (args, 2));
516   cyan_red = g_value_get_double (gimp_value_array_index (args, 3));
517   magenta_green = g_value_get_double (gimp_value_array_index (args, 4));
518   yellow_blue = g_value_get_double (gimp_value_array_index (args, 5));
519 
520   if (success)
521     {
522       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
523                                      GIMP_PDB_ITEM_CONTENT, error)  &&
524           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
525         {
526           GObject *config = g_object_new (GIMP_TYPE_COLOR_BALANCE_CONFIG,
527                                           "range",               transfer_mode,
528                                           "preserve-luminosity", preserve_lum,
529                                           NULL);
530 
531           g_object_set (config,
532                         "cyan-red",      cyan_red      / 100.0,
533                         "magenta-green", magenta_green / 100.0,
534                         "yellow-blue",   yellow_blue   / 100.0,
535                         NULL);
536 
537           gimp_drawable_apply_operation_by_name (drawable, progress,
538                                                  C_("undo-type", "Color Balance"),
539                                                  "gimp:color-balance",
540                                                  config);
541           g_object_unref (config);
542         }
543       else
544         success = FALSE;
545     }
546 
547   return gimp_procedure_get_return_values (procedure, success,
548                                            error ? *error : NULL);
549 }
550 
551 static GimpValueArray *
colorize_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)552 colorize_invoker (GimpProcedure         *procedure,
553                   Gimp                  *gimp,
554                   GimpContext           *context,
555                   GimpProgress          *progress,
556                   const GimpValueArray  *args,
557                   GError               **error)
558 {
559   gboolean success = TRUE;
560   GimpDrawable *drawable;
561   gdouble hue;
562   gdouble saturation;
563   gdouble lightness;
564 
565   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
566   hue = g_value_get_double (gimp_value_array_index (args, 1));
567   saturation = g_value_get_double (gimp_value_array_index (args, 2));
568   lightness = g_value_get_double (gimp_value_array_index (args, 3));
569 
570   if (success)
571     {
572       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
573                                      GIMP_PDB_ITEM_CONTENT, error) &&
574           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
575           ! gimp_drawable_is_gray (drawable))
576         {
577           GeglNode *node =
578             gegl_node_new_child (NULL,
579                                  "operation", "gimp:colorize",
580                                  "hue",        hue        / 360.0,
581                                  "saturation", saturation / 100.0,
582                                  "lightness",  lightness  / 100.0,
583                                  NULL);
584 
585           gimp_drawable_apply_operation (drawable, progress,
586                                          C_("undo-type", "Colorize"),
587                                          node);
588           g_object_unref (node);
589         }
590       else
591         success = FALSE;
592     }
593 
594   return gimp_procedure_get_return_values (procedure, success,
595                                            error ? *error : NULL);
596 }
597 
598 static GimpValueArray *
histogram_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)599 histogram_invoker (GimpProcedure         *procedure,
600                    Gimp                  *gimp,
601                    GimpContext           *context,
602                    GimpProgress          *progress,
603                    const GimpValueArray  *args,
604                    GError               **error)
605 {
606   gboolean success = TRUE;
607   GimpValueArray *return_vals;
608   GimpDrawable *drawable;
609   gint32 channel;
610   gint32 start_range;
611   gint32 end_range;
612   gdouble mean = 0.0;
613   gdouble std_dev = 0.0;
614   gdouble median = 0.0;
615   gdouble pixels = 0.0;
616   gdouble count = 0.0;
617   gdouble percentile = 0.0;
618 
619   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
620   channel = g_value_get_enum (gimp_value_array_index (args, 1));
621   start_range = g_value_get_int (gimp_value_array_index (args, 2));
622   end_range = g_value_get_int (gimp_value_array_index (args, 3));
623 
624   if (success)
625     {
626       if (! gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, 0, error) ||
627           (! gimp_drawable_has_alpha (drawable) &&
628            channel == GIMP_HISTOGRAM_ALPHA) ||
629           (gimp_drawable_is_gray (drawable) &&
630            channel != GIMP_HISTOGRAM_VALUE && channel != GIMP_HISTOGRAM_ALPHA))
631         success = FALSE;
632 
633       if (success)
634         {
635           GimpHistogram *histogram;
636           gint           start = start_range;
637           gint           end   = end_range;
638           gboolean       precision_enabled;
639           gboolean       linear;
640           gint           n_bins;
641 
642           precision_enabled =
643             gimp->plug_in_manager->current_plug_in &&
644             gimp_plug_in_precision_enabled (gimp->plug_in_manager->current_plug_in);
645 
646           if (precision_enabled)
647             linear = gimp_drawable_get_linear (drawable);
648           else
649             linear = FALSE;
650 
651           histogram = gimp_histogram_new (linear);
652           gimp_drawable_calculate_histogram (drawable, histogram, FALSE);
653 
654           n_bins = gimp_histogram_n_bins (histogram);
655 
656           if (n_bins != 256)
657             {
658               start = ROUND ((gdouble) start * (n_bins - 1) / 255);
659               end   = ROUND ((gdouble) end   * (n_bins - 1) / 255);
660             }
661 
662           mean       = gimp_histogram_get_mean (histogram, channel,
663                                                  start, end);
664           std_dev    = gimp_histogram_get_std_dev (histogram, channel,
665                                                    start, end);
666           median     = gimp_histogram_get_median (histogram, channel,
667                                                   start, end);
668           pixels     = gimp_histogram_get_count (histogram, channel, 0, n_bins - 1);
669           count      = gimp_histogram_get_count (histogram, channel,
670                                                  start, end);
671           percentile = count / pixels;
672 
673           g_object_unref (histogram);
674 
675           if (n_bins == 256 || ! precision_enabled)
676             {
677               mean    *= 255;
678               std_dev *= 255;
679               median  *= 255;
680             }
681         }
682     }
683 
684   return_vals = gimp_procedure_get_return_values (procedure, success,
685                                                   error ? *error : NULL);
686 
687   if (success)
688     {
689       g_value_set_double (gimp_value_array_index (return_vals, 1), mean);
690       g_value_set_double (gimp_value_array_index (return_vals, 2), std_dev);
691       g_value_set_double (gimp_value_array_index (return_vals, 3), median);
692       g_value_set_double (gimp_value_array_index (return_vals, 4), pixels);
693       g_value_set_double (gimp_value_array_index (return_vals, 5), count);
694       g_value_set_double (gimp_value_array_index (return_vals, 6), percentile);
695     }
696 
697   return return_vals;
698 }
699 
700 static GimpValueArray *
hue_saturation_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)701 hue_saturation_invoker (GimpProcedure         *procedure,
702                         Gimp                  *gimp,
703                         GimpContext           *context,
704                         GimpProgress          *progress,
705                         const GimpValueArray  *args,
706                         GError               **error)
707 {
708   gboolean success = TRUE;
709   GimpDrawable *drawable;
710   gint32 hue_range;
711   gdouble hue_offset;
712   gdouble lightness;
713   gdouble saturation;
714 
715   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
716   hue_range = g_value_get_enum (gimp_value_array_index (args, 1));
717   hue_offset = g_value_get_double (gimp_value_array_index (args, 2));
718   lightness = g_value_get_double (gimp_value_array_index (args, 3));
719   saturation = g_value_get_double (gimp_value_array_index (args, 4));
720 
721   if (success)
722     {
723       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
724                                      GIMP_PDB_ITEM_CONTENT, error) &&
725           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
726         {
727           GObject *config = g_object_new (GIMP_TYPE_HUE_SATURATION_CONFIG,
728                                           "range", hue_range,
729                                           NULL);
730 
731            g_object_set (config,
732                          "hue",        hue_offset / 180.0,
733                          "saturation", saturation / 100.0,
734                          "lightness",  lightness  / 100.0,
735                          NULL);
736 
737           gimp_drawable_apply_operation_by_name (drawable, progress,
738                                                  _("Hue-Saturation"),
739                                                  "gimp:hue-saturation",
740                                                  config);
741           g_object_unref (config);
742         }
743       else
744         success = FALSE;
745     }
746 
747   return gimp_procedure_get_return_values (procedure, success,
748                                            error ? *error : NULL);
749 }
750 
751 static GimpValueArray *
threshold_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)752 threshold_invoker (GimpProcedure         *procedure,
753                    Gimp                  *gimp,
754                    GimpContext           *context,
755                    GimpProgress          *progress,
756                    const GimpValueArray  *args,
757                    GError               **error)
758 {
759   gboolean success = TRUE;
760   GimpDrawable *drawable;
761   gint32 low_threshold;
762   gint32 high_threshold;
763 
764   drawable = gimp_value_get_drawable (gimp_value_array_index (args, 0), gimp);
765   low_threshold = g_value_get_int (gimp_value_array_index (args, 1));
766   high_threshold = g_value_get_int (gimp_value_array_index (args, 2));
767 
768   if (success)
769     {
770       if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
771                                      GIMP_PDB_ITEM_CONTENT, error) &&
772           gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
773         {
774           GeglNode *node =
775             gegl_node_new_child (NULL,
776                                  "operation", "gimp:threshold",
777                                  "low",       low_threshold  / 255.0,
778                                  "high",      high_threshold / 255.0,
779                                  NULL);
780 
781           gimp_drawable_apply_operation (drawable, progress,
782                                          C_("undo-type", "Threshold"),
783                                          node);
784           g_object_unref (node);
785         }
786       else
787         success = FALSE;
788     }
789 
790   return gimp_procedure_get_return_values (procedure, success,
791                                            error ? *error : NULL);
792 }
793 
794 void
register_color_procs(GimpPDB * pdb)795 register_color_procs (GimpPDB *pdb)
796 {
797   GimpProcedure *procedure;
798 
799   /*
800    * gimp-brightness-contrast
801    */
802   procedure = gimp_procedure_new (brightness_contrast_invoker);
803   gimp_object_set_static_name (GIMP_OBJECT (procedure),
804                                "gimp-brightness-contrast");
805   gimp_procedure_set_static_strings (procedure,
806                                      "gimp-brightness-contrast",
807                                      "Deprecated: Use 'gimp-drawable-brightness-contrast' instead.",
808                                      "Deprecated: Use 'gimp-drawable-brightness-contrast' instead.",
809                                      "",
810                                      "",
811                                      "",
812                                      "gimp-drawable-brightness-contrast");
813   gimp_procedure_add_argument (procedure,
814                                gimp_param_spec_drawable_id ("drawable",
815                                                             "drawable",
816                                                             "The drawable",
817                                                             pdb->gimp, FALSE,
818                                                             GIMP_PARAM_READWRITE));
819   gimp_procedure_add_argument (procedure,
820                                gimp_param_spec_int32 ("brightness",
821                                                       "brightness",
822                                                       "Brightness adjustment",
823                                                       -127, 127, -127,
824                                                       GIMP_PARAM_READWRITE));
825   gimp_procedure_add_argument (procedure,
826                                gimp_param_spec_int32 ("contrast",
827                                                       "contrast",
828                                                       "Contrast adjustment",
829                                                       -127, 127, -127,
830                                                       GIMP_PARAM_READWRITE));
831   gimp_pdb_register_procedure (pdb, procedure);
832   g_object_unref (procedure);
833 
834   /*
835    * gimp-levels
836    */
837   procedure = gimp_procedure_new (levels_invoker);
838   gimp_object_set_static_name (GIMP_OBJECT (procedure),
839                                "gimp-levels");
840   gimp_procedure_set_static_strings (procedure,
841                                      "gimp-levels",
842                                      "Deprecated: Use 'gimp-drawable-levels' instead.",
843                                      "Deprecated: Use 'gimp-drawable-levels' instead.",
844                                      "",
845                                      "",
846                                      "",
847                                      "gimp-drawable-levels");
848   gimp_procedure_add_argument (procedure,
849                                gimp_param_spec_drawable_id ("drawable",
850                                                             "drawable",
851                                                             "The drawable",
852                                                             pdb->gimp, FALSE,
853                                                             GIMP_PARAM_READWRITE));
854   gimp_procedure_add_argument (procedure,
855                                g_param_spec_enum ("channel",
856                                                   "channel",
857                                                   "The channel to modify",
858                                                   GIMP_TYPE_HISTOGRAM_CHANNEL,
859                                                   GIMP_HISTOGRAM_VALUE,
860                                                   GIMP_PARAM_READWRITE));
861   gimp_procedure_add_argument (procedure,
862                                gimp_param_spec_int32 ("low-input",
863                                                       "low input",
864                                                       "Intensity of lowest input",
865                                                       0, 255, 0,
866                                                       GIMP_PARAM_READWRITE));
867   gimp_procedure_add_argument (procedure,
868                                gimp_param_spec_int32 ("high-input",
869                                                       "high input",
870                                                       "Intensity of highest input",
871                                                       0, 255, 0,
872                                                       GIMP_PARAM_READWRITE));
873   gimp_procedure_add_argument (procedure,
874                                g_param_spec_double ("gamma",
875                                                     "gamma",
876                                                     "Gamma adjustment factor",
877                                                     0.1, 10, 0.1,
878                                                     GIMP_PARAM_READWRITE));
879   gimp_procedure_add_argument (procedure,
880                                gimp_param_spec_int32 ("low-output",
881                                                       "low output",
882                                                       "Intensity of lowest output",
883                                                       0, 255, 0,
884                                                       GIMP_PARAM_READWRITE));
885   gimp_procedure_add_argument (procedure,
886                                gimp_param_spec_int32 ("high-output",
887                                                       "high output",
888                                                       "Intensity of highest output",
889                                                       0, 255, 0,
890                                                       GIMP_PARAM_READWRITE));
891   gimp_pdb_register_procedure (pdb, procedure);
892   g_object_unref (procedure);
893 
894   /*
895    * gimp-levels-auto
896    */
897   procedure = gimp_procedure_new (levels_auto_invoker);
898   gimp_object_set_static_name (GIMP_OBJECT (procedure),
899                                "gimp-levels-auto");
900   gimp_procedure_set_static_strings (procedure,
901                                      "gimp-levels-auto",
902                                      "Deprecated: Use 'gimp-drawable-levels-stretch' instead.",
903                                      "Deprecated: Use 'gimp-drawable-levels-stretch' instead.",
904                                      "",
905                                      "",
906                                      "",
907                                      "gimp-drawable-levels-stretch");
908   gimp_procedure_add_argument (procedure,
909                                gimp_param_spec_drawable_id ("drawable",
910                                                             "drawable",
911                                                             "The drawable",
912                                                             pdb->gimp, FALSE,
913                                                             GIMP_PARAM_READWRITE));
914   gimp_pdb_register_procedure (pdb, procedure);
915   g_object_unref (procedure);
916 
917   /*
918    * gimp-levels-stretch
919    */
920   procedure = gimp_procedure_new (levels_stretch_invoker);
921   gimp_object_set_static_name (GIMP_OBJECT (procedure),
922                                "gimp-levels-stretch");
923   gimp_procedure_set_static_strings (procedure,
924                                      "gimp-levels-stretch",
925                                      "Deprecated: Use 'gimp-drawable-levels-stretch' instead.",
926                                      "Deprecated: Use 'gimp-drawable-levels-stretch' instead.",
927                                      "",
928                                      "",
929                                      "",
930                                      "gimp-drawable-levels-stretch");
931   gimp_procedure_add_argument (procedure,
932                                gimp_param_spec_drawable_id ("drawable",
933                                                             "drawable",
934                                                             "The drawable",
935                                                             pdb->gimp, FALSE,
936                                                             GIMP_PARAM_READWRITE));
937   gimp_pdb_register_procedure (pdb, procedure);
938   g_object_unref (procedure);
939 
940   /*
941    * gimp-posterize
942    */
943   procedure = gimp_procedure_new (posterize_invoker);
944   gimp_object_set_static_name (GIMP_OBJECT (procedure),
945                                "gimp-posterize");
946   gimp_procedure_set_static_strings (procedure,
947                                      "gimp-posterize",
948                                      "Deprecated: Use 'gimp-drawable-posterize' instead.",
949                                      "Deprecated: Use 'gimp-drawable-posterize' instead.",
950                                      "",
951                                      "",
952                                      "",
953                                      "gimp-drawable-posterize");
954   gimp_procedure_add_argument (procedure,
955                                gimp_param_spec_drawable_id ("drawable",
956                                                             "drawable",
957                                                             "The drawable",
958                                                             pdb->gimp, FALSE,
959                                                             GIMP_PARAM_READWRITE));
960   gimp_procedure_add_argument (procedure,
961                                gimp_param_spec_int32 ("levels",
962                                                       "levels",
963                                                       "Levels of posterization",
964                                                       2, 255, 2,
965                                                       GIMP_PARAM_READWRITE));
966   gimp_pdb_register_procedure (pdb, procedure);
967   g_object_unref (procedure);
968 
969   /*
970    * gimp-desaturate
971    */
972   procedure = gimp_procedure_new (desaturate_invoker);
973   gimp_object_set_static_name (GIMP_OBJECT (procedure),
974                                "gimp-desaturate");
975   gimp_procedure_set_static_strings (procedure,
976                                      "gimp-desaturate",
977                                      "Deprecated: Use 'gimp-drawable-desaturate' instead.",
978                                      "Deprecated: Use 'gimp-drawable-desaturate' instead.",
979                                      "",
980                                      "",
981                                      "",
982                                      "gimp-drawable-desaturate");
983   gimp_procedure_add_argument (procedure,
984                                gimp_param_spec_drawable_id ("drawable",
985                                                             "drawable",
986                                                             "The drawable",
987                                                             pdb->gimp, FALSE,
988                                                             GIMP_PARAM_READWRITE));
989   gimp_pdb_register_procedure (pdb, procedure);
990   g_object_unref (procedure);
991 
992   /*
993    * gimp-desaturate-full
994    */
995   procedure = gimp_procedure_new (desaturate_full_invoker);
996   gimp_object_set_static_name (GIMP_OBJECT (procedure),
997                                "gimp-desaturate-full");
998   gimp_procedure_set_static_strings (procedure,
999                                      "gimp-desaturate-full",
1000                                      "Deprecated: Use 'gimp-drawable-desaturate' instead.",
1001                                      "Deprecated: Use 'gimp-drawable-desaturate' instead.",
1002                                      "",
1003                                      "",
1004                                      "",
1005                                      "gimp-drawable-desaturate");
1006   gimp_procedure_add_argument (procedure,
1007                                gimp_param_spec_drawable_id ("drawable",
1008                                                             "drawable",
1009                                                             "The drawable",
1010                                                             pdb->gimp, FALSE,
1011                                                             GIMP_PARAM_READWRITE));
1012   gimp_procedure_add_argument (procedure,
1013                                g_param_spec_enum ("desaturate-mode",
1014                                                   "desaturate mode",
1015                                                   "The formula to use to desaturate",
1016                                                   GIMP_TYPE_DESATURATE_MODE,
1017                                                   GIMP_DESATURATE_LIGHTNESS,
1018                                                   GIMP_PARAM_READWRITE));
1019   gimp_pdb_register_procedure (pdb, procedure);
1020   g_object_unref (procedure);
1021 
1022   /*
1023    * gimp-equalize
1024    */
1025   procedure = gimp_procedure_new (equalize_invoker);
1026   gimp_object_set_static_name (GIMP_OBJECT (procedure),
1027                                "gimp-equalize");
1028   gimp_procedure_set_static_strings (procedure,
1029                                      "gimp-equalize",
1030                                      "Deprecated: Use 'gimp-drawable-equalize' instead.",
1031                                      "Deprecated: Use 'gimp-drawable-equalize' instead.",
1032                                      "",
1033                                      "",
1034                                      "",
1035                                      "gimp-drawable-equalize");
1036   gimp_procedure_add_argument (procedure,
1037                                gimp_param_spec_drawable_id ("drawable",
1038                                                             "drawable",
1039                                                             "The drawable",
1040                                                             pdb->gimp, FALSE,
1041                                                             GIMP_PARAM_READWRITE));
1042   gimp_procedure_add_argument (procedure,
1043                                g_param_spec_boolean ("mask-only",
1044                                                      "mask only",
1045                                                      "Equalization option",
1046                                                      FALSE,
1047                                                      GIMP_PARAM_READWRITE));
1048   gimp_pdb_register_procedure (pdb, procedure);
1049   g_object_unref (procedure);
1050 
1051   /*
1052    * gimp-invert
1053    */
1054   procedure = gimp_procedure_new (invert_invoker);
1055   gimp_object_set_static_name (GIMP_OBJECT (procedure),
1056                                "gimp-invert");
1057   gimp_procedure_set_static_strings (procedure,
1058                                      "gimp-invert",
1059                                      "Deprecated: Use 'gimp-drawable-invert' instead.",
1060                                      "Deprecated: Use 'gimp-drawable-invert' instead.",
1061                                      "",
1062                                      "",
1063                                      "",
1064                                      "gimp-drawable-invert");
1065   gimp_procedure_add_argument (procedure,
1066                                gimp_param_spec_drawable_id ("drawable",
1067                                                             "drawable",
1068                                                             "The drawable",
1069                                                             pdb->gimp, FALSE,
1070                                                             GIMP_PARAM_READWRITE));
1071   gimp_pdb_register_procedure (pdb, procedure);
1072   g_object_unref (procedure);
1073 
1074   /*
1075    * gimp-curves-spline
1076    */
1077   procedure = gimp_procedure_new (curves_spline_invoker);
1078   gimp_object_set_static_name (GIMP_OBJECT (procedure),
1079                                "gimp-curves-spline");
1080   gimp_procedure_set_static_strings (procedure,
1081                                      "gimp-curves-spline",
1082                                      "Deprecated: Use 'gimp-drawable-curves-spline' instead.",
1083                                      "Deprecated: Use 'gimp-drawable-curves-spline' instead.",
1084                                      "",
1085                                      "",
1086                                      "",
1087                                      "gimp-drawable-curves-spline");
1088   gimp_procedure_add_argument (procedure,
1089                                gimp_param_spec_drawable_id ("drawable",
1090                                                             "drawable",
1091                                                             "The drawable",
1092                                                             pdb->gimp, FALSE,
1093                                                             GIMP_PARAM_READWRITE));
1094   gimp_procedure_add_argument (procedure,
1095                                g_param_spec_enum ("channel",
1096                                                   "channel",
1097                                                   "The channel to modify",
1098                                                   GIMP_TYPE_HISTOGRAM_CHANNEL,
1099                                                   GIMP_HISTOGRAM_VALUE,
1100                                                   GIMP_PARAM_READWRITE));
1101   gimp_procedure_add_argument (procedure,
1102                                gimp_param_spec_int32 ("num-points",
1103                                                       "num points",
1104                                                       "The number of values in the control point array",
1105                                                       4, 34, 4,
1106                                                       GIMP_PARAM_READWRITE));
1107   gimp_procedure_add_argument (procedure,
1108                                gimp_param_spec_int8_array ("control-pts",
1109                                                            "control pts",
1110                                                            "The spline control points: { cp1.x, cp1.y, cp2.x, cp2.y, ... }",
1111                                                            GIMP_PARAM_READWRITE));
1112   gimp_pdb_register_procedure (pdb, procedure);
1113   g_object_unref (procedure);
1114 
1115   /*
1116    * gimp-curves-explicit
1117    */
1118   procedure = gimp_procedure_new (curves_explicit_invoker);
1119   gimp_object_set_static_name (GIMP_OBJECT (procedure),
1120                                "gimp-curves-explicit");
1121   gimp_procedure_set_static_strings (procedure,
1122                                      "gimp-curves-explicit",
1123                                      "Deprecated: Use 'gimp-drawable-curves-explicit' instead.",
1124                                      "Deprecated: Use 'gimp-drawable-curves-explicit' instead.",
1125                                      "",
1126                                      "",
1127                                      "",
1128                                      "gimp-drawable-curves-explicit");
1129   gimp_procedure_add_argument (procedure,
1130                                gimp_param_spec_drawable_id ("drawable",
1131                                                             "drawable",
1132                                                             "The drawable",
1133                                                             pdb->gimp, FALSE,
1134                                                             GIMP_PARAM_READWRITE));
1135   gimp_procedure_add_argument (procedure,
1136                                g_param_spec_enum ("channel",
1137                                                   "channel",
1138                                                   "The channel to modify",
1139                                                   GIMP_TYPE_HISTOGRAM_CHANNEL,
1140                                                   GIMP_HISTOGRAM_VALUE,
1141                                                   GIMP_PARAM_READWRITE));
1142   gimp_procedure_add_argument (procedure,
1143                                gimp_param_spec_int32 ("num-bytes",
1144                                                       "num bytes",
1145                                                       "The number of bytes in the new curve (always 256)",
1146                                                       0, G_MAXINT32, 0,
1147                                                       GIMP_PARAM_READWRITE));
1148   gimp_procedure_add_argument (procedure,
1149                                gimp_param_spec_int8_array ("curve",
1150                                                            "curve",
1151                                                            "The explicit curve",
1152                                                            GIMP_PARAM_READWRITE));
1153   gimp_pdb_register_procedure (pdb, procedure);
1154   g_object_unref (procedure);
1155 
1156   /*
1157    * gimp-color-balance
1158    */
1159   procedure = gimp_procedure_new (color_balance_invoker);
1160   gimp_object_set_static_name (GIMP_OBJECT (procedure),
1161                                "gimp-color-balance");
1162   gimp_procedure_set_static_strings (procedure,
1163                                      "gimp-color-balance",
1164                                      "Modify the color balance of the specified drawable.",
1165                                      "Modify the color balance of the specified drawable. There are three axis which can be modified: cyan-red, magenta-green, and yellow-blue. Negative values increase the amount of the former, positive values increase the amount of the latter. Color balance can be controlled with the 'transfer_mode' setting, which allows shadows, mid-tones, and highlights in an image to be affected differently. The 'preserve-lum' parameter, if TRUE, ensures that the luminosity of each pixel remains fixed.\n"
1166                                      "\n"
1167                                      "Deprecated: Use 'gimp-drawable-color-color-balance' instead.",
1168                                      "Spencer Kimball & Peter Mattis",
1169                                      "Spencer Kimball & Peter Mattis",
1170                                      "1997",
1171                                      "gimp-drawable-color-color-balance");
1172   gimp_procedure_add_argument (procedure,
1173                                gimp_param_spec_drawable_id ("drawable",
1174                                                             "drawable",
1175                                                             "The drawable",
1176                                                             pdb->gimp, FALSE,
1177                                                             GIMP_PARAM_READWRITE));
1178   gimp_procedure_add_argument (procedure,
1179                                g_param_spec_enum ("transfer-mode",
1180                                                   "transfer mode",
1181                                                   "Transfer mode",
1182                                                   GIMP_TYPE_TRANSFER_MODE,
1183                                                   GIMP_TRANSFER_SHADOWS,
1184                                                   GIMP_PARAM_READWRITE));
1185   gimp_procedure_add_argument (procedure,
1186                                g_param_spec_boolean ("preserve-lum",
1187                                                      "preserve lum",
1188                                                      "Preserve luminosity values at each pixel",
1189                                                      FALSE,
1190                                                      GIMP_PARAM_READWRITE));
1191   gimp_procedure_add_argument (procedure,
1192                                g_param_spec_double ("cyan-red",
1193                                                     "cyan red",
1194                                                     "Cyan-Red color balance",
1195                                                     -100, 100, -100,
1196                                                     GIMP_PARAM_READWRITE));
1197   gimp_procedure_add_argument (procedure,
1198                                g_param_spec_double ("magenta-green",
1199                                                     "magenta green",
1200                                                     "Magenta-Green color balance",
1201                                                     -100, 100, -100,
1202                                                     GIMP_PARAM_READWRITE));
1203   gimp_procedure_add_argument (procedure,
1204                                g_param_spec_double ("yellow-blue",
1205                                                     "yellow blue",
1206                                                     "Yellow-Blue color balance",
1207                                                     -100, 100, -100,
1208                                                     GIMP_PARAM_READWRITE));
1209   gimp_pdb_register_procedure (pdb, procedure);
1210   g_object_unref (procedure);
1211 
1212   /*
1213    * gimp-colorize
1214    */
1215   procedure = gimp_procedure_new (colorize_invoker);
1216   gimp_object_set_static_name (GIMP_OBJECT (procedure),
1217                                "gimp-colorize");
1218   gimp_procedure_set_static_strings (procedure,
1219                                      "gimp-colorize",
1220                                      "Deprecated: Use 'gimp-drawable-colorize-hsl' instead.",
1221                                      "Deprecated: Use 'gimp-drawable-colorize-hsl' instead.",
1222                                      "",
1223                                      "",
1224                                      "",
1225                                      "gimp-drawable-colorize-hsl");
1226   gimp_procedure_add_argument (procedure,
1227                                gimp_param_spec_drawable_id ("drawable",
1228                                                             "drawable",
1229                                                             "The drawable",
1230                                                             pdb->gimp, FALSE,
1231                                                             GIMP_PARAM_READWRITE));
1232   gimp_procedure_add_argument (procedure,
1233                                g_param_spec_double ("hue",
1234                                                     "hue",
1235                                                     "Hue in degrees",
1236                                                     0, 360, 0,
1237                                                     GIMP_PARAM_READWRITE));
1238   gimp_procedure_add_argument (procedure,
1239                                g_param_spec_double ("saturation",
1240                                                     "saturation",
1241                                                     "Saturation in percent",
1242                                                     0, 100, 0,
1243                                                     GIMP_PARAM_READWRITE));
1244   gimp_procedure_add_argument (procedure,
1245                                g_param_spec_double ("lightness",
1246                                                     "lightness",
1247                                                     "Lightness in percent",
1248                                                     -100, 100, -100,
1249                                                     GIMP_PARAM_READWRITE));
1250   gimp_pdb_register_procedure (pdb, procedure);
1251   g_object_unref (procedure);
1252 
1253   /*
1254    * gimp-histogram
1255    */
1256   procedure = gimp_procedure_new (histogram_invoker);
1257   gimp_object_set_static_name (GIMP_OBJECT (procedure),
1258                                "gimp-histogram");
1259   gimp_procedure_set_static_strings (procedure,
1260                                      "gimp-histogram",
1261                                      "Deprecated: Use 'gimp-drawable-histogram' instead.",
1262                                      "Deprecated: Use 'gimp-drawable-histogram' instead.",
1263                                      "",
1264                                      "",
1265                                      "",
1266                                      "gimp-drawable-histogram");
1267   gimp_procedure_add_argument (procedure,
1268                                gimp_param_spec_drawable_id ("drawable",
1269                                                             "drawable",
1270                                                             "The drawable",
1271                                                             pdb->gimp, FALSE,
1272                                                             GIMP_PARAM_READWRITE));
1273   gimp_procedure_add_argument (procedure,
1274                                g_param_spec_enum ("channel",
1275                                                   "channel",
1276                                                   "The channel to modify",
1277                                                   GIMP_TYPE_HISTOGRAM_CHANNEL,
1278                                                   GIMP_HISTOGRAM_VALUE,
1279                                                   GIMP_PARAM_READWRITE));
1280   gimp_procedure_add_argument (procedure,
1281                                gimp_param_spec_int32 ("start-range",
1282                                                       "start range",
1283                                                       "Start of the intensity measurement range",
1284                                                       0, 255, 0,
1285                                                       GIMP_PARAM_READWRITE));
1286   gimp_procedure_add_argument (procedure,
1287                                gimp_param_spec_int32 ("end-range",
1288                                                       "end range",
1289                                                       "End of the intensity measurement range",
1290                                                       0, 255, 0,
1291                                                       GIMP_PARAM_READWRITE));
1292   gimp_procedure_add_return_value (procedure,
1293                                    g_param_spec_double ("mean",
1294                                                         "mean",
1295                                                         "Mean intensity value",
1296                                                         -G_MAXDOUBLE, G_MAXDOUBLE, 0,
1297                                                         GIMP_PARAM_READWRITE));
1298   gimp_procedure_add_return_value (procedure,
1299                                    g_param_spec_double ("std-dev",
1300                                                         "std dev",
1301                                                         "Standard deviation of intensity values",
1302                                                         -G_MAXDOUBLE, G_MAXDOUBLE, 0,
1303                                                         GIMP_PARAM_READWRITE));
1304   gimp_procedure_add_return_value (procedure,
1305                                    g_param_spec_double ("median",
1306                                                         "median",
1307                                                         "Median intensity value",
1308                                                         -G_MAXDOUBLE, G_MAXDOUBLE, 0,
1309                                                         GIMP_PARAM_READWRITE));
1310   gimp_procedure_add_return_value (procedure,
1311                                    g_param_spec_double ("pixels",
1312                                                         "pixels",
1313                                                         "Alpha-weighted pixel count for entire image",
1314                                                         -G_MAXDOUBLE, G_MAXDOUBLE, 0,
1315                                                         GIMP_PARAM_READWRITE));
1316   gimp_procedure_add_return_value (procedure,
1317                                    g_param_spec_double ("count",
1318                                                         "count",
1319                                                         "Alpha-weighted pixel count for range",
1320                                                         -G_MAXDOUBLE, G_MAXDOUBLE, 0,
1321                                                         GIMP_PARAM_READWRITE));
1322   gimp_procedure_add_return_value (procedure,
1323                                    g_param_spec_double ("percentile",
1324                                                         "percentile",
1325                                                         "Percentile that range falls under",
1326                                                         -G_MAXDOUBLE, G_MAXDOUBLE, 0,
1327                                                         GIMP_PARAM_READWRITE));
1328   gimp_pdb_register_procedure (pdb, procedure);
1329   g_object_unref (procedure);
1330 
1331   /*
1332    * gimp-hue-saturation
1333    */
1334   procedure = gimp_procedure_new (hue_saturation_invoker);
1335   gimp_object_set_static_name (GIMP_OBJECT (procedure),
1336                                "gimp-hue-saturation");
1337   gimp_procedure_set_static_strings (procedure,
1338                                      "gimp-hue-saturation",
1339                                      "Deprecated: Use 'gimp-drawable-hue-saturation' instead.",
1340                                      "Deprecated: Use 'gimp-drawable-hue-saturation' instead.",
1341                                      "",
1342                                      "",
1343                                      "",
1344                                      "gimp-drawable-hue-saturation");
1345   gimp_procedure_add_argument (procedure,
1346                                gimp_param_spec_drawable_id ("drawable",
1347                                                             "drawable",
1348                                                             "The drawable",
1349                                                             pdb->gimp, FALSE,
1350                                                             GIMP_PARAM_READWRITE));
1351   gimp_procedure_add_argument (procedure,
1352                                g_param_spec_enum ("hue-range",
1353                                                   "hue range",
1354                                                   "Range of affected hues",
1355                                                   GIMP_TYPE_HUE_RANGE,
1356                                                   GIMP_HUE_RANGE_ALL,
1357                                                   GIMP_PARAM_READWRITE));
1358   gimp_procedure_add_argument (procedure,
1359                                g_param_spec_double ("hue-offset",
1360                                                     "hue offset",
1361                                                     "Hue offset in degrees",
1362                                                     -180, 180, -180,
1363                                                     GIMP_PARAM_READWRITE));
1364   gimp_procedure_add_argument (procedure,
1365                                g_param_spec_double ("lightness",
1366                                                     "lightness",
1367                                                     "Lightness modification",
1368                                                     -100, 100, -100,
1369                                                     GIMP_PARAM_READWRITE));
1370   gimp_procedure_add_argument (procedure,
1371                                g_param_spec_double ("saturation",
1372                                                     "saturation",
1373                                                     "Saturation modification",
1374                                                     -100, 100, -100,
1375                                                     GIMP_PARAM_READWRITE));
1376   gimp_pdb_register_procedure (pdb, procedure);
1377   g_object_unref (procedure);
1378 
1379   /*
1380    * gimp-threshold
1381    */
1382   procedure = gimp_procedure_new (threshold_invoker);
1383   gimp_object_set_static_name (GIMP_OBJECT (procedure),
1384                                "gimp-threshold");
1385   gimp_procedure_set_static_strings (procedure,
1386                                      "gimp-threshold",
1387                                      "Deprecated: Use 'gimp-drawable-threshold' instead.",
1388                                      "Deprecated: Use 'gimp-drawable-threshold' instead.",
1389                                      "",
1390                                      "",
1391                                      "",
1392                                      "gimp-drawable-threshold");
1393   gimp_procedure_add_argument (procedure,
1394                                gimp_param_spec_drawable_id ("drawable",
1395                                                             "drawable",
1396                                                             "The drawable",
1397                                                             pdb->gimp, FALSE,
1398                                                             GIMP_PARAM_READWRITE));
1399   gimp_procedure_add_argument (procedure,
1400                                gimp_param_spec_int32 ("low-threshold",
1401                                                       "low threshold",
1402                                                       "The low threshold value",
1403                                                       0, 255, 0,
1404                                                       GIMP_PARAM_READWRITE));
1405   gimp_procedure_add_argument (procedure,
1406                                gimp_param_spec_int32 ("high-threshold",
1407                                                       "high threshold",
1408                                                       "The high threshold value",
1409                                                       0, 255, 0,
1410                                                       GIMP_PARAM_READWRITE));
1411   gimp_pdb_register_procedure (pdb, procedure);
1412   g_object_unref (procedure);
1413 }
1414