gimpselection_pdb.c 15.4 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 30 31 32 33 34 35 36

/**
 * SECTION: gimpselection
 * @title: gimpselection
 * @short_description: Functions for manipulating selections.
 *
 * Functions for manipulating selections.
 **/


37 38 39
/**
 * gimp_selection_bounds:
 * @image_ID: The image.
40
 * @non_empty: TRUE if there is a selection.
41 42 43 44 45 46 47 48 49 50
 * @x1: x coordinate of upper left corner of selection bounds.
 * @y1: y coordinate of upper left corner of selection bounds.
 * @x2: x coordinate of lower right corner of selection bounds.
 * @y2: y coordinate of lower right corner of selection bounds.
 *
 * 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
gimp_selection_bounds (gint32    image_ID,
61 62 63 64 65
                       gboolean *non_empty,
                       gint     *x1,
                       gint     *y1,
                       gint     *x2,
                       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 73 74
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_END);
75

76 77 78 79 80 81
  *non_empty = FALSE;
  *x1 = 0;
  *y1 = 0;
  *x2 = 0;
  *y2 = 0;

82 83 84
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  if (success)
85
    {
86
      *non_empty = return_vals[1].data.d_int32;
87 88 89 90 91
      *x1 = return_vals[2].data.d_int32;
      *y1 = return_vals[3].data.d_int32;
      *x2 = return_vals[4].data.d_int32;
      *y2 = return_vals[5].data.d_int32;
    }
92

93
  gimp_destroy_params (return_vals, nreturn_vals);
94 95

  return success;
96 97
}

98 99 100 101 102 103 104 105 106 107 108 109
/**
 * gimp_selection_value:
 * @image_ID: The image.
 * @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.
110
 **/
111 112
gint
gimp_selection_value (gint32 image_ID,
113 114
                      gint   x,
                      gint   y)
115 116 117 118 119
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gint value = 0;

120
  return_vals = gimp_run_procedure ("gimp-selection-value",
121 122 123 124 125
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_INT32, x,
                                    GIMP_PDB_INT32, y,
                                    GIMP_PDB_END);
126 127 128 129 130 131 132 133 134

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    value = return_vals[1].data.d_int32;

  gimp_destroy_params (return_vals, nreturn_vals);

  return value;
}

135 136 137 138 139 140
/**
 * gimp_selection_is_empty:
 * @image_ID: The image.
 *
 * Determine whether the selection is empty.
 *
141
 * This procedure returns TRUE if the selection for the specified image
142
 * is empty.
143 144
 *
 * Returns: Is the selection empty?
145
 **/
146 147
gboolean
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 155 156
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    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 162

  gimp_destroy_params (return_vals, nreturn_vals);

163
  return is_empty;
164
}
165

166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
/**
 * gimp_selection_translate:
 * @image_ID: The image.
 * @offx: x offset for translation.
 * @offy: y offset for translation.
 *
 * Translate the selection by the specified offsets.
 *
 * 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.
 *
 * Returns: TRUE on success.
181
 **/
182 183
gboolean
gimp_selection_translate (gint32 image_ID,
184 185
                          gint   offx,
                          gint   offy)
186 187 188 189 190
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

191
  return_vals = gimp_run_procedure ("gimp-selection-translate",
192 193 194 195 196
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_INT32, offx,
                                    GIMP_PDB_INT32, offy,
                                    GIMP_PDB_END);
197 198 199 200 201 202 203 204

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
/**
 * _gimp_selection_float:
 * @drawable_ID: The drawable from which to float selection.
 * @offx: x offset for translation.
 * @offy: y offset for translation.
 *
 * Float the selection from the specified drawable with initial offsets
 * as specified.
 *
 * 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.
 *
 * Returns: The floated layer.
221
 **/
222 223
gint32
_gimp_selection_float (gint32 drawable_ID,
224 225
                       gint   offx,
                       gint   offy)
226
{
227
  GimpParam *return_vals;
228
  gint nreturn_vals;
229 230
  gint32 layer_ID = -1;

231
  return_vals = gimp_run_procedure ("gimp-selection-float",
232 233 234 235 236
                                    &nreturn_vals,
                                    GIMP_PDB_DRAWABLE, drawable_ID,
                                    GIMP_PDB_INT32, offx,
                                    GIMP_PDB_INT32, offy,
                                    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 242

  gimp_destroy_params (return_vals, nreturn_vals);

243
  return layer_ID;
244 245
}

246 247 248 249 250 251 252
/**
 * gimp_selection_invert:
 * @image_ID: The image.
 *
 * Invert the selection mask.
 *
 * 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 258 259 260 261 262 263
gboolean
gimp_selection_invert (gint32 image_ID)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

264
  return_vals = gimp_run_procedure ("gimp-selection-invert",
265 266 267
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_END);
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_selection_sharpen:
 * @image_ID: The image.
 *
 * Sharpen the selection mask.
 *
 * This procedure sharpens the selection mask. For every pixel in the
283 284 285
 * 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.
286 287
 *
 * Returns: TRUE on success.
288
 **/
289 290 291 292 293 294 295
gboolean
gimp_selection_sharpen (gint32 image_ID)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

296
  return_vals = gimp_run_procedure ("gimp-selection-sharpen",
297 298 299
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_END);
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_selection_all:
 * @image_ID: The image.
 *
 * Select all of the image.
 *
 * This procedure sets the selection mask to completely encompass the
 * image. Every pixel in the selection channel is set to 255.
 *
 * Returns: TRUE on success.
318
 **/
319 320 321 322 323 324 325
gboolean
gimp_selection_all (gint32 image_ID)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

326
  return_vals = gimp_run_procedure ("gimp-selection-all",
327 328 329
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_END);
330 331 332 333 334 335 336 337

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

338 339 340 341 342 343 344 345 346 347
/**
 * gimp_selection_none:
 * @image_ID: The image.
 *
 * Deselect the entire image.
 *
 * This procedure deselects the entire image. Every pixel in the
 * selection channel is set to 0.
 *
 * Returns: TRUE on success.
348
 **/
349
gboolean
350 351
gimp_selection_none (gint32 image_ID)
{
352
  GimpParam *return_vals;
353
  gint nreturn_vals;
354
  gboolean success = TRUE;
355

356
  return_vals = gimp_run_procedure ("gimp-selection-none",
357 358 359
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_END);
360

361 362
  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

363
  gimp_destroy_params (return_vals, nreturn_vals);
364 365

  return success;
366
}
367 368 369 370 371 372 373 374 375 376 377 378

/**
 * gimp_selection_feather:
 * @image_ID: The image.
 * @radius: Radius of feather (in pixels).
 *
 * Feather the image's selection
 *
 * This procedure feathers the selection. Feathering is implemented
 * using a gaussian blur.
 *
 * Returns: TRUE on success.
379
 **/
380 381
gboolean
gimp_selection_feather (gint32  image_ID,
382
                        gdouble radius)
383 384 385 386 387
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

388
  return_vals = gimp_run_procedure ("gimp-selection-feather",
389 390 391 392
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_FLOAT, radius,
                                    GIMP_PDB_END);
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_selection_border:
 * @image_ID: The image.
 * @radius: Radius of border (in pixels).
 *
 * Border the image's selection
 *
 * 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.
 *
 * Returns: TRUE on success.
413
 **/
414 415
gboolean
gimp_selection_border (gint32 image_ID,
416
                       gint   radius)
417 418 419 420 421
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

422
  return_vals = gimp_run_procedure ("gimp-selection-border",
423 424 425 426
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_INT32, radius,
                                    GIMP_PDB_END);
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_selection_grow:
 * @image_ID: The image.
 * @steps: Steps of grow (in pixels).
 *
 * Grow the image's selection
 *
 * This procedure grows the selection. Growing involves expanding the
 * boundary in all directions by the specified pixel amount.
 *
 * Returns: TRUE on success.
446
 **/
447 448
gboolean
gimp_selection_grow (gint32 image_ID,
449
                     gint   steps)
450 451 452 453 454
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

455
  return_vals = gimp_run_procedure ("gimp-selection-grow",
456 457 458 459
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_INT32, steps,
                                    GIMP_PDB_END);
460 461 462 463 464 465 466 467 468 469 470

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_selection_shrink:
 * @image_ID: The image.
471
 * @steps: Steps of shrink (in pixels).
472 473 474
 *
 * Shrink the image's selection
 *
475
 * This procedure shrinks the selection. Shrinking involves trimming
476 477 478 479
 * the existing selection boundary on all sides by the specified number
 * of pixels.
 *
 * Returns: TRUE on success.
480
 **/
481 482
gboolean
gimp_selection_shrink (gint32 image_ID,
483
                       gint   steps)
484 485 486 487 488
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

489
  return_vals = gimp_run_procedure ("gimp-selection-shrink",
490 491 492 493
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_INT32, steps,
                                    GIMP_PDB_END);
494 495

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
Ell's avatar
Ell committed
496 497 498 499 500 501 502 503 504 505

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_selection_flood:
 * @image_ID: The image.
 *
506
 * Remove holes from the image's selection
Ell's avatar
Ell committed
507
 *
508 509 510 511
 * 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
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
 *
 * Returns: TRUE on success.
 *
 * Since: 2.10
 **/
gboolean
gimp_selection_flood (gint32 image_ID)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gboolean success = TRUE;

  return_vals = gimp_run_procedure ("gimp-selection-flood",
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_END);

  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546

  gimp_destroy_params (return_vals, nreturn_vals);

  return success;
}

/**
 * gimp_selection_save:
 * @image_ID: The image.
 *
 * 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.
 *
 * Returns: The new channel.
547
 **/
548 549 550 551 552 553 554
gint32
gimp_selection_save (gint32 image_ID)
{
  GimpParam *return_vals;
  gint nreturn_vals;
  gint32 channel_ID = -1;

555
  return_vals = gimp_run_procedure ("gimp-selection-save",
556 557 558
                                    &nreturn_vals,
                                    GIMP_PDB_IMAGE, image_ID,
                                    GIMP_PDB_END);
559 560 561 562 563 564 565 566

  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
    channel_ID = return_vals[1].data.d_channel;

  gimp_destroy_params (return_vals, nreturn_vals);

  return channel_ID;
}