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 <cairo.h>
23 #include <string.h>
24 
25 #include <gegl.h>
26 
27 #include <gdk-pixbuf/gdk-pixbuf.h>
28 
29 #include "libgimpcolor/gimpcolor.h"
30 
31 #include "libgimpbase/gimpbase.h"
32 
33 #include "pdb-types.h"
34 
35 #include "core/gimp.h"
36 #include "core/gimpcontainer-filter.h"
37 #include "core/gimpcontext.h"
38 #include "core/gimpdatafactory.h"
39 #include "core/gimppalette.h"
40 #include "core/gimpparamspecs.h"
41 
42 #include "gimppdb.h"
43 #include "gimppdb-utils.h"
44 #include "gimpprocedure.h"
45 #include "internal-procs.h"
46 
47 
48 static GimpValueArray *
palettes_refresh_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)49 palettes_refresh_invoker (GimpProcedure         *procedure,
50                           Gimp                  *gimp,
51                           GimpContext           *context,
52                           GimpProgress          *progress,
53                           const GimpValueArray  *args,
54                           GError               **error)
55 {
56   gimp_data_factory_data_refresh (gimp->palette_factory, context);
57 
58   return gimp_procedure_get_return_values (procedure, TRUE, NULL);
59 }
60 
61 static GimpValueArray *
palettes_get_list_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)62 palettes_get_list_invoker (GimpProcedure         *procedure,
63                            Gimp                  *gimp,
64                            GimpContext           *context,
65                            GimpProgress          *progress,
66                            const GimpValueArray  *args,
67                            GError               **error)
68 {
69   gboolean success = TRUE;
70   GimpValueArray *return_vals;
71   const gchar *filter;
72   gint32 num_palettes = 0;
73   gchar **palette_list = NULL;
74 
75   filter = g_value_get_string (gimp_value_array_index (args, 0));
76 
77   if (success)
78     {
79       palette_list = gimp_container_get_filtered_name_array (gimp_data_factory_get_container (gimp->palette_factory),
80                                                              filter, &num_palettes);
81     }
82 
83   return_vals = gimp_procedure_get_return_values (procedure, success,
84                                                   error ? *error : NULL);
85 
86   if (success)
87     {
88       g_value_set_int (gimp_value_array_index (return_vals, 1), num_palettes);
89       gimp_value_take_stringarray (gimp_value_array_index (return_vals, 2), palette_list, num_palettes);
90     }
91 
92   return return_vals;
93 }
94 
95 static GimpValueArray *
palettes_get_palette_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)96 palettes_get_palette_invoker (GimpProcedure         *procedure,
97                               Gimp                  *gimp,
98                               GimpContext           *context,
99                               GimpProgress          *progress,
100                               const GimpValueArray  *args,
101                               GError               **error)
102 {
103   gboolean success = TRUE;
104   GimpValueArray *return_vals;
105   gchar *name = NULL;
106   gint32 num_colors = 0;
107 
108   GimpPalette *palette = gimp_context_get_palette (context);
109 
110   if (palette)
111     {
112       name       = g_strdup (gimp_object_get_name (palette));
113       num_colors = gimp_palette_get_n_colors (palette);
114     }
115   else
116     success = FALSE;
117 
118   return_vals = gimp_procedure_get_return_values (procedure, success,
119                                                   error ? *error : NULL);
120 
121   if (success)
122     {
123       g_value_take_string (gimp_value_array_index (return_vals, 1), name);
124       g_value_set_int (gimp_value_array_index (return_vals, 2), num_colors);
125     }
126 
127   return return_vals;
128 }
129 
130 static GimpValueArray *
palettes_get_palette_entry_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)131 palettes_get_palette_entry_invoker (GimpProcedure         *procedure,
132                                     Gimp                  *gimp,
133                                     GimpContext           *context,
134                                     GimpProgress          *progress,
135                                     const GimpValueArray  *args,
136                                     GError               **error)
137 {
138   gboolean success = TRUE;
139   GimpValueArray *return_vals;
140   const gchar *name;
141   gint32 entry_num;
142   gchar *actual_name = NULL;
143   gint32 num_colors = 0;
144   GimpRGB color = { 0.0, 0.0, 0.0, 1.0 };
145 
146   name = g_value_get_string (gimp_value_array_index (args, 0));
147   entry_num = g_value_get_int (gimp_value_array_index (args, 1));
148 
149   if (success)
150     {
151       GimpPalette *palette;
152 
153       if (name && strlen (name))
154         palette = gimp_pdb_get_palette (gimp, name, FALSE, error);
155       else
156         palette = gimp_context_get_palette (context);
157 
158       if (palette)
159         {
160           GimpPaletteEntry *entry = gimp_palette_get_entry (palette, entry_num);
161 
162           if (entry)
163             {
164               actual_name = g_strdup (gimp_object_get_name (palette));
165               num_colors  = gimp_palette_get_n_colors (palette);
166               color       = entry->color;
167             }
168           else
169             success = FALSE;
170         }
171       else
172         success = FALSE;
173     }
174 
175   return_vals = gimp_procedure_get_return_values (procedure, success,
176                                                   error ? *error : NULL);
177 
178   if (success)
179     {
180       g_value_take_string (gimp_value_array_index (return_vals, 1), actual_name);
181       g_value_set_int (gimp_value_array_index (return_vals, 2), num_colors);
182       gimp_value_set_rgb (gimp_value_array_index (return_vals, 3), &color);
183     }
184 
185   return return_vals;
186 }
187 
188 void
register_palettes_procs(GimpPDB * pdb)189 register_palettes_procs (GimpPDB *pdb)
190 {
191   GimpProcedure *procedure;
192 
193   /*
194    * gimp-palettes-refresh
195    */
196   procedure = gimp_procedure_new (palettes_refresh_invoker);
197   gimp_object_set_static_name (GIMP_OBJECT (procedure),
198                                "gimp-palettes-refresh");
199   gimp_procedure_set_static_strings (procedure,
200                                      "gimp-palettes-refresh",
201                                      "Refreshes current palettes. This function always succeeds.",
202                                      "This procedure retrieves all palettes currently in the user's palette path and updates the palette dialogs accordingly.",
203                                      "Adrian Likins <adrian@gimp.org>",
204                                      "Adrian Likins",
205                                      "1998",
206                                      NULL);
207   gimp_pdb_register_procedure (pdb, procedure);
208   g_object_unref (procedure);
209 
210   /*
211    * gimp-palettes-get-list
212    */
213   procedure = gimp_procedure_new (palettes_get_list_invoker);
214   gimp_object_set_static_name (GIMP_OBJECT (procedure),
215                                "gimp-palettes-get-list");
216   gimp_procedure_set_static_strings (procedure,
217                                      "gimp-palettes-get-list",
218                                      "Retrieves a list of all of the available palettes",
219                                      "This procedure returns a complete listing of available palettes. Each name returned can be used as input to the command 'gimp-context-set-palette'.",
220                                      "Nathan Summers <rock@gimp.org>",
221                                      "Nathan Summers",
222                                      "2001",
223                                      NULL);
224   gimp_procedure_add_argument (procedure,
225                                gimp_param_spec_string ("filter",
226                                                        "filter",
227                                                        "An optional regular expression used to filter the list",
228                                                        FALSE, TRUE, FALSE,
229                                                        NULL,
230                                                        GIMP_PARAM_READWRITE));
231   gimp_procedure_add_return_value (procedure,
232                                    gimp_param_spec_int32 ("num-palettes",
233                                                           "num palettes",
234                                                           "The number of palettes in the list",
235                                                           0, G_MAXINT32, 0,
236                                                           GIMP_PARAM_READWRITE));
237   gimp_procedure_add_return_value (procedure,
238                                    gimp_param_spec_string_array ("palette-list",
239                                                                  "palette list",
240                                                                  "The list of palette names",
241                                                                  GIMP_PARAM_READWRITE));
242   gimp_pdb_register_procedure (pdb, procedure);
243   g_object_unref (procedure);
244 
245   /*
246    * gimp-palettes-get-palette
247    */
248   procedure = gimp_procedure_new (palettes_get_palette_invoker);
249   gimp_object_set_static_name (GIMP_OBJECT (procedure),
250                                "gimp-palettes-get-palette");
251   gimp_procedure_set_static_strings (procedure,
252                                      "gimp-palettes-get-palette",
253                                      "Deprecated: Use 'gimp-context-get-palette' instead.",
254                                      "Deprecated: Use 'gimp-context-get-palette' instead.",
255                                      "",
256                                      "",
257                                      "",
258                                      "gimp-context-get-palette");
259   gimp_procedure_add_return_value (procedure,
260                                    gimp_param_spec_string ("name",
261                                                            "name",
262                                                            "The palette name",
263                                                            FALSE, TRUE, FALSE,
264                                                            NULL,
265                                                            GIMP_PARAM_READWRITE));
266   gimp_procedure_add_return_value (procedure,
267                                    gimp_param_spec_int32 ("num-colors",
268                                                           "num colors",
269                                                           "The palette num_colors",
270                                                           G_MININT32, G_MAXINT32, 0,
271                                                           GIMP_PARAM_READWRITE));
272   gimp_pdb_register_procedure (pdb, procedure);
273   g_object_unref (procedure);
274 
275   /*
276    * gimp-palettes-get-palette-entry
277    */
278   procedure = gimp_procedure_new (palettes_get_palette_entry_invoker);
279   gimp_object_set_static_name (GIMP_OBJECT (procedure),
280                                "gimp-palettes-get-palette-entry");
281   gimp_procedure_set_static_strings (procedure,
282                                      "gimp-palettes-get-palette-entry",
283                                      "Deprecated: Use 'gimp-palette-entry-get-color' instead.",
284                                      "Deprecated: Use 'gimp-palette-entry-get-color' instead.",
285                                      "",
286                                      "",
287                                      "",
288                                      "gimp-palette-entry-get-color");
289   gimp_procedure_add_argument (procedure,
290                                gimp_param_spec_string ("name",
291                                                        "name",
292                                                        "The palette name (\"\" means currently active palette)",
293                                                        FALSE, TRUE, FALSE,
294                                                        NULL,
295                                                        GIMP_PARAM_READWRITE));
296   gimp_procedure_add_argument (procedure,
297                                gimp_param_spec_int32 ("entry-num",
298                                                       "entry num",
299                                                       "The entry to retrieve",
300                                                       G_MININT32, G_MAXINT32, 0,
301                                                       GIMP_PARAM_READWRITE));
302   gimp_procedure_add_return_value (procedure,
303                                    gimp_param_spec_string ("actual-name",
304                                                            "actual name",
305                                                            "The palette name",
306                                                            FALSE, FALSE, FALSE,
307                                                            NULL,
308                                                            GIMP_PARAM_READWRITE));
309   gimp_procedure_add_return_value (procedure,
310                                    gimp_param_spec_int32 ("num-colors",
311                                                           "num colors",
312                                                           "The palette num_colors",
313                                                           G_MININT32, G_MAXINT32, 0,
314                                                           GIMP_PARAM_READWRITE));
315   gimp_procedure_add_return_value (procedure,
316                                    gimp_param_spec_rgb ("color",
317                                                         "color",
318                                                         "The color requested",
319                                                         FALSE,
320                                                         NULL,
321                                                         GIMP_PARAM_READWRITE));
322   gimp_pdb_register_procedure (pdb, procedure);
323   g_object_unref (procedure);
324 }
325