buffer-cmds.c 20.8 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
#include "libgimpbase/gimpbase.h"

30 31 32 33
#include "pdb-types.h"

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

39 40 41
#include "gimppdb.h"
#include "gimppdb-utils.h"
#include "gimpprocedure.h"
42
#include "internal-procs.h"
43

44

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

59
  filter = g_value_get_string (gimp_value_array_index (args, 0));
60 61

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

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

  if (success)
    {
72 73
      g_value_set_int (gimp_value_array_index (return_vals, 1), num_buffers);
      gimp_value_take_stringarray (gimp_value_array_index (return_vals, 2), buffer_list, num_buffers);
74 75
    }

76
  return return_vals;
77 78
}

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

93 94
  buffer_name = g_value_get_string (gimp_value_array_index (args, 0));
  new_name = g_value_get_string (gimp_value_array_index (args, 1));
95 96 97

  if (success)
    {
98
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
99

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

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

  if (success)
113
    g_value_take_string (gimp_value_array_index (return_vals, 1), real_name);
114

115
  return return_vals;
116 117
}

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

129
  buffer_name = g_value_get_string (gimp_value_array_index (args, 0));
130 131 132

  if (success)
    {
133
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
134

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

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

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

158
  buffer_name = g_value_get_string (gimp_value_array_index (args, 0));
159 160 161

  if (success)
    {
162
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
163

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

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

  if (success)
174
    g_value_set_int (gimp_value_array_index (return_vals, 1), width);
175

176
  return return_vals;
177 178
}

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

192
  buffer_name = g_value_get_string (gimp_value_array_index (args, 0));
193 194 195

  if (success)
    {
196
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
197

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

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

  if (success)
208
    g_value_set_int (gimp_value_array_index (return_vals, 1), height);
209

210
  return return_vals;
211 212
}

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

226
  buffer_name = g_value_get_string (gimp_value_array_index (args, 0));
227 228 229

  if (success)
    {
230
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
231

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

          bytes = babl_format_get_bytes_per_pixel (format);
        }
238 239
      else
        success = FALSE;
240 241
    }

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

  if (success)
246
    g_value_set_int (gimp_value_array_index (return_vals, 1), bytes);
247

248
  return return_vals;
249 250
}

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

264
  buffer_name = g_value_get_string (gimp_value_array_index (args, 0));
265 266 267

  if (success)
    {
268
      GimpBuffer *buffer = gimp_pdb_get_buffer (gimp, buffer_name, error);
269

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

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

  if (success)
280
    g_value_set_enum (gimp_value_array_index (return_vals, 1), image_type);
281

282
  return return_vals;
283 284
}

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

  /*
   * gimp-buffers-get-list
   */
293
  procedure = gimp_procedure_new (buffers_get_list_invoker);
294 295
  gimp_object_set_static_name (GIMP_OBJECT (procedure),
                               "gimp-buffers-get-list");
296 297 298 299 300 301 302 303 304 305 306 307
  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",
308
                                                       FALSE, TRUE, FALSE,
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",
320
                                                                 "The list of buffer names",
321
                                                                 GIMP_PARAM_READWRITE));
322
  gimp_pdb_register_procedure (pdb, procedure);
323
  g_object_unref (procedure);
324 325 326 327

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

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

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

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

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

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