~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# The GIMP -- an image manipulation program
 
2
# Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
 
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
 
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 
 
18
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
 
19
 
 
20
sub drawable_arg () {{
 
21
    name => 'drawable',
 
22
    type => 'drawable',
 
23
    desc => 'The drawable',
 
24
}}
 
25
 
 
26
sub channel_arg () {{
 
27
    name => 'channel',
 
28
    type => 'enum GimpHistogramChannel',
 
29
    desc => 'The channel to modify: { %%desc%% }'
 
30
}}
 
31
 
 
32
sub brightness_contrast {
 
33
    $blurb = 'Modify brightness/contrast in the specified drawable.';
 
34
 
 
35
    $help = <<'HELP';
 
36
This procedures allows the brightness and contrast of the specified drawable to
 
37
be modified.  Both 'brightness' and 'contrast' parameters are defined between
 
38
-127 and 127.
 
39
HELP
 
40
 
 
41
    &std_pdb_misc;
 
42
    $date = '1997';
 
43
 
 
44
    @inargs = ( &drawable_arg );
 
45
    foreach (qw( brightness contrast)) {
 
46
        push @inargs, { name => $_, type => '-127 <= int32 <= 127',
 
47
                        desc => "\u$_ adjustment: (%%desc%%)" }
 
48
    }
 
49
 
 
50
    %invoke = (
 
51
        code => <<'CODE'
 
52
{
 
53
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
54
      gimp_drawable_is_indexed (drawable))
 
55
    success = FALSE;
 
56
 
 
57
  if (success)
 
58
    {
 
59
      gint x, y, width, height;
 
60
 
 
61
      /* The application should occur only within selection bounds */
 
62
      if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
 
63
        {
 
64
          GimpLut     *lut;
 
65
          PixelRegion  srcPR, destPR;
 
66
 
 
67
          lut = brightness_contrast_lut_new (brightness / 255.0,
 
68
                                             contrast / 127.0,
 
69
                                             gimp_drawable_bytes (drawable));
 
70
 
 
71
          pixel_region_init (&srcPR, gimp_drawable_data (drawable),
 
72
                             x, y, width, height, FALSE);
 
73
          pixel_region_init (&destPR, gimp_drawable_shadow (drawable),
 
74
                             x, y, width, height, TRUE);
 
75
 
 
76
          pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2,
 
77
                                          &srcPR, &destPR);
 
78
 
 
79
          gimp_lut_free (lut);
 
80
 
 
81
          gimp_drawable_merge_shadow (drawable, TRUE, _("Brightness-Contrast"));
 
82
          gimp_drawable_update (drawable, x, y, width, height);
 
83
        }
 
84
    }
 
85
}
 
86
CODE
 
87
    );
 
88
}
 
89
 
 
90
sub levels {
 
91
    $blurb = 'Modifies intensity levels in the specified drawable.';
 
92
 
 
93
    $help = <<'HELP';
 
94
This tool allows intensity levels in the specified drawable to be remapped
 
95
according to a set of parameters. The low/high input levels specify an initial
 
96
mapping from the source intensities. The gamma value determines how intensities
 
97
between the low and high input intensities are interpolated. A gamma value of
 
98
1.0 results in a linear interpolation. Higher gamma values result in more
 
99
high-level intensities. Lower gamma values result in more low-level
 
100
intensities. The low/high output levels constrain the final intensity
 
101
mapping--that is, no final intensity will be lower than the low output level
 
102
and no final intensity will be higher than the high output level. This tool is
 
103
only valid on RGB color and grayscale images. It will not operate on indexed
 
104
drawables.
 
105
HELP
 
106
 
 
107
    &std_pdb_misc;
 
108
 
 
109
    @inargs = (
 
110
        &drawable_arg,
 
111
        &channel_arg
 
112
    );
 
113
 
 
114
    foreach $arg (qw(input output)) {
 
115
        foreach (qw(low high)) {
 
116
            push @inargs, { name => "${_}_$arg", type => '0 <= int32 <= 255',
 
117
                            desc => "Intensity of ${_}est $arg: (%%desc%%)" }
 
118
        }
 
119
        push @inargs, { name => 'gamma', type => '0.1 <= float <= 10',
 
120
                        desc => 'Gamma correction factor: (%%desc%%)' }
 
121
    }
 
122
    $#inargs--;
 
123
 
 
124
    %invoke = (
 
125
        headers => [ qw("base/levels.h"
 
126
                        "core/gimpdrawable-levels.h") ],
 
127
        code => <<'CODE'
 
128
{
 
129
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
130
      gimp_drawable_is_indexed (drawable) ||
 
131
      (! gimp_drawable_has_alpha (drawable) &&
 
132
       channel == GIMP_HISTOGRAM_ALPHA) ||
 
133
      (gimp_drawable_is_gray (drawable) &&
 
134
       channel != GIMP_HISTOGRAM_VALUE && channel != GIMP_HISTOGRAM_ALPHA))
 
135
    success = FALSE;
 
136
 
 
137
  if (success)
 
138
    gimp_drawable_levels (drawable, context,
 
139
                          channel,
 
140
                          low_input,
 
141
                          high_input,
 
142
                          gamma,
 
143
                          low_output,
 
144
                          high_output);
 
145
}
 
146
CODE
 
147
    );
 
148
}
 
149
 
 
150
sub levels_stretch {
 
151
    $blurb = 'Automatically modifies intensity levels in the specified drawable.';
 
152
 
 
153
    $help = <<'HELP';
 
154
This procedure allows intensity levels in the specified drawable to be
 
155
remapped according to a set of guessed parameters. It is equivalent to
 
156
clicking the "Auto" button in the Levels tool. This procedure is
 
157
only valid on RGB color and grayscale images. It will not operate on
 
158
indexed drawables.
 
159
HELP
 
160
 
 
161
    $author = $copyright = 'Joao S.O. Bueno, Shawn Willden';
 
162
    $date = '2003';
 
163
 
 
164
    @inargs = ( &drawable_arg );
 
165
 
 
166
    %invoke = (
 
167
        headers => [ qw("base/levels.h"
 
168
                        "base/gimphistogram.h"
 
169
                        "core/gimpdrawable-histogram.h"
 
170
                        "core/gimpdrawable-levels.h") ],
 
171
        code => <<'CODE'
 
172
{
 
173
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
174
      gimp_drawable_is_indexed (drawable))
 
175
    success = FALSE;
 
176
 
 
177
  if (success)
 
178
    gimp_drawable_levels_stretch (drawable, context);
 
179
}
 
180
CODE
 
181
    );
 
182
}
 
183
 
 
184
 
 
185
 
 
186
sub levels_auto {
 
187
    &std_pdb_deprecated ('gimp_levels_stretch');
 
188
 
 
189
    @inargs = ( &drawable_arg );
 
190
 
 
191
    %invoke = (
 
192
        headers => [ qw("base/levels.h"
 
193
                        "base/gimphistogram.h"
 
194
                        "core/gimpdrawable-histogram.h"
 
195
                        "core/gimpdrawable-levels.h") ],
 
196
        code => <<'CODE'
 
197
{
 
198
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
199
      gimp_drawable_is_indexed (drawable))
 
200
    success = FALSE;
 
201
 
 
202
  if (success)
 
203
    gimp_drawable_levels_stretch (drawable, context);
 
204
}
 
205
CODE
 
206
    );
 
207
}
 
208
 
 
209
sub posterize {
 
210
    $blurb = 'Posterize the specified drawable.';
 
211
 
 
212
    $help = <<'HELP';
 
213
This procedures reduces the number of shades allows in each intensity channel
 
214
to the specified 'levels' parameter.
 
215
HELP
 
216
 
 
217
    &std_pdb_misc;
 
218
    $date = '1997';
 
219
 
 
220
    @inargs = (
 
221
        &drawable_arg,
 
222
        { name => 'levels', type => '2 <= int32 <= 255',
 
223
          desc => 'Levels of posterization: (%%desc%%)' }
 
224
    );
 
225
 
 
226
    %invoke = (
 
227
        code => <<'CODE'
 
228
{
 
229
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
230
      gimp_drawable_is_indexed (drawable))
 
231
    success = FALSE;
 
232
 
 
233
  if (success)
 
234
    {
 
235
      gint x, y, width, height;
 
236
 
 
237
      /* The application should occur only within selection bounds */
 
238
      if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
 
239
        {
 
240
          GimpLut     *lut;
 
241
          PixelRegion  srcPR, destPR;
 
242
 
 
243
          lut = posterize_lut_new (levels, gimp_drawable_bytes (drawable)); 
 
244
 
 
245
          pixel_region_init (&srcPR, gimp_drawable_data (drawable),
 
246
                             x, y, width, height, FALSE);
 
247
          pixel_region_init (&destPR, gimp_drawable_shadow (drawable),
 
248
                             x, y, width, height, TRUE);
 
249
 
 
250
          pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2,
 
251
                                          &srcPR, &destPR);
 
252
 
 
253
          gimp_lut_free (lut);
 
254
 
 
255
          gimp_drawable_merge_shadow (drawable, TRUE, _("Posterize"));
 
256
          gimp_drawable_update (drawable, x, y, width, height);
 
257
        }
 
258
    }
 
259
}
 
260
CODE
 
261
    );
 
262
}
 
263
 
 
264
sub desaturate {
 
265
    $blurb = 'Desaturate the contents of the specified drawable.';
 
266
 
 
267
    $help = <<'HELP';
 
268
This procedure desaturates the contents of the specified drawable. This
 
269
procedure only works on drawables of type RGB color.
 
270
HELP
 
271
 
 
272
    &std_pdb_misc;
 
273
 
 
274
    @inargs = ( &drawable_arg );
 
275
 
 
276
    %invoke = (
 
277
        headers => [ qw("core/gimpdrawable-desaturate.h") ],
 
278
        code => <<'CODE'
 
279
{
 
280
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
281
      ! gimp_drawable_is_rgb (drawable))
 
282
    success = FALSE;
 
283
 
 
284
  if (success)
 
285
    gimp_drawable_desaturate (drawable);
 
286
}
 
287
CODE
 
288
    );
 
289
}
 
290
 
 
291
sub equalize {
 
292
    $blurb = 'Equalize the contents of the specified drawable.';
 
293
 
 
294
    $help = <<'HELP';
 
295
This procedure equalizes the contents of the specified drawable. Each intensity
 
296
channel is equalizeed independently. The equalized intensity is given as inten'
 
297
= (255 - inten). Indexed color drawables are not valid for this operation. The
 
298
'mask_only' option specifies whether to adjust only the area of the image
 
299
within the selection bounds, or the entire image based on the histogram of the
 
300
selected area. If there is no selection, the entire image is adjusted based on
 
301
the histogram for the entire image.
 
302
HELP
 
303
 
 
304
    &std_pdb_misc;
 
305
 
 
306
    @inargs = (
 
307
        &drawable_arg,
 
308
        { name => 'mask_only', type => 'boolean',
 
309
          desc => 'Equalization option' }
 
310
    );
 
311
 
 
312
    %invoke = (
 
313
        headers => [ qw("core/gimpdrawable-equalize.h") ],
 
314
        code => <<'CODE'
 
315
{
 
316
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
317
      gimp_drawable_is_indexed (drawable))
 
318
    success = FALSE;
 
319
 
 
320
  if (success)
 
321
    gimp_drawable_equalize (drawable, mask_only);
 
322
}
 
323
CODE
 
324
    );
 
325
}
 
326
 
 
327
sub invert {
 
328
    $blurb = 'Invert the contents of the specified drawable.';
 
329
 
 
330
    $help = <<'HELP';
 
331
This procedure inverts the contents of the specified drawable. Each intensity
 
332
channel is inverted independently. The inverted intensity is given as inten' =
 
333
(255 - inten). Indexed color drawables are not valid for this operation.
 
334
HELP
 
335
 
 
336
    &std_pdb_misc;
 
337
 
 
338
    @inargs = ( &drawable_arg );
 
339
 
 
340
    %invoke = (
 
341
        headers => [ qw("core/gimpdrawable-invert.h") ],
 
342
        code => <<'CODE'
 
343
{
 
344
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
345
      gimp_drawable_is_indexed (drawable))
 
346
    success = FALSE;
 
347
 
 
348
  if (success)
 
349
    gimp_drawable_invert (drawable);
 
350
}
 
351
CODE
 
352
    );
 
353
}
 
354
 
 
355
sub curves_spline {
 
356
    $blurb = 'Modifies the intensity curve(s) for specified drawable.';
 
357
 
 
358
    $help = <<'HELP';
 
359
Modifies the intensity mapping for one channel in the specified drawable. The
 
360
drawable must be either grayscale or RGB, and the channel can be either an
 
361
intensity component, or the value. The 'control_pts' parameter is an array of
 
362
integers which define a set of control points which describe a Catmull Rom
 
363
spline which yields the final intensity curve. Use the 'gimp_curves_explicit'
 
364
function to explicitly modify intensity levels.
 
365
HELP
 
366
 
 
367
    &std_pdb_misc;
 
368
 
 
369
    @inargs = (
 
370
        &drawable_arg,
 
371
        &channel_arg,
 
372
        { name => 'control_pts', type => 'int8array',
 
373
          desc => 'The spline control points: { cp1.x, cp1.y, cp2.x, cp2.y,
 
374
                   ... }',
 
375
          array => { name => 'num_points', type => '3 < int32 <= 34',
 
376
                     desc => 'The number of values in the control point array
 
377
                              (%%desc%%)' } }
 
378
    );
 
379
 
 
380
    %invoke = (
 
381
        headers => [ qw("base/curves.h") ],
 
382
        code => <<'CODE'
 
383
{
 
384
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
385
      gimp_drawable_is_indexed (drawable) || (num_points & 1) ||
 
386
      (! gimp_drawable_has_alpha (drawable) &&
 
387
       channel == GIMP_HISTOGRAM_ALPHA) ||
 
388
      (gimp_drawable_is_gray (drawable) &&
 
389
       channel != GIMP_HISTOGRAM_VALUE && channel != GIMP_HISTOGRAM_ALPHA))
 
390
    success = FALSE;
 
391
 
 
392
  if (success)
 
393
    {
 
394
      gint x, y, width, height;
 
395
 
 
396
      /* The application should occur only within selection bounds */
 
397
      if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
 
398
        {
 
399
          Curves       c;
 
400
          gint         j;
 
401
          PixelRegion  srcPR, destPR;
 
402
          GimpLut     *lut;
 
403
 
 
404
          /* FIXME: hack */
 
405
          if (gimp_drawable_is_gray (drawable) &&
 
406
              channel == GIMP_HISTOGRAM_ALPHA)
 
407
            channel = 1;
 
408
 
 
409
          lut = gimp_lut_new ();
 
410
 
 
411
          curves_init (&c);
 
412
 
 
413
          /*  unset the last point  */
 
414
          c.points[channel][CURVES_NUM_POINTS - 1][0] = -1;
 
415
          c.points[channel][CURVES_NUM_POINTS - 1][1] = -1;
 
416
 
 
417
          for (j = 0; j < num_points / 2; j++)
 
418
            {
 
419
              c.points[channel][j][0] = control_pts[j * 2];
 
420
              c.points[channel][j][1] = control_pts[j * 2 + 1];
 
421
            }
 
422
 
 
423
          curves_calculate_curve (&c, channel);
 
424
 
 
425
          gimp_lut_setup (lut,
 
426
                          (GimpLutFunc) curves_lut_func,
 
427
                          &c,
 
428
                          gimp_drawable_bytes (drawable));
 
429
 
 
430
          pixel_region_init (&srcPR, gimp_drawable_data (drawable),
 
431
                             x, y, width, height, FALSE);
 
432
          pixel_region_init (&destPR, gimp_drawable_shadow (drawable),
 
433
                             x, y, width, height, TRUE);
 
434
 
 
435
          pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2,
 
436
                                          &srcPR, &destPR);
 
437
 
 
438
          gimp_lut_free (lut);
 
439
 
 
440
          gimp_drawable_merge_shadow (drawable, TRUE, _("Curves"));
 
441
          gimp_drawable_update (drawable, x, y, width, height);
 
442
        }
 
443
    }
 
444
}
 
445
CODE
 
446
    );
 
447
}
 
448
 
 
449
sub curves_explicit {
 
450
    $blurb = 'Modifies the intensity curve(s) for specified drawable.';
 
451
 
 
452
    $help = <<'HELP';
 
453
Modifies the intensity mapping for one channel in the specified drawable. The
 
454
drawable must be either grayscale or RGB, and the channel can be either an
 
455
intensity component, or the value. The 'curve' parameter is an array of bytes
 
456
which explicitly defines how each pixel value in the drawable will be modified.
 
457
Use the 'gimp_curves_spline' function to modify intensity levels with Catmull
 
458
Rom splines.
 
459
HELP
 
460
 
 
461
    &std_pdb_misc;
 
462
 
 
463
    @inargs = (
 
464
        &drawable_arg,
 
465
        &channel_arg,
 
466
        { name => 'curve', type => 'int8array',
 
467
          desc => 'The explicit curve',
 
468
          array => { name => 'num_bytes',
 
469
                     desc => 'The number of bytes in the new curve (always
 
470
                              256)' } }
 
471
    );
 
472
 
 
473
    %invoke = (
 
474
        headers => [ qw("base/curves.h") ],
 
475
        code => <<'CODE'
 
476
{
 
477
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
478
      gimp_drawable_is_indexed (drawable) || (num_bytes != 256) ||
 
479
      (! gimp_drawable_has_alpha (drawable) &&
 
480
       channel == GIMP_HISTOGRAM_ALPHA) ||
 
481
      (gimp_drawable_is_gray (drawable) &&
 
482
       channel != GIMP_HISTOGRAM_VALUE && channel != GIMP_HISTOGRAM_ALPHA))
 
483
    success = FALSE;
 
484
 
 
485
  if (success)
 
486
    {
 
487
      gint x, y, width, height;
 
488
 
 
489
      /* The application should occur only within selection bounds */
 
490
      if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
 
491
        {
 
492
          Curves       c;
 
493
          gint         j;
 
494
          PixelRegion  srcPR, destPR;
 
495
          GimpLut     *lut;
 
496
 
 
497
          /* FIXME: hack */
 
498
          if (gimp_drawable_is_gray (drawable) &&
 
499
              channel == GIMP_HISTOGRAM_ALPHA)
 
500
            channel = 1;
 
501
 
 
502
          lut = gimp_lut_new ();
 
503
 
 
504
          curves_init (&c);
 
505
 
 
506
          for (j = 0; j < 256; j++)
 
507
            c.curve[channel][j] = curve[j];
 
508
 
 
509
          gimp_lut_setup (lut,
 
510
                          (GimpLutFunc) curves_lut_func,
 
511
                          &c,
 
512
                          gimp_drawable_bytes (drawable));
 
513
      
 
514
          pixel_region_init (&srcPR, gimp_drawable_data (drawable),
 
515
                             x, y, width, height, FALSE);
 
516
          pixel_region_init (&destPR, gimp_drawable_shadow (drawable),
 
517
                             x, y, width, height, TRUE);
 
518
 
 
519
          pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2,
 
520
                                          &srcPR, &destPR);
 
521
 
 
522
          gimp_lut_free (lut);
 
523
 
 
524
          gimp_drawable_merge_shadow (drawable, TRUE, _("Curves"));
 
525
          gimp_drawable_update (drawable, x, y, width, height);
 
526
        }
 
527
    }
 
528
}
 
529
CODE
 
530
    );
 
531
}
 
532
 
 
533
sub color_balance {
 
534
    $blurb = 'Modify the color balance of the specified drawable.';
 
535
 
 
536
    $help = <<'HELP';
 
537
Modify the color balance of the specified drawable. There are three axis which
 
538
can be modified: cyan-red, magenta-green, and yellow-blue. Negative values
 
539
increase the amount of the former, positive values increase the amount of the
 
540
latter. Color balance can be controlled with the 'transfer_mode' setting, which
 
541
allows shadows, midtones, and highlights in an image to be affected
 
542
differently. The 'preserve_lum' parameter, if non-zero, ensures that the
 
543
luminosity of each pixel remains fixed.
 
544
HELP
 
545
 
 
546
    &std_pdb_misc;
 
547
    $date = '1997';
 
548
 
 
549
    @inargs = (
 
550
        &drawable_arg,
 
551
        { name => 'transfer_mode', type => 'enum GimpTransferMode',
 
552
          desc => 'Transfer mode: { %%desc%% }' },
 
553
        { name => 'preserve_lum', type => 'boolean',
 
554
          desc => 'Preserve luminosity values at each pixel' }
 
555
    );
 
556
 
 
557
    foreach (qw(cyan_red magenta_green yellow_blue)) {
 
558
        my $arg = { name => $_, type => '-100 <= float <= 100' };
 
559
        ($arg->{desc} = ucfirst $_) =~ s/_(.)/-\U$1\E/;
 
560
         $arg->{desc} .= ' color balance: (%%desc%%)';
 
561
        push @inargs, $arg;
 
562
    }
 
563
 
 
564
    %invoke = (
 
565
        headers => [ qw("base/color-balance.h") ],
 
566
        code => <<'CODE'
 
567
{
 
568
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
569
      gimp_drawable_is_indexed (drawable))
 
570
    success = FALSE;
 
571
 
 
572
  if (success)
 
573
    {
 
574
      gint x, y, width, height;
 
575
 
 
576
      /* The application should occur only within selection bounds */
 
577
      if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
 
578
        {
 
579
          ColorBalance         cb;
 
580
          PixelRegionIterator *pr;
 
581
          PixelRegion          srcPR, destPR;
 
582
 
 
583
          color_balance_init (&cb);
 
584
 
 
585
          cb.preserve_luminosity = preserve_lum;
 
586
 
 
587
          cb.cyan_red[transfer_mode]      = cyan_red;
 
588
          cb.magenta_green[transfer_mode] = magenta_green;
 
589
          cb.yellow_blue[transfer_mode]   = yellow_blue;
 
590
 
 
591
          color_balance_create_lookup_tables (&cb);
 
592
 
 
593
          pixel_region_init (&srcPR, gimp_drawable_data (drawable),
 
594
                             x, y, width, height, FALSE);
 
595
          pixel_region_init (&destPR, gimp_drawable_shadow (drawable),
 
596
                             x, y, width, height, TRUE);
 
597
 
 
598
          for (pr = pixel_regions_register (2, &srcPR, &destPR);
 
599
               pr;
 
600
               pr = pixel_regions_process (pr))
 
601
            {
 
602
              color_balance (&srcPR, &destPR, &cb);
 
603
            }
 
604
 
 
605
          gimp_drawable_merge_shadow (drawable, TRUE, _("Color Balance"));
 
606
          gimp_drawable_update (drawable, x, y, width, height);
 
607
        }
 
608
    }
 
609
}
 
610
CODE
 
611
    );
 
612
}
 
613
 
 
614
sub colorize {
 
615
    $blurb = 'Render the drawable as a grayscale image seen through a colored glass.';
 
616
 
 
617
    $help = <<'HELP';
 
618
Desatures the drawable, then tints it with the specified color. This tool is
 
619
only valid on RGB color images. It will not operate on grayscale or indexed
 
620
drawables.
 
621
HELP
 
622
 
 
623
    &std_pdb_misc;
 
624
    $date = '2004';
 
625
    $since = '2.2';
 
626
 
 
627
    @inargs = (
 
628
        &drawable_arg,
 
629
        { name => 'hue', type => '0 <= float <= 360',
 
630
          desc => 'Hue in degrees: (%%desc%%)' },
 
631
        { name => 'saturation', type => '0 <= float <= 100',
 
632
          desc => 'Saturation in percent: (%%desc%%)' },
 
633
        { name => 'lightness', type => '-100 <= float <= 100',
 
634
          desc => 'Lightness in percent: (%%desc%%)' }
 
635
    );
 
636
 
 
637
    %invoke = (
 
638
        headers => [ qw("base/colorize.h") ],
 
639
        code => <<'CODE'
 
640
{
 
641
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
642
      ! gimp_drawable_is_rgb (drawable))
 
643
    success = FALSE;
 
644
 
 
645
  if (success)
 
646
    {
 
647
      gint x, y, width, height;
 
648
 
 
649
      /* The application should occur only within selection bounds */
 
650
      if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
 
651
        {
 
652
          Colorize             colors;
 
653
          PixelRegionIterator *pr;
 
654
          PixelRegion          srcPR, destPR;
 
655
 
 
656
          colorize_init (&colors);
 
657
 
 
658
          colors.hue        = hue;
 
659
          colors.saturation = saturation;
 
660
          colors.lightness  = lightness;
 
661
 
 
662
          colorize_calculate (&colors);
 
663
 
 
664
          pixel_region_init (&srcPR, gimp_drawable_data (drawable),
 
665
                             x, y, width, height, FALSE);
 
666
          pixel_region_init (&destPR, gimp_drawable_shadow (drawable),
 
667
                             x, y, width, height, TRUE);
 
668
 
 
669
          for (pr = pixel_regions_register (2, &srcPR, &destPR);
 
670
               pr;
 
671
               pr = pixel_regions_process (pr))
 
672
            {
 
673
              colorize (&srcPR, &destPR, &colors);
 
674
            }
 
675
 
 
676
          gimp_drawable_merge_shadow (drawable, TRUE, _("Colorize"));
 
677
          gimp_drawable_update (drawable, x, y, width, height);
 
678
        }
 
679
    }
 
680
}
 
681
CODE
 
682
    );
 
683
}
 
684
 
 
685
sub histogram {
 
686
    $blurb = <<'BLURB';
 
687
Returns information on the intensity histogram for the specified drawable.
 
688
BLURB
 
689
 
 
690
    $help = <<'HELP';
 
691
This tool makes it possible to gather information about the intensity histogram
 
692
of a drawable. A channel to examine is first specified. This can be either
 
693
value, red, green, or blue, depending on whether the drawable is of type color
 
694
or grayscale. The drawable may not be indexed. Second, a range of intensities
 
695
are specified. The gimp_histogram function returns statistics based on the
 
696
pixels in the drawable that fall under this range of values. Mean, standard
 
697
deviation, median, number of pixels, and percentile are all returned.
 
698
Additionally, the total count of pixels in the image is returned. Counts of
 
699
pixels are weighted by any associated alpha values and by the current selection
 
700
mask. That is, pixels that lie outside an active selection mask will not be
 
701
counted. Similarly, pixels with transparent alpha values will not be counted.
 
702
HELP
 
703
 
 
704
    &std_pdb_misc;
 
705
 
 
706
    @inargs = (
 
707
        &drawable_arg,
 
708
        &channel_arg,
 
709
    );
 
710
 
 
711
    foreach (qw(start end)) {
 
712
        push @inargs, { name => "${_}_range", type => '0 <= int32 < 256',
 
713
                        desc => "\u$_ of the intensity measurement range" }
 
714
    }
 
715
 
 
716
    @outargs = (
 
717
        { name => 'mean', void_ret => 1, init => 1,
 
718
          desc => 'Mean intensity value' },
 
719
        { name => 'std_dev', init => 1,
 
720
          desc => 'Standard deviation of intensity values' },
 
721
        { name => 'median', init => 1,
 
722
          desc => 'Median intensity value' },
 
723
        { name => 'pixels', init => 1,
 
724
          desc => 'Alpha-weighted pixel count for entire image' },
 
725
        { name => 'count', init => 1,
 
726
          desc => 'Alpha-weighted pixel count for range' },
 
727
        { name => 'percentile', init => 1,
 
728
          desc => 'Percentile that range falls under' }
 
729
    );
 
730
 
 
731
    foreach (@outargs) {
 
732
       @$_{qw(type alias)} = ('float', "$_->{name}", 1)
 
733
    }
 
734
 
 
735
    %invoke = (
 
736
        headers => [ qw("config/gimpbaseconfig.h" "core/gimp.h"
 
737
                        "core/gimpdrawable-histogram.h") ],
 
738
        code => <<'CODE'
 
739
{
 
740
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
741
      gimp_drawable_is_indexed (drawable) ||
 
742
      (! gimp_drawable_has_alpha (drawable) &&
 
743
       channel == GIMP_HISTOGRAM_ALPHA) ||
 
744
      (gimp_drawable_is_gray (drawable) &&
 
745
       channel != GIMP_HISTOGRAM_VALUE && channel != GIMP_HISTOGRAM_ALPHA))
 
746
    success = FALSE;
 
747
 
 
748
  if (success)
 
749
    {
 
750
      GimpHistogram *histogram;
 
751
 
 
752
      histogram = gimp_histogram_new (GIMP_BASE_CONFIG (gimp->config));
 
753
 
 
754
      gimp_drawable_calculate_histogram (drawable, histogram);
 
755
 
 
756
      mean       = gimp_histogram_get_mean (histogram, channel,
 
757
                                            start_range, end_range);
 
758
      std_dev    = gimp_histogram_get_std_dev (histogram, channel,
 
759
                                               start_range, end_range);
 
760
      median     = gimp_histogram_get_median (histogram, channel,
 
761
                                              start_range, end_range);
 
762
      pixels     = gimp_histogram_get_count (histogram, channel, 0, 255);
 
763
      count      = gimp_histogram_get_count (histogram, channel,
 
764
                                             start_range, end_range);
 
765
      percentile = count / pixels;
 
766
 
 
767
      gimp_histogram_free (histogram);
 
768
    }
 
769
}
 
770
CODE
 
771
    );
 
772
}
 
773
 
 
774
sub hue_saturation {
 
775
    $blurb = <<'BLURB';
 
776
Modify hue, lightness, and saturation in the specified drawable.
 
777
BLURB
 
778
 
 
779
    $help = <<'HELP';
 
780
This procedures allows the hue, lightness, and saturation in the specified
 
781
drawable to be modified. The 'hue_range' parameter provides the capability to
 
782
limit range of affected hues.
 
783
HELP
 
784
 
 
785
    &std_pdb_misc;
 
786
    $date = '1997';
 
787
 
 
788
    @inargs = (
 
789
        &drawable_arg,
 
790
        { name => 'hue_range', type => 'enum GimpHueRange',
 
791
          desc => 'Range of affected hues: { %%desc%% }' },
 
792
        { name => 'hue_offset', type => '-180 <= float <= 180',
 
793
          desc => 'Hue offset in degrees: (%%desc%%)' }
 
794
    );
 
795
 
 
796
    foreach (qw(lightness saturation)) {
 
797
        push @inargs, { name => $_, type => '-100 <= float <= 100',
 
798
                        desc => "$_ modification: (%%desc%%)" }
 
799
    }
 
800
 
 
801
    %invoke = (
 
802
        headers => [ qw("base/hue-saturation.h") ],
 
803
        code => <<'CODE'
 
804
{
 
805
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
806
      gimp_drawable_is_indexed (drawable))
 
807
    success = FALSE;
 
808
 
 
809
  if (success)
 
810
    {
 
811
      gint x, y, width, height;
 
812
 
 
813
      /* The application should occur only within selection bounds */
 
814
      if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
 
815
        {
 
816
          HueSaturation        hs;
 
817
          PixelRegionIterator *pr;
 
818
          PixelRegion          srcPR, destPR;
 
819
 
 
820
          hue_saturation_init (&hs);
 
821
 
 
822
          hs.hue[hue_range]        = hue_offset;
 
823
          hs.lightness[hue_range]  = lightness;
 
824
          hs.saturation[hue_range] = saturation;
 
825
 
 
826
          /* Calculate the transfer arrays */
 
827
          hue_saturation_calculate_transfers (&hs);
 
828
 
 
829
          pixel_region_init (&srcPR, gimp_drawable_data (drawable),
 
830
                             x, y, width, height, FALSE);
 
831
          pixel_region_init (&destPR, gimp_drawable_shadow (drawable),
 
832
                             x, y, width, height, TRUE);
 
833
 
 
834
          for (pr = pixel_regions_register (2, &srcPR, &destPR);
 
835
               pr;
 
836
               pr = pixel_regions_process (pr))
 
837
            {
 
838
              hue_saturation (&srcPR, &destPR, &hs);
 
839
            }
 
840
 
 
841
          gimp_drawable_merge_shadow (drawable, TRUE, _("Hue-Saturation"));
 
842
          gimp_drawable_update (drawable, x, y, width, height);
 
843
        }
 
844
    }
 
845
}
 
846
CODE
 
847
    );
 
848
}
 
849
 
 
850
sub threshold {
 
851
    $blurb = 'Threshold the specified drawable.';
 
852
 
 
853
    $help = <<'HELP';
 
854
This procedures generates a threshold map of the specified drawable. All pixels
 
855
between the values of 'low_threshold' and 'high_threshold' are replaced with
 
856
white, and all other pixels with black.
 
857
HELP
 
858
 
 
859
    &std_pdb_misc;
 
860
    $date = '1997';
 
861
 
 
862
    @inargs = ( &drawable_arg );
 
863
    foreach (qw(low high)) {
 
864
        push @inargs, { name => "${_}_threshold", type => '0 <= int32 <= 255',
 
865
                        desc => "The $_ threshold value: %%desc%%" }
 
866
    }
 
867
 
 
868
    %invoke = (
 
869
        headers => [ qw("base/threshold.h") ],
 
870
        code => <<'CODE'
 
871
{
 
872
  if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
 
873
      gimp_drawable_is_indexed (drawable) ||
 
874
      (low_threshold >= high_threshold))
 
875
    success = FALSE;
 
876
 
 
877
  if (success)
 
878
    {
 
879
      gint x, y, width, height;
 
880
 
 
881
      /* The application should occur only within selection bounds */
 
882
      if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
 
883
        {
 
884
          Threshold   tr;
 
885
          PixelRegion srcPR, destPR;
 
886
 
 
887
          tr.color          = gimp_drawable_is_rgb (drawable);
 
888
          tr.low_threshold  = low_threshold;
 
889
          tr.high_threshold = high_threshold;
 
890
 
 
891
          pixel_region_init (&srcPR, gimp_drawable_data (drawable),
 
892
                             x, y, width, height, FALSE);
 
893
          pixel_region_init (&destPR, gimp_drawable_shadow (drawable),
 
894
                             x, y, width, height, TRUE);
 
895
 
 
896
          pixel_regions_process_parallel ((p_func) threshold_2, &tr, 2,
 
897
                                          &srcPR, &destPR);
 
898
 
 
899
          gimp_drawable_merge_shadow (drawable, TRUE, _("Threshold"));
 
900
          gimp_drawable_update (drawable, x, y, width, height);
 
901
        }
 
902
    }
 
903
}
 
904
CODE
 
905
    );
 
906
}
 
907
 
 
908
@headers = qw("base/gimphistogram.h"
 
909
              "base/gimplut.h" "base/lut-funcs.h"
 
910
              "base/pixel-region.h" "base/pixel-processor.h"
 
911
              "core/gimpdrawable.h" "core/gimpimage.h"
 
912
              "gimp-intl.h");
 
913
 
 
914
@procs = qw(brightness_contrast levels levels_auto levels_stretch posterize desaturate
 
915
            equalize invert curves_spline curves_explicit color_balance
 
916
            colorize histogram hue_saturation threshold);
 
917
%exports = (app => [@procs], lib => [@procs]);
 
918
 
 
919
$desc = 'Color';
 
920
 
 
921
1;