image.pdb 41.8 KB
Newer Older
Manish Singh's avatar
Stuff    
Manish Singh committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# The GIMP -- an image manipulation program
# Copyright (C) 1995 Spencer Kimball and Peter Mattis

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# "Perlized" from C source by Manish Singh <yosh@gimp.org>

sub layer_arg () {{
    name => 'layer',
    type => 'layer',
    desc => 'The layer'
}}

sub channel_arg () {{
    name => 'channel',
    type => 'channel',
    desc => 'The channel'
}}

sub new_dim_args {
    foreach (qw(width height)) {
34
35
	push @inargs, { name => "new_$_",
                        type => '0 < int32',
Manish Singh's avatar
Stuff    
Manish Singh committed
36
37
38
39
40
41
42
43
44
45
			desc => "New image $_: %%desc%%" }
    }
}

sub image_list_proc {
    my $type = shift;

    $blurb = "Returns the list of ${type}s contained in the specified image.";

    $help = <<HELP;
46
This procedure returns the list of ${type}s contained in the specified image.
Manish Singh's avatar
Stuff    
Manish Singh committed
47
48
49
HELP

    &std_pdb_misc;
50

Manish Singh's avatar
Stuff    
Manish Singh committed
51
52
53
54
55
56
57
58
59
60
    @inargs = ( &std_image_arg );

    @outargs = (
	{ name => "${type}_ids", type => 'int32array', init => 1,
	  desc => "The list of ${type}s contained in the image",
	  array => { name => "num_${type}s", init => 1,
		     desc => "The number of ${type}s contained in the image" } }
    );

    %invoke = (
61
	vars => [ 'GList *list = NULL', 'gint i' ],
Manish Singh's avatar
Stuff    
Manish Singh committed
62
63
	code => <<CODE
{
64
65
  list = GIMP_LIST (gimage->${type}s)->list;
  num_${type}s = g_list_length (list);
Manish Singh's avatar
Stuff    
Manish Singh committed
66
67
68
69

  if (num_${type}s)
    {
      ${type}_ids = g_new (gint32, num_${type}s);
70
      for (i = 0; i < num_${type}s; i++, list = g_list_next (list))
71
	${type}_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data));
Manish Singh's avatar
Stuff    
Manish Singh committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
    }
}
CODE
    );
}

sub type_move {
    my ($type, $op, $pos) = @_;
    my $extra = "";

    if ($op =~ /_/) {
	($op, $extra) = $op =~ /([^_]+)_(.*)/;
	$extra =~ s/_/ /g;
    }

    my $layer = "";
    $layer = ', or the layer has no alpha channel' if $type eq 'layer';

Manish Singh's avatar
Manish Singh committed
90
    $blurb = "\u$op the specified $type in the image's $type stack";
Manish Singh's avatar
Stuff    
Manish Singh committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    $blurb .= " $extra of stack" if $extra;

    $help = <<HELP;
This procedure ${op}s the specified $type one step in the existing $type stack.
It will not move the $type if there is no $type $pos it$layer.
HELP
    $help =~ s/one step in/"$extra of"/e if $extra;

    @inargs = (
	&std_image_arg,
	&{"${type}_arg"}
    );
    $inargs[1]->{desc} .= " to $op $extra";

    if ($extra) {
	$extra =~ s/ /_/g;
	$extra = "_$extra";
    }

    %invoke = (
111
	code => "success = gimp_image_${op}_$type$extra (gimage, $type);"
Manish Singh's avatar
Stuff    
Manish Singh committed
112
113
114
115
116
117
    );
}

sub image_get_prop_proc {
    my ($prop, $type, $desc, $func) = @_;

118
119
120
121
122
123
124
    if ($desc =~ /\bis\b/) {
	$blurb = "Returns if the specified image's $desc.";
	$help = "This procedure returns if the specified image's $desc. ";
    } else {
	$blurb = "Returns the specified image's $desc.";
	$help = "This procedure returns the specified image's $desc. ";
    }
Manish Singh's avatar
Stuff    
Manish Singh committed
125
126
127
128
129
130
131
132
133
134

    &std_pdb_misc;

    @inargs = ( &std_image_arg );

    @outargs = (
	{ name => $prop, type => $type,
	  desc => "The $desc", no_declare => 1 }
    );

135
    my $alias = $func ? "gimp_image_get_$prop (gimage)" : "gimage->$prop";
Manish Singh's avatar
Stuff    
Manish Singh committed
136
137
138
139
140
141
142
    $alias = "g_strdup ($alias)" if $type eq 'string';
    $outargs[0]->{alias} .= "$alias";
}

sub image_set_prop_proc {
    my ($prop, $type, $desc, $func) = @_;

143
144
145
146
147
148
149
    if ($desc =~ /\bis\b/) {
	$blurb = "Sets if the specified image's $desc.";
	$help = "This procedure sets if the specified image's $desc. ";
    } else {
	$blurb = "Sets the specified image's $desc.";
	$help = "This procedure sets the specified image's $desc. ";
    }
Manish Singh's avatar
Stuff    
Manish Singh committed
150
151
152
153
154
155
156
157
158
159
160
161
162

    &std_pdb_misc;

    @inargs = (
	&std_image_arg,
	{ name => $prop, type => $type,
	  desc => "The new image $desc" }
    );

    if ($type =~ /float/) {
	$inargs[1]->{desc} .= ' (%%desc%%)';
    }

163
    $invoke{code} = $func ? "gimp_image_set_$prop (gimage, $prop);"
Manish Singh's avatar
Stuff    
Manish Singh committed
164
165
166
167
168
169
170
171
172
173
			  : "gimage->$prop = $prop;";
}

sub image_accessors {
    my ($prop, $type, $desc, $func, $extra) = @_;
    my (@extra, %extra); my $once = 0;

    ref($extra) ? (@extra = @$extra) : (@extra = ($extra, $extra));
    %extra = map { $once++ ? 'set' : 'get', $_ ? $_ : "" } @extra;

Manish Singh's avatar
Manish Singh committed
174
    foreach (sort keys %extra) {
Manish Singh's avatar
Stuff    
Manish Singh committed
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
	my $proc = "image_${_}_$prop";

	push @procs, $proc;

	eval <<SUB;
sub @{[ scalar caller ]}::$proc {
    \&image_${_}_prop_proc('$prop', '$type', '$desc', $func);
    $extra{$_}
}
SUB
    }
}

# The defs

Marc Lehmann's avatar
Marc Lehmann committed
190
sub image_list {
Manish Singh's avatar
Stuff    
Manish Singh committed
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
    $blurb = 'Returns the list of images currently open.';

    $help = <<'HELP';
This procedure returns the list of images currently open in the GIMP.
HELP

    &image_list_proc('image');

    undef @inargs;

    foreach ($blurb, $help, $outargs[0]->{desc}, $outargs[0]->{array}->{desc}) {
	s/contained.*/currently open/
    }

    $blurb .= '.';
    $help  .= ' in the GIMP.';

    for ($invoke{code}) {
209
	s/gimage->images/gimp->images/;
210
211
	s/ITEM/IMAGE/;
	s/gimp_item_get_ID/gimp_image_get_ID/;
Manish Singh's avatar
Stuff    
Manish Singh committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
    }
}

sub image_new {
    $blurb = 'Creates a new image with the specified width, height, and type.';

    $help = <<'HELP';
Creates a new image, undisplayed with the specified extents and type. A layer
should be created and added before this image is displayed, or subsequent calls
to 'gimp_display_new' with this image as an argument will fail. Layers can be
created using the 'gimp_layer_new' commands. They can be added to an image
using the 'gimp_image_add_layer' command.
HELP

    &std_pdb_misc;

    @inargs = (
	{ name => 'type', type => 'enum GimpImageBaseType',
	  desc => 'The type of image: { %%desc%% }' }
    );

    foreach (qw(height width)) {
	unshift @inargs, { name => $_, type => '0 < int32',
			   desc => "The $_ of the image" }
    }

    @outargs = (
239
	{ name => 'image', type => 'image', init => 1,
Manish Singh's avatar
Stuff    
Manish Singh committed
240
241
242
243
244
	  desc => 'The ID of the newly created image' }
    );

    %invoke = (
	code => <<'CODE'
245
246
247
248
{
  image = gimp_create_image (gimp, width, height, type, FALSE);
  success = (image != NULL);
}
Manish Singh's avatar
Stuff    
Manish Singh committed
249
250
251
252
CODE
    );
}

253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
sub image_duplicate {
    $blurb = 'Duplicate the specified image';

    $help = <<'HELP';
This procedure duplicates the specified image, copying all layers, channels,
and image information.
HELP

    &std_pdb_misc;
    $date = '1997';

    @inargs = ( &std_image_arg );

    @outargs = (
	{ name => 'new_image', type => 'image',
	  desc => 'The new, duplicated image', init => 1 }
    );

    %invoke = (
	headers => [ qw("core/gimpimage-duplicate.h") ],
        code => <<'CODE'
success = (new_image = gimp_image_duplicate (gimage)) != NULL;
CODE
    );
}

sub image_delete {
    $blurb = 'Delete the specified image.';

    $help = <<'HELP';
If there are no displays associated with this image it will be deleted.
This means that you can not delete an image through the PDB that was
created by the user. If the associated display was however created
through the PDB and you know the display ID, you may delete the display.
Removal of the last associated display will then delete the image.
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );

    %invoke = ( code => <<'CODE' );
{
  if (gimage->disp_count == 0)
    g_object_unref (gimage);
  else
    success = FALSE;
}
CODE
}

Manish Singh's avatar
Stuff    
Manish Singh committed
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
sub image_resize {
    $blurb = 'Resize the image to the specified extents.';

    $help = <<'HELP';
This procedure resizes the image so that it's new width and height are equal to
the supplied parameters. Offsets are also provided which describe the position
of the previous image's content. No bounds checking is currently provided, so
don't supply parameters that are out of bounds. All channels within the image
are resized according to the specified parameters; this includes the image
selection mask. All layers within the image are repositioned according to the
specified offsets.
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );
    &new_dim_args;

    foreach (qw(x y)) {
	push @inargs, { name => "off$_", type => 'int32',
			desc => "$_ offset between upper left corner of old and
				 new images: (new - old)" }
    }

    %invoke = (
329
	headers => [ qw("core/gimpimage-resize.h") ],
Manish Singh's avatar
Stuff    
Manish Singh committed
330
331
	code => <<'CODE'
{
332
  gimp_image_resize (gimage, context,
333
                     new_width, new_height, offx, offy, NULL);
Manish Singh's avatar
Stuff    
Manish Singh committed
334
335
336
337
338
}
CODE
    );
}

339
340
341
342
sub image_resize_to_layers {
    $blurb = 'Resize the image to fit all layers.';

    $help = <<'HELP';
343
This procedure resizes the image to the bounding box of all layers of the
344
345
346
347
348
349
350
image. All channels within the image are resized to the new size; this includes
the image selection mask. All layers within the image are repositioned to the
new image area.
HELP

    $author = $copyright = 'Simon Budig';
    $date = '2004';
351
352
    
    $since = '2.2';
353
354
355
356
357
358
359
360
361
362
363
364
365

    @inargs = ( &std_image_arg );

    %invoke = (
	headers => [ qw("core/gimpimage-resize.h") ],
	code => <<'CODE'
{
  gimp_image_resize_to_layers (gimage, context, NULL);
}
CODE
    );
}

Manish Singh's avatar
Stuff    
Manish Singh committed
366
367
368
369
sub image_scale {
    $blurb = 'Scale the image to the specified extents.';

    $help = <<'HELP';
370
This procedure scales the image so that its new width and height are equal to
Manish Singh's avatar
Stuff    
Manish Singh committed
371
372
373
374
375
376
377
378
379
380
381
382
383
384
the supplied parameters. Offsets are also provided which describe the position
of the previous image's content. No bounds checking is currently provided, so
don't supply parameters that are out of bounds. All channels within the image
are scaled according to the specified parameters; this includes the image
selection mask. All layers within the image are repositioned according to the
specified offsets.
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );
    &new_dim_args;

    %invoke = (
385
	headers => [ qw("config/gimpcoreconfig.h" "core/gimpimage-scale.h") ],
Manish Singh's avatar
Stuff    
Manish Singh committed
386
387
	code => <<'CODE'
{
388
389
  gimp_image_scale (gimage, new_width, new_height,
                    gimp->config->interpolation_type,
390
                    NULL);
Manish Singh's avatar
Stuff    
Manish Singh committed
391
392
393
394
395
}
CODE
    );
}

396
397
398
399
400
401
sub image_crop {
    $blurb = 'Crop the image to the specified extents.';

    $help = <<'HELP';
This procedure crops the image so that it's new width and height are equal to
the supplied parameters. Offsets are also provided which describe the position
402
of the previous image's content. All channels and layers within the image are
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
cropped to the new image extents; this includes the image selection mask. If
any parameters are out of range, an error is returned.
HELP

    &std_pdb_misc;

    @inargs = (
	&std_image_arg,
	{ name => 'new_width', type => '0 < int32',
	  desc => 'New image width: (0 < new_width <= width)' },
	{ name => 'new_height', type => '0 < int32',
	  desc => 'New image height: (0 < new_height <= height)' },
	{ name => 'offx', type => '0 <= int32',
	  desc => 'x offset: (0 <= offx <= (width - new_width))' },
	{ name => 'offy', type => '0 <= int32',
	  desc => 'y offset: (0 <= offy <= (height - new_height))' }
    );

    %invoke = (
	headers => [ qw("core/gimpimage-crop.h") ],
	code => <<'CODE'
{
425
426
427
  if (new_width  > gimage->width          ||
      new_height > gimage->height         ||
      offx > (gimage->width  - new_width) ||
428
429
430
      offy > (gimage->height - new_height))
    success = FALSE;
  else
431
432
    gimp_image_crop (gimage, context,
                     offx, offy, offx + new_width, offy + new_height,
433
434
435
436
437
438
		     FALSE, TRUE);
}
CODE
    );
}

439
440
441
442
sub image_flip {
    $blurb = 'Flips the image horizontally or vertically.';

    $help = <<'HELP';
443
This procedure flips (mirrors) the image.
444
445
446
447
448
449
450
451
452
453
454
455
456
457
HELP

    &std_pdb_misc;

    @inargs = (
        &std_image_arg,
	{ name => 'flip_type', type => &std_orientation_enum,
	  desc => 'Type of flip: %%desc%%' }
    );

    %invoke = (
	headers => [ qw("core/gimpimage-flip.h") ],
	code => <<'CODE'
{
458
  gimp_image_flip (gimage, context, flip_type, NULL);
459
460
461
462
463
}
CODE
    );
}

464
sub image_rotate {
465
    $blurb = 'Rotates the image by the specified degrees.';
466
467
468
469
470
471
472
473
474
475
476
477
478
479
    $help = 'This procedure rotates the image.';
    $author = $copyright = 'Michael Natterer';
    $date = '2003';

    @inargs = (
        &std_image_arg,
	{ name => 'rotate_type', type => 'enum GimpRotationType',
	  desc => 'Angle of rotation: %%desc%%' }
    );

    %invoke = (
	headers => [ qw("core/gimpimage-rotate.h") ],
	code => <<'CODE'
{
480
  gimp_image_rotate (gimage, context, rotate_type, NULL);
481
482
483
484
485
}
CODE
    );
}

Manish Singh's avatar
Stuff    
Manish Singh committed
486
487
488
489
490
491
492
493
494
495
496
497
498
sub image_free_shadow {
    $blurb = "Free the specified image's shadow data (if it exists).";

    $help = <<'HELP';
This procedure is intended as a memory saving device. If any shadow memory has
been allocated, it will be freed automatically on a call to
'gimp_image_delete'.
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );

499
    %invoke = ( code => 'gimp_image_free_shadow (gimage);' );
Manish Singh's avatar
Stuff    
Manish Singh committed
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
}

sub image_get_layers {
    &image_list_proc('layer');

    $help .= 'The order of layers is from topmost to bottommost.';
}

sub image_get_channels {
    &image_list_proc('channel');

    $help .= <<'HELP';
This does not include the selection mask, or layer masks. The order is from
topmost to bottommost.
HELP
}

517
518
519
520
521
522
sub image_get_vectors {
    &image_list_proc('vector');

    $since = '2.4';
}

Manish Singh's avatar
Stuff    
Manish Singh committed
523
524
525
526
527
528
529
530
531
532
533
534
535
sub image_unset_active_channel {
    $blurb = 'Unsets the active channel in the specified image.';

    $help = <<'HELP';
If an active channel exists, it is unset. There then exists no active channel,
and if desired, one can be set through a call to 'Set Active Channel'. No error
is returned in the case of no existing active channel.
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );

536
    %invoke = ( code => 'gimp_image_unset_active_channel (gimage);' );
Manish Singh's avatar
Stuff    
Manish Singh committed
537
538
}

539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
sub image_pick_color {
    $blurb = <<'BLURB';
Determine the color at the given drawable coordinates
BLURB

    $help = <<'HELP';
This tool determines the color at the specified coordinates. The
returned color is an RGB triplet even for grayscale and indexed
drawables. If the coordinates lie outside of the extents of the
specified drawable, then an error is returned. If the drawable has an
alpha channel, the algorithm examines the alpha value of the drawable
at the coordinates. If the alpha value is completely transparent (0),
then an error is returned. If the sample_merged parameter is non-zero,
the data of the composite image will be used instead of that for the
specified drawable. This is equivalent to sampling for colors after
merging all visible layers. In the case of a merged sampling, the
supplied drawable is ignored except for finding the image it belongs
to.
HELP

    &std_pdb_misc;

    @inargs = (
	&std_image_arg,
	{ name => 'drawable', type => 'drawable',
          desc => 'The drawable to pick from' },
	{ name => 'x', type => 'float',
	  desc => 'x coordinate of upper-left corner of rectangle' },
	{ name => 'y', type => 'float',
	  desc => 'y coordinate of upper-left corner of rectangle' },
	{ name => 'sample_merged', type => 'boolean',
          desc => 'Use the composite image, not the drawable' },
	{ name => 'sample_average', type => 'boolean',
	  desc => 'Average the color of all the pixels in a specified
		   radius' },
	{ name => 'average_radius', type => '0 < float',
	  desc => 'The radius of pixels to average',
	  cond => [ 'sample_average' ] }
    );
    $inargs[1]->{no_success} = 1;

    @outargs = (
	{ name => 'color', type => 'color', void_ret => 1,
	  desc => 'The return color', init => 1 }
    );

    %invoke = (
	headers => [ qw("core/gimpimage-pick-color.h") ],
	code => <<'CODE'
{
  if (!sample_merged)
    if (!drawable || (gimp_item_get_image (GIMP_ITEM (drawable)) != gimage))
      success = FALSE;

  if (success)
    success = gimp_image_pick_color (gimage,
                                     drawable,
                                     (gint) x, (gint) y,
			             sample_merged,
                                     sample_average,
                                     average_radius,
                                     NULL,
                                     &color,
                                     NULL);
}
CODE
    );
}

Manish Singh's avatar
Stuff    
Manish Singh committed
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
sub image_pick_correlate_layer {
    $blurb = 'Find the layer visible at the specified coordinates.';

    $help = <<'HELP';
This procedure finds the layer which is visible at the specified coordinates.
Layers which do not qualify are those whose extents do not pass within the
specified coordinates, or which are transparent at the specified coordinates.
This procedure will return -1 if no layer is found.
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );
    foreach (qw(x y)) {
	push @inargs, { name => $_, type => 'int32',
			desc => "The $_ coordinate for the pick" }
    }

    @outargs = (
	{ name => 'layer', type => 'layer', init => 1,
	  desc => 'The layer found at the specified coordinates' }
    );

    %invoke = (
632
	code => 'layer = gimp_image_pick_correlate_layer (gimage, x, y);'
Manish Singh's avatar
Stuff    
Manish Singh committed
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
    );
}

sub image_raise_layer {
    &type_move('layer', 'raise', 'above');
    &std_pdb_misc;
}

sub image_lower_layer {
    &type_move('layer', 'lower', 'below');
    &std_pdb_misc;
}

sub image_raise_layer_to_top {
    &type_move('layer', 'raise_to_top', 'above');
    $copyright = "Wolfgang Hofer";
    $author = $copyright . ", Sven Neumann";
    $date = 1998;
}

sub image_lower_layer_to_bottom {
    &type_move('layer', 'lower_to_bottom', 'below');
    $copyright = "Wolfgang Hofer";
    $author = $copyright . ", Sven Neumann";
    $date = 1998;
}

sub image_merge_visible_layers {
    $blurb = 'Merge the visible image layers into one.';

    $help = <<'HELP';
This procedure combines the visible layers into a single layer using the
specified merge type. A merge type of EXPAND_AS_NECESSARY expands the final
layer to encompass the areas of the visible layers. A merge type of
CLIP_TO_IMAGE clips the final layer to the extents of the image. A merge type
of CLIP_TO_BOTTOM_LAYER clips the final layer to the size of the bottommost
layer.
HELP

    &std_pdb_misc;

    @inargs = (
	&std_image_arg,
676
677
	{ name => 'merge_type',
	  type => 'enum GimpMergeType (no GIMP_FLATTEN_IMAGE)',
Manish Singh's avatar
Stuff    
Manish Singh committed
678
679
680
681
682
683
684
685
686
	  desc => 'The type of merge: { %%desc%% }' }
    );

    @outargs = (
	{ name => 'layer', type => 'layer', init => 1,
	  desc => 'The resulting layer' }
    );

    %invoke = (
687
	headers => [ qw("core/gimpimage-merge.h") ],
Manish Singh's avatar
Stuff    
Manish Singh committed
688
689
	code => <<'CODE'
{
690
  layer = gimp_image_merge_visible_layers (gimage, context, merge_type);
Manish Singh's avatar
Stuff    
Manish Singh committed
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
  success = layer != NULL;
}
CODE
    );
}

sub image_merge_down {
    $blurb = 'Merge the layer passed and the first visible layer below.';

    $help = <<'HELP';
This procedure combines the passed layer and the first visible layer below it
using the specified merge type. A merge type of EXPAND_AS_NECESSARY expands the
final layer to encompass the areas of the visible layers. A merge type of
CLIP_TO_IMAGE clips the final layer to the extents of the image. A merge type
of CLIP_TO_BOTTOM_LAYER clips the final layer to the size of the bottommost
layer.
HELP

    $author = $copyright = 'Larry Ewing';
    $date = '1998';

    @inargs = (
	&std_image_arg,
	{ name => 'merge_layer', type => 'layer',
	  desc => 'The layer to merge down from' },
716
	{ name => 'merge_type',
717
	  type => 'enum GimpMergeType (no GIMP_FLATTEN_IMAGE)',
Manish Singh's avatar
Stuff    
Manish Singh committed
718
719
720
721
722
723
724
725
726
	  desc => 'The type of merge: { %%desc%% }' }
    );

    @outargs = (
	{ name => 'layer', type => 'layer', init => 1,
	  desc => 'The resulting layer' }
    );

    %invoke = (
727
	headers => [ qw("core/gimpimage-merge.h") ],
Manish Singh's avatar
Stuff    
Manish Singh committed
728
729
	code => <<'CODE'
{
730
  layer = gimp_image_merge_down (gimage, merge_layer, context, merge_type);
Manish Singh's avatar
Stuff    
Manish Singh committed
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
  success = layer != NULL;
}
CODE
    );
}

sub image_flatten {
    $blurb = <<'BLURB';
Flatten all visible layers into a single layer. Discard all invisible layers.
BLURB

    $help = <<'HELP';
This procedure combines the visible layers in a manner analogous to merging
with the CLIP_TO_IMAGE merge type. Non-visible layers are discarded, and the
resulting image is stripped of its alpha channel.
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );

    @outargs = (
	{ name => 'layer', type => 'layer', init => 1,
	  desc => 'The resulting layer' }
    );

    %invoke = (
758
	headers => [ qw("core/gimpimage-merge.h") ],
759
	code => 'success = (layer = gimp_image_flatten (gimage, context)) != NULL;'
Manish Singh's avatar
Stuff    
Manish Singh committed
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
    );
}

sub image_add_layer {
    $blurb = 'Add the specified layer to the image.';

    $help = <<'HELP';
This procedure adds the specified layer to the gimage at the given position. If
the position is specified as -1, then the layer is inserted at the top of the
layer stack. If the layer to be added has no alpha channel, it must be added at
position 0. The layer type must be compatible with the image base type.
HELP

    &std_pdb_misc;

    @inargs = (
	&std_image_arg,
	&layer_arg,
	{ name => 'position', type => 'int32',
	  desc => 'The layer position' }
    );

782
783
    $invoke{code} = <<'CODE';
{
784
785
  if (! gimp_item_is_floating (GIMP_ITEM (layer)) ||
      GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (GIMP_DRAWABLE (layer))) !=
786
787
788
      gimp_image_base_type (gimage))
    {
      success = FALSE;
Manish Singh's avatar
Stuff    
Manish Singh committed
789
790
    }
  else
791
792
793
    {
      success = gimp_image_add_layer (gimage, layer, MAX (position, -1));
    }
Manish Singh's avatar
Stuff    
Manish Singh committed
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
}
CODE
}

sub image_remove_layer {
    $blurb = 'Remove the specified layer from the image.';

    $help = <<'HELP';
This procedure removes the specified layer from the image. If the layer doesn't
exist, an error is returned. If there are no layers left in the image, this
call will fail. If this layer is the last layer remaining, the image will
become empty and have no active layer.
HELP

    &std_pdb_misc;

    @inargs = (
	&std_image_arg,
	&layer_arg
    );

815
    %invoke = ( code => 'gimp_image_remove_layer (gimage, layer);' );
Manish Singh's avatar
Stuff    
Manish Singh committed
816
817
818
}

sub image_add_layer_mask {
819
    &std_pdb_deprecated ('gimp_layer_add_mask');
820

Manish Singh's avatar
Stuff    
Manish Singh committed
821
822
823
824
825
826
827
828
829
830
    @inargs = (
	&std_image_arg,
	&layer_arg,
	{ name => 'mask', type => 'layer_mask',
	  desc => 'The mask to add to the layer' }
    );
    $inargs[1]->{desc} .= ' to receive the mask';

    %invoke = (
	code => <<'CODE'
831
832
833
{
  success = gimp_layer_add_mask (layer, mask, TRUE) != NULL;
}
Manish Singh's avatar
Stuff    
Manish Singh committed
834
835
836
837
838
CODE
    );
}

sub image_remove_layer_mask {
839
    &std_pdb_deprecated ('gimp_layer_remove_mask');
840

Manish Singh's avatar
Stuff    
Manish Singh committed
841
842
843
    @inargs = (
	&std_image_arg,
	&layer_arg,
844
	{ name => 'mode', type => 'enum GimpMaskApplyMode',
Manish Singh's avatar
Stuff    
Manish Singh committed
845
846
847
848
	  desc => 'Removal mode: { %%desc%% }' }
    );
    $inargs[1]->{desc} .= ' from which to remove mask';

849
    %invoke = ( code => 'gimp_layer_apply_mask (layer, mode, TRUE);' );
Manish Singh's avatar
Stuff    
Manish Singh committed
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
}

sub image_raise_channel {
    &type_move('channel', 'raise', 'above');
    &std_pdb_misc;
}

sub image_lower_channel {
    &type_move('layer', 'lower', 'below');
    &std_pdb_misc;
}

sub image_add_channel {
    $blurb = 'Add the specified channel to the image.';

    $help = <<'HELP';
This procedure adds the specified channel to the image. The position channel is
not currently used, so the channel is always inserted at the top of the channel
stack.
HELP

    &std_pdb_misc;

    @inargs = (
	&std_image_arg,
	&channel_arg,
	{ name => 'position', type => 'int32',
	  desc => 'The channel position' }
    );

    %invoke = (
	code => <<'CODE'
882
883
884
885
886
887
{
  success = gimp_item_is_floating (GIMP_ITEM (channel));

  if (success)
    success = gimp_image_add_channel (gimage, channel, MAX (position, -1));
}
Manish Singh's avatar
Stuff    
Manish Singh committed
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
CODE
    );
}

sub image_remove_channel {
    $blurb = 'Remove the specified channel from the image.';

    $help = <<'HELP';
This procedure removes the specified channel from the image. If the channel
doesn't exist, an error is returned.
HELP

    &std_pdb_misc;

    @inargs = (
	&std_image_arg,
	&channel_arg
    );

907
    %invoke = ( code => 'gimp_image_remove_channel (gimage, channel);' );
Manish Singh's avatar
Stuff    
Manish Singh committed
908
909
}

910
sub image_get_active_drawable {
Manish Singh's avatar
Stuff    
Manish Singh committed
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
    $blurb = "Get the image's active drawable";

    $help = <<'HELP';
This procedure returns the ID of the image's active drawable. This can be
either a layer, a channel, or a layer mask. The active drawable is specified by
the active image channel. If that is -1, then by the active image layer. If the
active image layer has a layer mask and the layer mask is in edit mode, then
the layer mask is the active drawable.
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );

    @outargs = (
	{ name => 'drawable', type => 'drawable', init => 1,
	  desc => 'The active drawable' }
    );

    %invoke = (
	code => <<'CODE'
932
success = (drawable = gimp_image_active_drawable (gimage)) != NULL;
Manish Singh's avatar
Stuff    
Manish Singh committed
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
CODE
    );
}

sub image_base_type {
    $blurb = 'Get the base type of the image.';

    $help = <<'HELP';
This procedure returns the image's base type. Layers in the image must be of
this subtype, but can have an optional alpha channel.
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );

    @outargs = (
	{ name => 'base_type', type => 'enum GimpImageBaseType', init => 1,
	  desc => "The image's base type: { %%desc%% }" }
    );

954
    %invoke = ( code => 'base_type = gimp_image_base_type (gimage);' );
Manish Singh's avatar
Stuff    
Manish Singh committed
955
956
}

Michael Natterer's avatar
Michael Natterer committed
957
sub image_get_colormap {
Manish Singh's avatar
Stuff    
Manish Singh committed
958
959
960
961
962
963
    $blurb = "Returns the image's colormap";

    $help = <<'HELP';
This procedure returns an actual pointer to the image's colormap, as well as
the number of bytes contained in the colormap. The actual number of colors in
the transmitted colormap will be "num_bytes" / 3. If the image is not of base
964
type GIMP_INDEXED, this pointer will be NULL.
Manish Singh's avatar
Stuff    
Manish Singh committed
965
966
967
968
969
970
971
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );

    @outargs = (
Michael Natterer's avatar
Michael Natterer committed
972
	{ name => 'colormap', type => 'int8array', init => 1, wrap => 1,
Manish Singh's avatar
Stuff    
Manish Singh committed
973
974
975
976
977
978
979
	  desc => "The image's colormap",
	  array => { name => 'num_bytes', init => 1,
		     desc => 'Number of bytes in the colormap array:
			      %%desc%%' } }
    );

    %invoke = (
980
	headers => [ qw("core/gimpimage-colormap.h") ],
Manish Singh's avatar
Stuff    
Manish Singh committed
981
982
	code => <<'CODE'
{
983
  num_bytes = 3 * gimp_image_get_colormap_size (gimage);
Michael Natterer's avatar
Michael Natterer committed
984
  colormap = g_memdup (gimp_image_get_colormap (gimage), num_bytes);
Manish Singh's avatar
Stuff    
Manish Singh committed
985
986
987
988
989
}
CODE
    );
}

Michael Natterer's avatar
Michael Natterer committed
990
sub image_set_colormap {
Manish Singh's avatar
Stuff    
Manish Singh committed
991
992
993
994
995
    $blurb = "Sets the entries in the image's colormap.";

    $help = <<'HELP';
This procedure sets the entries in the specified image's colormap. The number
of entries is specified by the "num_bytes" parameter and corresponds to the
Michael Natterer's avatar
Michael Natterer committed
996
number of INT8 triples that must be contained in the "colormap" array. The actual
Manish Singh's avatar
Stuff    
Manish Singh committed
997
998
999
1000
1001
1002
1003
number of colors in the transmitted colormap is "num_bytes" / 3.
HELP

    &std_pdb_misc;

    @inargs = (
	&std_image_arg,
Michael Natterer's avatar
Michael Natterer committed
1004
	{ name => 'colormap', type => 'int8array', wrap => 1,
Manish Singh's avatar
Stuff    
Manish Singh committed
1005
1006
1007
1008
1009
1010
	  desc => "The new colormap values",
	  array => { name => 'num_bytes', type => '0 <= int32 <= 768',
		     desc => 'Number of bytes in the colormap array:
			      %%desc%%' } }
    );

1011
1012
    %invoke = (
	headers => [ qw("core/gimpimage-colormap.h") ],
Michael Natterer's avatar
Michael Natterer committed
1013
        code => 'gimp_image_set_colormap (gimage, colormap, num_bytes / 3, TRUE);' );
Manish Singh's avatar
Stuff    
Manish Singh committed
1014
1015
1016
1017
1018
1019
1020
}

sub image_clean_all {
    $blurb = 'Set the image dirty count to 0.';

    $help = <<'HELP';
This procedure sets the specified image's dirty count to 0, allowing operations
1021
1022
to occur without having a 'dirtied' image. This is especially useful for
creating and loading images which should not initially be considered dirty, even
Manish Singh's avatar
Stuff    
Manish Singh committed
1023
1024
1025
1026
1027
1028
1029
though layers must be created, filled, and installed in the image.
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );

1030
    %invoke = ( code => 'gimp_image_clean_all (gimage);' );
Manish Singh's avatar
Stuff    
Manish Singh committed
1031
1032
}

1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
sub image_is_dirty {
    $blurb = 'Checks if the image has unsaved changes.';

    $help = <<'HELP';
This procedure checks the specified image's dirty count to see if it needs
to be saved.
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );

    @outargs = (
	{ name => 'dirty', type => 'boolean', init => 1,
1047
	  desc => 'True if the image has unsaved changes.' }
1048
1049
1050
1051
1052
    );

    %invoke = ( code => 'dirty = (gimage->dirty != 0);' );
}

1053
sub image_get_floating_sel {
Manish Singh's avatar
Stuff    
Manish Singh committed
1054
1055
1056
    $blurb = 'Return the floating selection of the image.';

    $help = <<'HELP';
1057
1058
This procedure returns the image's floating selection, if it exists.
If it doesn't exist, -1 is returned as the layer ID.
Manish Singh's avatar
Stuff    
Manish Singh committed
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
HELP

    &std_pdb_misc;

    @inargs = ( &std_image_arg );

    @outargs = (
	{ name => 'floating_sel', type => 'layer', init => 1,
	  desc => "The image's floating selection",
	  return_fail => -1 }
    );

1071
    %invoke = ( code => 'floating_sel = gimp_image_floating_sel (gimage);' );
Manish Singh's avatar
Stuff    
Manish Singh committed
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
}

sub image_floating_sel_attached_to {
    $blurb = 'Return the drawable the floating selection is attached to.';

    $help = <<'HELP';
This procedure returns the drawable the image's floating selection is attached
to, if it exists. If it doesn't exist, -1 is returned as the drawable ID.
HELP

    $author = $copyright = 'Wolfgang Hofer';
    $date = '1998';

    @inargs = ( &std_image_arg );

    @outargs = (
	{ name => 'drawable', type => 'drawable', init => 1,
	  desc => 'The drawable the floating selection is attached to',
	  return_fail => -1 }
    );

    %invoke = (
1094
	vars => [ 'GimpLayer *floating_sel' ],
Manish Singh's avatar
Stuff    
Manish Singh committed
1095
1096
	code => <<'CODE'
{
1097
  floating_sel = gimp_image_floating_sel (gimage);
Sven Neumann's avatar
Sven Neumann committed
1098
1099
1100
1101
1102

  if (floating_sel)
    drawable = GIMP_DRAWABLE (GIMP_LAYER (floating_sel)->fs.drawable);
  else
    drawable = NULL;
Manish Singh's avatar
Stuff    
Manish Singh committed
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
}
CODE
    );
}

foreach (qw(width height)) {
    eval <<SUB;
sub image_$_ {
    \$blurb = 'Return the $_ of the image';

    \$help = <<'HELP';
Marc Lehmann's avatar
Marc Lehmann committed
1114
This procedure returns the image's $_. This value is independent of any of
Manish Singh's avatar
Stuff    
Manish Singh committed
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
the layers in this image. This is the "canvas" $_.
HELP

    \&std_pdb_misc;

    \@inargs = ( \&std_image_arg );

    \@outargs = (
	{ name => '$_', type => 'int32',
	  desc => "The image's $_",
	  alias => 'gimage->$_', no_declare => 1 }
    );
}
SUB
}

&image_accessors('active_layer', 'layer', 'active layer', 1,
		 [ <<'CODE1', <<'CODE2' ]);
    $invoke{code} = "active_layer = $outargs[0]->{alias};";
    delete @{$outargs[0]}{qw(alias no_declare)};
    $outargs[0]->{return_fail} = -1;
    $outargs[0]->{init} = 1;

    $help = <<'HELP';
If there is an active layer, its ID will be returned, otherwise, -1.  If a
channel is currently active, then no layer will be. If a layer mask is active,
then this will return the associated layer.
HELP
CODE1
1144
1145
1146
    $invoke{code} =~ s/;//g;
    $invoke{code} = "success = ($invoke{code} == active_layer);";

Manish Singh's avatar
Stuff    
Manish Singh committed
1147
    $help = <<'HELP';
1148
1149
1150
1151
If the layer exists, it is set as the active layer in the image. Any
previous active layer or channel is set to inactive. An exception is a
previously existing floating selection, in which case this procedure
will return an execution error.
Manish Singh's avatar
Stuff    
Manish Singh committed
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
HELP
CODE2

&image_accessors('active_channel', 'channel', 'active channel', 1,
		 [ <<'CODE1', <<'CODE2' ]);
    $invoke{code} = "active_channel = $outargs[0]->{alias};";
    delete @{$outargs[0]}{qw(alias no_declare)};
    $outargs[0]->{return_fail} = -1;
    $outargs[0]->{init} = 1;

    $help = <<'HELP';
If there is an active channel, this will return the channel ID, otherwise, -1.
HELP
CODE1
1166
1167
1168
    $invoke{code} =~ s/;//g;
    $invoke{code} = "success = ($invoke{code} == active_channel);";

Manish Singh's avatar
Stuff    
Manish Singh committed
1169
    $help = <<'HELP';
1170
1171
1172
1173
If the channel exists, it is set as the active channel in the
image. Any previous active channel or channel is set to inactive. An
exception is a previously existing floating selection, in which case
this procedure will return an execution error.
Manish Singh's avatar
Stuff    
Manish Singh committed
1174
1175
1176
1177
1178
HELP
CODE2

&image_accessors('selection', 'selection', 'selection', 1,
		 [ <<'CODE', undef ]);
1179
    $invoke{code} = "success = (selection = gimp_image_get_mask (gimage)) != NULL;";
Manish Singh's avatar
Stuff    
Manish Singh committed
1180
1181
1182
1183
1184
    delete @{$outargs[0]}{qw(alias no_declare)};
    $outargs[0]->{desc} .= ' channel';
    $outargs[0]->{init} = 1;

    $help = <<'HELP';
1185
This will always return a valid ID for a selection -- which is represented as a
Manish Singh's avatar
Stuff    
Manish Singh committed
1186
1187
1188
1189
1190
1191
1192
channel internally.
HELP
CODE
$#procs--;

my $comp_arg = <<'CODE';
    splice @inargs, 1, 0, ({ name => 'component',
1193
			     type => 'enum GimpChannelType',
Manish Singh's avatar
Stuff    
Manish Singh committed
1194
1195
1196
1197
			     desc => 'The image component: { %%desc%% }' });

    $invoke{code} = <<'SUCCESS';
{
1198
  if (component == GIMP_GRAY_CHANNEL)
1199
    success = gimp_image_base_type (gimage) == GIMP_GRAY;
1200
  else if (component == GIMP_INDEXED_CHANNEL)
1201
    success = gimp_image_base_type (gimage) == GIMP_INDEXED;
Manish Singh's avatar
Stuff    
Manish Singh committed
1202
  else
1203
    success = gimp_image_base_type (gimage) == GIMP_RGB;
Manish Singh's avatar
Stuff    
Manish Singh committed
1204
1205
1206
1207
1208
1209
1210
1211
1212
}
SUCCESS
CODE

my $comp_help = <<'CODE';
	$help =~ s/(component)/$1 (i.e. Red, Green, Blue intensity channels
			       in an RGB image)/;
	$help =~ s/\. $/ /;
	$help .= <<HELP;
1213
or in%%type%% -- whether or not it can be %%action%%. If the specified component
1214
is not valid for the image type, an error is returned.
Manish Singh's avatar
Stuff    
Manish Singh committed
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
HELP
CODE

my %comp_action = (
    active => 'modified',
    visible => 'seen'
);

foreach (sort keys %comp_action) {
    my $help = $comp_help;

    $help =~ s/%%type%%/$_/e;
    $help =~ s/%%action%%/$comp_action{$_}/e;

    &image_accessors("component_$_", 'boolean', "image component is $_", 1,
		     [ <<CODE1, <<CODE2 ]);
	$comp_arg;
	\$outargs[0]->{name} = '$_';
	\$outargs[0]->{desc} = 'Component is $_ (%%desc%%)';

	chop \$outargs[0]->{alias};
	\$outargs[0]->{alias} .= ', component)';
	$help;
CODE1
	my \$code = <<CODE;

  if (success)
    \$invoke{code}
CODE
	$comp_arg;
Manish Singh's avatar
Manish Singh committed
1245
	\$invoke{code} =~ s/}/"\$code}"/e;
Manish Singh's avatar
Stuff    
Manish Singh committed
1246
1247
1248
1249
1250
1251
1252
1253
	\$invoke{code} =~ s/ component_$_/ component, $_/;
	\$inargs[2]->{name} = '$_';
	\$inargs[2]->{desc} = 'Component is $_ (%%desc%%)';
 	$help;
CODE2
}

&image_accessors('filename', 'string', 'filename', 1,
1254
		 [ <<'CODE1', <<'CODE2' ]);
Manish Singh's avatar
Stuff    
Manish Singh committed
1255
1256
    $help =~ s/\. $//;
    $help .= <<'HELP';
1257
1258
 in the filesystem encoding. The image has a filename only if it was loaded
or has since been saved. Otherwise, this function returns %NULL.
Manish Singh's avatar
Stuff    
Manish Singh committed
1259
1260
HELP

1261
    $outargs[0]->{alias} =~ s/g_strdup \((.*)\)/$1/;
1262
CODE1
1263
    $help .= " The filename should be in the filesystem encoding.";
1264
1265

    $inargs[1]->{no_validate} = 1;
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279

    $invoke{code} = <<CODE3;
{
  /*  verify that the filename can be converted to UTF-8 and back  */
  gchar *utf8 = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);

  if (utf8)
    {
      gchar *tmp = g_filename_from_utf8 (utf8, -1, NULL, NULL, NULL);

      if (tmp)
        g_free (tmp);
      else
        success = FALSE;
Sven Neumann's avatar
Sven Neumann committed
1280
1281

      g_free (utf8);
1282
1283
1284
1285
1286
1287
1288
1289
    }
  else
    success = FALSE;

  if (success)
    $invoke{code}
}
CODE3
1290
CODE2
Manish Singh's avatar
Stuff    
Manish Singh committed
1291

1292
1293
1294
&image_accessors('name', 'string', 'name', 1,
		 [ <<'CODE1', undef ]);
    delete @{$outargs[0]}{qw(alias no_declare)};
1295
    $outargs[0]->{init} = 1;
1296
1297
1298
1299
1300
1301
1302
1303

    %invoke = (
	vars => [ 'gchar *filename' ],
	code => <<'CODE2'
{
  filename = gimp_image_get_filename (gimage);

  if (filename)
1304
    name = g_filename_display_basename (filename);
1305
  else
1306
    name = g_strdup (_("Untitled"));
1307
1308
1309
1310
1311
1312
}
CODE2
    );
CODE1
$#procs--;

Manish Singh's avatar
Stuff    
Manish Singh committed
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
&image_accessors('resolution', 'float', 'resolution', 0,
		 [ <<'CODE1', <<'CODE2' ]);
    $help =~ s/\. $/ /;
    $help .= <<'HELP';
in dots per inch. This value is independent of any of the layers in this image.
HELP

    $author = $copyright = 'Austin Donnelly';
    $date = '1998';

    push @outargs, { %{$outargs[0]} };
1324
    $outargs[0]->{void_ret} = 1;
Manish Singh's avatar
Stuff    
Manish Singh committed
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351

    my $count = 0;
    foreach $coord (qw(x y)) {
	foreach (qw(name alias)) {
	    $outargs[$count]->{$_} =~ s/res/"${coord}res"/e
	}
	$outargs[$count++]->{desc} .= "in the $coord-axis, in dots per inch";
    }
CODE1
    $help =~ s/\. $/ /;
    $help .= <<'HELP';
in dots per inch. This value is independent of any of the layers in this image.
No scaling or resizing is performed.
HELP

    $author = $copyright = 'Austin Donnelly';
    $date = '1998';

    push @inargs, { %{$inargs[1]} };

    my $count = 1; undef %invoke;
    foreach $coord (qw(x y)) {
	my $arg = $inargs[$count];
	$arg->{name} =~ s/res/"${coord}res"/e;
	$arg->{desc} .= "in the $coord-axis, in dots per inch";
	$count++;
    }
1352
1353
1354

    $invoke{code} = <<'CODE';
{
1355
  if (! FINITE (xresolution) ||
1356
      xresolution < GIMP_MIN_RESOLUTION || xresolution > GIMP_MAX_RESOLUTION ||
1357
      ! FINITE (yresolution) ||
1358
      yresolution < GIMP_MIN_RESOLUTION || yresolution > GIMP_MAX_RESOLUTION)
1359
    {
1360
      g_message (_("Image resolution is out of bounds, "
1361
1362
1363
                   "using the default resolution instead."));
      success = FALSE;
    }
1364
1365
  else
    {
1366
      gimp_image_set_resolution (gimage, xresolution, yresolution);
1367
1368
1369
    }
}
CODE
Manish Singh's avatar
Stuff    
Manish Singh committed
1370
1371
CODE2

1372

Manish Singh's avatar
Stuff    
Manish Singh committed
1373
1374
1375
1376
1377
1378
1379
my $unit_help = <<'HELP';
This value is independent of any of the layers in this image. See the
gimp_unit_* procedure definitions for the valid range of unit IDs and a
description of the unit system.
HELP

my $unit_misc = <<'CODE';
1380
    $author = $copyright = 'Michael Natterer';
Manish Singh's avatar
Stuff    
Manish Singh committed
1381
1382
    $date = '1998';
CODE
1383

1384
&image_accessors('unit', 'unit (min GIMP_UNIT_INCH)', 'unit', 1,
Manish Singh's avatar
Stuff    
Manish Singh committed
1385
1386
1387
1388
1389
1390
1391
1392
		 [ <<CODE1, <<CODE2 ]);
    \$help .= '$unit_help';
    $unit_misc
CODE1
    \$help .= 'No scaling or resizing is performed. $unit_help';
    $unit_misc
CODE2

1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425

my $tattoo_state_misc = <<'CODE';
    $author = $copyright = 'Andy Thomas';
    $date = '2000';
CODE
&image_accessors('tattoo_state', 'int32', 'tattoo_state', 1,
		 [ <<CODE1, <<CODE2 ]);
    \$blurb = 'Returns the tattoo state associated with the image.';
    \$help = <<'HELP';
This procedure returns the tattoo state of the image. Use only by
save/load plugins that wish to preserve an images tattoo state. Using this
function at other times will produce unexpected results.
HELP
    $tattoo_state_misc
CODE1
    \$blurb = 'Set the tattoo state associated with the image.';
    \$help = <<'HELP';
This procedure sets the tattoo state of the image. Use only by
save/load plugins that wish to preserve an images tattoo state. Using
this function at other times will produce unexpected results. A full
check of uniqueness of states in layers, channels and paths will be
performed by this procedure and a execution failure will be returned
if this fails. A failure will also be returned if the new tattoo state
value is less than the maximum tattoo value from all of the tattoos
from the paths, layers and channels. After the image data has been
loaded and all the tattoos have been set then this is the last
procedure that should be called. If effectively does a status check on
the tattoo values that have been set to make sure that all is OK.
HELP
    $tattoo_state_misc
CODE2


Manish Singh's avatar
Stuff    
Manish Singh committed
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
foreach (qw(layer channel)) {
    push @procs, "image_get_${_}_by_tattoo";
    eval <<SUB;
sub image_get_${_}_by_tattoo {
    \$blurb = 'Find a $_ with a given tattoo in an image.';

    \$help = <<'HELP';
This procedure returns the $_ with the given tattoo in the specified image.
HELP

    \$author = \$copyright = 'Jay Cox';
    \$date = '1998';

    \@inargs = (
	\&std_image_arg,
	{ name => 'tattoo', type => 'tattoo',
	  desc => 'The tattoo of the $_ to find' }
    );

    \@outargs = (
	{ name => '$_', type => '$_', init => 1,
	  desc => 'The $_ with the specified tattoo' }
    );

    \%invoke = (
	code => <<'CODE'
{
  $_ = gimp_image_get_${_}_by_tattoo (gimage, tattoo);
  success = $_ != NULL;
}
CODE
    );
}
SUB
}

1462
1463
1464
sub preview_dim_args () {
    my @args;
    foreach (qw(width height bpp)) {
1465
1466
1467
1468
	push @args, { name => $_,
                      type => 'int32',
                      desc => "The previews $_",
                      init => 1 };
1469
1470
1471
1472
1473
1474
1475
1476
    }
    @args;
}

sub image_thumbnail {
    $blurb = 'Get a thumbnail of an image.';

    $help = <<'HELP';
1477
1478
1479
1480
This function gets data from which a thumbnail of an image preview can
be created. Maximum x or y dimension is 1024 pixels. The pixels are
returned in RGB[A] or GRAY[A] format. The bpp return value gives the
number of bits per pixel in the image.
1481
1482
1483
1484
1485
1486
1487
HELP

    $author = $copyright = 'Andy Thomas';
    $date = '1999';

    @inargs = (
    	&std_image_arg,
1488
1489
1490
1491
	{ name => 'width', type => '0 < int32 <= 1024',
	  desc => 'The thumbnail width', alias => 'req_width' },
	{ name => 'height', type => '0 < int32 <= 1024',
	  desc => 'The thumbnail height', alias => 'req_height' }
1492
1493
1494
1495
    );

    @outargs = (
	&preview_dim_args,
1496
        { name => 'thumbnail_data', type => 'int8array', wrap => 1,
1497
1498
	  desc => 'The thumbnail data', init => 1,
	  array => { name => 'thumbnail_data_count',
1499
1500
		     desc => 'The number of bytes in thumbnail data',
		     alias => 'num_bytes', init => 1 } }
1501
    );
1502
    $outargs[0]->{void_ret} = 1;
1503
1504
1505
1506

    %invoke = (
	code => <<'CODE'
{
1507
1508
  TempBuf *buf;
  gint     dwidth, dheight;
1509

1510
1511
1512
  g_assert (GIMP_VIEWABLE_MAX_PREVIEW_SIZE >= 1024);

  /* Adjust the width/height ratio */
1513
1514
  dwidth  = gimp_image_get_width  (gimage);
  dheight = gimp_image_get_height (gimage);
1515
1516
1517
1518
1519
1520

  if (dwidth > dheight)
    req_height = MAX (1, (req_width * dheight) / dwidth);
  else
    req_width  = MAX (1, (req_height * dwidth) / dheight);

1521
1522
1523
1524
1525
1526
1527
1528
  if (gimage->gimp->config->layer_previews)
    buf = gimp_viewable_get_new_preview (GIMP_VIEWABLE (gimage),
                                         req_width, req_height);
  else
    buf = gimp_viewable_get_dummy_preview (GIMP_VIEWABLE (gimage),
                                           req_width, req_height,
                                           gimp_image_has_alpha (gimage) ?
                                           4 : 3);
1529
1530
1531

  if (buf)
    {
1532
      num_bytes      = buf->height * buf->width * buf->bytes;
1533
      thumbnail_data = g_memdup (temp_buf_data (buf), num_bytes);
1534
      width          = buf->width;
1535
1536
1537
      height         = buf->height;
      bpp            = buf->bytes;

1538
      temp_buf_free (buf);
1539
    }
1540
1541
1542
1543
  else
    {
      success = FALSE;
    }
1544
1545
1546
1547
1548
}
CODE
    );
}

1549

1550
@headers = qw("core/gimp.h" "core/gimplist.h" "core/gimpunit.h"
1551
              "base/temp-buf.h" "libgimpmath/gimpmath.h"
1552
              "libgimpbase/gimpbase.h" "gimp-intl.h");
Manish Singh's avatar
Stuff    
Manish Singh committed
1553
1554

$extra{app}->{code} = <<'CODE';
1555
1556
1557
1558
1559
1560
1561
1562
1563
#if defined (HAVE_FINITE)
#define FINITE(x) finite(x)
#elif defined (HAVE_ISFINITE)
#define FINITE(x) isfinite(x)
#elif defined (G_OS_WIN32)
#define FINITE(x) _finite(x)
#else
#error "no FINITE() implementation available?!"
#endif
Manish Singh's avatar
Stuff    
Manish Singh committed
1564
1565
CODE

1566
1567
1568
unshift @procs, qw(image_list image_new image_duplicate image_delete
                   image_base_type
                   image_width image_height
1569
		   image_free_shadow
1570
1571
                   image_resize image_resize_to_layers image_scale
		   image_crop image_flip image_rotate
1572
                   image_get_layers image_get_channels
1573
		   image_get_vectors
1574
		   image_get_active_drawable
1575
1576
                   image_unset_active_channel
                   image_get_floating_sel image_floating_sel_attached_to
1577
                   image_pick_color image_pick_correlate_layer
1578
                   image_add_layer image_remove_layer
1579
1580
		   image_raise_layer image_lower_layer
                   image_raise_layer_to_top image_lower_layer_to_bottom
1581
                   image_add_channel image_remove_channel
1582
1583
1584
                   image_raise_channel image_lower_channel
                   image_flatten image_merge_visible_layers image_merge_down
                   image_add_layer_mask image_remove_layer_mask
Michael Natterer's avatar
Michael Natterer committed
1585
                   image_get_colormap image_set_colormap
1586
		   image_clean_all image_is_dirty
1587
                   image_thumbnail);
1588
%exports = (app => [@procs], lib => [@procs[0..35,38..62]]);
Manish Singh's avatar
Stuff    
Manish Singh committed
1589
1590
1591
1592

$desc = 'Image';

1;