buffer.pdb 6.21 KB
Newer Older
1
# GIMP - The GNU Image Manipulation Program
2 3
# 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 3 of the License, or
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/>.
16 17 18

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

19 20 21 22 23 24 25
sub buffers_get_list {
    $blurb = 'Retrieve a complete listing of the available buffers.';

    $help = <<'HELP';
This procedure returns a complete listing of available named buffers.
HELP

26
    &mitch_pdb_misc('2005', '2.4');
27 28 29 30 31 32 33 34

    @inargs = (
	{ name => 'filter', type => 'string', null_ok => 1,
          desc => 'An optional regular expression used to filter the list' }
    );

    @outargs = (
	{ name => 'buffer_list', type => 'stringarray',
35
	  desc => 'The list of buffer names',
36
	  array => { name => 'num_buffers',
37
		     desc => 'The number of buffers' } }
38 39 40
    );

    %invoke = (
41 42 43 44 45 46
	code => <<'CODE'
{
  buffer_list = gimp_container_get_filtered_name_array (gimp->named_buffers,
                                                        filter, &num_buffers);
}
CODE
47 48 49
    );
}

50 51
sub buffer_rename {
    $blurb = 'Renames a named buffer.';
52
    $help  = 'This procedure renames a named buffer.';
53

54
    &mitch_pdb_misc('2005', '2.4');
55 56

    @inargs = (
57
        { name => 'buffer_name', type => 'string', non_empty => 1,
58
          desc => 'The buffer name' },
59
        { name => 'new_name', type => 'string', non_empty => 1,
60 61 62 63
          desc => 'The buffer\'s new name' }
    );

    @outargs = (
64
	{ name => 'real_name', type => 'string',
65 66 67 68
	  desc => 'The real name given to the buffer' }
    );

    %invoke = (
69
	code => <<'CODE'
70
{
71
  GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
72

73
  if (buffer)
74 75
    {
      gimp_object_set_name (GIMP_OBJECT (buffer), new_name);
76
      real_name = g_strdup (gimp_object_get_name (buffer));
77
    }
78 79
  else
    success = FALSE;
80 81 82 83 84 85 86
}
CODE
    );
}

sub buffer_delete {
    $blurb = 'Deletes a named buffer.';
87
    $help  = 'This procedure deletes a named buffer.';
88 89 90 91 92 93

    $author = $copyright = 'David Gowers <neota@softhome.net>';
    $date   = '2005';
    $since  = '2.4';

    @inargs = (
94
        { name => 'buffer_name', type => 'string', non_empty => 1,
95 96 97 98
          desc => 'The buffer name' }
    );

    %invoke = (
99
	code => <<'CODE'
100
{
101
  GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
102

103
  if (buffer)
104
    success = gimp_container_remove (gimp->named_buffers, GIMP_OBJECT (buffer));
105 106
  else
    success = FALSE;
107 108 109 110 111 112 113
}
CODE
    );
}

sub buffer_get_width {
    $blurb = "Retrieves the specified buffer's width.";
114
    $help  = "This procedure retrieves the specified named buffer's width.";
115

116
    &mitch_pdb_misc('2005', '2.4');
117 118

    @inargs = (
119
        { name => 'buffer_name', type => 'string', non_empty => 1,
120 121 122 123
          desc => 'The buffer name' }
    );

    @outargs = (
124
	{ name => 'width', type => 'int32',
125 126 127 128 129 130
          desc => "The buffer width" }
    );

    %invoke = (
	code => <<'CODE'
{
131
  GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
132

133 134 135 136
  if (buffer)
    width = gimp_buffer_get_width (buffer);
  else
    success = FALSE;
137 138 139 140 141 142 143
}
CODE
    );
}

sub buffer_get_height {
    $blurb = "Retrieves the specified buffer's height.";
144
    $help  = "This procedure retrieves the specified named buffer's height.";
145

146
    &mitch_pdb_misc('2005', '2.4');
147 148

    @inargs = (
149
        { name => 'buffer_name', type => 'string', non_empty => 1,
150 151 152 153
          desc => 'The buffer name' }
    );

    @outargs = (
154
	{ name => 'height', type => 'int32',
155 156 157 158 159 160
          desc => "The buffer height" }
    );

    %invoke = (
	code => <<'CODE'
{
161
  GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
162

163 164 165 166
  if (buffer)
    height = gimp_buffer_get_height (buffer);
  else
    success = FALSE;
167 168 169 170 171 172 173
}
CODE
    );
}

sub buffer_get_bytes {
    $blurb = "Retrieves the specified buffer's bytes.";
174
    $help  = "This procedure retrieves the specified named buffer's bytes.";
175

176
    &mitch_pdb_misc('2005', '2.4');
177 178

    @inargs = (
179
        { name => 'buffer_name', type => 'string', non_empty => 1,
180 181 182 183
          desc => 'The buffer name' }
    );

    @outargs = (
184
	{ name => 'bytes', type => 'int32',
185 186 187 188 189 190
          desc => "The buffer bpp" }
    );

    %invoke = (
	code => <<'CODE'
{
191
  GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
192

193
  if (buffer)
194 195 196 197 198
    {
      const Babl *format = gimp_buffer_get_format (buffer);

      bytes = babl_format_get_bytes_per_pixel (format);
    }
199 200
  else
    success = FALSE;
201 202 203 204 205 206 207
}
CODE
    );
}

sub buffer_get_image_type {
    $blurb = "Retrieves the specified buffer's image type.";
208
    $help  = "This procedure retrieves the specified named buffer's image type.";
209

210
    &mitch_pdb_misc('2005', '2.4');
211 212

    @inargs = (
213
        { name => 'buffer_name', type => 'string', non_empty => 1,
214 215 216 217
          desc => 'The buffer name' }
    );

    @outargs = (
218
	{ name => 'image_type', type => 'enum GimpImageBaseType',
219
          desc => "The buffer image type" }
220 221 222 223 224
    );

    %invoke = (
	code => <<'CODE'
{
225
  GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
226

227
  if (buffer)
228
    image_type = gimp_babl_format_get_image_type (gimp_buffer_get_format (buffer));
229 230
  else
    success = FALSE;
231 232 233 234 235
}
CODE
    );
}

236

237
@headers = qw(<string.h>
238
              "gegl/gimp-babl-compat.h"
239 240 241 242 243
              "core/gimp.h"
              "core/gimpbuffer.h"
              "core/gimpcontainer.h"
              "core/gimpcontainer-filter.h"
	      "gimppdb-utils.h");
244

245
@procs = qw(buffers_get_list
246 247 248 249 250 251
            buffer_rename
            buffer_delete
	    buffer_get_width
            buffer_get_height
            buffer_get_bytes
            buffer_get_image_type);
252

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

$desc = 'Buffer procedures';
256 257 258
$doc_title = 'gimpbuffer';
$doc_short_desc = 'Functions for manipulating cut buffers.';
$doc_long_desc = 'Functions related to named cut buffers.';
259 260

1;