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 "libgimpbase/gimpbase.h"
27 
28 #include "pdb-types.h"
29 
30 #include "core/gimpimage-sample-points.h"
31 #include "core/gimpimage.h"
32 #include "core/gimpparamspecs.h"
33 #include "core/gimpsamplepoint.h"
34 
35 #include "gimppdb.h"
36 #include "gimppdberror.h"
37 #include "gimppdb-utils.h"
38 #include "gimpprocedure.h"
39 #include "internal-procs.h"
40 
41 #include "gimp-intl.h"
42 
43 
44 static GimpValueArray *
image_add_sample_point_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)45 image_add_sample_point_invoker (GimpProcedure         *procedure,
46                                 Gimp                  *gimp,
47                                 GimpContext           *context,
48                                 GimpProgress          *progress,
49                                 const GimpValueArray  *args,
50                                 GError               **error)
51 {
52   gboolean success = TRUE;
53   GimpValueArray *return_vals;
54   GimpImage *image;
55   gint32 position_x;
56   gint32 position_y;
57   gint32 sample_point = 0;
58 
59   image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
60   position_x = g_value_get_int (gimp_value_array_index (args, 1));
61   position_y = g_value_get_int (gimp_value_array_index (args, 2));
62 
63   if (success)
64     {
65       if (position_x <= gimp_image_get_width  (image) &&
66           position_y <= gimp_image_get_height (image))
67         {
68           GimpSamplePoint *sp;
69 
70           sp = gimp_image_add_sample_point_at_pos (image, position_x, position_y,
71                                                    TRUE);
72           sample_point = gimp_aux_item_get_ID (GIMP_AUX_ITEM (sp));
73         }
74       else
75         success = FALSE;
76     }
77 
78   return_vals = gimp_procedure_get_return_values (procedure, success,
79                                                   error ? *error : NULL);
80 
81   if (success)
82     g_value_set_uint (gimp_value_array_index (return_vals, 1), sample_point);
83 
84   return return_vals;
85 }
86 
87 static GimpValueArray *
image_delete_sample_point_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)88 image_delete_sample_point_invoker (GimpProcedure         *procedure,
89                                    Gimp                  *gimp,
90                                    GimpContext           *context,
91                                    GimpProgress          *progress,
92                                    const GimpValueArray  *args,
93                                    GError               **error)
94 {
95   gboolean success = TRUE;
96   GimpImage *image;
97   gint32 sample_point;
98 
99   image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
100   sample_point = g_value_get_uint (gimp_value_array_index (args, 1));
101 
102   if (success)
103     {
104       GimpSamplePoint *sp = gimp_pdb_image_get_sample_point (image, sample_point,
105                                                              error);
106 
107       if (sp)
108         gimp_image_remove_sample_point (image, sp, TRUE);
109       else
110         success = FALSE;
111     }
112 
113   return gimp_procedure_get_return_values (procedure, success,
114                                            error ? *error : NULL);
115 }
116 
117 static GimpValueArray *
image_find_next_sample_point_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)118 image_find_next_sample_point_invoker (GimpProcedure         *procedure,
119                                       Gimp                  *gimp,
120                                       GimpContext           *context,
121                                       GimpProgress          *progress,
122                                       const GimpValueArray  *args,
123                                       GError               **error)
124 {
125   gboolean success = TRUE;
126   GimpValueArray *return_vals;
127   GimpImage *image;
128   gint32 sample_point;
129   gint32 next_sample_point = 0;
130 
131   image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
132   sample_point = g_value_get_uint (gimp_value_array_index (args, 1));
133 
134   if (success)
135     {
136       GimpSamplePoint *sp = gimp_image_get_next_sample_point (image, sample_point,
137                                                               &success);
138 
139       if (sp)
140         next_sample_point = gimp_aux_item_get_ID (GIMP_AUX_ITEM (sp));
141 
142       if (! success)
143         g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
144                      _("Image '%s' (%d) does not contain sample point with ID %d"),
145                      gimp_image_get_display_name (image),
146                      gimp_image_get_ID (image),
147                      sample_point);
148     }
149 
150   return_vals = gimp_procedure_get_return_values (procedure, success,
151                                                   error ? *error : NULL);
152 
153   if (success)
154     g_value_set_uint (gimp_value_array_index (return_vals, 1), next_sample_point);
155 
156   return return_vals;
157 }
158 
159 static GimpValueArray *
image_get_sample_point_position_invoker(GimpProcedure * procedure,Gimp * gimp,GimpContext * context,GimpProgress * progress,const GimpValueArray * args,GError ** error)160 image_get_sample_point_position_invoker (GimpProcedure         *procedure,
161                                          Gimp                  *gimp,
162                                          GimpContext           *context,
163                                          GimpProgress          *progress,
164                                          const GimpValueArray  *args,
165                                          GError               **error)
166 {
167   gboolean success = TRUE;
168   GimpValueArray *return_vals;
169   GimpImage *image;
170   gint32 sample_point;
171   gint32 position_x = 0;
172   gint32 position_y = 0;
173 
174   image = gimp_value_get_image (gimp_value_array_index (args, 0), gimp);
175   sample_point = g_value_get_uint (gimp_value_array_index (args, 1));
176 
177   if (success)
178     {
179       GimpSamplePoint *sp = gimp_pdb_image_get_sample_point (image, sample_point,
180                                                              error);
181 
182       if (sp)
183         gimp_sample_point_get_position (sp, &position_x, &position_y);
184       else
185         success = FALSE;
186     }
187 
188   return_vals = gimp_procedure_get_return_values (procedure, success,
189                                                   error ? *error : NULL);
190 
191   if (success)
192     {
193       g_value_set_int (gimp_value_array_index (return_vals, 1), position_x);
194       g_value_set_int (gimp_value_array_index (return_vals, 2), position_y);
195     }
196 
197   return return_vals;
198 }
199 
200 void
register_image_sample_points_procs(GimpPDB * pdb)201 register_image_sample_points_procs (GimpPDB *pdb)
202 {
203   GimpProcedure *procedure;
204 
205   /*
206    * gimp-image-add-sample-point
207    */
208   procedure = gimp_procedure_new (image_add_sample_point_invoker);
209   gimp_object_set_static_name (GIMP_OBJECT (procedure),
210                                "gimp-image-add-sample-point");
211   gimp_procedure_set_static_strings (procedure,
212                                      "gimp-image-add-sample-point",
213                                      "Add a sample point to an image.",
214                                      "This procedure adds a sample point to an image. It takes the input image and the position of the new sample points as parameters. It returns the sample point ID of the new sample point.",
215                                      "Michael Natterer <mitch@gimp.org>",
216                                      "Michael Natterer",
217                                      "2016",
218                                      NULL);
219   gimp_procedure_add_argument (procedure,
220                                gimp_param_spec_image_id ("image",
221                                                          "image",
222                                                          "The image",
223                                                          pdb->gimp, FALSE,
224                                                          GIMP_PARAM_READWRITE));
225   gimp_procedure_add_argument (procedure,
226                                gimp_param_spec_int32 ("position-x",
227                                                       "position x",
228                                                       "The guide'sample points x-offset from left of image",
229                                                       0, G_MAXINT32, 0,
230                                                       GIMP_PARAM_READWRITE));
231   gimp_procedure_add_argument (procedure,
232                                gimp_param_spec_int32 ("position-y",
233                                                       "position y",
234                                                       "The guide'sample points y-offset from top of image",
235                                                       0, G_MAXINT32, 0,
236                                                       GIMP_PARAM_READWRITE));
237   gimp_procedure_add_return_value (procedure,
238                                    g_param_spec_uint ("sample-point",
239                                                       "sample point",
240                                                       "The new sample point",
241                                                       1, G_MAXUINT32, 1,
242                                                       GIMP_PARAM_READWRITE));
243   gimp_pdb_register_procedure (pdb, procedure);
244   g_object_unref (procedure);
245 
246   /*
247    * gimp-image-delete-sample-point
248    */
249   procedure = gimp_procedure_new (image_delete_sample_point_invoker);
250   gimp_object_set_static_name (GIMP_OBJECT (procedure),
251                                "gimp-image-delete-sample-point");
252   gimp_procedure_set_static_strings (procedure,
253                                      "gimp-image-delete-sample-point",
254                                      "Deletes a sample point from an image.",
255                                      "This procedure takes an image and a sample point ID as input and removes the specified sample point from the specified image.",
256                                      "Michael Natterer <mitch@gimp.org>",
257                                      "Michael Natterer",
258                                      "2016",
259                                      NULL);
260   gimp_procedure_add_argument (procedure,
261                                gimp_param_spec_image_id ("image",
262                                                          "image",
263                                                          "The image",
264                                                          pdb->gimp, FALSE,
265                                                          GIMP_PARAM_READWRITE));
266   gimp_procedure_add_argument (procedure,
267                                g_param_spec_uint ("sample-point",
268                                                   "sample point",
269                                                   "The ID of the sample point to be removed",
270                                                   1, G_MAXUINT32, 1,
271                                                   GIMP_PARAM_READWRITE));
272   gimp_pdb_register_procedure (pdb, procedure);
273   g_object_unref (procedure);
274 
275   /*
276    * gimp-image-find-next-sample-point
277    */
278   procedure = gimp_procedure_new (image_find_next_sample_point_invoker);
279   gimp_object_set_static_name (GIMP_OBJECT (procedure),
280                                "gimp-image-find-next-sample-point");
281   gimp_procedure_set_static_strings (procedure,
282                                      "gimp-image-find-next-sample-point",
283                                      "Find next sample point on an image.",
284                                      "This procedure takes an image and a sample point ID as input and finds the sample point ID of the successor of the given sample point ID in the image's sample point list. If the supplied sample point ID is 0, the procedure will return the first sample point. The procedure will return 0 if given the final sample point ID as an argument or the image has no sample points.",
285                                      "Michael Natterer <mitch@gimp.org>",
286                                      "Michael Natterer",
287                                      "2016",
288                                      NULL);
289   gimp_procedure_add_argument (procedure,
290                                gimp_param_spec_image_id ("image",
291                                                          "image",
292                                                          "The image",
293                                                          pdb->gimp, FALSE,
294                                                          GIMP_PARAM_READWRITE));
295   gimp_procedure_add_argument (procedure,
296                                g_param_spec_uint ("sample-point",
297                                                   "sample point",
298                                                   "The ID of the current sample point (0 if first invocation)",
299                                                   1, G_MAXUINT32, 1,
300                                                   GIMP_PARAM_READWRITE | GIMP_PARAM_NO_VALIDATE));
301   gimp_procedure_add_return_value (procedure,
302                                    g_param_spec_uint ("next-sample-point",
303                                                       "next sample point",
304                                                       "The next sample point's ID",
305                                                       1, G_MAXUINT32, 1,
306                                                       GIMP_PARAM_READWRITE));
307   gimp_pdb_register_procedure (pdb, procedure);
308   g_object_unref (procedure);
309 
310   /*
311    * gimp-image-get-sample-point-position
312    */
313   procedure = gimp_procedure_new (image_get_sample_point_position_invoker);
314   gimp_object_set_static_name (GIMP_OBJECT (procedure),
315                                "gimp-image-get-sample-point-position");
316   gimp_procedure_set_static_strings (procedure,
317                                      "gimp-image-get-sample-point-position",
318                                      "Get position of a sample point on an image.",
319                                      "This procedure takes an image and a sample point ID as input and returns the position of the sample point relative to the top and left of the image.",
320                                      "Michael Natterer <mitch@gimp.org>",
321                                      "Michael Natterer",
322                                      "2016",
323                                      NULL);
324   gimp_procedure_add_argument (procedure,
325                                gimp_param_spec_image_id ("image",
326                                                          "image",
327                                                          "The image",
328                                                          pdb->gimp, FALSE,
329                                                          GIMP_PARAM_READWRITE));
330   gimp_procedure_add_argument (procedure,
331                                g_param_spec_uint ("sample-point",
332                                                   "sample point",
333                                                   "The guide",
334                                                   1, G_MAXUINT32, 1,
335                                                   GIMP_PARAM_READWRITE));
336   gimp_procedure_add_return_value (procedure,
337                                    gimp_param_spec_int32 ("position-x",
338                                                           "position x",
339                                                           "The sample points's position relative to top of image",
340                                                           G_MININT32, G_MAXINT32, 0,
341                                                           GIMP_PARAM_READWRITE));
342   gimp_procedure_add_return_value (procedure,
343                                    gimp_param_spec_int32 ("position-y",
344                                                           "position y",
345                                                           "The sample points's position relative to top of image",
346                                                           G_MININT32, G_MAXINT32, 0,
347                                                           GIMP_PARAM_READWRITE));
348   gimp_pdb_register_procedure (pdb, procedure);
349   g_object_unref (procedure);
350 }
351