gimpselection_pdb.c 18.1 KB
Newer Older
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
Marc Lehmann's avatar
Marc Lehmann committed
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 13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
Marc Lehmann's avatar
Marc Lehmann committed
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

Sven Neumann's avatar
Sven Neumann committed
23 24
#include "config.h"

25
#include "gimp.h"
26

27 28

/**
29
 * SECTION: gimpselection
30 31 32 33 34 35 36
 * @title: gimpselection
 * @short_description: Functions for manipulating selections.
 *
 * Functions for manipulating selections.
 **/


37 38
/**
 * gimp_selection_bounds:
39
 * @image: The image.
40 41 42 43 44
 * @non_empty: (out): TRUE if there is a selection.
 * @x1: (out): x coordinate of upper left corner of selection bounds.
 * @y1: (out): y coordinate of upper left corner of selection bounds.
 * @x2: (out): x coordinate of lower right corner of selection bounds.
 * @y2: (out): y coordinate of lower right corner of selection bounds.
45 46 47 48 49 50
 *
 * Find the bounding box of the current selection.
 *
 * This procedure returns whether there is a selection for the
 * specified image. If there is one, the upper left and lower right
 * 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 54 55
 * selection. The selection ends at the upper left corner of this
 * pixel. This means the width of the selection can be calculated as
 * (x2 - x1), its height as (y2 - y1).
56 57
 *
 * Returns: TRUE on success.
58
 **/
59
gboolean
60 61 62 63 64 65
gimp_selection_bounds (GimpImage *image,
                       gboolean  *non_empty,
                       gint      *x1,
                       gint      *y1,
                       gint      *x2,
                       gint      *y2)
66
{
67 68
  GimpValueArray *args;
  GimpValueArray *return_vals;
69
  gboolean success = TRUE;
70

71
  args = gimp_value_array_new_from_types (NULL,
72
                                          GIMP_TYPE_IMAGE, image,
73 74
                                          G_TYPE_NONE);

75 76 77
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-bounds",
                                              args);
78
  gimp_value_array_unref (args);
79

80 81 82 83 84 85
  *non_empty = FALSE;
  *x1 = 0;
  *y1 = 0;
  *x2 = 0;
  *y2 = 0;

86
  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
87 88

  if (success)
89
    {
90 91 92 93 94
      *non_empty = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
      *x1 = GIMP_VALUES_GET_INT (return_vals, 2);
      *y1 = GIMP_VALUES_GET_INT (return_vals, 3);
      *x2 = GIMP_VALUES_GET_INT (return_vals, 4);
      *y2 = GIMP_VALUES_GET_INT (return_vals, 5);
95
    }
96

97
  gimp_value_array_unref (return_vals);
98 99

  return success;
100 101
}

102 103
/**
 * gimp_selection_value:
104
 * @image: The image.
105 106 107 108 109 110 111 112 113
 * @x: x coordinate of value.
 * @y: y coordinate of value.
 *
 * Find the value of the selection at the specified coordinates.
 *
 * This procedure returns the value of the selection at the specified
 * coordinates. If the coordinates lie out of bounds, 0 is returned.
 *
 * Returns: Value of the selection.
114
 **/
115
gint
116 117 118
gimp_selection_value (GimpImage *image,
                      gint       x,
                      gint       y)
119
{
120 121
  GimpValueArray *args;
  GimpValueArray *return_vals;
122 123
  gint value = 0;

124
  args = gimp_value_array_new_from_types (NULL,
125
                                          GIMP_TYPE_IMAGE, image,
126 127
                                          G_TYPE_INT, x,
                                          G_TYPE_INT, y,
128 129
                                          G_TYPE_NONE);

130 131 132
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-value",
                                              args);
133
  gimp_value_array_unref (args);
134

135
  if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
136
    value = GIMP_VALUES_GET_INT (return_vals, 1);
137

138
  gimp_value_array_unref (return_vals);
139 140 141 142

  return value;
}

143 144
/**
 * gimp_selection_is_empty:
145
 * @image: The image.
146 147 148
 *
 * Determine whether the selection is empty.
 *
149
 * This procedure returns TRUE if the selection for the specified image
150
 * is empty.
151 152
 *
 * Returns: Is the selection empty?
153
 **/
154
gboolean
155
gimp_selection_is_empty (GimpImage *image)
156
{
157 158
  GimpValueArray *args;
  GimpValueArray *return_vals;
159
  gboolean is_empty = FALSE;
160

161
  args = gimp_value_array_new_from_types (NULL,
162
                                          GIMP_TYPE_IMAGE, image,
163
                                          G_TYPE_NONE);
164

165 166 167
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-is-empty",
                                              args);
168
  gimp_value_array_unref (args);
169

170
  if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
171
    is_empty = GIMP_VALUES_GET_BOOLEAN (return_vals, 1);
172 173

  gimp_value_array_unref (return_vals);
174

175
  return is_empty;
176
}
177

178 179
/**
 * gimp_selection_translate:
180
 * @image: The image.
181 182 183 184 185
 * @offx: x offset for translation.
 * @offy: y offset for translation.
 *
 * Translate the selection by the specified offsets.
 *
186 187 188 189 190 191
 * This procedure actually translates the selection for the specified
 * image by the specified offsets. Regions that are translated from
 * beyond the bounds of the image are set to empty. Valid regions of
 * the selection which are translated beyond the bounds of the image
 * because of this call are lost.
 *
192 193 194
 * Returns: TRUE on success.
 **/
gboolean
195 196 197
gimp_selection_translate (GimpImage *image,
                          gint       offx,
                          gint       offy)
198
{
199 200
  GimpValueArray *args;
  GimpValueArray *return_vals;
201 202
  gboolean success = TRUE;

203
  args = gimp_value_array_new_from_types (NULL,
204
                                          GIMP_TYPE_IMAGE, image,
205 206
                                          G_TYPE_INT, offx,
                                          G_TYPE_INT, offy,
207 208
                                          G_TYPE_NONE);

209 210 211
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-translate",
                                              args);
212
  gimp_value_array_unref (args);
213

214
  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
215

216
  gimp_value_array_unref (return_vals);
217 218 219 220

  return success;
}

221
/**
222 223 224 225
 * _gimp_selection_float:
 * @drawable: The drawable from which to float selection.
 * @offx: x offset for translation.
 * @offy: y offset for translation.
226
 *
227 228
 * Float the selection from the specified drawable with initial offsets
 * as specified.
229
 *
230 231 232 233 234
 * This procedure determines the region of the specified drawable that
 * lies beneath the current selection. The region is then cut from the
 * drawable and the resulting data is made into a new layer which is
 * instantiated as a floating selection. The offsets allow initial
 * positioning of the new floating selection.
235
 *
236
 * Returns: (transfer none): The floated layer.
237
 **/
238 239 240 241
GimpLayer *
_gimp_selection_float (GimpDrawable *drawable,
                       gint          offx,
                       gint          offy)
242
{
243 244
  GimpValueArray *args;
  GimpValueArray *return_vals;
245
  GimpLayer *layer = NULL;
246

247
  args = gimp_value_array_new_from_types (NULL,
248 249 250
                                          GIMP_TYPE_DRAWABLE, drawable,
                                          G_TYPE_INT, offx,
                                          G_TYPE_INT, offy,
251
                                          G_TYPE_NONE);
252

253 254 255
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-float",
                                              args);
256
  gimp_value_array_unref (args);
257

258
  if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
259
    layer = GIMP_VALUES_GET_LAYER (return_vals, 1);
260 261

  gimp_value_array_unref (return_vals);
262

263
  return layer;
264 265
}

266
/**
267
 * gimp_selection_invert:
268
 * @image: The image.
269
 *
270
 * Invert the selection mask.
271
 *
272 273
 * This procedure inverts the selection mask. For every pixel in the
 * selection channel, its new value is calculated as (255 - old-value).
274 275
 *
 * Returns: TRUE on success.
276
 **/
277
gboolean
278
gimp_selection_invert (GimpImage *image)
279
{
280 281
  GimpValueArray *args;
  GimpValueArray *return_vals;
282 283
  gboolean success = TRUE;

284
  args = gimp_value_array_new_from_types (NULL,
285
                                          GIMP_TYPE_IMAGE, image,
286 287
                                          G_TYPE_NONE);

288 289 290
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-invert",
                                              args);
291
  gimp_value_array_unref (args);
292

293
  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
294

295
  gimp_value_array_unref (return_vals);
296 297 298 299 300

  return success;
}

/**
301 302
 * gimp_selection_sharpen:
 * @image: The image.
303
 *
304
 * Sharpen the selection mask.
305
 *
306 307 308 309
 * This procedure sharpens the selection mask. For every pixel in the
 * selection channel, if the value is &gt; 127, the new pixel is
 * assigned a value of 255. This removes any \"anti-aliasing\" that
 * might exist in the selection mask's boundary.
310 311
 *
 * Returns: TRUE on success.
312
 **/
313
gboolean
314
gimp_selection_sharpen (GimpImage *image)
315
{
316 317
  GimpValueArray *args;
  GimpValueArray *return_vals;
318 319
  gboolean success = TRUE;

320
  args = gimp_value_array_new_from_types (NULL,
321
                                          GIMP_TYPE_IMAGE, image,
322
                                          G_TYPE_NONE);
323

324 325 326
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-sharpen",
                                              args);
327
  gimp_value_array_unref (args);
328

329
  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
330 331

  gimp_value_array_unref (return_vals);
332 333 334 335 336

  return success;
}

/**
337
 * gimp_selection_all:
338
 * @image: The image.
339
 *
340
 * Select all of the image.
341
 *
342 343
 * This procedure sets the selection mask to completely encompass the
 * image. Every pixel in the selection channel is set to 255.
344 345
 *
 * Returns: TRUE on success.
346
 **/
347
gboolean
348
gimp_selection_all (GimpImage *image)
349
{
350 351
  GimpValueArray *args;
  GimpValueArray *return_vals;
352 353
  gboolean success = TRUE;

354
  args = gimp_value_array_new_from_types (NULL,
355
                                          GIMP_TYPE_IMAGE, image,
356 357
                                          G_TYPE_NONE);

358 359 360
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-all",
                                              args);
361
  gimp_value_array_unref (args);
362

363
  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
364

365
  gimp_value_array_unref (return_vals);
366 367 368 369

  return success;
}

370
/**
371 372
 * gimp_selection_none:
 * @image: The image.
373
 *
374
 * Deselect the entire image.
375
 *
376 377
 * This procedure deselects the entire image. Every pixel in the
 * selection channel is set to 0.
378 379
 *
 * Returns: TRUE on success.
380
 **/
381
gboolean
382
gimp_selection_none (GimpImage *image)
383
{
384 385
  GimpValueArray *args;
  GimpValueArray *return_vals;
386
  gboolean success = TRUE;
387

388
  args = gimp_value_array_new_from_types (NULL,
389
                                          GIMP_TYPE_IMAGE, image,
390
                                          G_TYPE_NONE);
391

392 393 394
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-none",
                                              args);
395
  gimp_value_array_unref (args);
396

397
  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
398 399

  gimp_value_array_unref (return_vals);
400 401

  return success;
402
}
403 404

/**
405
 * gimp_selection_feather:
406
 * @image: The image.
407
 * @radius: Radius of feather (in pixels).
408
 *
409
 * Feather the image's selection
410
 *
411 412
 * This procedure feathers the selection. Feathering is implemented
 * using a gaussian blur.
413 414
 *
 * Returns: TRUE on success.
415
 **/
416
gboolean
417 418
gimp_selection_feather (GimpImage *image,
                        gdouble    radius)
419
{
420 421
  GimpValueArray *args;
  GimpValueArray *return_vals;
422 423
  gboolean success = TRUE;

424
  args = gimp_value_array_new_from_types (NULL,
425
                                          GIMP_TYPE_IMAGE, image,
426
                                          G_TYPE_DOUBLE, radius,
427 428
                                          G_TYPE_NONE);

429 430 431
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-feather",
                                              args);
432
  gimp_value_array_unref (args);
433

434
  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
435

436
  gimp_value_array_unref (return_vals);
437 438 439 440 441

  return success;
}

/**
442 443 444
 * gimp_selection_border:
 * @image: The image.
 * @radius: Radius of border (in pixels).
445
 *
446
 * Border the image's selection
447
 *
448 449 450
 * This procedure borders the selection. Bordering creates a new
 * selection which is defined along the boundary of the previous
 * selection at every point within the specified radius.
451 452
 *
 * Returns: TRUE on success.
453
 **/
454
gboolean
455 456
gimp_selection_border (GimpImage *image,
                       gint       radius)
457
{
458 459
  GimpValueArray *args;
  GimpValueArray *return_vals;
460 461
  gboolean success = TRUE;

462
  args = gimp_value_array_new_from_types (NULL,
463 464
                                          GIMP_TYPE_IMAGE, image,
                                          G_TYPE_INT, radius,
465
                                          G_TYPE_NONE);
466

467 468 469
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-border",
                                              args);
470
  gimp_value_array_unref (args);
471

472
  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
473 474

  gimp_value_array_unref (return_vals);
475 476 477 478 479

  return success;
}

/**
480
 * gimp_selection_grow:
481
 * @image: The image.
482
 * @steps: Steps of grow (in pixels).
483
 *
484
 * Grow the image's selection
485
 *
486 487
 * This procedure grows the selection. Growing involves expanding the
 * boundary in all directions by the specified pixel amount.
488 489
 *
 * Returns: TRUE on success.
490
 **/
491
gboolean
492 493
gimp_selection_grow (GimpImage *image,
                     gint       steps)
494
{
495 496
  GimpValueArray *args;
  GimpValueArray *return_vals;
497 498
  gboolean success = TRUE;

499
  args = gimp_value_array_new_from_types (NULL,
500
                                          GIMP_TYPE_IMAGE, image,
501
                                          G_TYPE_INT, steps,
502 503
                                          G_TYPE_NONE);

504 505 506
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-grow",
                                              args);
507
  gimp_value_array_unref (args);
508

509
  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
510

511
  gimp_value_array_unref (return_vals);
512 513 514 515 516

  return success;
}

/**
517 518
 * gimp_selection_shrink:
 * @image: The image.
519
 * @steps: Steps of shrink (in pixels).
520 521 522
 *
 * Shrink the image's selection
 *
523
 * This procedure shrinks the selection. Shrinking involves trimming
524 525 526 527
 * the existing selection boundary on all sides by the specified number
 * of pixels.
 *
 * Returns: TRUE on success.
528
 **/
529
gboolean
530 531
gimp_selection_shrink (GimpImage *image,
                       gint       steps)
532
{
533 534
  GimpValueArray *args;
  GimpValueArray *return_vals;
535 536
  gboolean success = TRUE;

537
  args = gimp_value_array_new_from_types (NULL,
538
                                          GIMP_TYPE_IMAGE, image,
539
                                          G_TYPE_INT, steps,
540
                                          G_TYPE_NONE);
541

542 543 544
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-shrink",
                                              args);
545
  gimp_value_array_unref (args);
Ell's avatar
Ell committed
546

547
  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
548 549

  gimp_value_array_unref (return_vals);
Ell's avatar
Ell committed
550 551 552 553 554 555

  return success;
}

/**
 * gimp_selection_flood:
556
 * @image: The image.
Ell's avatar
Ell committed
557
 *
558
 * Remove holes from the image's selection
Ell's avatar
Ell committed
559
 *
560 561 562 563
 * This procedure removes holes from the selection, that can come from
 * selecting a patchy area with the Fuzzy Select Tool. In technical
 * terms this procedure floods the selection. See the Algorithms page
 * in the developer wiki for details.
Ell's avatar
Ell committed
564 565 566 567 568 569
 *
 * Returns: TRUE on success.
 *
 * Since: 2.10
 **/
gboolean
570
gimp_selection_flood (GimpImage *image)
Ell's avatar
Ell committed
571
{
572 573
  GimpValueArray *args;
  GimpValueArray *return_vals;
Ell's avatar
Ell committed
574 575
  gboolean success = TRUE;

576
  args = gimp_value_array_new_from_types (NULL,
577
                                          GIMP_TYPE_IMAGE, image,
578 579
                                          G_TYPE_NONE);

580 581 582
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-flood",
                                              args);
583
  gimp_value_array_unref (args);
Ell's avatar
Ell committed
584

585
  success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS;
586

587
  gimp_value_array_unref (return_vals);
588 589 590 591 592 593

  return success;
}

/**
 * gimp_selection_save:
594
 * @image: The image.
595 596 597 598 599 600 601
 *
 * Copy the selection mask to a new channel.
 *
 * This procedure copies the selection mask and stores the content in a
 * new channel. The new channel is automatically inserted into the
 * image's list of channels.
 *
602
 * Returns: (transfer none): The new channel.
603
 **/
604
GimpChannel *
605
gimp_selection_save (GimpImage *image)
606
{
607 608
  GimpValueArray *args;
  GimpValueArray *return_vals;
609
  GimpChannel *channel = NULL;
610

611
  args = gimp_value_array_new_from_types (NULL,
612
                                          GIMP_TYPE_IMAGE, image,
613 614
                                          G_TYPE_NONE);

615 616 617
  return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
                                              "gimp-selection-save",
                                              args);
618
  gimp_value_array_unref (args);
619

620
  if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
621
    channel = GIMP_VALUES_GET_CHANNEL (return_vals, 1);
622

623
  gimp_value_array_unref (return_vals);
624

625
  return channel;
626
}