~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to tools/pdbgen/pdb/selection.pdb

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# The GIMP -- an image manipulation program
 
1
# GIMP - The GNU Image Manipulation Program
2
2
# Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 
4
4
# This program is free software; you can redistribute it and/or modify
17
17
 
18
18
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
19
19
 
20
 
sub channel_arg () {{
21
 
    name => 'channel',
22
 
    type => 'channel',
23
 
    desc => 'The channel'
24
 
}}
25
 
 
26
 
sub operation_arg () {{
27
 
    name => 'operation',
28
 
    type => 'enum GimpChannelOps',
29
 
    desc => 'The selection operation: { %%desc%% }'
30
 
}}
31
 
 
32
 
sub coord_args {
33
 
    my ($name, $desc, $args) = @_;
34
 
    foreach (qw(x y)) {
35
 
        push @$args, { name => eval qq/"$name"/, type => 'int32',
36
 
                       desc => eval qq/"$desc"/ }
37
 
    }
38
 
}
39
 
 
40
 
sub selection_simple_proc {
41
 
    my $op = shift;
42
 
 
43
 
    &std_pdb_misc;
44
 
 
45
 
    @inargs = ( &std_image_arg );
46
 
 
47
 
    %invoke = ( code => "gimp_channel_$op (gimp_image_get_mask (gimage), TRUE);" );
48
 
}
49
 
 
50
 
sub selection_change_proc {
51
 
    my ($op, $arg, $type, $edge_lock) = @_;
52
 
 
53
 
    $blurb = "\u$op the image's selection";
54
 
 
55
 
    $help = "This procedure ${op}s the selection. ";
56
 
 
57
 
    &std_pdb_misc;
58
 
 
59
 
    @inargs = (
60
 
        &std_image_arg,
61
 
        { name => $arg, type => "0 <= $type",
62
 
          desc => "\u$arg of $op (in pixels)" }
63
 
    );
64
 
 
65
 
    %invoke = ( code => "gimp_channel_$op (gimp_image_get_mask (gimage), $arg, $arg$edge_lock, TRUE);" );
66
 
}
67
 
 
68
 
# The defs
69
 
 
70
20
sub selection_bounds {
71
21
    $blurb = 'Find the bounding box of the current selection.';
72
22
 
82
32
 
83
33
    &std_pdb_misc;
84
34
 
85
 
    @inargs = ( &std_image_arg );
 
35
    @inargs = (
 
36
        { name => 'image', type => 'image',
 
37
          desc => 'The image' }
 
38
    );
86
39
 
87
40
    @outargs = (
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' }
90
51
    );
91
52
 
92
 
    my $count = 1;
93
 
    foreach ('upper left', 'lower right') {
94
 
        &coord_args("\${_}$count",
95
 
                    "\$_ coordinate of $_ corner of selection bounds",
96
 
                    \@outargs);
97
 
        $count++;
98
 
    }
99
 
 
100
53
    %invoke = (
101
 
        code => 'non_empty = gimp_channel_bounds (gimp_image_get_mask (gimage), &x1, &y1, &x2, &y2);'
 
54
        code => <<'CODE'
 
55
{
 
56
  non_empty = gimp_channel_bounds (gimp_image_get_mask (image),
 
57
                                   &x1, &y1, &x2, &y2);
 
58
}
 
59
CODE
102
60
    );
103
61
}
104
62
 
112
70
 
113
71
    &std_pdb_misc;
114
72
 
115
 
    @inargs = ( &std_image_arg );
116
 
    &coord_args('$_', '$_ coordinate of value', \@inargs);
 
73
    @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' }
 
80
    );
117
81
 
118
82
    @outargs = (
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)',
122
 
          no_declare => 1 }
 
84
          desc => 'Value of the selection' }
 
85
    );
 
86
 
 
87
    %invoke = (
 
88
        code => <<'CODE'
 
89
{
 
90
  value = gimp_pickable_get_opacity_at (GIMP_PICKABLE (gimp_image_get_mask (image)), x, y);
 
91
}
 
92
CODE
123
93
    );
124
94
}
125
95
 
127
97
    $blurb = 'Determine whether the selection is empty.';
128
98
 
129
99
    $help = <<'HELP';
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
131
101
empty.
132
102
HELP
133
103
 
134
104
    &std_pdb_misc;
135
105
 
136
 
    @inargs = ( &std_image_arg);
 
106
    @inargs = (
 
107
        { name => 'image', type => 'image',
 
108
          desc => 'The image' }
 
109
    );
137
110
 
138
111
    @outargs = (
139
112
        { name => 'is_empty', type => 'boolean',
140
 
          desc => 'Is the selection empty?',
141
 
          alias => 'gimp_channel_is_empty (gimp_image_get_mask (gimage))',
142
 
          no_declare => 1 }
 
113
          desc => 'Is the selection empty?' }
 
114
    );
 
115
 
 
116
    %invoke = (
 
117
        code => <<'CODE'
 
118
{
 
119
  is_empty = gimp_channel_is_empty (gimp_image_get_mask (image));
 
120
}
 
121
CODE
143
122
    );
144
123
}
145
124
 
155
134
 
156
135
    &std_pdb_misc;
157
136
 
158
 
    @inargs = ( &std_image_arg );
159
 
    &coord_args('off$_', '$_ offset for translation', \@inargs);
 
137
    @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' }
 
144
    );
160
145
 
161
 
    %invoke = ( code => 'gimp_item_translate (GIMP_ITEM (gimp_image_get_mask (gimage)), offx, offy, TRUE);' );
 
146
    %invoke = (
 
147
        code => <<'CODE'
 
148
{
 
149
  gimp_item_translate (GIMP_ITEM (gimp_image_get_mask (image)),
 
150
                       offx, offy, TRUE);
 
151
}
 
152
CODE
 
153
    );
162
154
}
163
155
 
164
156
sub selection_float {
178
170
 
179
171
    @inargs = (
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' }
182
178
    );
183
 
    &coord_args('off$_', '$_ offset for translation', \@inargs);
184
179
 
185
180
    @outargs = (
186
181
        { name => 'layer', type => 'layer', wrap => 1,
187
 
          desc => 'The floated layer', init => 1 }
 
182
          desc => 'The floated layer' }
188
183
    );
189
184
 
190
185
    %invoke = (
191
186
        code => <<'CODE'
192
187
{
193
 
  success = gimp_item_is_attached (GIMP_ITEM (drawable));
194
 
 
195
 
  if (success)
 
188
  if (gimp_item_is_attached (GIMP_ITEM (drawable)))
196
189
    {
197
 
      GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (drawable));
 
190
      GimpImage *image = gimp_item_get_image (GIMP_ITEM (drawable));
198
191
 
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);
201
194
      if (! layer)
202
195
        success = FALSE;
203
196
    }
 
197
  else
 
198
    success = FALSE;
204
199
}
205
200
CODE
206
201
    );
207
202
}
208
203
 
209
204
sub selection_invert {
210
 
    &selection_simple_proc('invert');
211
 
 
212
205
    $blurb = 'Invert the selection mask.';
213
206
 
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).
217
210
HELP
 
211
 
 
212
    &std_pdb_misc;
 
213
 
 
214
    @inargs = (
 
215
        { name => 'image', type => 'image',
 
216
          desc => 'The image' }
 
217
    );
 
218
 
 
219
    %invoke = (
 
220
        code => <<'CODE'
 
221
{
 
222
  gimp_channel_invert (gimp_image_get_mask (image), TRUE);
 
223
}
 
224
CODE
 
225
    );
218
226
}
219
227
 
220
228
sub selection_sharpen {
221
 
    &selection_simple_proc('sharpen');
222
 
 
223
229
    $blurb = 'Sharpen the selection mask.';
224
230
 
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
 
235
boundary.
229
236
HELP
 
237
 
 
238
    &std_pdb_misc;
 
239
 
 
240
    @inargs = (
 
241
        { name => 'image', type => 'image',
 
242
          desc => 'The image' }
 
243
    );
 
244
 
 
245
    %invoke = (
 
246
        code => <<'CODE'
 
247
{
 
248
  gimp_channel_sharpen (gimp_image_get_mask (image), TRUE);
 
249
}
 
250
CODE
 
251
    );
230
252
}
231
253
 
232
254
sub selection_all {
233
 
    &selection_simple_proc('all');
234
 
 
235
255
    $blurb = 'Select all of the image.';
236
256
 
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.
240
260
HELP
 
261
 
 
262
    &std_pdb_misc;
 
263
 
 
264
    @inargs = (
 
265
        { name => 'image', type => 'image',
 
266
          desc => 'The image' }
 
267
    );
 
268
 
 
269
    %invoke = (
 
270
        code => <<'CODE'
 
271
{
 
272
  gimp_channel_all (gimp_image_get_mask (image), TRUE);
 
273
}
 
274
CODE
 
275
    );
241
276
}
242
277
 
243
278
sub selection_none {
250
285
 
251
286
    &std_pdb_misc;
252
287
 
253
 
    @inargs = ( &std_image_arg );
 
288
    @inargs = (
 
289
        { name => 'image', type => 'image',
 
290
          desc => 'The image' }
 
291
    );
254
292
 
255
 
    %invoke = ( code => "gimp_channel_clear (gimp_image_get_mask (gimage), NULL, TRUE);" );
 
293
    %invoke = (
 
294
        code => <<'CODE'
 
295
{
 
296
  gimp_channel_clear (gimp_image_get_mask (image), NULL, TRUE);
 
297
}
 
298
CODE
 
299
    );
256
300
}
257
301
 
258
302
sub selection_feather {
259
 
    &selection_change_proc('feather', 'radius', 'float', '');
260
 
 
261
 
    $help .= 'Feathering is implemented using a gaussian blur.';
 
303
    $blurb = "Feather the image's selection";
 
304
 
 
305
    $help = <<'HELP';
 
306
This procedure feathers the selection. Feathering is implemented
 
307
using a gaussian blur.
 
308
HELP
 
309
 
 
310
    &std_pdb_misc;
 
311
 
 
312
    @inargs = (
 
313
        { name => 'image', type => 'image',
 
314
          desc => 'The image' },
 
315
        { name => 'radius', type => '0 <= float',
 
316
          desc => 'Radius of feather (in pixels)' }
 
317
    );
 
318
 
 
319
    %invoke = (
 
320
        code => <<'CODE'
 
321
{
 
322
  gimp_channel_feather (gimp_image_get_mask (image),
 
323
                        radius, radius, TRUE);
 
324
}
 
325
CODE
 
326
    );
262
327
}
263
328
 
264
329
sub selection_border {
265
 
    &selection_change_proc('border', 'radius', 'int32', '');
 
330
    $blurb = "Border the image's selection";
266
331
 
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.
270
336
HELP
 
337
 
 
338
    &std_pdb_misc;
 
339
 
 
340
    @inargs = (
 
341
        { name => 'image', type => 'image',
 
342
          desc => 'The image' },
 
343
        { name => 'radius', type => '0 <= int32',
 
344
          desc => 'Radius of border (in pixels)' }
 
345
    );
 
346
 
 
347
    %invoke = (
 
348
        code => <<'CODE'
 
349
{
 
350
  /* FIXME: "feather" and "edge-lock" hardcoded to TRUE */
 
351
  gimp_channel_border (gimp_image_get_mask (image),
 
352
                       radius, radius, TRUE, TRUE, TRUE);
 
353
}
 
354
CODE
 
355
    );
271
356
}
272
357
 
273
358
sub selection_grow {
274
 
    &selection_change_proc('grow', 'steps', 'int32', '');
 
359
    $blurb = "Grow the image's selection";
275
360
 
276
361
    $help .= <<'HELP';
277
 
Growing involves expanding the boundary in all directions by the specified
278
 
pixel amount.
 
362
This procedure grows the selection. Growing involves expanding the
 
363
boundary in all directions by the specified pixel amount.
279
364
HELP
 
365
 
 
366
    &std_pdb_misc;
 
367
 
 
368
    @inargs = (
 
369
        { name => 'image', type => 'image',
 
370
          desc => 'The image' },
 
371
        { name => 'steps', type => '0 <= int32',
 
372
          desc => 'Steps of grow (in pixels)' }
 
373
    );
 
374
 
 
375
    %invoke = (
 
376
        code => <<'CODE'
 
377
{
 
378
  gimp_channel_grow (gimp_image_get_mask (image),
 
379
                     steps, steps, TRUE);
 
380
}
 
381
CODE
 
382
    );
280
383
}
281
384
 
282
385
sub selection_shrink {
283
 
    &selection_change_proc('shrink', 'radius', 'int32', ', FALSE');
 
386
    $blurb = "Shrink the image's selection";
284
387
 
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
 
391
pixels.
288
392
HELP
 
393
 
 
394
    &std_pdb_misc;
 
395
 
 
396
    @inargs = (
 
397
        { name => 'image', type => 'image',
 
398
          desc => 'The image' },
 
399
        { name => 'steps', type => '0 <= int32',
 
400
          desc => 'Steps of shrink (in pixels)' }
 
401
    );
 
402
 
 
403
    %invoke = (
 
404
        code => <<'CODE'
 
405
{
 
406
  gimp_channel_shrink (gimp_image_get_mask (image),
 
407
                       steps, steps, FALSE, TRUE);
 
408
}
 
409
CODE
 
410
    );
289
411
}
290
412
 
291
413
sub selection_layer_alpha {
309
431
    );
310
432
 
311
433
    %invoke = (
312
 
        vars => [ 'GimpImage *gimage' ],
313
434
        code => <<'CODE'
314
435
{
315
 
  gimage = gimp_item_get_image (GIMP_ITEM (layer));
316
 
  gimp_channel_select_alpha (gimp_image_get_mask (gimage),
 
436
  GimpImage *image = gimp_item_get_image (GIMP_ITEM (layer));
 
437
 
 
438
  gimp_channel_select_alpha (gimp_image_get_mask (image),
317
439
                             GIMP_DRAWABLE (layer),
318
440
                             GIMP_CHANNEL_OP_REPLACE, FALSE, 0.0, 0.0);
319
441
}
330
452
 
331
453
    &std_pdb_misc;
332
454
 
333
 
    @inargs = ( &channel_arg );
 
455
    @inargs = (
 
456
        { name => 'channel', type => 'channel',
 
457
          desc => 'The channel' }
 
458
    );
334
459
 
335
460
    %invoke = (
336
461
        code => <<'CODE'
337
462
{
338
 
  GimpImage *gimage;
 
463
  GimpImage *image;
339
464
  gint       off_x, off_y;
340
465
 
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);
343
468
 
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"),
346
 
                               channel, 
 
471
                               channel,
347
472
                               off_x, off_y,
348
473
                               GIMP_CHANNEL_OP_REPLACE,
349
474
                               FALSE, 0.0, 0.0);
361
486
 
362
487
    &std_pdb_misc;
363
488
 
364
 
    @inargs = ( &channel_arg, &operation_arg );
365
 
               
 
489
    @inargs = (
 
490
        { name => 'channel', type => 'channel',
 
491
          desc => 'The channel' },
 
492
        { name => 'operation', type => 'enum GimpChannelOps',
 
493
          desc => 'The selection operation' }
 
494
    );
 
495
 
366
496
    %invoke = (
367
497
        code => <<'CODE'
368
498
{
369
 
  GimpImage *gimage;
 
499
  GimpImage *image;
370
500
  gint       off_x, off_y;
371
501
 
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);
374
504
 
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"),
377
 
                               channel, 
 
507
                               channel,
378
508
                               off_x, off_y,
379
509
                               operation,
380
510
                               FALSE, 0.0, 0.0);
394
524
 
395
525
    &std_pdb_misc;
396
526
 
397
 
    @inargs = ( &std_image_arg );
 
527
    @inargs = (
 
528
        { name => 'image', type => 'image',
 
529
          desc => 'The image' }
 
530
    );
398
531
 
399
532
    @outargs = (
400
533
        { name => 'channel', type => 'channel',
401
 
          desc => 'The new channel', init => 1 }
 
534
          desc => 'The new channel' }
402
535
    );
403
536
 
404
537
    %invoke = (
405
538
        headers => [qw("core/gimpselection.h") ],
406
 
        code => 'success = (channel = gimp_selection_save (gimp_image_get_mask (gimage))) != NULL;'
 
539
        code    => <<'CODE'
 
540
{
 
541
  channel = gimp_selection_save (gimp_image_get_mask (image));
 
542
 
 
543
  if (! channel)
 
544
    success = FALSE;
 
545
}
 
546
CODE
407
547
    );
408
548
}
409
549
 
410
 
@headers = qw("core/gimpchannel-select.h" "gimp-intl.h");
 
550
 
 
551
@headers = qw("core/gimpchannel-select.h" "core/gimppickable.h"
 
552
              "gimp-intl.h");
411
553
 
412
554
@procs = qw(selection_bounds selection_value selection_is_empty
413
555
            selection_translate selection_float
415
557
            selection_feather selection_border selection_grow selection_shrink
416
558
            selection_layer_alpha selection_load selection_save
417
559
            selection_combine);
 
560
 
418
561
%exports = (app => [@procs], lib => [@procs]);
419
562
 
420
563
$desc = 'Image mask';