1
# The GIMP -- an image manipulation program
2
# Copyright (C) 1995 Spencer Kimball and Peter Mattis
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.
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.
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.
18
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
20
sub drawable_arg () {{
23
desc => 'The drawable',
28
type => 'enum GimpHistogramChannel',
29
desc => 'The channel to modify: { %%desc%% }'
32
sub brightness_contrast {
33
$blurb = 'Modify brightness/contrast in the specified drawable.';
36
This procedures allows the brightness and contrast of the specified drawable to
37
be modified. Both 'brightness' and 'contrast' parameters are defined between
44
@inargs = ( &drawable_arg );
45
foreach (qw( brightness contrast)) {
46
push @inargs, { name => $_, type => '-127 <= int32 <= 127',
47
desc => "\u$_ adjustment: (%%desc%%)" }
53
if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
54
gimp_drawable_is_indexed (drawable))
59
gint x, y, width, height;
61
/* The application should occur only within selection bounds */
62
if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
65
PixelRegion srcPR, destPR;
67
lut = brightness_contrast_lut_new (brightness / 255.0,
69
gimp_drawable_bytes (drawable));
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);
76
pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2,
81
gimp_drawable_merge_shadow (drawable, TRUE, _("Brightness-Contrast"));
82
gimp_drawable_update (drawable, x, y, width, height);
91
$blurb = 'Modifies intensity levels in the specified drawable.';
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
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%%)" }
119
push @inargs, { name => 'gamma', type => '0.1 <= float <= 10',
120
desc => 'Gamma correction factor: (%%desc%%)' }
125
headers => [ qw("base/levels.h"
126
"core/gimpdrawable-levels.h") ],
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))
138
gimp_drawable_levels (drawable, context,
151
$blurb = 'Automatically modifies intensity levels in the specified drawable.';
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
161
$author = $copyright = 'Joao S.O. Bueno, Shawn Willden';
164
@inargs = ( &drawable_arg );
167
headers => [ qw("base/levels.h"
168
"base/gimphistogram.h"
169
"core/gimpdrawable-histogram.h"
170
"core/gimpdrawable-levels.h") ],
173
if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
174
gimp_drawable_is_indexed (drawable))
178
gimp_drawable_levels_stretch (drawable, context);
187
&std_pdb_deprecated ('gimp_levels_stretch');
189
@inargs = ( &drawable_arg );
192
headers => [ qw("base/levels.h"
193
"base/gimphistogram.h"
194
"core/gimpdrawable-histogram.h"
195
"core/gimpdrawable-levels.h") ],
198
if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
199
gimp_drawable_is_indexed (drawable))
203
gimp_drawable_levels_stretch (drawable, context);
210
$blurb = 'Posterize the specified drawable.';
213
This procedures reduces the number of shades allows in each intensity channel
214
to the specified 'levels' parameter.
222
{ name => 'levels', type => '2 <= int32 <= 255',
223
desc => 'Levels of posterization: (%%desc%%)' }
229
if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
230
gimp_drawable_is_indexed (drawable))
235
gint x, y, width, height;
237
/* The application should occur only within selection bounds */
238
if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
241
PixelRegion srcPR, destPR;
243
lut = posterize_lut_new (levels, gimp_drawable_bytes (drawable));
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);
250
pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2,
255
gimp_drawable_merge_shadow (drawable, TRUE, _("Posterize"));
256
gimp_drawable_update (drawable, x, y, width, height);
265
$blurb = 'Desaturate the contents of the specified drawable.';
268
This procedure desaturates the contents of the specified drawable. This
269
procedure only works on drawables of type RGB color.
274
@inargs = ( &drawable_arg );
277
headers => [ qw("core/gimpdrawable-desaturate.h") ],
280
if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
281
! gimp_drawable_is_rgb (drawable))
285
gimp_drawable_desaturate (drawable);
292
$blurb = 'Equalize the contents of the specified drawable.';
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.
308
{ name => 'mask_only', type => 'boolean',
309
desc => 'Equalization option' }
313
headers => [ qw("core/gimpdrawable-equalize.h") ],
316
if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
317
gimp_drawable_is_indexed (drawable))
321
gimp_drawable_equalize (drawable, mask_only);
328
$blurb = 'Invert the contents of the specified drawable.';
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.
338
@inargs = ( &drawable_arg );
341
headers => [ qw("core/gimpdrawable-invert.h") ],
344
if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
345
gimp_drawable_is_indexed (drawable))
349
gimp_drawable_invert (drawable);
356
$blurb = 'Modifies the intensity curve(s) for specified drawable.';
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.
372
{ name => 'control_pts', type => 'int8array',
373
desc => 'The spline control points: { cp1.x, cp1.y, cp2.x, cp2.y,
375
array => { name => 'num_points', type => '3 < int32 <= 34',
376
desc => 'The number of values in the control point array
381
headers => [ qw("base/curves.h") ],
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))
394
gint x, y, width, height;
396
/* The application should occur only within selection bounds */
397
if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
401
PixelRegion srcPR, destPR;
405
if (gimp_drawable_is_gray (drawable) &&
406
channel == GIMP_HISTOGRAM_ALPHA)
409
lut = gimp_lut_new ();
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;
417
for (j = 0; j < num_points / 2; j++)
419
c.points[channel][j][0] = control_pts[j * 2];
420
c.points[channel][j][1] = control_pts[j * 2 + 1];
423
curves_calculate_curve (&c, channel);
426
(GimpLutFunc) curves_lut_func,
428
gimp_drawable_bytes (drawable));
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);
435
pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2,
440
gimp_drawable_merge_shadow (drawable, TRUE, _("Curves"));
441
gimp_drawable_update (drawable, x, y, width, height);
449
sub curves_explicit {
450
$blurb = 'Modifies the intensity curve(s) for specified drawable.';
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
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
474
headers => [ qw("base/curves.h") ],
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))
487
gint x, y, width, height;
489
/* The application should occur only within selection bounds */
490
if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
494
PixelRegion srcPR, destPR;
498
if (gimp_drawable_is_gray (drawable) &&
499
channel == GIMP_HISTOGRAM_ALPHA)
502
lut = gimp_lut_new ();
506
for (j = 0; j < 256; j++)
507
c.curve[channel][j] = curve[j];
510
(GimpLutFunc) curves_lut_func,
512
gimp_drawable_bytes (drawable));
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);
519
pixel_regions_process_parallel ((p_func) gimp_lut_process, lut, 2,
524
gimp_drawable_merge_shadow (drawable, TRUE, _("Curves"));
525
gimp_drawable_update (drawable, x, y, width, height);
534
$blurb = 'Modify the color balance of the specified drawable.';
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.
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' }
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%%)';
565
headers => [ qw("base/color-balance.h") ],
568
if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
569
gimp_drawable_is_indexed (drawable))
574
gint x, y, width, height;
576
/* The application should occur only within selection bounds */
577
if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
580
PixelRegionIterator *pr;
581
PixelRegion srcPR, destPR;
583
color_balance_init (&cb);
585
cb.preserve_luminosity = preserve_lum;
587
cb.cyan_red[transfer_mode] = cyan_red;
588
cb.magenta_green[transfer_mode] = magenta_green;
589
cb.yellow_blue[transfer_mode] = yellow_blue;
591
color_balance_create_lookup_tables (&cb);
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);
598
for (pr = pixel_regions_register (2, &srcPR, &destPR);
600
pr = pixel_regions_process (pr))
602
color_balance (&srcPR, &destPR, &cb);
605
gimp_drawable_merge_shadow (drawable, TRUE, _("Color Balance"));
606
gimp_drawable_update (drawable, x, y, width, height);
615
$blurb = 'Render the drawable as a grayscale image seen through a colored glass.';
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
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%%)' }
638
headers => [ qw("base/colorize.h") ],
641
if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
642
! gimp_drawable_is_rgb (drawable))
647
gint x, y, width, height;
649
/* The application should occur only within selection bounds */
650
if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
653
PixelRegionIterator *pr;
654
PixelRegion srcPR, destPR;
656
colorize_init (&colors);
659
colors.saturation = saturation;
660
colors.lightness = lightness;
662
colorize_calculate (&colors);
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);
669
for (pr = pixel_regions_register (2, &srcPR, &destPR);
671
pr = pixel_regions_process (pr))
673
colorize (&srcPR, &destPR, &colors);
676
gimp_drawable_merge_shadow (drawable, TRUE, _("Colorize"));
677
gimp_drawable_update (drawable, x, y, width, height);
687
Returns information on the intensity histogram for the specified drawable.
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.
711
foreach (qw(start end)) {
712
push @inargs, { name => "${_}_range", type => '0 <= int32 < 256',
713
desc => "\u$_ of the intensity measurement range" }
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' }
732
@$_{qw(type alias)} = ('float', "$_->{name}", 1)
736
headers => [ qw("config/gimpbaseconfig.h" "core/gimp.h"
737
"core/gimpdrawable-histogram.h") ],
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))
750
GimpHistogram *histogram;
752
histogram = gimp_histogram_new (GIMP_BASE_CONFIG (gimp->config));
754
gimp_drawable_calculate_histogram (drawable, histogram);
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;
767
gimp_histogram_free (histogram);
776
Modify hue, lightness, and saturation in the specified drawable.
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.
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%%)' }
796
foreach (qw(lightness saturation)) {
797
push @inargs, { name => $_, type => '-100 <= float <= 100',
798
desc => "$_ modification: (%%desc%%)" }
802
headers => [ qw("base/hue-saturation.h") ],
805
if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
806
gimp_drawable_is_indexed (drawable))
811
gint x, y, width, height;
813
/* The application should occur only within selection bounds */
814
if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
817
PixelRegionIterator *pr;
818
PixelRegion srcPR, destPR;
820
hue_saturation_init (&hs);
822
hs.hue[hue_range] = hue_offset;
823
hs.lightness[hue_range] = lightness;
824
hs.saturation[hue_range] = saturation;
826
/* Calculate the transfer arrays */
827
hue_saturation_calculate_transfers (&hs);
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);
834
for (pr = pixel_regions_register (2, &srcPR, &destPR);
836
pr = pixel_regions_process (pr))
838
hue_saturation (&srcPR, &destPR, &hs);
841
gimp_drawable_merge_shadow (drawable, TRUE, _("Hue-Saturation"));
842
gimp_drawable_update (drawable, x, y, width, height);
851
$blurb = 'Threshold the specified drawable.';
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.
862
@inargs = ( &drawable_arg );
863
foreach (qw(low high)) {
864
push @inargs, { name => "${_}_threshold", type => '0 <= int32 <= 255',
865
desc => "The $_ threshold value: %%desc%%" }
869
headers => [ qw("base/threshold.h") ],
872
if (! gimp_item_is_attached (GIMP_ITEM (drawable)) ||
873
gimp_drawable_is_indexed (drawable) ||
874
(low_threshold >= high_threshold))
879
gint x, y, width, height;
881
/* The application should occur only within selection bounds */
882
if (gimp_drawable_mask_intersect (drawable, &x, &y, &width, &height))
885
PixelRegion srcPR, destPR;
887
tr.color = gimp_drawable_is_rgb (drawable);
888
tr.low_threshold = low_threshold;
889
tr.high_threshold = high_threshold;
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);
896
pixel_regions_process_parallel ((p_func) threshold_2, &tr, 2,
899
gimp_drawable_merge_shadow (drawable, TRUE, _("Threshold"));
900
gimp_drawable_update (drawable, x, y, width, height);
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"
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]);