18
18
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
26
sub operation_arg () {{
28
type => 'enum GimpChannelOps',
29
desc => 'The selection operation: { %%desc%% }'
33
my ($name, $desc, $args) = @_;
35
push @$args, { name => eval qq/"$name"/, type => 'int32',
36
desc => eval qq/"$desc"/ }
40
sub selection_simple_proc {
45
@inargs = ( &std_image_arg );
47
%invoke = ( code => "gimp_channel_$op (gimp_image_get_mask (gimage), TRUE);" );
50
sub selection_change_proc {
51
my ($op, $arg, $type, $edge_lock) = @_;
53
$blurb = "\u$op the image's selection";
55
$help = "This procedure ${op}s the selection. ";
61
{ name => $arg, type => "0 <= $type",
62
desc => "\u$arg of $op (in pixels)" }
65
%invoke = ( code => "gimp_channel_$op (gimp_image_get_mask (gimage), $arg, $arg$edge_lock, TRUE);" );
70
20
sub selection_bounds {
71
21
$blurb = 'Find the bounding box of the current selection.';
85
@inargs = ( &std_image_arg );
36
{ name => 'image', type => 'image',
88
41
{ name => 'non_empty', type => 'boolean', void_ret => 1,
89
desc => 'True if there is a selection', init => 1 }
42
desc => 'TRUE if there is a selection' },
43
{ name => 'x1', type => 'int32',
44
desc => 'x coordinate of upper left corner of selection bounds' },
45
{ name => 'y1', type => 'int32',
46
desc => 'y coordinate of upper left corner of selection bounds' },
47
{ name => 'x2', type => 'int32',
48
desc => 'x coordinate of lower right corner of selection bounds' },
49
{ name => 'y2', type => 'int32',
50
desc => 'y coordinate of lower right corner of selection bounds' }
93
foreach ('upper left', 'lower right') {
94
&coord_args("\${_}$count",
95
"\$_ coordinate of $_ corner of selection bounds",
101
code => 'non_empty = gimp_channel_bounds (gimp_image_get_mask (gimage), &x1, &y1, &x2, &y2);'
56
non_empty = gimp_channel_bounds (gimp_image_get_mask (image),
115
@inargs = ( &std_image_arg );
116
&coord_args('$_', '$_ coordinate of value', \@inargs);
74
{ name => 'image', type => 'image',
75
desc => 'The image' },
76
{ name => 'x', type => 'int32',
77
desc => 'x coordinate of value' },
78
{ name => 'y', type => 'int32',
79
desc => 'y coordinate of value' }
119
83
{ name => 'value', type => '0 <= int32 <= 255',
120
desc => 'Value of the selection: (%%desc%%)',
121
alias => 'gimp_channel_value (gimp_image_get_mask (gimage), x, y)',
84
desc => 'Value of the selection' }
90
value = gimp_pickable_get_opacity_at (GIMP_PICKABLE (gimp_image_get_mask (image)), x, y);
127
97
$blurb = 'Determine whether the selection is empty.';
130
This procedure returns non-zero if the selection for the specified image is not
100
This procedure returns TRUE if the selection for the specified image is not
136
@inargs = ( &std_image_arg);
107
{ name => 'image', type => 'image',
108
desc => 'The image' }
139
112
{ name => 'is_empty', type => 'boolean',
140
desc => 'Is the selection empty?',
141
alias => 'gimp_channel_is_empty (gimp_image_get_mask (gimage))',
113
desc => 'Is the selection empty?' }
119
is_empty = gimp_channel_is_empty (gimp_image_get_mask (image));
158
@inargs = ( &std_image_arg );
159
&coord_args('off$_', '$_ offset for translation', \@inargs);
138
{ name => 'image', type => 'image',
139
desc => 'The image' },
140
{ name => 'offx', type => 'int32',
141
desc => 'x offset for translation' },
142
{ name => 'offy', type => 'int32',
143
desc => 'y offset for translation' }
161
%invoke = ( code => 'gimp_item_translate (GIMP_ITEM (gimp_image_get_mask (gimage)), offx, offy, TRUE);' );
149
gimp_item_translate (GIMP_ITEM (gimp_image_get_mask (image)),
164
156
sub selection_float {
180
172
{ name => 'drawable', type => 'drawable',
181
desc => 'The drawable from which to float selection' }
173
desc => 'The drawable from which to float selection' },
174
{ name => 'offx', type => 'int32',
175
desc => 'x offset for translation' },
176
{ name => 'offy', type => 'int32',
177
desc => 'y offset for translation' }
183
&coord_args('off$_', '$_ offset for translation', \@inargs);
186
181
{ name => 'layer', type => 'layer', wrap => 1,
187
desc => 'The floated layer', init => 1 }
182
desc => 'The floated layer' }
193
success = gimp_item_is_attached (GIMP_ITEM (drawable));
188
if (gimp_item_is_attached (GIMP_ITEM (drawable)))
197
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (drawable));
190
GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
199
layer = gimp_selection_float (gimp_image_get_mask (gimage),
192
layer = gimp_selection_float (gimp_image_get_mask (image),
200
193
drawable, context, TRUE, offx, offy);
209
204
sub selection_invert {
210
&selection_simple_proc('invert');
212
205
$blurb = 'Invert the selection mask.';
214
207
$help = <<'HELP';
215
208
This procedure inverts the selection mask. For every pixel in the selection
216
channel, its new value is calculated as (255 - old_value).
209
channel, its new value is calculated as (255 - old-value).
215
{ name => 'image', type => 'image',
216
desc => 'The image' }
222
gimp_channel_invert (gimp_image_get_mask (image), TRUE);
220
228
sub selection_sharpen {
221
&selection_simple_proc('sharpen');
223
229
$blurb = 'Sharpen the selection mask.';
225
231
$help = <<'HELP';
226
232
This procedure sharpens the selection mask. For every pixel in the selection
227
channel, if the value is > 0, the new pixel is assigned a value of 255. This
228
removes any "anti-aliasing" that might exist in the selection mask's boundary.
233
channel, if the value is > 127, the new pixel is assigned a value of 255.
234
This removes any "anti-aliasing" that might exist in the selection mask's
241
{ name => 'image', type => 'image',
242
desc => 'The image' }
248
gimp_channel_sharpen (gimp_image_get_mask (image), TRUE);
232
254
sub selection_all {
233
&selection_simple_proc('all');
235
255
$blurb = 'Select all of the image.';
237
257
$help = <<'HELP';
238
This procedure sets the selection mask to completely encompass the image. Every
239
pixel in the selection channel is set to 255.
258
This procedure sets the selection mask to completely encompass the image.
259
Every pixel in the selection channel is set to 255.
265
{ name => 'image', type => 'image',
266
desc => 'The image' }
272
gimp_channel_all (gimp_image_get_mask (image), TRUE);
243
278
sub selection_none {
253
@inargs = ( &std_image_arg );
289
{ name => 'image', type => 'image',
290
desc => 'The image' }
255
%invoke = ( code => "gimp_channel_clear (gimp_image_get_mask (gimage), NULL, TRUE);" );
296
gimp_channel_clear (gimp_image_get_mask (image), NULL, TRUE);
258
302
sub selection_feather {
259
&selection_change_proc('feather', 'radius', 'float', '');
261
$help .= 'Feathering is implemented using a gaussian blur.';
303
$blurb = "Feather the image's selection";
306
This procedure feathers the selection. Feathering is implemented
307
using a gaussian blur.
313
{ name => 'image', type => 'image',
314
desc => 'The image' },
315
{ name => 'radius', type => '0 <= float',
316
desc => 'Radius of feather (in pixels)' }
322
gimp_channel_feather (gimp_image_get_mask (image),
323
radius, radius, TRUE);
264
329
sub selection_border {
265
&selection_change_proc('border', 'radius', 'int32', '');
330
$blurb = "Border the image's selection";
267
332
$help .= <<'HELP';
268
Bordering creates a new selection which is defined along the boundary of the
269
previous selection at every point within the specified radius.
333
This procedure borders the selection. Bordering creates a new
334
selection which is defined along the boundary of the previous
335
selection at every point within the specified radius.
341
{ name => 'image', type => 'image',
342
desc => 'The image' },
343
{ name => 'radius', type => '0 <= int32',
344
desc => 'Radius of border (in pixels)' }
350
/* FIXME: "feather" and "edge-lock" hardcoded to TRUE */
351
gimp_channel_border (gimp_image_get_mask (image),
352
radius, radius, TRUE, TRUE, TRUE);
273
358
sub selection_grow {
274
&selection_change_proc('grow', 'steps', 'int32', '');
359
$blurb = "Grow the image's selection";
276
361
$help .= <<'HELP';
277
Growing involves expanding the boundary in all directions by the specified
362
This procedure grows the selection. Growing involves expanding the
363
boundary in all directions by the specified pixel amount.
369
{ name => 'image', type => 'image',
370
desc => 'The image' },
371
{ name => 'steps', type => '0 <= int32',
372
desc => 'Steps of grow (in pixels)' }
378
gimp_channel_grow (gimp_image_get_mask (image),
282
385
sub selection_shrink {
283
&selection_change_proc('shrink', 'radius', 'int32', ', FALSE');
386
$blurb = "Shrink the image's selection";
285
388
$help .= <<'HELP';
286
Shrinking invovles trimming the existing selection boundary on all sides by the
287
specified number of pixels.
389
This procedure shrinks the selection. Shrinking invovles trimming the
390
existing selection boundary on all sides by the specified number of
397
{ name => 'image', type => 'image',
398
desc => 'The image' },
399
{ name => 'steps', type => '0 <= int32',
400
desc => 'Steps of shrink (in pixels)' }
406
gimp_channel_shrink (gimp_image_get_mask (image),
407
steps, steps, FALSE, TRUE);
291
413
sub selection_layer_alpha {
333
@inargs = ( &channel_arg );
456
{ name => 'channel', type => 'channel',
457
desc => 'The channel' }
339
464
gint off_x, off_y;
341
gimage = gimp_item_get_image (GIMP_ITEM (channel));
466
image = gimp_item_get_image (GIMP_ITEM (channel));
342
467
gimp_item_offsets (GIMP_ITEM (channel), &off_x, &off_y);
344
gimp_channel_select_channel (gimp_image_get_mask (gimage),
469
gimp_channel_select_channel (gimp_image_get_mask (image),
345
470
_("Channel to Selection"),
348
473
GIMP_CHANNEL_OP_REPLACE,
349
474
FALSE, 0.0, 0.0);
364
@inargs = ( &channel_arg, &operation_arg );
490
{ name => 'channel', type => 'channel',
491
desc => 'The channel' },
492
{ name => 'operation', type => 'enum GimpChannelOps',
493
desc => 'The selection operation' }
370
500
gint off_x, off_y;
372
gimage = gimp_item_get_image (GIMP_ITEM (channel));
502
image = gimp_item_get_image (GIMP_ITEM (channel));
373
503
gimp_item_offsets (GIMP_ITEM (channel), &off_x, &off_y);
375
gimp_channel_select_channel (gimp_image_get_mask (gimage),
505
gimp_channel_select_channel (gimp_image_get_mask (image),
376
506
_("Channel to Selection"),
380
510
FALSE, 0.0, 0.0);
397
@inargs = ( &std_image_arg );
528
{ name => 'image', type => 'image',
529
desc => 'The image' }
400
533
{ name => 'channel', type => 'channel',
401
desc => 'The new channel', init => 1 }
534
desc => 'The new channel' }
405
538
headers => [qw("core/gimpselection.h") ],
406
code => 'success = (channel = gimp_selection_save (gimp_image_get_mask (gimage))) != NULL;'
541
channel = gimp_selection_save (gimp_image_get_mask (image));
410
@headers = qw("core/gimpchannel-select.h" "gimp-intl.h");
551
@headers = qw("core/gimpchannel-select.h" "core/gimppickable.h"
412
554
@procs = qw(selection_bounds selection_value selection_is_empty
413
555
selection_translate selection_float