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

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

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

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

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

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

26 27
sub operation_arg () {{
    name => 'operation',
28
    type => 'enum GimpChannelOps',
29 30 31
    desc => 'The selection operation: { %%desc%% }'
}}

Manish Singh's avatar
Manish Singh committed
32
sub channel_get_prop_proc {
33
    my ($prop, $type, $desc, $undo, $core_type, $core_var) = @_;
Manish Singh's avatar
Manish Singh committed
34

35 36 37
    $core_type = 'channel' unless $core_type;
    $core_var  = 'channel' unless $core_var;

Manish Singh's avatar
Manish Singh committed
38 39
    $blurb = "Get the $desc of the specified channel.";

Manish Singh's avatar
Manish Singh committed
40
    $help = "This procedure returns the specified channel's $desc. ";
Manish Singh's avatar
Manish Singh committed
41 42 43 44 45 46 47 48 49 50

    &std_pdb_misc;

    @inargs = ( &channel_arg );

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

51
    my $alias = "gimp_${core_type}_get_$prop ($core_var)";
Manish Singh's avatar
Manish Singh committed
52 53 54 55 56 57 58
    $alias = "g_strdup ($alias)" if $type eq 'string';
    $outargs[0]->{alias} .= "$alias";

    if ($type eq 'color') {
	$outargs[0]->{init} = 1;
	delete @{$outargs[0]}{qw(alias no_declare)};

59
	$invoke{headers} = [ qw("core/gimpimage.h") ];
Manish Singh's avatar
Manish Singh committed
60

61 62
	$invoke{code} = <<'CODE'
{
63
  gimp_channel_get_color (channel, &color);
64 65
}
CODE
Manish Singh's avatar
Manish Singh committed
66 67 68 69
    }
}

sub channel_set_prop_proc {
70
    my ($prop, $type, $desc, $undo, $core_type, $core_var) = @_;
Manish Singh's avatar
Manish Singh committed
71

72 73 74
    $core_type = 'channel' unless $core_type;
    $core_var  = 'channel' unless $core_var;

Manish Singh's avatar
Manish Singh committed
75 76
    $blurb = "Set the $desc of the specified channel.";

Manish Singh's avatar
Manish Singh committed
77
    $help = "This procedure sets the specified channel's $desc. ";
Manish Singh's avatar
Manish Singh committed
78 79 80 81 82 83 84 85 86

    &std_pdb_misc;

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

Manish Singh's avatar
Manish Singh committed
87 88 89 90
    if ($type =~ /float/) {
	$inargs[1]->{desc} .= ' (%%desc%%)';
    }

91 92
    $invoke{code} = $undo ? "gimp_${core_type}_set_$prop ($core_var, $prop, TRUE);"
			  : "gimp_${core_type}_set_$prop ($core_var, $prop);";
Manish Singh's avatar
Manish Singh committed
93 94 95

    if ($type eq 'color') {
	%invoke = (
96 97
	    code => <<'CODE'
{
Sven Neumann's avatar
Sven Neumann committed
98
  GimpRGB rgb_color = color;
99

100
  rgb_color.a = channel->color.a;
101
  gimp_channel_set_color (channel, &rgb_color, TRUE);
102 103 104 105
}
CODE
	);
    }
Manish Singh's avatar
Manish Singh committed
106 107 108
}

sub channel_accessors {
109
    my ($prop, $type, $desc, $undo, $extra, $core_type, $core_var) = @_;
110 111 112 113

    $core_type = 'channel' unless $core_type;
    $core_var  = 'channel' unless $core_var;

Manish Singh's avatar
Manish Singh committed
114 115 116 117 118
    my (@extra, %extra); my $once = 0;

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

Manish Singh's avatar
Manish Singh committed
119
    foreach (sort keys %extra) {
Manish Singh's avatar
Manish Singh committed
120 121 122 123 124 125
	my $proc = "channel_${_}_$prop";

	push @procs, $proc;

	eval <<SUB;
sub @{[ scalar caller ]}::$proc {
126
    \&channel_${_}_prop_proc('$prop', '$type', '$desc', $undo,
Michael Natterer's avatar
Michael Natterer committed
127
                             '$core_type', '$core_var');
Manish Singh's avatar
Manish Singh committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    $extra{$_}
}
SUB
    }
}

sub channel_new {
    $blurb = 'Create a new channel.';

    $help = <<'HELP';
This procedure creates a new channel with the specified width and height. Name,
opacity, and color are also supplied parameters. The new channel still needs to
be added to the image, as this is not automatic. Add the new channel with the
'gimp_image_add_channel' command. Other attributes such as channel show masked,
should be set with explicit procedure calls. The channel's contents are
undefined initially.
HELP

    &std_pdb_misc;

    @inargs = (
	&std_image_arg,
	{ name => 'width', type => '0 < int32',
	  desc => 'The channel width: (%%desc%%)' },
	{ name => 'height', type => '0 < int32',
	  desc => 'The channel height: (%%desc%%)' },
	{ name => 'name', type => 'string',
155
	  desc => 'The channel name' },
Manish Singh's avatar
Manish Singh committed
156
	{ name => 'opacity', type => '0 <= float <= 100',
Manish Singh's avatar
Manish Singh committed
157
	  desc => 'The channel opacity: (%%desc%%)' },
Manish Singh's avatar
Manish Singh committed
158
	{ name => 'color', type => 'color',
159 160
	  desc => 'The channel compositing color'
	}
Manish Singh's avatar
Manish Singh committed
161 162 163 164
    );
    $inargs[0]->{desc} .= ' to which to add the channel';

    @outargs = (
165
	{ name => 'channel', type => 'channel', wrap => 1,
Manish Singh's avatar
Manish Singh committed
166 167 168 169 170 171
	  desc => 'The newly created channel', init => 1 }
    );

    %invoke = (
	code => <<'CODE'
{
Sven Neumann's avatar
Sven Neumann committed
172
  GimpRGB rgb_color = color;
173 174

  rgb_color.a = opacity / 100.0;
Michael Natterer's avatar
Michael Natterer committed
175
  channel = gimp_channel_new (gimage, width, height, name, &rgb_color);
Manish Singh's avatar
Manish Singh committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
  success = channel != NULL;
}
CODE
    );
}

sub channel_copy {
    $blurb = 'Copy a channel.';

    $help = <<'HELP';
This procedure copies the specified channel and returns the copy.
HELP

    &std_pdb_misc;

Manish Singh's avatar
Manish Singh committed
191 192
    @inargs = ( &channel_arg );
    $inargs[0]->{desc} .= ' to copy';
Manish Singh's avatar
Manish Singh committed
193 194 195 196 197 198

    @outargs = (
	{ name => 'channel_copy', type => 'channel', init => 1,
	  desc => 'The newly copied channel', alias => 'copy' }
    );

199
    %invoke = ( code => 'success = (copy = GIMP_CHANNEL (gimp_item_duplicate (GIMP_ITEM (channel), G_TYPE_FROM_INSTANCE (channel), FALSE))) != NULL;' );
Manish Singh's avatar
Manish Singh committed
200 201 202 203 204 205
}

sub channel_delete {
    $blurb = 'Delete a channel.';

    $help = <<'HELP';
206 207 208 209 210
This procedure deletes the specified channel. This must not be done if the 
gimage containing this channel was already deleted or if the channel was 
already removed from the image. The only case in which this procedure is
useful is if you want to get rid of a channel which has not yet been
added to an image.
Manish Singh's avatar
Manish Singh committed
211 212 213 214
HELP

    &std_pdb_misc;

Manish Singh's avatar
Manish Singh committed
215 216
    @inargs = ( &channel_arg );
    $inargs[0]->{desc} .= ' to delete';
Manish Singh's avatar
Manish Singh committed
217

218 219
    %invoke = ( code => <<'CODE' );
{
220
  if (! gimp_item_get_image (GIMP_ITEM (channel)))
221
    {
222
      g_object_unref (channel);
223 224 225 226 227
      success = TRUE;
    }

}
CODE
Manish Singh's avatar
Manish Singh committed
228 229
}

230 231 232 233 234 235 236 237 238 239 240 241
sub channel_combine_masks {
    $blurb = 'Combine two channel masks.';

    $help = <<'HELP';
This procedure combines two channel masks.  The result is stored
in the first channel.
HELP

    &std_pdb_misc;

    @inargs = ( &channel_arg, &channel_arg, &operation_arg );
	       
242 243 244 245
    foreach my $i (0,1) {
        foreach my $unused (qw(name desc)) {
  	  $inargs[$i]{$unused} .= $i + 1;
        }
246 247 248 249 250 251 252 253
    }

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

254 255 256
    %invoke = (
        headers => [ qw("core/gimpchannel-combine.h") ],
        code => <<'CODE'
257
{
Michael Natterer's avatar
Michael Natterer committed
258
  gimp_channel_combine_mask (channel1, channel2, operation, offx, offy);
259 260
}
CODE
261
    );
262 263
}

264
&channel_accessors('name', 'string', 'name', 0, [ undef, <<'CODE' ],
265 266 267
$invoke{code} =~ s/gimp_object_set_name/gimp_item_rename/;
$invoke{code} =~ s/GIMP_OBJECT/GIMP_ITEM/;
CODE
Michael Natterer's avatar
Michael Natterer committed
268
                   'object', 'GIMP_OBJECT (channel)');
Manish Singh's avatar
Manish Singh committed
269

270
&channel_accessors('visible', 'boolean', 'visibility', 1, undef,
Michael Natterer's avatar
Michael Natterer committed
271
                   'drawable', 'GIMP_DRAWABLE (channel)');
Manish Singh's avatar
Manish Singh committed
272

273
&channel_accessors('show_masked', 'boolean', 'composite method', 0,
Manish Singh's avatar
Manish Singh committed
274 275
		   <<'CODE');
    $help .= <<'HELP'
Manish Singh's avatar
Manish Singh committed
276 277
If it is non-zero, then the channel is composited with the image so that masked
regions are shown. Otherwise, selected regions are shown.
Manish Singh's avatar
Manish Singh committed
278 279 280
HELP
CODE

281 282 283 284 285
&channel_accessors('opacity', '0 <= float <= 100', 'opacity', 1,
		 [ '$outargs[0]->{alias} =
		        "gimp_channel_get_opacity (channel) * 100.0"',
		   '$invoke{code} =~
			s%opacity, %opacity / 100.0, %' ]);
Manish Singh's avatar
Manish Singh committed
286

Michael Natterer's avatar
Michael Natterer committed
287
&channel_accessors('color', 'color', 'compositing color', 0,
Manish Singh's avatar
Manish Singh committed
288
                   [ '$outargs[0]->{void_ret} = 1', '' ]);
Manish Singh's avatar
Manish Singh committed
289

290
&channel_accessors('tattoo', 'tattoo', 'tattoo', 0,
291
		   <<'CODE', 'item', 'GIMP_ITEM (channel)');
292 293 294
    $help .= <<'HELP';
A tattoo is a unique and permanent identifier attached to a channel that can be
used to uniquely identify a channel within an image even between sessions.
Manish Singh's avatar
Manish Singh committed
295 296 297 298 299 300
HELP

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

301 302
unshift @procs, qw(channel_new channel_copy channel_delete
		   channel_combine_masks);
Manish Singh's avatar
Manish Singh committed
303
%exports = (app => [@procs], lib => [@procs]);
Manish Singh's avatar
Manish Singh committed
304 305 306 307

$desc = 'Channel';

1;