1 /* LIBGIMP - The GIMP Library
2  * Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
3  *
4  * gimpselection_pdb.c
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 3 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library.  If not, see
18  * <https://www.gnu.org/licenses/>.
19  */
20 
21 /* NOTE: This file is auto-generated by pdbgen.pl */
22 
23 #include "config.h"
24 
25 #include "gimp.h"
26 
27 
28 /**
29  * SECTION: gimpselection
30  * @title: gimpselection
31  * @short_description: Functions for manipulating selections.
32  *
33  * Functions for manipulating selections.
34  **/
35 
36 
37 /**
38  * gimp_selection_bounds:
39  * @image_ID: The image.
40  * @non_empty: TRUE if there is a selection.
41  * @x1: x coordinate of upper left corner of selection bounds.
42  * @y1: y coordinate of upper left corner of selection bounds.
43  * @x2: x coordinate of lower right corner of selection bounds.
44  * @y2: y coordinate of lower right corner of selection bounds.
45  *
46  * Find the bounding box of the current selection.
47  *
48  * This procedure returns whether there is a selection for the
49  * specified image. If there is one, the upper left and lower right
50  * corners of the bounding box are returned. These coordinates are
51  * relative to the image. Please note that the pixel specified by the
52  * lower right coordinate of the bounding box is not part of the
53  * selection. The selection ends at the upper left corner of this
54  * pixel. This means the width of the selection can be calculated as
55  * (x2 - x1), its height as (y2 - y1).
56  *
57  * Returns: TRUE on success.
58  **/
59 gboolean
gimp_selection_bounds(gint32 image_ID,gboolean * non_empty,gint * x1,gint * y1,gint * x2,gint * y2)60 gimp_selection_bounds (gint32    image_ID,
61                        gboolean *non_empty,
62                        gint     *x1,
63                        gint     *y1,
64                        gint     *x2,
65                        gint     *y2)
66 {
67   GimpParam *return_vals;
68   gint nreturn_vals;
69   gboolean success = TRUE;
70 
71   return_vals = gimp_run_procedure ("gimp-selection-bounds",
72                                     &nreturn_vals,
73                                     GIMP_PDB_IMAGE, image_ID,
74                                     GIMP_PDB_END);
75 
76   *non_empty = FALSE;
77   *x1 = 0;
78   *y1 = 0;
79   *x2 = 0;
80   *y2 = 0;
81 
82   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
83 
84   if (success)
85     {
86       *non_empty = return_vals[1].data.d_int32;
87       *x1 = return_vals[2].data.d_int32;
88       *y1 = return_vals[3].data.d_int32;
89       *x2 = return_vals[4].data.d_int32;
90       *y2 = return_vals[5].data.d_int32;
91     }
92 
93   gimp_destroy_params (return_vals, nreturn_vals);
94 
95   return success;
96 }
97 
98 /**
99  * gimp_selection_value:
100  * @image_ID: The image.
101  * @x: x coordinate of value.
102  * @y: y coordinate of value.
103  *
104  * Find the value of the selection at the specified coordinates.
105  *
106  * This procedure returns the value of the selection at the specified
107  * coordinates. If the coordinates lie out of bounds, 0 is returned.
108  *
109  * Returns: Value of the selection.
110  **/
111 gint
gimp_selection_value(gint32 image_ID,gint x,gint y)112 gimp_selection_value (gint32 image_ID,
113                       gint   x,
114                       gint   y)
115 {
116   GimpParam *return_vals;
117   gint nreturn_vals;
118   gint value = 0;
119 
120   return_vals = gimp_run_procedure ("gimp-selection-value",
121                                     &nreturn_vals,
122                                     GIMP_PDB_IMAGE, image_ID,
123                                     GIMP_PDB_INT32, x,
124                                     GIMP_PDB_INT32, y,
125                                     GIMP_PDB_END);
126 
127   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
128     value = return_vals[1].data.d_int32;
129 
130   gimp_destroy_params (return_vals, nreturn_vals);
131 
132   return value;
133 }
134 
135 /**
136  * gimp_selection_is_empty:
137  * @image_ID: The image.
138  *
139  * Determine whether the selection is empty.
140  *
141  * This procedure returns TRUE if the selection for the specified image
142  * is empty.
143  *
144  * Returns: Is the selection empty?
145  **/
146 gboolean
gimp_selection_is_empty(gint32 image_ID)147 gimp_selection_is_empty (gint32 image_ID)
148 {
149   GimpParam *return_vals;
150   gint nreturn_vals;
151   gboolean is_empty = FALSE;
152 
153   return_vals = gimp_run_procedure ("gimp-selection-is-empty",
154                                     &nreturn_vals,
155                                     GIMP_PDB_IMAGE, image_ID,
156                                     GIMP_PDB_END);
157 
158   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
159     is_empty = return_vals[1].data.d_int32;
160 
161   gimp_destroy_params (return_vals, nreturn_vals);
162 
163   return is_empty;
164 }
165 
166 /**
167  * gimp_selection_translate:
168  * @image_ID: The image.
169  * @offx: x offset for translation.
170  * @offy: y offset for translation.
171  *
172  * Translate the selection by the specified offsets.
173  *
174  * This procedure actually translates the selection for the specified
175  * image by the specified offsets. Regions that are translated from
176  * beyond the bounds of the image are set to empty. Valid regions of
177  * the selection which are translated beyond the bounds of the image
178  * because of this call are lost.
179  *
180  * Returns: TRUE on success.
181  **/
182 gboolean
gimp_selection_translate(gint32 image_ID,gint offx,gint offy)183 gimp_selection_translate (gint32 image_ID,
184                           gint   offx,
185                           gint   offy)
186 {
187   GimpParam *return_vals;
188   gint nreturn_vals;
189   gboolean success = TRUE;
190 
191   return_vals = gimp_run_procedure ("gimp-selection-translate",
192                                     &nreturn_vals,
193                                     GIMP_PDB_IMAGE, image_ID,
194                                     GIMP_PDB_INT32, offx,
195                                     GIMP_PDB_INT32, offy,
196                                     GIMP_PDB_END);
197 
198   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
199 
200   gimp_destroy_params (return_vals, nreturn_vals);
201 
202   return success;
203 }
204 
205 /**
206  * _gimp_selection_float:
207  * @drawable_ID: The drawable from which to float selection.
208  * @offx: x offset for translation.
209  * @offy: y offset for translation.
210  *
211  * Float the selection from the specified drawable with initial offsets
212  * as specified.
213  *
214  * This procedure determines the region of the specified drawable that
215  * lies beneath the current selection. The region is then cut from the
216  * drawable and the resulting data is made into a new layer which is
217  * instantiated as a floating selection. The offsets allow initial
218  * positioning of the new floating selection.
219  *
220  * Returns: The floated layer.
221  **/
222 gint32
_gimp_selection_float(gint32 drawable_ID,gint offx,gint offy)223 _gimp_selection_float (gint32 drawable_ID,
224                        gint   offx,
225                        gint   offy)
226 {
227   GimpParam *return_vals;
228   gint nreturn_vals;
229   gint32 layer_ID = -1;
230 
231   return_vals = gimp_run_procedure ("gimp-selection-float",
232                                     &nreturn_vals,
233                                     GIMP_PDB_DRAWABLE, drawable_ID,
234                                     GIMP_PDB_INT32, offx,
235                                     GIMP_PDB_INT32, offy,
236                                     GIMP_PDB_END);
237 
238   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
239     layer_ID = return_vals[1].data.d_layer;
240 
241   gimp_destroy_params (return_vals, nreturn_vals);
242 
243   return layer_ID;
244 }
245 
246 /**
247  * gimp_selection_invert:
248  * @image_ID: The image.
249  *
250  * Invert the selection mask.
251  *
252  * This procedure inverts the selection mask. For every pixel in the
253  * selection channel, its new value is calculated as (255 - old-value).
254  *
255  * Returns: TRUE on success.
256  **/
257 gboolean
gimp_selection_invert(gint32 image_ID)258 gimp_selection_invert (gint32 image_ID)
259 {
260   GimpParam *return_vals;
261   gint nreturn_vals;
262   gboolean success = TRUE;
263 
264   return_vals = gimp_run_procedure ("gimp-selection-invert",
265                                     &nreturn_vals,
266                                     GIMP_PDB_IMAGE, image_ID,
267                                     GIMP_PDB_END);
268 
269   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
270 
271   gimp_destroy_params (return_vals, nreturn_vals);
272 
273   return success;
274 }
275 
276 /**
277  * gimp_selection_sharpen:
278  * @image_ID: The image.
279  *
280  * Sharpen the selection mask.
281  *
282  * This procedure sharpens the selection mask. For every pixel in the
283  * selection channel, if the value is &gt; 127, the new pixel is
284  * assigned a value of 255. This removes any \"anti-aliasing\" that
285  * might exist in the selection mask's boundary.
286  *
287  * Returns: TRUE on success.
288  **/
289 gboolean
gimp_selection_sharpen(gint32 image_ID)290 gimp_selection_sharpen (gint32 image_ID)
291 {
292   GimpParam *return_vals;
293   gint nreturn_vals;
294   gboolean success = TRUE;
295 
296   return_vals = gimp_run_procedure ("gimp-selection-sharpen",
297                                     &nreturn_vals,
298                                     GIMP_PDB_IMAGE, image_ID,
299                                     GIMP_PDB_END);
300 
301   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
302 
303   gimp_destroy_params (return_vals, nreturn_vals);
304 
305   return success;
306 }
307 
308 /**
309  * gimp_selection_all:
310  * @image_ID: The image.
311  *
312  * Select all of the image.
313  *
314  * This procedure sets the selection mask to completely encompass the
315  * image. Every pixel in the selection channel is set to 255.
316  *
317  * Returns: TRUE on success.
318  **/
319 gboolean
gimp_selection_all(gint32 image_ID)320 gimp_selection_all (gint32 image_ID)
321 {
322   GimpParam *return_vals;
323   gint nreturn_vals;
324   gboolean success = TRUE;
325 
326   return_vals = gimp_run_procedure ("gimp-selection-all",
327                                     &nreturn_vals,
328                                     GIMP_PDB_IMAGE, image_ID,
329                                     GIMP_PDB_END);
330 
331   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
332 
333   gimp_destroy_params (return_vals, nreturn_vals);
334 
335   return success;
336 }
337 
338 /**
339  * gimp_selection_none:
340  * @image_ID: The image.
341  *
342  * Deselect the entire image.
343  *
344  * This procedure deselects the entire image. Every pixel in the
345  * selection channel is set to 0.
346  *
347  * Returns: TRUE on success.
348  **/
349 gboolean
gimp_selection_none(gint32 image_ID)350 gimp_selection_none (gint32 image_ID)
351 {
352   GimpParam *return_vals;
353   gint nreturn_vals;
354   gboolean success = TRUE;
355 
356   return_vals = gimp_run_procedure ("gimp-selection-none",
357                                     &nreturn_vals,
358                                     GIMP_PDB_IMAGE, image_ID,
359                                     GIMP_PDB_END);
360 
361   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
362 
363   gimp_destroy_params (return_vals, nreturn_vals);
364 
365   return success;
366 }
367 
368 /**
369  * gimp_selection_feather:
370  * @image_ID: The image.
371  * @radius: Radius of feather (in pixels).
372  *
373  * Feather the image's selection
374  *
375  * This procedure feathers the selection. Feathering is implemented
376  * using a gaussian blur.
377  *
378  * Returns: TRUE on success.
379  **/
380 gboolean
gimp_selection_feather(gint32 image_ID,gdouble radius)381 gimp_selection_feather (gint32  image_ID,
382                         gdouble radius)
383 {
384   GimpParam *return_vals;
385   gint nreturn_vals;
386   gboolean success = TRUE;
387 
388   return_vals = gimp_run_procedure ("gimp-selection-feather",
389                                     &nreturn_vals,
390                                     GIMP_PDB_IMAGE, image_ID,
391                                     GIMP_PDB_FLOAT, radius,
392                                     GIMP_PDB_END);
393 
394   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
395 
396   gimp_destroy_params (return_vals, nreturn_vals);
397 
398   return success;
399 }
400 
401 /**
402  * gimp_selection_border:
403  * @image_ID: The image.
404  * @radius: Radius of border (in pixels).
405  *
406  * Border the image's selection
407  *
408  * This procedure borders the selection. Bordering creates a new
409  * selection which is defined along the boundary of the previous
410  * selection at every point within the specified radius.
411  *
412  * Returns: TRUE on success.
413  **/
414 gboolean
gimp_selection_border(gint32 image_ID,gint radius)415 gimp_selection_border (gint32 image_ID,
416                        gint   radius)
417 {
418   GimpParam *return_vals;
419   gint nreturn_vals;
420   gboolean success = TRUE;
421 
422   return_vals = gimp_run_procedure ("gimp-selection-border",
423                                     &nreturn_vals,
424                                     GIMP_PDB_IMAGE, image_ID,
425                                     GIMP_PDB_INT32, radius,
426                                     GIMP_PDB_END);
427 
428   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
429 
430   gimp_destroy_params (return_vals, nreturn_vals);
431 
432   return success;
433 }
434 
435 /**
436  * gimp_selection_grow:
437  * @image_ID: The image.
438  * @steps: Steps of grow (in pixels).
439  *
440  * Grow the image's selection
441  *
442  * This procedure grows the selection. Growing involves expanding the
443  * boundary in all directions by the specified pixel amount.
444  *
445  * Returns: TRUE on success.
446  **/
447 gboolean
gimp_selection_grow(gint32 image_ID,gint steps)448 gimp_selection_grow (gint32 image_ID,
449                      gint   steps)
450 {
451   GimpParam *return_vals;
452   gint nreturn_vals;
453   gboolean success = TRUE;
454 
455   return_vals = gimp_run_procedure ("gimp-selection-grow",
456                                     &nreturn_vals,
457                                     GIMP_PDB_IMAGE, image_ID,
458                                     GIMP_PDB_INT32, steps,
459                                     GIMP_PDB_END);
460 
461   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
462 
463   gimp_destroy_params (return_vals, nreturn_vals);
464 
465   return success;
466 }
467 
468 /**
469  * gimp_selection_shrink:
470  * @image_ID: The image.
471  * @steps: Steps of shrink (in pixels).
472  *
473  * Shrink the image's selection
474  *
475  * This procedure shrinks the selection. Shrinking involves trimming
476  * the existing selection boundary on all sides by the specified number
477  * of pixels.
478  *
479  * Returns: TRUE on success.
480  **/
481 gboolean
gimp_selection_shrink(gint32 image_ID,gint steps)482 gimp_selection_shrink (gint32 image_ID,
483                        gint   steps)
484 {
485   GimpParam *return_vals;
486   gint nreturn_vals;
487   gboolean success = TRUE;
488 
489   return_vals = gimp_run_procedure ("gimp-selection-shrink",
490                                     &nreturn_vals,
491                                     GIMP_PDB_IMAGE, image_ID,
492                                     GIMP_PDB_INT32, steps,
493                                     GIMP_PDB_END);
494 
495   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
496 
497   gimp_destroy_params (return_vals, nreturn_vals);
498 
499   return success;
500 }
501 
502 /**
503  * gimp_selection_flood:
504  * @image_ID: The image.
505  *
506  * Remove holes from the image's selection
507  *
508  * This procedure removes holes from the selection, that can come from
509  * selecting a patchy area with the Fuzzy Select Tool. In technical
510  * terms this procedure floods the selection. See the Algorithms page
511  * in the developer wiki for details.
512  *
513  * Returns: TRUE on success.
514  *
515  * Since: 2.10
516  **/
517 gboolean
gimp_selection_flood(gint32 image_ID)518 gimp_selection_flood (gint32 image_ID)
519 {
520   GimpParam *return_vals;
521   gint nreturn_vals;
522   gboolean success = TRUE;
523 
524   return_vals = gimp_run_procedure ("gimp-selection-flood",
525                                     &nreturn_vals,
526                                     GIMP_PDB_IMAGE, image_ID,
527                                     GIMP_PDB_END);
528 
529   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
530 
531   gimp_destroy_params (return_vals, nreturn_vals);
532 
533   return success;
534 }
535 
536 /**
537  * gimp_selection_layer_alpha:
538  * @layer_ID: Layer with alpha.
539  *
540  * Deprecated: Use gimp_image_select_item() instead.
541  *
542  * Returns: TRUE on success.
543  **/
544 gboolean
gimp_selection_layer_alpha(gint32 layer_ID)545 gimp_selection_layer_alpha (gint32 layer_ID)
546 {
547   GimpParam *return_vals;
548   gint nreturn_vals;
549   gboolean success = TRUE;
550 
551   return_vals = gimp_run_procedure ("gimp-selection-layer-alpha",
552                                     &nreturn_vals,
553                                     GIMP_PDB_LAYER, layer_ID,
554                                     GIMP_PDB_END);
555 
556   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
557 
558   gimp_destroy_params (return_vals, nreturn_vals);
559 
560   return success;
561 }
562 
563 /**
564  * gimp_selection_load:
565  * @channel_ID: The channel.
566  *
567  * Deprecated: Use gimp_image_select_item() instead.
568  *
569  * Returns: TRUE on success.
570  **/
571 gboolean
gimp_selection_load(gint32 channel_ID)572 gimp_selection_load (gint32 channel_ID)
573 {
574   GimpParam *return_vals;
575   gint nreturn_vals;
576   gboolean success = TRUE;
577 
578   return_vals = gimp_run_procedure ("gimp-selection-load",
579                                     &nreturn_vals,
580                                     GIMP_PDB_CHANNEL, channel_ID,
581                                     GIMP_PDB_END);
582 
583   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
584 
585   gimp_destroy_params (return_vals, nreturn_vals);
586 
587   return success;
588 }
589 
590 /**
591  * gimp_selection_save:
592  * @image_ID: The image.
593  *
594  * Copy the selection mask to a new channel.
595  *
596  * This procedure copies the selection mask and stores the content in a
597  * new channel. The new channel is automatically inserted into the
598  * image's list of channels.
599  *
600  * Returns: The new channel.
601  **/
602 gint32
gimp_selection_save(gint32 image_ID)603 gimp_selection_save (gint32 image_ID)
604 {
605   GimpParam *return_vals;
606   gint nreturn_vals;
607   gint32 channel_ID = -1;
608 
609   return_vals = gimp_run_procedure ("gimp-selection-save",
610                                     &nreturn_vals,
611                                     GIMP_PDB_IMAGE, image_ID,
612                                     GIMP_PDB_END);
613 
614   if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
615     channel_ID = return_vals[1].data.d_channel;
616 
617   gimp_destroy_params (return_vals, nreturn_vals);
618 
619   return channel_ID;
620 }
621 
622 /**
623  * gimp_selection_combine:
624  * @channel_ID: The channel.
625  * @operation: The selection operation.
626  *
627  * Deprecated: Use gimp_image_select_item() instead.
628  *
629  * Returns: TRUE on success.
630  **/
631 gboolean
gimp_selection_combine(gint32 channel_ID,GimpChannelOps operation)632 gimp_selection_combine (gint32         channel_ID,
633                         GimpChannelOps operation)
634 {
635   GimpParam *return_vals;
636   gint nreturn_vals;
637   gboolean success = TRUE;
638 
639   return_vals = gimp_run_procedure ("gimp-selection-combine",
640                                     &nreturn_vals,
641                                     GIMP_PDB_CHANNEL, channel_ID,
642                                     GIMP_PDB_INT32, operation,
643                                     GIMP_PDB_END);
644 
645   success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
646 
647   gimp_destroy_params (return_vals, nreturn_vals);
648 
649   return success;
650 }
651