buffer-cmds.c 20.3 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995-2003 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
/* NOTE: This file is auto-generated by pdbgen.pl. */
19 20 21 22 23

#include "config.h"

#include <string.h>

24
#include <gegl.h>
25

26 27
#include <gdk-pixbuf/gdk-pixbuf.h>

28 29 30 31
#include "pdb-types.h"

#include "core/gimp.h"
#include "core/gimpbuffer.h"
32
#include "core/gimpcontainer-filter.h"
33
#include "core/gimpcontainer.h"
34
#include "core/gimpparamspecs.h"
35
#include "gegl/gimp-babl-compat.h"
36

37 38 39
#include "gimppdb.h"
#include "gimppdb-utils.h"
#include "gimpprocedure.h"
40
#include "internal-procs.h"
41

42

43
static GValueArray *
44 45 46 47 48 49
buffers_get_list_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
50 51
{
  gboolean success = TRUE;
52
  GValueArray *return_vals;
53
  const gchar *filter;
54
  gint32 num_buffers = 0;
55 56
  gchar **buffer_list = NULL;

57
  filter = g_value_get_string (&args->values[0]);
58 59

  if (success)
60 61 62 63
    {
      buffer_list = gimp_container_get_filtered_name_array (gimp->named_buffers,
                                                            filter, &num_buffers);
    }
64

65 66
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
67 68 69

  if (success)
    {
70 71
      g_value_set_int (&return_vals->values[1], num_buffers);
      gimp_value_take_stringarray (&return_vals->values[2], buffer_list, num_buffers);
72 73
    }

74
  return return_vals;
75 76
}

77
static GValueArray *
78 79 80 81 82 83
buffer_rename_invoker (GimpProcedure      *procedure,
                       Gimp               *gimp,
                       GimpContext        *context,
                       GimpProgress       *progress,
                       const GValueArray  *args,
                       GError            **error)
84 85
{
  gboolean success = TRUE;
86
  GValueArray *return_vals;
87 88
  const gchar *buffer_name;
  const gchar *new_name;
89 90
  gchar *real_name = NULL;

91 92
  buffer_name = g_value_get_string (&args->values[0]);
  new_name = g_value_get_string (&args->values[1]);
93 94 95

  if (success)
    {
96
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
97

98
      if (buffer)
99 100
        {
          gimp_object_set_name (GIMP_OBJECT (buffer), new_name);
101
          real_name = g_strdup (gimp_object_get_name (buffer));
102
        }
103 104
      else
        success = FALSE;
105 106
    }

107 108
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
109 110

  if (success)
111
    g_value_take_string (&return_vals->values[1], real_name);
112

113
  return return_vals;
114 115
}

116
static GValueArray *
117 118 119 120 121 122
buffer_delete_invoker (GimpProcedure      *procedure,
                       Gimp               *gimp,
                       GimpContext        *context,
                       GimpProgress       *progress,
                       const GValueArray  *args,
                       GError            **error)
123 124
{
  gboolean success = TRUE;
125
  const gchar *buffer_name;
126

127
  buffer_name = g_value_get_string (&args->values[0]);
128 129 130

  if (success)
    {
131
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
132

133
      if (buffer)
134
        success = gimp_container_remove (gimp->named_buffers, GIMP_OBJECT (buffer));
135 136
      else
        success = FALSE;
137 138
    }

139 140
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
141 142
}

143
static GValueArray *
144 145 146 147 148 149
buffer_get_width_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
150 151
{
  gboolean success = TRUE;
152
  GValueArray *return_vals;
153
  const gchar *buffer_name;
154
  gint32 width = 0;
155

156
  buffer_name = g_value_get_string (&args->values[0]);
157 158 159

  if (success)
    {
160
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
161

162 163 164 165
      if (buffer)
        width = gimp_buffer_get_width (buffer);
      else
        success = FALSE;
166 167
    }

168 169
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
170 171

  if (success)
172
    g_value_set_int (&return_vals->values[1], width);
173

174
  return return_vals;
175 176
}

177
static GValueArray *
178 179 180 181 182 183
buffer_get_height_invoker (GimpProcedure      *procedure,
                           Gimp               *gimp,
                           GimpContext        *context,
                           GimpProgress       *progress,
                           const GValueArray  *args,
                           GError            **error)
184 185
{
  gboolean success = TRUE;
186
  GValueArray *return_vals;
187
  const gchar *buffer_name;
188
  gint32 height = 0;
189

190
  buffer_name = g_value_get_string (&args->values[0]);
191 192 193

  if (success)
    {
194
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
195

196 197 198 199
      if (buffer)
        height = gimp_buffer_get_height (buffer);
      else
        success = FALSE;
200 201
    }

202 203
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
204 205

  if (success)
206
    g_value_set_int (&return_vals->values[1], height);
207

208
  return return_vals;
209 210
}

211
static GValueArray *
212 213 214 215 216 217
buffer_get_bytes_invoker (GimpProcedure      *procedure,
                          Gimp               *gimp,
                          GimpContext        *context,
                          GimpProgress       *progress,
                          const GValueArray  *args,
                          GError            **error)
218 219
{
  gboolean success = TRUE;
220
  GValueArray *return_vals;
221
  const gchar *buffer_name;
222
  gint32 bytes = 0;
223

224
  buffer_name = g_value_get_string (&args->values[0]);
225 226 227

  if (success)
    {
228
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
229

230
      if (buffer)
231 232 233 234 235
        {
          const Babl *format = gimp_buffer_get_format (buffer);

          bytes = babl_format_get_bytes_per_pixel (format);
        }
236 237
      else
        success = FALSE;
238 239
    }

240 241
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
242 243

  if (success)
244
    g_value_set_int (&return_vals->values[1], bytes);
245

246
  return return_vals;
247 248
}

249
static GValueArray *
250 251 252 253 254 255
buffer_get_image_type_invoker (GimpProcedure      *procedure,
                               Gimp               *gimp,
                               GimpContext        *context,
                               GimpProgress       *progress,
                               const GValueArray  *args,
                               GError            **error)
256 257
{
  gboolean success = TRUE;
258
  GValueArray *return_vals;
259
  const gchar *buffer_name;
260
  gint32 image_type = 0;
261

262
  buffer_name = g_value_get_string (&args->values[0]);
263 264 265

  if (success)
    {
266
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
267

268
      if (buffer)
269
        image_type = gimp_babl_format_get_image_type (gimp_buffer_get_format (buffer));
270 271
      else
        success = FALSE;
272 273
    }

274 275
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
276 277

  if (success)
278
    g_value_set_enum (&return_vals->values[1], image_type);
279

280
  return return_vals;
281 282
}

283
void
284
register_buffer_procs (GimpPDB *pdb)
285
{
286 287 288 289 290
  GimpProcedure *procedure;

  /*
   * gimp-buffers-get-list
   */
291
  procedure = gimp_procedure_new (buffers_get_list_invoker);
292 293
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffers-get-list");
294 295 296 297 298 299 300 301 302 303 304 305
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-buffers-get-list",
                                     "Retrieve a complete listing of the available buffers.",
                                     "This procedure returns a complete listing of available named buffers.",
                                     "Michael Natterer <mitch@gimp.org>",
                                     "Michael Natterer",
                                     "2005",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("filter",
                                                       "filter",
                                                       "An optional regular expression used to filter the list",
306
                                                       FALSE, TRUE, FALSE,
307 308 309 310 311 312 313 314 315 316 317 318 319
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
  gimp_procedure_add_return_value (procedure,
                                   gimp_param_spec_int32 ("num-buffers",
                                                          "num buffers",
                                                          "The number of buffers",
                                                          0, G_MAXINT32, 0,
                                                          GIMP_PARAM_READWRITE));
  gimp_procedure_add_return_value (procedure,
                                   gimp_param_spec_string_array ("buffer-list",
                                                                 "buffer list",
                                                                 "The list of buffer names",
                                                                 GIMP_PARAM_READWRITE));
320
  gimp_pdb_register_procedure (pdb, procedure);
321
  g_object_unref (procedure);
322 323 324 325

  /*
   * gimp-buffer-rename
   */
326
  procedure = gimp_procedure_new (buffer_rename_invoker);
327 328
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffer-rename");
329 330 331 332 333 334 335 336 337 338 339 340
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-buffer-rename",
                                     "Renames a named buffer.",
                                     "This procedure renames a named buffer.",
                                     "Michael Natterer <mitch@gimp.org>",
                                     "Michael Natterer",
                                     "2005",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("buffer-name",
                                                       "buffer name",
                                                       "The buffer name",
341
                                                       FALSE, FALSE, TRUE,
342 343 344 345 346 347
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("new-name",
                                                       "new name",
                                                       "The buffer's new name",
348
                                                       FALSE, FALSE, TRUE,
349 350 351 352 353 354
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
  gimp_procedure_add_return_value (procedure,
                                   gimp_param_spec_string ("real-name",
                                                           "real name",
                                                           "The real name given to the buffer",
355
                                                           FALSE, FALSE, FALSE,
356 357
                                                           NULL,
                                                           GIMP_PARAM_READWRITE));
358
  gimp_pdb_register_procedure (pdb, procedure);
359
  g_object_unref (procedure);
360 361 362 363

  /*
   * gimp-buffer-delete
   */
364
  procedure = gimp_procedure_new (buffer_delete_invoker);
365 366
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffer-delete");
367 368 369 370 371 372 373 374 375 376 377 378
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-buffer-delete",
                                     "Deletes a named buffer.",
                                     "This procedure deletes a named buffer.",
                                     "David Gowers <neota@softhome.net>",
                                     "David Gowers <neota@softhome.net>",
                                     "2005",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("buffer-name",
                                                       "buffer name",
                                                       "The buffer name",
379
                                                       FALSE, FALSE, TRUE,
380 381
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
382
  gimp_pdb_register_procedure (pdb, procedure);
383
  g_object_unref (procedure);
384 385 386 387

  /*
   * gimp-buffer-get-width
   */
388
  procedure = gimp_procedure_new (buffer_get_width_invoker);
389 390
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffer-get-width");
391 392 393 394 395 396 397 398 399 400 401 402
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-buffer-get-width",
                                     "Retrieves the specified buffer's width.",
                                     "This procedure retrieves the specified named buffer's width.",
                                     "Michael Natterer <mitch@gimp.org>",
                                     "Michael Natterer",
                                     "2005",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("buffer-name",
                                                       "buffer name",
                                                       "The buffer name",
403
                                                       FALSE, FALSE, TRUE,
404 405 406 407 408 409 410 411
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
  gimp_procedure_add_return_value (procedure,
                                   gimp_param_spec_int32 ("width",
                                                          "width",
                                                          "The buffer width",
                                                          G_MININT32, G_MAXINT32, 0,
                                                          GIMP_PARAM_READWRITE));
412
  gimp_pdb_register_procedure (pdb, procedure);
413
  g_object_unref (procedure);
414 415 416 417

  /*
   * gimp-buffer-get-height
   */
418
  procedure = gimp_procedure_new (buffer_get_height_invoker);
419 420
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffer-get-height");
421 422 423 424 425 426 427 428 429 430 431 432
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-buffer-get-height",
                                     "Retrieves the specified buffer's height.",
                                     "This procedure retrieves the specified named buffer's height.",
                                     "Michael Natterer <mitch@gimp.org>",
                                     "Michael Natterer",
                                     "2005",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("buffer-name",
                                                       "buffer name",
                                                       "The buffer name",
433
                                                       FALSE, FALSE, TRUE,
434 435 436 437 438 439 440 441
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
  gimp_procedure_add_return_value (procedure,
                                   gimp_param_spec_int32 ("height",
                                                          "height",
                                                          "The buffer height",
                                                          G_MININT32, G_MAXINT32, 0,
                                                          GIMP_PARAM_READWRITE));
442
  gimp_pdb_register_procedure (pdb, procedure);
443
  g_object_unref (procedure);
444 445 446 447

  /*
   * gimp-buffer-get-bytes
   */
448
  procedure = gimp_procedure_new (buffer_get_bytes_invoker);
449 450
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffer-get-bytes");
451 452 453 454 455 456 457 458 459 460 461 462
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-buffer-get-bytes",
                                     "Retrieves the specified buffer's bytes.",
                                     "This procedure retrieves the specified named buffer's bytes.",
                                     "Michael Natterer <mitch@gimp.org>",
                                     "Michael Natterer",
                                     "2005",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("buffer-name",
                                                       "buffer name",
                                                       "The buffer name",
463
                                                       FALSE, FALSE, TRUE,
464 465 466 467 468 469 470 471
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
  gimp_procedure_add_return_value (procedure,
                                   gimp_param_spec_int32 ("bytes",
                                                          "bytes",
                                                          "The buffer bpp",
                                                          G_MININT32, G_MAXINT32, 0,
                                                          GIMP_PARAM_READWRITE));
472
  gimp_pdb_register_procedure (pdb, procedure);
473
  g_object_unref (procedure);
474 475 476 477

  /*
   * gimp-buffer-get-image-type
   */
478
  procedure = gimp_procedure_new (buffer_get_image_type_invoker);
479 480
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffer-get-image-type");
481 482 483 484 485 486 487 488 489 490 491 492
  gimp_procedure_set_static_strings (procedure,
                                     "gimp-buffer-get-image-type",
                                     "Retrieves the specified buffer's image type.",
                                     "This procedure retrieves the specified named buffer's image type.",
                                     "Michael Natterer <mitch@gimp.org>",
                                     "Michael Natterer",
                                     "2005",
                                     NULL);
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("buffer-name",
                                                       "buffer name",
                                                       "The buffer name",
493
                                                       FALSE, FALSE, TRUE,
494 495 496 497 498
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
  gimp_procedure_add_return_value (procedure,
                                   g_param_spec_enum ("image-type",
                                                      "image type",
499
                                                      "The buffer image type",
500 501 502
                                                      GIMP_TYPE_IMAGE_BASE_TYPE,
                                                      GIMP_RGB,
                                                      GIMP_PARAM_READWRITE));
503
  gimp_pdb_register_procedure (pdb, procedure);
504
  g_object_unref (procedure);
505
}