summaryrefslogtreecommitdiffstats
path: root/pdb/groups/image_sample_points.pdb
blob: e116f7a9027028a2e8facec5f07a166d88e35c13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# GIMP - The GNU 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 3 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, see <https://www.gnu.org/licenses/>.

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

sub image_add_sample_point {
    $blurb = 'Add a sample point to an image.';

    $help = <<HELP;
This procedure adds a sample point to an image. It takes the input
image and the position of the new sample points as parameters. It
returns the sample point ID of the new sample point.
HELP

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

    @inargs = (
	{ name => 'image', type => 'image',
	  desc => 'The image' },
	{ name => 'position_x', type => '0 <= int32',
	  desc => "The guide'sample points x-offset from left of image" },
	{ name => 'position_y', type => '0 <= int32',
	  desc => "The guide'sample points y-offset from top of image" }
    );

    @outargs = (
	{ name => 'sample_point', type => 'sample_point',
	  desc => 'The new sample point' }
    );

    %invoke = (
	code => <<'CODE'
{
  if (position_x <= gimp_image_get_width  (image) &&
      position_y <= gimp_image_get_height (image))
    {
      GimpSamplePoint *sp;

      sp = gimp_image_add_sample_point_at_pos (image, position_x, position_y,
                                               TRUE);
      sample_point = gimp_aux_item_get_ID (GIMP_AUX_ITEM (sp));
    }
  else
    success = FALSE;
}
CODE
    );
}

sub image_delete_sample_point {
    $blurb = 'Deletes a sample point from an image.';

    $help = <<'HELP';
This procedure takes an image and a sample point ID as input and
removes the specified sample point from the specified image.
HELP

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

    @inargs = (
	{ name => 'image', type => 'image',
	  desc => 'The image' },
	{ name => 'sample_point', type => 'sample_point',
	  desc => 'The ID of the sample point to be removed' }
    );

    %invoke = (
	code => <<'CODE'
{
  GimpSamplePoint *sp = gimp_pdb_image_get_sample_point (image, sample_point,
                                                         error);

  if (sp)
    gimp_image_remove_sample_point (image, sp, TRUE);
  else
    success = FALSE;
}
CODE
    );
}

sub image_find_next_sample_point {
    $blurb = 'Find next sample point on an image.';

    $help = <<'HELP';
This procedure takes an image and a sample point ID as input and finds
the sample point ID of the successor of the given sample point ID in
the image's sample point list. If the supplied sample point ID is 0,
the procedure will return the first sample point. The procedure will
return 0 if given the final sample point ID as an argument or the
image has no sample points.
HELP

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

    @inargs = (
	{ name => 'image', type => 'image',
	  desc => 'The image' },
	{ name => 'sample_point', type => 'sample_point', no_validate => 1,
	  desc => 'The ID of the current sample point (0 if first invocation)' }
    );

    @outargs = (
	{ name => 'next_sample_point', type => 'sample_point',
	  desc => "The next sample point's ID" }
    );

    %invoke = (
	code => <<'CODE'
{
  GimpSamplePoint *sp = gimp_image_get_next_sample_point (image, sample_point,
                                                          &success);

  if (sp)
    next_sample_point = gimp_aux_item_get_ID (GIMP_AUX_ITEM (sp));

  if (! success)
    g_set_error (error, GIMP_PDB_ERROR, GIMP_PDB_ERROR_INVALID_ARGUMENT,
                 _("Image '%s' (%d) does not contain sample point with ID %d"),
                 gimp_image_get_display_name (image),
                 gimp_image_get_ID (image),
                 sample_point);
}
CODE
    );
}

sub image_get_sample_point_position {
    $blurb = 'Get position of a sample point on an image.';

    $help = <<'HELP';
This procedure takes an image and a sample point ID as input and
returns the position of the sample point relative to the top and left
of the image.
HELP

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

    @inargs = (
	{ name => 'image', type => 'image',
	  desc => 'The image' },
	{ name => 'sample_point', type => 'sample_point',
	  desc => 'The guide' }
    );

    @outargs = (
	{ name => 'position_x', type => 'int32',
          libdef => 'G_MININT',
	  desc => "The sample points's position relative to top of image" },
	{ name => 'position_y', type => 'int32',
          libdef => 'G_MININT',
	  desc => "The sample points's position relative to top of image" }
    );

    %invoke = (
	code => <<'CODE'
{
  GimpSamplePoint *sp = gimp_pdb_image_get_sample_point (image, sample_point,
                                                         error);

  if (sp)
    gimp_sample_point_get_position (sp, &position_x, &position_y);
  else
    success = FALSE;
}
CODE
    );
}


@headers = qw("core/gimpsamplepoint.h"
              "core/gimpimage-sample-points.h"
              "gimppdb-utils.h"
              "gimppdberror.h"
              "gimp-intl.h");

@procs = qw(image_add_sample_point
            image_delete_sample_point
            image_find_next_sample_point
	    image_get_sample_point_position);

%exports = (app => [@procs], lib => [@procs]);

$desc = 'Image Sample Point procedures';
$doc_title = 'gimpimagesamplepoints';
$doc_short_desc = 'Functions for manipulating an image\'s sample points.';
$doc_long_desc = 'Functions for manipulating an image\'s sample points.';

1;