drawable.pdb 28.8 KB
Newer Older
1
# GIMP - The GNU Image Manipulation Program
Manish Singh's avatar
Manish Singh committed
2
3
# Copyright (C) 1995 Spencer Kimball and Peter Mattis

4
# This program is free software: you can redistribute it and/or modify
Manish Singh's avatar
Manish Singh committed
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 3 of the License, or
Manish Singh's avatar
Manish Singh committed
7
8
9
10
11
12
13
14
# (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
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Manish Singh's avatar
Manish Singh committed
16
17
18
19
20
21
22

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

sub drawable_merge_shadow {
    $blurb = 'Merge the shadow buffer with the specified drawable.';

    $help = <<'HELP';
23
24
This procedure combines the contents of the drawable's shadow buffer
(for temporary processing) with the specified drawable. The 'undo'
25
26
parameter specifies whether to add an undo step for the operation.
Requesting no undo is useful for such applications as 'auto-apply'.
Manish Singh's avatar
Manish Singh committed
27
28
29
30
31
HELP

    &std_pdb_misc;

    @inargs = (
32
33
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' },
Manish Singh's avatar
Manish Singh committed
34
35
36
37
        { name => 'undo', type => 'boolean',
	  desc => 'Push merge to undo stack?' }
    );

38
    %invoke = (
39
40
41
	headers => [ qw("core/gimpdrawable-shadow.h"
                        "plug-in/gimpplugin.h"
                        "plug-in/gimppluginmanager.h") ],
42
	code    => <<'CODE'
43
{
44
45
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                 GIMP_PDB_ITEM_CONTENT, error) &&
46
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
47
    {
48
      const gchar *undo_desc = _("Plug-In");
49

50
      if (gimp->plug_in_manager->current_plug_in)
51
        undo_desc = gimp_plug_in_get_undo_desc (gimp->plug_in_manager->current_plug_in);
52

53
      gimp_drawable_merge_shadow_buffer (drawable, undo, undo_desc);
54
    }
55
56
  else
    success = FALSE;
57
58
59
}
CODE
    );
Manish Singh's avatar
Manish Singh committed
60
61
}

62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
sub drawable_free_shadow {
    $blurb = "Free the specified drawable'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 when the
drawable is removed from the image, or when the plug-in procedure
which allocated it returns.
HELP

    &mitch_pdb_misc('2008', '2.6');

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );

    %invoke = (
	headers => [ qw("plug-in/gimpplugin-cleanup.h") ],
	code => <<'CODE'
{
  if (gimp->plug_in_manager->current_plug_in)
    gimp_plug_in_cleanup_remove_shadow (gimp->plug_in_manager->current_plug_in,
                                        drawable);

87
  gimp_drawable_free_shadow_buffer (drawable);
88
89
90
91
92
}
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
93
94
95
96
sub drawable_fill {
    $blurb = 'Fill the drawable with the specified fill mode.';

    $help = <<'HELP';
97
98
99
100
101
102
103
104
105

This procedure fills the drawable. If the fill mode is foreground the
current foreground color is used. If the fill mode is background, the
current background color is used. If the fill type is white, then
white is used. Transparent fill only affects layers with an alpha
channel, in which case the alpha channel is set to transparent. If the
drawable has no alpha channel, it is filled to white. No fill leaves
the drawable's contents undefined.

106
107
108
109
This procedure is unlike gimp_edit_fill() or the bucket fill tool
because it fills regardless of a selection. Its main purpose is to
fill a newly created drawable before adding it to the image. This
operation cannot be undone.
Manish Singh's avatar
Manish Singh committed
110
111
112
113
114
HELP

    &std_pdb_misc;

    @inargs = (
115
116
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' },
Manish Singh's avatar
Manish Singh committed
117
	{ name => 'fill_type', type => 'enum GimpFillType',
118
	  desc => 'The type of fill' }
Manish Singh's avatar
Manish Singh committed
119
120
    );

121
122
123
    %invoke = (
	code => <<'CODE'
{
124
125
  if (gimp_pdb_item_is_modifyable (GIMP_ITEM (drawable),
                                   GIMP_PDB_ITEM_CONTENT, error) &&
126
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
127
128
129
    {
      gimp_drawable_fill (drawable, context, (GimpFillType) fill_type);
    }
130
131
  else
    success = FALSE;
132
133
134
}
CODE
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
135
136
137
138
139
140
141
142
}

sub drawable_update {
    $blurb = 'Update the specified region of the drawable.';

    $help = <<'HELP';
This procedure updates the specified region of the drawable. The (x, y)
coordinate pair is relative to the drawable's origin, not to the image origin.
Sven Neumann's avatar
Sven Neumann committed
143
Therefore, the entire drawable can be updated using (0, 0, width, height).
Manish Singh's avatar
Stuff    
Manish Singh committed
144
145
146
147
148
HELP

    &std_pdb_misc;

    @inargs = (
149
150
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' },
Manish Singh's avatar
Stuff    
Manish Singh committed
151
152
153
154
155
156
157
158
159
160
	{ name => 'x', type => 'int32',
	  desc => 'x coordinate of upper left corner of update region' },
	{ name => 'y', type => 'int32',
	  desc => 'y coordinate of upper left corner of update region' },
	{ name => 'width', type => 'int32',
	  desc => 'Width of update region' },
	{ name => 'height', type => 'int32',
	  desc => 'Height of update region' }
    );

161
162
163
164
165
166
167
    %invoke = (
	code => <<'CODE'
{
  gimp_drawable_update (drawable, x, y, width, height);
}
CODE
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
168
169
170
171
172
173
174
175
176
}

sub drawable_mask_bounds {
    $blurb = <<'BLURB';
Find the bounding box of the current selection in relation to the specified
drawable.
BLURB

    $help = <<'HELP';
177
This procedure returns whether there is a selection. If there is one, the
178
upper left and lower right-hand corners of its bounding box are returned. These
Manish Singh's avatar
Stuff    
Manish Singh committed
179
coordinates are specified relative to the drawable's origin, and bounded by
180
the drawable's extents. Please note that the pixel specified by the lower
181
right-hand coordinate of the bounding box is not part of the selection. The
182
183
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).
184
185
186
187
188

Note that the returned boolean does NOT correspond with the returned
region being empty or not, it always returns whether the selection
is non_empty. See gimp_drawable_mask_intersect() for a boolean
return value which is more useful in most cases.
Manish Singh's avatar
Stuff    
Manish Singh committed
189
190
191
192
HELP

    &std_pdb_misc;

193
194
195
196
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
197
198

    @outargs = (
199
	{ name => 'non_empty', type => 'boolean',
Manish Singh's avatar
Stuff    
Manish Singh committed
200
	  desc => 'TRUE if there is a selection' },
201
202
203
204
205
206
207
208
	{ name => 'x1', type => 'int32',
	  desc => "x coordinate of the upper left corner of selection bounds" },
	{ name => 'y1', type => 'int32',
	  desc => "y coordinate of the upper left corner of selection bounds" },
	{ name => 'x2', type => 'int32',
	  desc => "x coordinate of the lower right corner of selection bounds" },
	{ name => 'y2', type => 'int32',
	  desc => "y coordinate of the lower right corner of selection bounds" }
Manish Singh's avatar
Stuff    
Manish Singh committed
209
210
    );

Manish Singh's avatar
Manish Singh committed
211
    %invoke = (
Manish Singh's avatar
Stuff    
Manish Singh committed
212
	code => <<'CODE'
213
{
214
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, 0, error))
215
    non_empty = gimp_item_mask_bounds (GIMP_ITEM (drawable), &x1, &y1, &x2, &y2);
216
217
  else
    success = FALSE;
218
}
Manish Singh's avatar
Stuff    
Manish Singh committed
219
CODE
Manish Singh's avatar
Manish Singh committed
220
221
    );
}
Manish Singh's avatar
Stuff    
Manish Singh committed
222

223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
sub drawable_mask_intersect {
    $blurb = <<'BLURB';
Find the bounding box of the current selection in relation to the specified
drawable.
BLURB

    $help = <<'HELP';
This procedure returns whether there is an intersection between the
drawable and the selection. Unlike gimp_drawable_mask_bounds(), the
intersection's bounds are returned as x, y, width, height.

If there is no selection this function returns TRUE and the returned
bounds are the extents of the whole drawable.
HELP

238
    &mitch_pdb_misc('2004', '2.2');
239

240
241
242
243
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );
244
245

    @outargs = (
246
	{ name => 'non_empty', type => 'boolean',
247
248
249
250
251
252
253
254
255
256
257
258
259
	  desc => 'TRUE if the returned area is not empty' },
	{ name => 'x', type => 'int32',
          desc => 'x coordinate of the upper left corner of the intersection' },
	{ name => 'y', type => 'int32',
          desc => 'y coordinate of the upper left corner of the intersection' },
	{ name => 'width', type => 'int32',
          desc => 'width of the intersection' },
	{ name => 'height', type => 'int32',
          desc => 'height of the intersection' }
    );

    %invoke = (
	code => <<'CODE'
260
{
261
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, 0, error))
262
263
    non_empty = gimp_item_mask_intersect (GIMP_ITEM (drawable),
                                          &x, &y, &width, &height);
264
265
  else
    success = FALSE;
266
}
267
268
269
270
CODE
    );
}

271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
sub drawable_get_format {
    $blurb = "Returns the drawable's Babl format";
    $help  = "This procedure returns the drawable's Babl format.";

    &mitch_pdb_misc('2012', '2.10');

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );

    @outargs = (
	{ name => 'format', type => 'string', wrap => 1,
	  desc => "The drawable's Babl format" }
    );

    %invoke = (
	code => <<'CODE'
{
290
291
292
  if (gimp->plug_in_manager->current_plug_in)
    gimp_plug_in_enable_precision (gimp->plug_in_manager->current_plug_in);

293
294
295
296
297
298
  format = g_strdup (babl_get_name (gimp_drawable_get_format (drawable)));
}
CODE
    );
}

Manish Singh's avatar
Stuff    
Manish Singh committed
299
sub drawable_type {
300
301
302
303
304
305
306
307
308
309
310
311
    $blurb = "Returns the drawable's type.";
    $help  = "This procedure returns the drawable's type.";

    &std_pdb_misc;

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );

    @outargs = (
	{ name => 'type', type => 'enum GimpImageType',
312
	  desc => "The drawable's type" }
313
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
314

315
316
317
    %invoke = (
	code => <<'CODE'
{
318
  type = gimp_babl_format_get_image_type (gimp_drawable_get_format (drawable));
319
320
321
}
CODE
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
322
323
324
}

sub drawable_has_alpha {
325
    $blurb = 'Returns TRUE if the drawable has an alpha channel.';
326

Manish Singh's avatar
Stuff    
Manish Singh committed
327
328
329
330
331
332
    $help = <<'HELP';
This procedure returns whether the specified drawable has an alpha channel.
This can only be true for layers, and the associated type will be one of:
{ RGBA , GRAYA, INDEXEDA }.
HELP

333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
    &std_pdb_misc;

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );

    @outargs = (
	{ name => 'has_alpha', type => 'boolean',
	  desc => 'Does the drawable have an alpha channel?' }
    );

    %invoke = (
	code => <<'CODE'
{
  has_alpha = gimp_drawable_has_alpha (drawable);
}
CODE
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
352
353
354
}

sub drawable_type_with_alpha {
355
356
    $blurb = "Returns the drawable's type with alpha.";

Manish Singh's avatar
Stuff    
Manish Singh committed
357
    $help = <<'HELP';
358
359
360
361
This procedure returns the drawable's type as if had an alpha
channel. If the type is currently Gray, for instance, the returned
type would be GrayA. If the drawable already has an alpha channel, the
drawable's type is simply returned.
Manish Singh's avatar
Stuff    
Manish Singh committed
362
363
HELP

364
365
366
367
368
369
370
371
372
    &std_pdb_misc;

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );

    @outargs = (
	{ name => 'type_with_alpha', type => 'enum GimpImageType
373
374
375
					      (no GIMP_RGB_IMAGE,
					       GIMP_GRAY_IMAGE,
					       GIMP_INDEXED_IMAGE)',
376
	  desc => "The drawable's type with alpha" }
377
378
379
380
381
    );

    %invoke = (
	code => <<'CODE'
{
382
383
384
  const Babl *format = gimp_drawable_get_format_with_alpha (drawable);

  type_with_alpha = gimp_babl_format_get_image_type (format);
385
386
387
}
CODE
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
388
389
}

Marc Lehmann's avatar
Marc Lehmann committed
390
sub drawable_is_rgb {
391
392
393
    $blurb = 'Returns whether the drawable is an RGB type.';

    $help = <<HELP;
394
This procedure returns TRUE if the specified drawable
395
396
397
398
399
400
401
402
403
404
405
406
is of type { RGB, RGBA }.
HELP

    &std_pdb_misc;

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );

    @outargs = (
	{ name => 'is_rgb', type => 'boolean',
407
	  desc => 'TRUE if the drawable is an RGB type' }
408
409
410
411
412
413
414
415
416
    );

    %invoke = (
	code => <<'CODE'
{
  is_rgb = gimp_drawable_is_rgb (drawable);
}
CODE
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
417
418
}

Marc Lehmann's avatar
Marc Lehmann committed
419
sub drawable_is_gray {
420
421
422
    $blurb = 'Returns whether the drawable is a grayscale type.';

    $help = <<HELP;
423
This procedure returns TRUE if the specified drawable
424
425
426
427
428
429
430
431
432
433
434
435
is of type { Gray, GrayA }.
HELP

    &std_pdb_misc;

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );

    @outargs = (
	{ name => 'is_gray', type => 'boolean',
436
	  desc => 'TRUE if the drawable is a grayscale type' }
437
438
439
440
441
442
443
444
445
    );

    %invoke = (
	code => <<'CODE'
{
  is_gray = gimp_drawable_is_gray (drawable);
}
CODE
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
446
447
}

Marc Lehmann's avatar
Marc Lehmann committed
448
sub drawable_is_indexed {
449
450
451
    $blurb = 'Returns whether the drawable is an indexed type.';

    $help = <<HELP;
452
This procedure returns TRUE if the specified drawable
453
454
455
456
457
458
459
460
461
462
463
464
is of type { Indexed, IndexedA }.
HELP

    &std_pdb_misc;

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );

    @outargs = (
	{ name => 'is_indexed', type => 'boolean',
465
	  desc => 'TRUE if the drawable is an indexed type' }
466
467
468
469
470
471
472
473
474
    );

    %invoke = (
	code => <<'CODE'
{
  is_indexed = gimp_drawable_is_indexed (drawable);
}
CODE
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
475
476
}

477
sub drawable_bpp {
478
479
    $blurb = 'Returns the bytes per pixel.';

Manish Singh's avatar
Stuff    
Manish Singh committed
480
    $help = <<'HELP';
481
482
This procedure returns the number of bytes per pixel, which corresponds to
the number of components unless gimp_plugin_enable_precision() was called.
Manish Singh's avatar
Stuff    
Manish Singh committed
483
484
HELP

485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
    &std_pdb_misc;

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );

    @outargs = (
	{ name => 'bpp', type => 'int32',
	  desc => 'Bytes per pixel' }
    );

    %invoke = (
	code => <<'CODE'
{
500
501
502
503
504
  const Babl *format = gimp_drawable_get_format (drawable);

  if (! gimp->plug_in_manager->current_plug_in ||
      ! gimp_plug_in_precision_enabled (gimp->plug_in_manager->current_plug_in))
    {
505
      format = gimp_babl_compat_u8_format (format);
506
507
508
    }

  bpp = babl_format_get_bytes_per_pixel (format);
509
510
511
}
CODE
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
512
513
514
}

sub drawable_width {
515
516
517
518
519
520
521
522
523
524
525
526
527
528
    $blurb = 'Returns the width of the drawable.';
    $help  = "This procedure returns the specified drawable's width in pixels.";

    &std_pdb_misc;

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );

    @outargs = (
	{ name => 'width', type => 'int32',
	  desc => 'Width of drawable' }
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
529

530
531
532
    %invoke = (
	code => <<'CODE'
{
533
  width = gimp_item_get_width (GIMP_ITEM (drawable));
534
535
536
}
CODE
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
537
538
539
}

sub drawable_height {
540
541
542
543
    $blurb = 'Returns the height of the drawable.';
    $help  = "This procedure returns the specified drawable's height in pixels.";

    &std_pdb_misc;
Manish Singh's avatar
Stuff    
Manish Singh committed
544

545
546
547
548
549
550
551
552
553
554
555
556
557
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );

    @outargs = (
	{ name => 'height', type => 'int32',
	  desc => 'Height of drawable' }
    );

    %invoke = (
	code => <<'CODE'
{
558
  height = gimp_item_get_height (GIMP_ITEM (drawable));
559
560
561
}
CODE
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
562
563
564
565
566
567
568
569
570
571
572
573
574
}

sub drawable_offsets {
    $blurb = 'Returns the offsets for the drawable.';

    $help = <<'HELP';
This procedure returns the specified drawable's offsets. This only makes sense
if the drawable is a layer since channels are anchored. The offsets of a
channel will be returned as 0.
HELP

    &std_pdb_misc;

575
576
577
578
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' }
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
579

580
    @outargs = (
581
582
	{ name => 'offset_x', type => 'int32', void_ret => 1,
	  desc => "x offset of drawable" },
583
584
585
	{ name => 'offset_y', type => 'int32',
	  desc => "y offset of drawable" }
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
586

587
588
589
    %invoke = (
	code => <<'CODE'
{
590
  gimp_item_get_offset (GIMP_ITEM (drawable), &offset_x, &offset_y);
591
592
593
}
CODE
    );
Manish Singh's avatar
Stuff    
Manish Singh committed
594
595
}

Manish Singh's avatar
Manish Singh committed
596
597
sub drawable_get_pixel {
    $blurb = 'Gets the value of the pixel at the specified coordinates.';
Manish Singh's avatar
Manish Singh committed
598
599

    $help = <<'HELP';
Manish Singh's avatar
Manish Singh committed
600
This procedure gets the pixel value at the specified coordinates. The
Manish Singh's avatar
Manish Singh committed
601
'num_channels' argument must always be equal to the bytes-per-pixel value for
Manish Singh's avatar
Manish Singh committed
602
the specified drawable.
Manish Singh's avatar
Manish Singh committed
603
604
605
606
607
HELP

    &std_pdb_misc;
    $date = '1997';

608
609
610
611
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' },
	{ name => 'x_coord', type => '0 <= int32',
612
	  desc => 'The x coordinate' },
613
	{ name => 'y_coord', type => '0 <= int32',
614
	  desc => 'The y coordinate' }
615
    );
Manish Singh's avatar
Manish Singh committed
616

617
618
    @outargs = (
	{ name => 'pixel', type => 'int8array',
619
	  desc => 'The pixel value',
620
	  array => { name => 'num_channels', no_validate => 1,
621
	  	     desc => 'The number of channels for the pixel' } }
622
    );
Manish Singh's avatar
Manish Singh committed
623
624
625
626

    %invoke = (
	code => <<'CODE'
{
627
628
629
630
631
  const Babl *format = gimp_drawable_get_format (drawable);

  if (! gimp->plug_in_manager->current_plug_in ||
      ! gimp_plug_in_precision_enabled (gimp->plug_in_manager->current_plug_in))
    {
632
      format = gimp_babl_compat_u8_format (format);
633
634
    }

635
636
  if (x_coord < gimp_item_get_width  (GIMP_ITEM (drawable)) &&
      y_coord < gimp_item_get_height (GIMP_ITEM (drawable)))
637
    {
638
639
640
      num_channels = babl_format_get_bytes_per_pixel (format);
      pixel = g_new0 (guint8, num_channels);

641
      gegl_buffer_sample (gimp_drawable_get_buffer (drawable),
642
                          x_coord, y_coord, NULL, pixel, format,
643
                          GEGL_SAMPLER_NEAREST, GEGL_ABYSS_NONE);
Manish Singh's avatar
Manish Singh committed
644
645
646
647
648
649
650
651
    }
  else
    success = FALSE;
}
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
652
653
sub drawable_set_pixel {
    $blurb = 'Sets the value of the pixel at the specified coordinates.';
Manish Singh's avatar
Manish Singh committed
654
655

    $help = <<'HELP';
Manish Singh's avatar
Manish Singh committed
656
This procedure sets the pixel value at the specified coordinates. The
Manish Singh's avatar
Manish Singh committed
657
'num_channels' argument must always be equal to the bytes-per-pixel value for
Manish Singh's avatar
Manish Singh committed
658
the specified drawable. Note that this function is not undoable, you should
659
use it only on drawables you just created yourself.
Manish Singh's avatar
Manish Singh committed
660
661
662
663
664
HELP

    &std_pdb_misc;
    $date = '1997';

665
666
667
668
    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' },
	{ name => 'x_coord', type => '0 <= int32',
669
	  desc => 'The x coordinate' },
670
	{ name => 'y_coord', type => '0 <= int32',
671
	  desc => 'The y coordinate' },
672
673
	{ name => 'pixel', type => 'int8array',
	  desc => 'The pixel value',
674
	  array => { name => 'num_channels', no_validate => 1,
675
	  	     desc => 'The number of channels for the pixel' } }
676
    );
Manish Singh's avatar
Manish Singh committed
677
678
679
680

    %invoke = (
	code => <<'CODE'
{
681
682
683
684
685
  const Babl *format = gimp_drawable_get_format (drawable);

  if (! gimp->plug_in_manager->current_plug_in ||
      ! gimp_plug_in_precision_enabled (gimp->plug_in_manager->current_plug_in))
    {
686
      format = gimp_babl_compat_u8_format (format);
687
688
    }

689
690
  if (gimp_pdb_item_is_modifyable (GIMP_ITEM (drawable),
                                   GIMP_PDB_ITEM_CONTENT, error) &&
691
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error) &&
692
      x_coord < gimp_item_get_width  (GIMP_ITEM (drawable)) &&
693
      y_coord < gimp_item_get_height (GIMP_ITEM (drawable)) &&
694
      num_channels == babl_format_get_bytes_per_pixel (format))
Manish Singh's avatar
Manish Singh committed
695
    {
696
      gegl_buffer_set (gimp_drawable_get_buffer (drawable),
697
                       GEGL_RECTANGLE (x_coord, y_coord, 1, 1),
698
                       0, format, pixel, GEGL_AUTO_ROWSTRIDE);
Manish Singh's avatar
Manish Singh committed
699
700
701
702
703
704
705
706
    }
  else
    success = FALSE;
}
CODE
    );
}

Manish Singh's avatar
Manish Singh committed
707
sub drawable_set_image {
708
    &std_pdb_deprecated();
Manish Singh's avatar
Manish Singh committed
709
710

    @inargs = (
711
712
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' },
713
714
	{ name => 'image', type => 'image',
	  desc => 'The image' }
Manish Singh's avatar
Manish Singh committed
715
716
    );

717
718
    %invoke = (
	code =><<'CODE'
719
{
720
  if (image != gimp_item_get_image (GIMP_ITEM (drawable)))
721
    success = FALSE;
722
723
724
}
CODE
    );
Manish Singh's avatar
Manish Singh committed
725
726
}

727
728
729
730
sub drawable_thumbnail {
    $blurb = 'Get a thumbnail of a drawable.';

    $help = <<'HELP';
731
This function gets data from which a thumbnail of a drawable preview
732
can be created. Maximum x or y dimension is 1024 pixels. The pixels are
733
734
returned in RGB[A] or GRAY[A] format. The bpp return value gives the
number of bytes in the image.
735
736
HELP

737
    &andy_pdb_misc('1999');
738
739

    @inargs = (
740
741
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' },
742
	{ name => 'width', type => '1 <= int32 <= 1024',
743
	  desc => 'The requested thumbnail width' },
744
	{ name => 'height', type => '1 <= int32 <= 1024',
745
	  desc => 'The requested thumbnail height' }
746
747
748
    );

    @outargs = (
749
	{ name => 'actual_width', type => 'int32', void_ret => 1,
750
	  desc => 'The previews width' },
751
	{ name => 'actual_height', type => 'int32',
752
	  desc => 'The previews height' },
753
	{ name => 'bpp', type => 'int32',
754
	  desc => 'The previews bpp' },
755
        { name => 'thumbnail_data', type => 'int8array',
756
757
	  desc => 'The thumbnail data', wrap => 1,
	  array => { name => 'thumbnail_data_count',
758
		     desc => 'The number of bytes in thumbnail data' } }
759
760
761
762
763
    );

    %invoke = (
	code => <<'CODE'
{
764
765
766
  GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
  GimpTempBuf *buf;
  gint         dwidth, dheight;
767

768
769
  g_assert (GIMP_VIEWABLE_MAX_PREVIEW_SIZE >= 1024);

770
  /* Adjust the width/height ratio */
771
772
  dwidth  = gimp_item_get_width  (GIMP_ITEM (drawable));
  dheight = gimp_item_get_height (GIMP_ITEM (drawable));
773
774

  if (dwidth > dheight)
775
    height = MAX (1, (width * dheight) / dwidth);
776
  else
777
    width  = MAX (1, (height * dwidth) / dheight);
778

779
  if (image->gimp->config->layer_previews)
780
781
    buf = gimp_viewable_get_new_preview (GIMP_VIEWABLE (drawable), context,
                                         width, height);
782
  else
783
784
785
    buf = gimp_viewable_get_dummy_preview (GIMP_VIEWABLE (drawable),
                                           width, height,
                                           gimp_drawable_get_preview_format (drawable));
786
787
788

  if (buf)
    {
789
790
791
      actual_width         = gimp_temp_buf_get_width  (buf);
      actual_height        = gimp_temp_buf_get_height (buf);
      bpp                  = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (buf));
792
793
      thumbnail_data_count = gimp_temp_buf_get_data_size (buf);
      thumbnail_data       = g_memdup (gimp_temp_buf_get_data (buf),
794
                                       thumbnail_data_count);
795

796
      gimp_temp_buf_unref (buf);
797
798
    }
  else
799
    success = FALSE;
800
801
802
803
804
}
CODE
    );
}

805
806
807
808
809
sub drawable_sub_thumbnail {
    $blurb = 'Get a thumbnail of a sub-area of a drawable drawable.';

    $help = <<'HELP';
This function gets data from which a thumbnail of a drawable preview
810
can be created. Maximum x or y dimension is 1024 pixels. The pixels are
811
812
813
814
returned in RGB[A] or GRAY[A] format. The bpp return value gives the
number of bytes in the image.
HELP

815
    &mitch_pdb_misc('2004', '2.2');
816
817

    @inargs = (
818
819
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable' },
820
821
822
823
        { name => 'src_x', type => '0 <= int32',
          desc => 'The x coordinate of the area' },
        { name => 'src_y', type => '0 <= int32',
          desc => 'The y coordinate of the area' },
824
        { name => 'src_width', type => '1 <= int32',
825
          desc => 'The width of the area' },
826
        { name => 'src_height', type => '1 <= int32',
827
          desc => 'The height of the area' },
828
	{ name => 'dest_width', type => '1 <= int32 <= 1024',
829
	  desc => 'The thumbnail width' },
830
	{ name => 'dest_height', type => '1 <= int32 <= 1024',
831
832
833
834
	  desc => 'The thumbnail height' }
    );

    @outargs = (
835
	{ name => 'width', type => 'int32', void_ret => 1,
836
	  desc => 'The previews width' },
837
	{ name => 'height', type => 'int32',
838
	  desc => 'The previews height' },
839
	{ name => 'bpp', type => 'int32',
840
	  desc => 'The previews bpp' },
841
        { name => 'thumbnail_data', type => 'int8array',
842
843
	  desc => 'The thumbnail data', wrap => 1,
	  array => { name => 'thumbnail_data_count',
844
		     desc => 'The number of bytes in thumbnail data' } }
845
846
847
848
849
850
    );

    %invoke = (
	headers => [ qw("core/gimpdrawable-preview.h") ],
        code    => <<'CODE'
{
851
852
  if ((src_x + src_width)  <= gimp_item_get_width  (GIMP_ITEM (drawable)) &&
      (src_y + src_height) <= gimp_item_get_height (GIMP_ITEM (drawable)))
853
    {
854
855
      GimpImage   *image = gimp_item_get_image (GIMP_ITEM (drawable));
      GimpTempBuf *buf;
856

857
      if (image->gimp->config->layer_previews)
858
859
860
861
        buf = gimp_drawable_get_sub_preview (drawable,
                                             src_x, src_y,
                                             src_width, src_height,
                                             dest_width, dest_height);
862
      else
863
864
865
        buf = gimp_viewable_get_dummy_preview (GIMP_VIEWABLE (drawable),
                                               dest_width, dest_height,
                                               gimp_drawable_get_preview_format (drawable));
866
867
868

      if (buf)
        {
869
870
871
          width                = gimp_temp_buf_get_width  (buf);
          height               = gimp_temp_buf_get_height (buf);
          bpp                  = babl_format_get_bytes_per_pixel (gimp_temp_buf_get_format (buf));
872
873
          thumbnail_data_count = gimp_temp_buf_get_data_size (buf);
          thumbnail_data       = g_memdup (gimp_temp_buf_get_data (buf),
874
                                           thumbnail_data_count);
875

876
          gimp_temp_buf_unref (buf);
877
878
        }
      else
879
        success = FALSE;
880
    }
881
882
  else
    success = FALSE;
883
884
885
886
887
}
CODE
    );
}

888
889
890
891
892
893
894
895
896
897
sub drawable_offset {
    $blurb = <<'BLURB';
Offset the drawable by the specified amounts in the X and Y directions
BLURB

    $help = <<'HELP';
This procedure offsets the specified drawable by the amounts specified by
'offset_x' and 'offset_y'. If 'wrap_around' is set to TRUE, then portions of
the drawable which are offset out of bounds are wrapped around. Alternatively,
the undefined regions of the drawable can be filled with transparency or the
898
background color, as specified by the 'fill-type' parameter.
899
900
901
902
903
904
905
906
907
908
909
910
HELP

    &std_pdb_misc;
    $date = '1997';

    @inargs = (
	{ name => 'drawable', type => 'drawable',
	  desc => 'The drawable to offset' },
	{ name => 'wrap_around', type => 'boolean',
	  desc => 'wrap image around or fill vacated regions' },
	{ name => 'fill_type', type => 'enum GimpOffsetType',
	  desc => 'fill vacated regions of drawable with background or
911
		   transparent' },
912
913
914
915
916
917
918
919
920
	{ name => 'offset_x', type => 'int32',
	  desc => 'offset by this amount in X direction' },
	{ name => 'offset_y', type => 'int32',
	  desc => 'offset by this amount in Y direction' }
    );

    %invoke = (
	code => <<'CODE'
{
921
922
  if (gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL,
                                 GIMP_PDB_ITEM_CONTENT, error) &&
923
      gimp_pdb_item_is_not_group (GIMP_ITEM (drawable), error))
924
925
    gimp_drawable_offset (drawable, context, wrap_around, fill_type,
                          offset_x, offset_y);
926
927
  else
    success = FALSE;
928
929
930
931
932
}
CODE
    );
}

933
934
935
936
937
938
939
940
941
942
943
944
945
946
sub drawable_foreground_extract {
    $blurb = 'Extract the foreground of a drawable using a given trimap.';

    $help = <<'HELP';
Image Segmentation by Uniform Color Clustering, see
http://www.inf.fu-berlin.de/inst/pubs/tr-b-05-07.pdf
HELP

    $author    = 'Gerald Friedland <fland@inf.fu-berlin.de>, Kristian Jantz <jantz@inf.fu-berlin.de>, Sven Neumann <sven@gimp.org>';
    $copyright = 'Gerald Friedland';
    $date      = '2005';
    $since     = '2.4';

    @inargs = (
947
	{ name => 'drawable', type => 'drawable',
948
	  desc => 'The drawable' },
949
        { name => 'mode', type => 'enum GimpForegroundExtractMode',
950
	  desc => 'The algorithm to use' },
951
        { name => 'mask', type => 'drawable', desc => 'Tri-Map' }
952
953
    );

954
955
    %invoke = (
	headers => [ qw("core/gimpdrawable-foreground-extract.h") ],
956
957
        code    => <<'CODE'
{
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
  if (mode == GIMP_FOREGROUND_EXTRACT_MATTING &&
      gimp_pdb_item_is_attached (GIMP_ITEM (drawable), NULL, 0, error))
    {
      GimpPDBContext *pdb_context = GIMP_PDB_CONTEXT (context);
      GimpImage      *image       = gimp_item_get_image (GIMP_ITEM (drawable));
      GeglBuffer     *buffer;

      buffer = gimp_drawable_foreground_extract (drawable,
                                                 GIMP_MATTING_ENGINE_GLOBAL,
                                                 2,
                                                 2,
                                                 2,
                                                 gimp_drawable_get_buffer (mask),
                                                 progress);

      gimp_channel_select_buffer (gimp_image_get_mask (image),
                                  C_("command", "Foreground Select"),
                                  buffer,
                                  0, /* x offset */
                                  0, /* y offset */
                                  GIMP_CHANNEL_OP_REPLACE,
                                  pdb_context->feather,
                                  pdb_context->feather_radius_x,
                                  pdb_context->feather_radius_y);

      g_object_unref (buffer);
    }
985
986
  else
    success = FALSE;
987
988
989
990
991
992
}
CODE
    );
}


993
@headers = qw("config/gimpcoreconfig.h"
994
              "gegl/gimp-babl.h"
995
              "gegl/gimp-babl-compat.h"
996
              "core/gimp.h"
997
              "core/gimpchannel-select.h"
998
              "core/gimpdrawable-offset.h"
999
              "core/gimptempbuf.h"
1000
              "gimppdb-utils.h"
1001
              "gimppdbcontext.h"
1002
              "gimp-intl.h");
Manish Singh's avatar
Stuff    
Manish Singh committed
1003

1004
1005
@procs = qw(drawable_get_format
            drawable_type
1006
1007
1008
1009
1010
            drawable_type_with_alpha
            drawable_has_alpha
            drawable_is_rgb
            drawable_is_gray
            drawable_is_indexed
1011
1012
1013
1014
            drawable_bpp
            drawable_width
            drawable_height
            drawable_offsets
1015
            drawable_set_image
1016
1017
1018
            drawable_mask_bounds
            drawable_mask_intersect
            drawable_merge_shadow
1019
            drawable_free_shadow
1020
            drawable_update
1021
            drawable_get_pixel drawable_set_pixel
1022
1023
1024
1025
	    drawable_fill
            drawable_offset
            drawable_thumbnail
            drawable_sub_thumbnail
1026
            drawable_foreground_extract);
1027

1028
%exports = (app => [@procs], lib => [@procs]);
Manish Singh's avatar
Stuff    
Manish Singh committed
1029
1030

$desc = 'Drawable procedures';
1031
1032
1033
$doc_title = 'gimpdrawable';
$doc_short_desc = 'Functions to manipulate drawables.';
$doc_long_desc = 'Functions to manipulate drawables.';
Manish Singh's avatar
Stuff    
Manish Singh committed
1034
1035

1;