buffer-cmds.c 20.2 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 28 29

#include "pdb-types.h"

#include "core/gimp.h"
#include "core/gimpbuffer.h"
30
#include "core/gimpcontainer-filter.h"
31
#include "core/gimpcontainer.h"
32
#include "core/gimpparamspecs.h"
33

34 35 36
#include "gimppdb.h"
#include "gimppdb-utils.h"
#include "gimpprocedure.h"
37
#include "internal-procs.h"
38

39

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

54
  filter = g_value_get_string (&args->values[0]);
55 56

  if (success)
57 58 59 60
    {
      buffer_list = gimp_container_get_filtered_name_array (gimp->named_buffers,
                                                            filter, &num_buffers);
    }
61

62 63
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
64 65 66

  if (success)
    {
67 68
      g_value_set_int (&return_vals->values[1], num_buffers);
      gimp_value_take_stringarray (&return_vals->values[2], buffer_list, num_buffers);
69 70
    }

71
  return return_vals;
72 73
}

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

88 89
  buffer_name = g_value_get_string (&args->values[0]);
  new_name = g_value_get_string (&args->values[1]);
90 91 92

  if (success)
    {
93
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
94

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

104 105
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
106 107

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

110
  return return_vals;
111 112
}

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

124
  buffer_name = g_value_get_string (&args->values[0]);
125 126 127

  if (success)
    {
128
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
129

130
      if (buffer)
131
        success = gimp_container_remove (gimp->named_buffers, GIMP_OBJECT (buffer));
132 133
      else
        success = FALSE;
134 135
    }

136 137
  return gimp_procedure_get_return_values (procedure, success,
                                           error ? *error : NULL);
138 139
}

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

153
  buffer_name = g_value_get_string (&args->values[0]);
154 155 156

  if (success)
    {
157
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
158

159 160 161 162
      if (buffer)
        width = gimp_buffer_get_width (buffer);
      else
        success = FALSE;
163 164
    }

165 166
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
167 168

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

171
  return return_vals;
172 173
}

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

187
  buffer_name = g_value_get_string (&args->values[0]);
188 189 190

  if (success)
    {
191
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
192

193 194 195 196
      if (buffer)
        height = gimp_buffer_get_height (buffer);
      else
        success = FALSE;
197 198
    }

199 200
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
201 202

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

205
  return return_vals;
206 207
}

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

221
  buffer_name = g_value_get_string (&args->values[0]);
222 223 224

  if (success)
    {
225
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
226

227
      if (buffer)
228 229 230 231 232
        {
          const Babl *format = gimp_buffer_get_format (buffer);

          bytes = babl_format_get_bytes_per_pixel (format);
        }
233 234
      else
        success = FALSE;
235 236
    }

237 238
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
239 240

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

243
  return return_vals;
244 245
}

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

259
  buffer_name = g_value_get_string (&args->values[0]);
260 261 262

  if (success)
    {
263
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
264

265 266 267 268
      if (buffer)
        image_type = gimp_buffer_get_image_type (buffer);
      else
        success = FALSE;
269 270
    }

271 272
  return_vals = gimp_procedure_get_return_values (procedure, success,
                                                  error ? *error : NULL);
273 274

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

277
  return return_vals;
278 279
}

280
void
281
register_buffer_procs (GimpPDB *pdb)
282
{
283 284 285 286 287
  GimpProcedure *procedure;

  /*
   * gimp-buffers-get-list
   */
288
  procedure = gimp_procedure_new (buffers_get_list_invoker);
289 290
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffers-get-list");
291 292 293 294 295 296 297 298 299 300 301 302
  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",
303
                                                       FALSE, TRUE, FALSE,
304 305 306 307 308 309 310 311 312 313 314 315 316
                                                       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));
317
  gimp_pdb_register_procedure (pdb, procedure);
318
  g_object_unref (procedure);
319 320 321 322

  /*
   * gimp-buffer-rename
   */
323
  procedure = gimp_procedure_new (buffer_rename_invoker);
324 325
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffer-rename");
326 327 328 329 330 331 332 333 334 335 336 337
  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",
338
                                                       FALSE, FALSE, TRUE,
339 340 341 342 343 344
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
  gimp_procedure_add_argument (procedure,
                               gimp_param_spec_string ("new-name",
                                                       "new name",
                                                       "The buffer's new name",
345
                                                       FALSE, FALSE, TRUE,
346 347 348 349 350 351
                                                       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",
352
                                                           FALSE, FALSE, FALSE,
353 354
                                                           NULL,
                                                           GIMP_PARAM_READWRITE));
355
  gimp_pdb_register_procedure (pdb, procedure);
356
  g_object_unref (procedure);
357 358 359 360

  /*
   * gimp-buffer-delete
   */
361
  procedure = gimp_procedure_new (buffer_delete_invoker);
362 363
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffer-delete");
364 365 366 367 368 369 370 371 372 373 374 375
  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",
376
                                                       FALSE, FALSE, TRUE,
377 378
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
379
  gimp_pdb_register_procedure (pdb, procedure);
380
  g_object_unref (procedure);
381 382 383 384

  /*
   * gimp-buffer-get-width
   */
385
  procedure = gimp_procedure_new (buffer_get_width_invoker);
386 387
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffer-get-width");
388 389 390 391 392 393 394 395 396 397 398 399
  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",
400
                                                       FALSE, FALSE, TRUE,
401 402 403 404 405 406 407 408
                                                       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));
409
  gimp_pdb_register_procedure (pdb, procedure);
410
  g_object_unref (procedure);
411 412 413 414

  /*
   * gimp-buffer-get-height
   */
415
  procedure = gimp_procedure_new (buffer_get_height_invoker);
416 417
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffer-get-height");
418 419 420 421 422 423 424 425 426 427 428 429
  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",
430
                                                       FALSE, FALSE, TRUE,
431 432 433 434 435 436 437 438
                                                       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));
439
  gimp_pdb_register_procedure (pdb, procedure);
440
  g_object_unref (procedure);
441 442 443 444

  /*
   * gimp-buffer-get-bytes
   */
445
  procedure = gimp_procedure_new (buffer_get_bytes_invoker);
446 447
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffer-get-bytes");
448 449 450 451 452 453 454 455 456 457 458 459
  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",
460
                                                       FALSE, FALSE, TRUE,
461 462 463 464 465 466 467 468
                                                       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));
469
  gimp_pdb_register_procedure (pdb, procedure);
470
  g_object_unref (procedure);
471 472 473 474

  /*
   * gimp-buffer-get-image-type
   */
475
  procedure = gimp_procedure_new (buffer_get_image_type_invoker);
476 477
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffer-get-image-type");
478 479 480 481 482 483 484 485 486 487 488 489
  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",
490
                                                       FALSE, FALSE, TRUE,
491 492 493 494 495
                                                       NULL,
                                                       GIMP_PARAM_READWRITE));
  gimp_procedure_add_return_value (procedure,
                                   g_param_spec_enum ("image-type",
                                                      "image type",
496
                                                      "The buffer image type",
497 498 499
                                                      GIMP_TYPE_IMAGE_BASE_TYPE,
                                                      GIMP_RGB,
                                                      GIMP_PARAM_READWRITE));
500
  gimp_pdb_register_procedure (pdb, procedure);
501
  g_object_unref (procedure);
502
}