gimage_cmds.c 85.3 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1
/* The GIMP -- an image manipulation program
2
 * Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
Elliot Lee's avatar
Elliot Lee committed
3
4
5
6
7
8
9
10
11
12
13
14
15
 *
 * 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 2 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, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
17
 */
18
19
20
21
22

/* NOTE: This file is autogenerated by pdbgen.pl. */

#include "procedural_db.h"

Tor Lillqvist's avatar
Tor Lillqvist committed
23
24
#include <string.h>

25
#include "apptypes.h"
26
#include "channel.h"
27
#include "cursorutil.h"
Elliot Lee's avatar
Elliot Lee committed
28
29
30
#include "drawable.h"
#include "gdisplay.h"
#include "gimage.h"
31
32
33
34
#include "gimpimage.h"
#include "layer.h"
#include "layer_pvt.h"

35
36
#include "libgimp/gimplimits.h"

Marc Lehmann's avatar
Marc Lehmann committed
37
static ProcRecord image_list_proc;
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
static ProcRecord image_new_proc;
static ProcRecord image_resize_proc;
static ProcRecord image_scale_proc;
static ProcRecord image_delete_proc;
static ProcRecord image_free_shadow_proc;
static ProcRecord image_get_layers_proc;
static ProcRecord image_get_channels_proc;
static ProcRecord image_unset_active_channel_proc;
static ProcRecord image_pick_correlate_layer_proc;
static ProcRecord image_raise_layer_proc;
static ProcRecord image_lower_layer_proc;
static ProcRecord image_raise_layer_to_top_proc;
static ProcRecord image_lower_layer_to_bottom_proc;
static ProcRecord image_merge_visible_layers_proc;
static ProcRecord image_merge_down_proc;
static ProcRecord image_flatten_proc;
static ProcRecord image_add_layer_proc;
static ProcRecord image_remove_layer_proc;
static ProcRecord image_add_layer_mask_proc;
static ProcRecord image_remove_layer_mask_proc;
static ProcRecord image_raise_channel_proc;
static ProcRecord image_lower_channel_proc;
static ProcRecord image_add_channel_proc;
static ProcRecord image_remove_channel_proc;
static ProcRecord image_active_drawable_proc;
static ProcRecord image_base_type_proc;
static ProcRecord image_get_cmap_proc;
static ProcRecord image_set_cmap_proc;
66
static ProcRecord image_undo_is_enabled_proc;
Marc Lehmann's avatar
Marc Lehmann committed
67
68
69
70
static ProcRecord image_undo_enable_proc;
static ProcRecord image_undo_disable_proc;
static ProcRecord image_undo_freeze_proc;
static ProcRecord image_undo_thaw_proc;
71
72
73
static ProcRecord image_clean_all_proc;
static ProcRecord image_floating_selection_proc;
static ProcRecord image_floating_sel_attached_to_proc;
74
static ProcRecord image_thumbnail_proc;
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
static ProcRecord image_width_proc;
static ProcRecord image_height_proc;
static ProcRecord image_get_active_layer_proc;
static ProcRecord image_set_active_layer_proc;
static ProcRecord image_get_active_channel_proc;
static ProcRecord image_set_active_channel_proc;
static ProcRecord image_get_selection_proc;
static ProcRecord image_get_component_active_proc;
static ProcRecord image_set_component_active_proc;
static ProcRecord image_get_component_visible_proc;
static ProcRecord image_set_component_visible_proc;
static ProcRecord image_get_filename_proc;
static ProcRecord image_set_filename_proc;
static ProcRecord image_get_resolution_proc;
static ProcRecord image_set_resolution_proc;
static ProcRecord image_get_unit_proc;
static ProcRecord image_set_unit_proc;
static ProcRecord image_get_layer_by_tattoo_proc;
static ProcRecord image_get_channel_by_tattoo_proc;

void
register_gimage_procs (void)
{
Marc Lehmann's avatar
Marc Lehmann committed
98
  procedural_db_register (&image_list_proc);
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
  procedural_db_register (&image_new_proc);
  procedural_db_register (&image_resize_proc);
  procedural_db_register (&image_scale_proc);
  procedural_db_register (&image_delete_proc);
  procedural_db_register (&image_free_shadow_proc);
  procedural_db_register (&image_get_layers_proc);
  procedural_db_register (&image_get_channels_proc);
  procedural_db_register (&image_unset_active_channel_proc);
  procedural_db_register (&image_pick_correlate_layer_proc);
  procedural_db_register (&image_raise_layer_proc);
  procedural_db_register (&image_lower_layer_proc);
  procedural_db_register (&image_raise_layer_to_top_proc);
  procedural_db_register (&image_lower_layer_to_bottom_proc);
  procedural_db_register (&image_merge_visible_layers_proc);
  procedural_db_register (&image_merge_down_proc);
  procedural_db_register (&image_flatten_proc);
  procedural_db_register (&image_add_layer_proc);
  procedural_db_register (&image_remove_layer_proc);
  procedural_db_register (&image_add_layer_mask_proc);
  procedural_db_register (&image_remove_layer_mask_proc);
  procedural_db_register (&image_raise_channel_proc);
  procedural_db_register (&image_lower_channel_proc);
  procedural_db_register (&image_add_channel_proc);
  procedural_db_register (&image_remove_channel_proc);
  procedural_db_register (&image_active_drawable_proc);
  procedural_db_register (&image_base_type_proc);
  procedural_db_register (&image_get_cmap_proc);
  procedural_db_register (&image_set_cmap_proc);
127
  procedural_db_register (&image_undo_is_enabled_proc);
Marc Lehmann's avatar
Marc Lehmann committed
128
129
130
131
  procedural_db_register (&image_undo_enable_proc);
  procedural_db_register (&image_undo_disable_proc);
  procedural_db_register (&image_undo_freeze_proc);
  procedural_db_register (&image_undo_thaw_proc);
132
133
134
  procedural_db_register (&image_clean_all_proc);
  procedural_db_register (&image_floating_selection_proc);
  procedural_db_register (&image_floating_sel_attached_to_proc);
135
  procedural_db_register (&image_thumbnail_proc);
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
  procedural_db_register (&image_width_proc);
  procedural_db_register (&image_height_proc);
  procedural_db_register (&image_get_active_layer_proc);
  procedural_db_register (&image_set_active_layer_proc);
  procedural_db_register (&image_get_active_channel_proc);
  procedural_db_register (&image_set_active_channel_proc);
  procedural_db_register (&image_get_selection_proc);
  procedural_db_register (&image_get_component_active_proc);
  procedural_db_register (&image_set_component_active_proc);
  procedural_db_register (&image_get_component_visible_proc);
  procedural_db_register (&image_set_component_visible_proc);
  procedural_db_register (&image_get_filename_proc);
  procedural_db_register (&image_set_filename_proc);
  procedural_db_register (&image_get_resolution_proc);
  procedural_db_register (&image_set_resolution_proc);
  procedural_db_register (&image_get_unit_proc);
  procedural_db_register (&image_set_unit_proc);
  procedural_db_register (&image_get_layer_by_tattoo_proc);
  procedural_db_register (&image_get_channel_by_tattoo_proc);
}
Elliot Lee's avatar
Elliot Lee committed
156

157
158
159
/* Yuup, this is somewhat unsmooth, to say the least */

static void
160
161
162
163
164
gimlist_cb (gpointer im,
	    gpointer data)
{
  GSList **l = (GSList **) data;
  *l = g_slist_prepend (*l, im);
165
166
}

Elliot Lee's avatar
Elliot Lee committed
167
static Argument *
Marc Lehmann's avatar
Marc Lehmann committed
168
image_list_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
169
170
{
  Argument *return_args;
171
172
173
174
  gint32 num_images = 0;
  gint32 *image_ids = NULL;
  GSList *list = NULL;
  int i;
Elliot Lee's avatar
Elliot Lee committed
175

176
  gimage_foreach (gimlist_cb, &list);
177
  num_images = g_slist_length (list);
Elliot Lee's avatar
Elliot Lee committed
178

179
180
  if (num_images)
    {
181
182
183
      image_ids = g_new (gint32, num_images);
      for (i = 0; i < num_images; i++, list = list->next)
	image_ids[i] = pdb_image_to_id (GIMP_IMAGE (list->data));
Elliot Lee's avatar
Elliot Lee committed
184
    }
185

Marc Lehmann's avatar
Marc Lehmann committed
186
  return_args = procedural_db_return_args (&image_list_proc, TRUE);
187

188
189
  return_args[1].value.pdb_int = num_images;
  return_args[2].value.pdb_pointer = image_ids;
190

Elliot Lee's avatar
Elliot Lee committed
191
192
193
  return return_args;
}

Marc Lehmann's avatar
Marc Lehmann committed
194
static ProcArg image_list_outargs[] =
Elliot Lee's avatar
Elliot Lee committed
195
{
196
197
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
198
199
200
    "num_images",
    "The number of images currently open"
  },
201
202
  {
    PDB_INT32ARRAY,
Elliot Lee's avatar
Elliot Lee committed
203
204
205
206
207
    "image_ids",
    "The list of images currently open"
  }
};

Marc Lehmann's avatar
Marc Lehmann committed
208
static ProcRecord image_list_proc =
Elliot Lee's avatar
Elliot Lee committed
209
{
Marc Lehmann's avatar
Marc Lehmann committed
210
  "gimp_image_list",
211
  "Returns the list of images currently open.",
Elliot Lee's avatar
Elliot Lee committed
212
213
214
215
216
217
218
219
  "This procedure returns the list of images currently open in the GIMP.",
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
  0,
  NULL,
  2,
Marc Lehmann's avatar
Marc Lehmann committed
220
221
  image_list_outargs,
  { { image_list_invoker } }
Elliot Lee's avatar
Elliot Lee committed
222
223
224
};

static Argument *
225
image_new_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
226
{
227
228
229
230
231
232
  gboolean success = TRUE;
  Argument *return_args;
  gint32 width;
  gint32 height;
  gint32 type;
  GimpImage *gimage = NULL;
Elliot Lee's avatar
Elliot Lee committed
233

234
235
236
  width = args[0].value.pdb_int;
  if (width <= 0)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
237

238
239
240
  height = args[1].value.pdb_int;
  if (height <= 0)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
241

242
243
244
  type = args[2].value.pdb_int;
  if (type < RGB || type > INDEXED)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
245
246

  if (success)
247
    success = (gimage = gimage_new (width, height, type)) != NULL;
Elliot Lee's avatar
Elliot Lee committed
248

249
  return_args = procedural_db_return_args (&image_new_proc, success);
Elliot Lee's avatar
Elliot Lee committed
250
251

  if (success)
252
    return_args[1].value.pdb_int = pdb_image_to_id (gimage);
Elliot Lee's avatar
Elliot Lee committed
253
254
255
256

  return return_args;
}

257
static ProcArg image_new_inargs[] =
Elliot Lee's avatar
Elliot Lee committed
258
{
259
260
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
261
262
263
    "width",
    "The width of the image"
  },
264
265
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
266
267
268
    "height",
    "The height of the image"
  },
269
270
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
271
272
273
274
275
    "type",
    "The type of image: { RGB (0), GRAY (1), INDEXED (2) }"
  }
};

276
static ProcArg image_new_outargs[] =
Elliot Lee's avatar
Elliot Lee committed
277
{
278
279
  {
    PDB_IMAGE,
Elliot Lee's avatar
Elliot Lee committed
280
281
282
283
284
    "image",
    "The ID of the newly created image"
  }
};

285
static ProcRecord image_new_proc =
Elliot Lee's avatar
Elliot Lee committed
286
287
{
  "gimp_image_new",
288
289
  "Creates a new image with the specified width, height, and type.",
  "Creates a new image, undisplayed with the specified extents and type. A layer should be created and added before this image is displayed, or subsequent calls to 'gimp_display_new' with this image as an argument will fail. Layers can be created using the 'gimp_layer_new' commands. They can be added to an image using the 'gimp_image_add_layer' command.",
Elliot Lee's avatar
Elliot Lee committed
290
291
292
293
294
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
  3,
295
  image_new_inargs,
Elliot Lee's avatar
Elliot Lee committed
296
  1,
297
298
  image_new_outargs,
  { { image_new_invoker } }
Elliot Lee's avatar
Elliot Lee committed
299
300
301
};

static Argument *
302
image_resize_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
303
{
304
305
306
307
308
309
  gboolean success = TRUE;
  GimpImage *gimage;
  gint32 new_width;
  gint32 new_height;
  gint32 offx;
  gint32 offy;
Elliot Lee's avatar
Elliot Lee committed
310

311
312
313
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;
314

315
316
317
318
319
320
321
322
323
324
325
  new_width = args[1].value.pdb_int;
  if (new_width <= 0)
    success = FALSE;

  new_height = args[2].value.pdb_int;
  if (new_height <= 0)
    success = FALSE;

  offx = args[3].value.pdb_int;

  offy = args[4].value.pdb_int;
Elliot Lee's avatar
Elliot Lee committed
326
327
328

  if (success)
    {
329
330
      gimp_add_busy_cursors_until_idle ();
      gimage_resize (gimage, new_width, new_height, offx, offy);
Elliot Lee's avatar
Elliot Lee committed
331
332
    }

333
  return procedural_db_return_args (&image_resize_proc, success);
Elliot Lee's avatar
Elliot Lee committed
334
335
}

336
static ProcArg image_resize_inargs[] =
Elliot Lee's avatar
Elliot Lee committed
337
{
338
339
  {
    PDB_IMAGE,
Elliot Lee's avatar
Elliot Lee committed
340
    "image",
341
    "The image"
Elliot Lee's avatar
Elliot Lee committed
342
  },
343
344
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
345
    "new_width",
346
    "New image width: 0 < new_width"
Elliot Lee's avatar
Elliot Lee committed
347
  },
348
349
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
350
    "new_height",
351
    "New image height: 0 < new_height"
Elliot Lee's avatar
Elliot Lee committed
352
  },
353
354
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
355
356
357
    "offx",
    "x offset between upper left corner of old and new images: (new - old)"
  },
358
359
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
360
361
362
363
364
    "offy",
    "y offset between upper left corner of old and new images: (new - old)"
  }
};

365
static ProcRecord image_resize_proc =
Elliot Lee's avatar
Elliot Lee committed
366
367
368
{
  "gimp_image_resize",
  "Resize the image to the specified extents.",
369
  "This procedure resizes the image so that it's new width and height are equal to the supplied parameters. Offsets are also provided which describe the position of the previous image's content. No bounds checking is currently provided, so don't supply parameters that are out of bounds. All channels within the image are resized according to the specified parameters; this includes the image selection mask. All layers within the image are repositioned according to the specified offsets.",
Elliot Lee's avatar
Elliot Lee committed
370
371
372
373
374
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
  5,
375
  image_resize_inargs,
Elliot Lee's avatar
Elliot Lee committed
376
377
  0,
  NULL,
378
  { { image_resize_invoker } }
Elliot Lee's avatar
Elliot Lee committed
379
380
381
};

static Argument *
382
image_scale_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
383
{
384
385
386
387
  gboolean success = TRUE;
  GimpImage *gimage;
  gint32 new_width;
  gint32 new_height;
Elliot Lee's avatar
Elliot Lee committed
388

389
390
391
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
392

393
394
395
396
397
398
399
  new_width = args[1].value.pdb_int;
  if (new_width <= 0)
    success = FALSE;

  new_height = args[2].value.pdb_int;
  if (new_height <= 0)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
400
401

  if (success)
402
403
404
405
    {
      gimp_add_busy_cursors_until_idle ();
      gimage_scale (gimage, new_width, new_height);
    }
Elliot Lee's avatar
Elliot Lee committed
406

407
  return procedural_db_return_args (&image_scale_proc, success);
Elliot Lee's avatar
Elliot Lee committed
408
409
}

410
static ProcArg image_scale_inargs[] =
Elliot Lee's avatar
Elliot Lee committed
411
{
412
413
  {
    PDB_IMAGE,
Elliot Lee's avatar
Elliot Lee committed
414
    "image",
415
    "The image"
Elliot Lee's avatar
Elliot Lee committed
416
  },
417
418
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
419
    "new_width",
420
    "New image width: 0 < new_width"
Elliot Lee's avatar
Elliot Lee committed
421
  },
422
423
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
424
    "new_height",
425
    "New image height: 0 < new_height"
Elliot Lee's avatar
Elliot Lee committed
426
427
428
  }
};

429
static ProcRecord image_scale_proc =
Elliot Lee's avatar
Elliot Lee committed
430
431
432
{
  "gimp_image_scale",
  "Scale the image to the specified extents.",
433
  "This procedure scales the image so that it's new width and height are equal to the supplied parameters. Offsets are also provided which describe the position of the previous image's content. No bounds checking is currently provided, so don't supply parameters that are out of bounds. All channels within the image are scaled according to the specified parameters; this includes the image selection mask. All layers within the image are repositioned according to the specified offsets.",
Elliot Lee's avatar
Elliot Lee committed
434
435
436
437
438
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
  3,
439
  image_scale_inargs,
Elliot Lee's avatar
Elliot Lee committed
440
441
  0,
  NULL,
442
  { { image_scale_invoker } }
Elliot Lee's avatar
Elliot Lee committed
443
444
445
};

static Argument *
446
image_delete_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
447
{
448
449
  gboolean success = TRUE;
  GimpImage *gimage;
Elliot Lee's avatar
Elliot Lee committed
450

451
452
453
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
454

455
  if (success)
Elliot Lee's avatar
Elliot Lee committed
456
457
    gimage_delete (gimage);

458
  return procedural_db_return_args (&image_delete_proc, success);
Elliot Lee's avatar
Elliot Lee committed
459
460
}

461
static ProcArg image_delete_inargs[] =
Elliot Lee's avatar
Elliot Lee committed
462
{
463
464
  {
    PDB_IMAGE,
Elliot Lee's avatar
Elliot Lee committed
465
    "image",
466
    "The image"
Elliot Lee's avatar
Elliot Lee committed
467
468
469
  }
};

470
static ProcRecord image_delete_proc =
Elliot Lee's avatar
Elliot Lee committed
471
472
{
  "gimp_image_delete",
473
474
  "Delete the specified image.",
  "If there are no other references to this image it will be deleted. Other references are possible when more than one view to an image exists.",
Elliot Lee's avatar
Elliot Lee committed
475
476
477
478
479
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
  1,
480
  image_delete_inargs,
Elliot Lee's avatar
Elliot Lee committed
481
482
  0,
  NULL,
483
  { { image_delete_invoker } }
Elliot Lee's avatar
Elliot Lee committed
484
485
486
};

static Argument *
487
image_free_shadow_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
488
{
489
490
  gboolean success = TRUE;
  GimpImage *gimage;
Elliot Lee's avatar
Elliot Lee committed
491

492
493
494
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
495

496
  if (success)
Elliot Lee's avatar
Elliot Lee committed
497
498
    gimage_free_shadow (gimage);

499
  return procedural_db_return_args (&image_free_shadow_proc, success);
Elliot Lee's avatar
Elliot Lee committed
500
501
}

502
static ProcArg image_free_shadow_inargs[] =
Elliot Lee's avatar
Elliot Lee committed
503
{
504
505
  {
    PDB_IMAGE,
Elliot Lee's avatar
Elliot Lee committed
506
    "image",
507
    "The image"
Elliot Lee's avatar
Elliot Lee committed
508
509
510
  }
};

511
static ProcRecord image_free_shadow_proc =
Elliot Lee's avatar
Elliot Lee committed
512
513
{
  "gimp_image_free_shadow",
514
515
  "Free the specified image's shadow data (if it exists).",
  "This procedure is intended as a memory saving device. If any shadow memory has been allocated, it will be freed automatically on a call to 'gimp_image_delete'.",
Elliot Lee's avatar
Elliot Lee committed
516
517
518
519
520
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
  1,
521
  image_free_shadow_inargs,
Elliot Lee's avatar
Elliot Lee committed
522
523
  0,
  NULL,
524
  { { image_free_shadow_invoker } }
Elliot Lee's avatar
Elliot Lee committed
525
526
527
};

static Argument *
528
image_get_layers_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
529
{
530
  gboolean success = TRUE;
Elliot Lee's avatar
Elliot Lee committed
531
  Argument *return_args;
532
533
534
535
536
  GimpImage *gimage;
  gint32 num_layers = 0;
  gint32 *layer_ids = NULL;
  GSList *list = NULL;
  int i;
Elliot Lee's avatar
Elliot Lee committed
537

538
539
540
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
541
542
543

  if (success)
    {
544
545
546
      list = gimage->layers;
      num_layers = g_slist_length (list);
    
Elliot Lee's avatar
Elliot Lee committed
547
548
      if (num_layers)
	{
549
550
551
	  layer_ids = g_new (gint32, num_layers);
	  for (i = 0; i < num_layers; i++, list = list->next)
	    layer_ids[i] = drawable_ID (GIMP_DRAWABLE (list->data));
Elliot Lee's avatar
Elliot Lee committed
552
	}
553
554
555
    }

  return_args = procedural_db_return_args (&image_get_layers_proc, success);
Elliot Lee's avatar
Elliot Lee committed
556

557
558
  if (success)
    {
Elliot Lee's avatar
Elliot Lee committed
559
560
561
562
563
564
565
      return_args[1].value.pdb_int = num_layers;
      return_args[2].value.pdb_pointer = layer_ids;
    }

  return return_args;
}

566
static ProcArg image_get_layers_inargs[] =
Elliot Lee's avatar
Elliot Lee committed
567
{
568
569
  {
    PDB_IMAGE,
Elliot Lee's avatar
Elliot Lee committed
570
571
572
573
574
    "image",
    "The image"
  }
};

575
static ProcArg image_get_layers_outargs[] =
Elliot Lee's avatar
Elliot Lee committed
576
{
577
578
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
579
580
581
    "num_layers",
    "The number of layers contained in the image"
  },
582
583
  {
    PDB_INT32ARRAY,
Elliot Lee's avatar
Elliot Lee committed
584
585
586
587
588
    "layer_ids",
    "The list of layers contained in the image"
  }
};

589
static ProcRecord image_get_layers_proc =
Elliot Lee's avatar
Elliot Lee committed
590
591
{
  "gimp_image_get_layers",
592
593
  "Returns the list of layers contained in the specified image.",
  "This procedure returns the list of layers contained in the specified image. The order of layers is from topmost to bottommost.",
Elliot Lee's avatar
Elliot Lee committed
594
595
596
597
598
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
  1,
599
  image_get_layers_inargs,
Elliot Lee's avatar
Elliot Lee committed
600
  2,
601
602
  image_get_layers_outargs,
  { { image_get_layers_invoker } }
Elliot Lee's avatar
Elliot Lee committed
603
604
605
};

static Argument *
606
image_get_channels_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
607
{
608
  gboolean success = TRUE;
Elliot Lee's avatar
Elliot Lee committed
609
  Argument *return_args;
610
611
612
613
614
  GimpImage *gimage;
  gint32 num_channels = 0;
  gint32 *channel_ids = NULL;
  GSList *list = NULL;
  int i;
Elliot Lee's avatar
Elliot Lee committed
615

616
617
618
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
619
620
621

  if (success)
    {
622
623
624
      list = gimage->channels;
      num_channels = g_slist_length (list);
    
Elliot Lee's avatar
Elliot Lee committed
625
626
      if (num_channels)
	{
627
628
629
	  channel_ids = g_new (gint32, num_channels);
	  for (i = 0; i < num_channels; i++, list = list->next)
	    channel_ids[i] = drawable_ID (GIMP_DRAWABLE (list->data));
Elliot Lee's avatar
Elliot Lee committed
630
	}
631
    }
Elliot Lee's avatar
Elliot Lee committed
632

633
634
635
636
  return_args = procedural_db_return_args (&image_get_channels_proc, success);

  if (success)
    {
Elliot Lee's avatar
Elliot Lee committed
637
638
639
640
641
642
643
      return_args[1].value.pdb_int = num_channels;
      return_args[2].value.pdb_pointer = channel_ids;
    }

  return return_args;
}

644
static ProcArg image_get_channels_inargs[] =
Elliot Lee's avatar
Elliot Lee committed
645
{
646
647
  {
    PDB_IMAGE,
Elliot Lee's avatar
Elliot Lee committed
648
649
650
651
652
    "image",
    "The image"
  }
};

653
static ProcArg image_get_channels_outargs[] =
Elliot Lee's avatar
Elliot Lee committed
654
{
655
656
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
657
658
659
    "num_channels",
    "The number of channels contained in the image"
  },
660
661
  {
    PDB_INT32ARRAY,
Elliot Lee's avatar
Elliot Lee committed
662
663
664
665
666
    "channel_ids",
    "The list of channels contained in the image"
  }
};

667
static ProcRecord image_get_channels_proc =
Elliot Lee's avatar
Elliot Lee committed
668
669
{
  "gimp_image_get_channels",
670
671
  "Returns the list of channels contained in the specified image.",
  "This procedure returns the list of channels contained in the specified image. This does not include the selection mask, or layer masks. The order is from topmost to bottommost.",
Elliot Lee's avatar
Elliot Lee committed
672
673
674
675
676
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
  1,
677
  image_get_channels_inargs,
Elliot Lee's avatar
Elliot Lee committed
678
  2,
679
680
  image_get_channels_outargs,
  { { image_get_channels_invoker } }
Elliot Lee's avatar
Elliot Lee committed
681
682
683
};

static Argument *
684
image_unset_active_channel_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
685
{
686
687
  gboolean success = TRUE;
  GimpImage *gimage;
Elliot Lee's avatar
Elliot Lee committed
688

689
690
691
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
692
693

  if (success)
694
    gimage_unset_active_channel (gimage);
Elliot Lee's avatar
Elliot Lee committed
695

696
  return procedural_db_return_args (&image_unset_active_channel_proc, success);
Elliot Lee's avatar
Elliot Lee committed
697
698
}

699
static ProcArg image_unset_active_channel_inargs[] =
Elliot Lee's avatar
Elliot Lee committed
700
{
701
702
  {
    PDB_IMAGE,
Elliot Lee's avatar
Elliot Lee committed
703
704
705
706
707
    "image",
    "The image"
  }
};

708
static ProcRecord image_unset_active_channel_proc =
Elliot Lee's avatar
Elliot Lee committed
709
{
710
711
712
  "gimp_image_unset_active_channel",
  "Unsets the active channel in the specified image.",
  "If an active channel exists, it is unset. There then exists no active channel, and if desired, one can be set through a call to 'Set Active Channel'. No error is returned in the case of no existing active channel.",
Elliot Lee's avatar
Elliot Lee committed
713
714
715
716
717
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
  1,
718
719
720
721
  image_unset_active_channel_inargs,
  0,
  NULL,
  { { image_unset_active_channel_invoker } }
Elliot Lee's avatar
Elliot Lee committed
722
723
724
};

static Argument *
725
image_pick_correlate_layer_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
726
{
727
  gboolean success = TRUE;
Elliot Lee's avatar
Elliot Lee committed
728
  Argument *return_args;
729
730
731
732
  GimpImage *gimage;
  gint32 x;
  gint32 y;
  GimpLayer *layer = NULL;
Elliot Lee's avatar
Elliot Lee committed
733

734
735
736
737
738
739
740
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;

  x = args[1].value.pdb_int;

  y = args[2].value.pdb_int;
Elliot Lee's avatar
Elliot Lee committed
741
742

  if (success)
743
    layer = gimage_pick_correlate_layer (gimage, x, y);
Elliot Lee's avatar
Elliot Lee committed
744

745
  return_args = procedural_db_return_args (&image_pick_correlate_layer_proc, success);
Elliot Lee's avatar
Elliot Lee committed
746
747

  if (success)
748
    return_args[1].value.pdb_int = drawable_ID (GIMP_DRAWABLE (layer));
Elliot Lee's avatar
Elliot Lee committed
749
750
751
752

  return return_args;
}

753
static ProcArg image_pick_correlate_layer_inargs[] =
Elliot Lee's avatar
Elliot Lee committed
754
{
755
756
  {
    PDB_IMAGE,
Elliot Lee's avatar
Elliot Lee committed
757
758
    "image",
    "The image"
759
760
761
762
763
764
765
766
767
768
  },
  {
    PDB_INT32,
    "x",
    "The x coordinate for the pick"
  },
  {
    PDB_INT32,
    "y",
    "The y coordinate for the pick"
Elliot Lee's avatar
Elliot Lee committed
769
770
771
  }
};

772
static ProcArg image_pick_correlate_layer_outargs[] =
Elliot Lee's avatar
Elliot Lee committed
773
{
774
775
776
777
  {
    PDB_LAYER,
    "layer",
    "The layer found at the specified coordinates"
Elliot Lee's avatar
Elliot Lee committed
778
779
780
  }
};

781
static ProcRecord image_pick_correlate_layer_proc =
Elliot Lee's avatar
Elliot Lee committed
782
{
783
784
785
  "gimp_image_pick_correlate_layer",
  "Find the layer visible at the specified coordinates.",
  "This procedure finds the layer which is visible at the specified coordinates. Layers which do not qualify are those whose extents do not pass within the specified coordinates, or which are transparent at the specified coordinates. This procedure will return -1 if no layer is found.",
Elliot Lee's avatar
Elliot Lee committed
786
787
788
789
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
790
791
  3,
  image_pick_correlate_layer_inargs,
Elliot Lee's avatar
Elliot Lee committed
792
  1,
793
794
  image_pick_correlate_layer_outargs,
  { { image_pick_correlate_layer_invoker } }
Elliot Lee's avatar
Elliot Lee committed
795
796
797
};

static Argument *
798
image_raise_layer_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
799
{
800
801
802
  gboolean success = TRUE;
  GimpImage *gimage;
  GimpLayer *layer;
Elliot Lee's avatar
Elliot Lee committed
803

804
805
806
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
807

808
809
810
  layer = layer_get_ID (args[1].value.pdb_int);
  if (layer == NULL)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
811
812

  if (success)
813
    success = gimage_raise_layer (gimage, layer) != NULL;
Elliot Lee's avatar
Elliot Lee committed
814

815
  return procedural_db_return_args (&image_raise_layer_proc, success);
Elliot Lee's avatar
Elliot Lee committed
816
817
}

818
static ProcArg image_raise_layer_inargs[] =
Elliot Lee's avatar
Elliot Lee committed
819
{
820
821
  {
    PDB_IMAGE,
Elliot Lee's avatar
Elliot Lee committed
822
823
    "image",
    "The image"
824
825
826
827
828
  },
  {
    PDB_LAYER,
    "layer",
    "The layer to raise"
Elliot Lee's avatar
Elliot Lee committed
829
830
831
  }
};

832
static ProcRecord image_raise_layer_proc =
Elliot Lee's avatar
Elliot Lee committed
833
{
834
835
836
  "gimp_image_raise_layer",
  "Raise the specified layer in the image's layer stack",
  "This procedure raises the specified layer one step in the existing layer stack. It will not move the layer if there is no layer above it, or the layer has no alpha channel.",
Elliot Lee's avatar
Elliot Lee committed
837
838
839
840
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
841
842
843
844
845
846
  2,
  image_raise_layer_inargs,
  0,
  NULL,
  { { image_raise_layer_invoker } }
};
Elliot Lee's avatar
Elliot Lee committed
847
848

static Argument *
849
image_lower_layer_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
850
{
851
852
853
  gboolean success = TRUE;
  GimpImage *gimage;
  GimpLayer *layer;
Elliot Lee's avatar
Elliot Lee committed
854

855
856
857
858
859
860
861
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;

  layer = layer_get_ID (args[1].value.pdb_int);
  if (layer == NULL)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
862
863

  if (success)
864
    success = gimage_lower_layer (gimage, layer) != NULL;
Elliot Lee's avatar
Elliot Lee committed
865

866
  return procedural_db_return_args (&image_lower_layer_proc, success);
Elliot Lee's avatar
Elliot Lee committed
867
868
}

869
static ProcArg image_lower_layer_inargs[] =
Elliot Lee's avatar
Elliot Lee committed
870
{
871
872
  {
    PDB_IMAGE,
Elliot Lee's avatar
Elliot Lee committed
873
874
875
    "image",
    "The image"
  },
876
877
  {
    PDB_LAYER,
Elliot Lee's avatar
Elliot Lee committed
878
879
880
881
882
    "layer",
    "The layer to lower"
  }
};

883
static ProcRecord image_lower_layer_proc =
Elliot Lee's avatar
Elliot Lee committed
884
885
886
{
  "gimp_image_lower_layer",
  "Lower the specified layer in the image's layer stack",
887
  "This procedure lowers the specified layer one step in the existing layer stack. It will not move the layer if there is no layer below it, or the layer has no alpha channel.",
Elliot Lee's avatar
Elliot Lee committed
888
889
890
891
892
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
  2,
893
  image_lower_layer_inargs,
Elliot Lee's avatar
Elliot Lee committed
894
895
  0,
  NULL,
896
  { { image_lower_layer_invoker } }
Elliot Lee's avatar
Elliot Lee committed
897
898
};

899
static Argument *
900
image_raise_layer_to_top_invoker (Argument *args)
901
{
902
903
904
  gboolean success = TRUE;
  GimpImage *gimage;
  GimpLayer *layer;
905

906
907
908
909
910
911
912
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;

  layer = layer_get_ID (args[1].value.pdb_int);
  if (layer == NULL)
    success = FALSE;
913
914

  if (success)
915
    success = gimage_raise_layer_to_top (gimage, layer) != NULL;
916

917
  return procedural_db_return_args (&image_raise_layer_to_top_proc, success);
918
919
}

920
static ProcArg image_raise_layer_to_top_inargs[] =
921
{
922
923
  {
    PDB_IMAGE,
924
925
926
    "image",
    "The image"
  },
927
928
  {
    PDB_LAYER,
929
930
931
932
933
    "layer",
    "The layer to raise to top"
  }
};

934
static ProcRecord image_raise_layer_to_top_proc =
935
936
937
{
  "gimp_image_raise_layer_to_top",
  "Raise the specified layer in the image's layer stack to top of stack",
938
  "This procedure raises the specified layer to top of the existing layer stack. It will not move the layer if there is no layer above it, or the layer has no alpha channel.",
939
940
941
942
943
  "Wolfgang Hofer, Sven Neumann",
  "Wolfgang Hofer",
  "1998",
  PDB_INTERNAL,
  2,
944
  image_raise_layer_to_top_inargs,
945
946
  0,
  NULL,
947
  { { image_raise_layer_to_top_invoker } }
948
949
950
};

static Argument *
951
image_lower_layer_to_bottom_invoker (Argument *args)
952
{
953
954
955
  gboolean success = TRUE;
  GimpImage *gimage;
  GimpLayer *layer;
956

957
958
959
960
961
962
963
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;

  layer = layer_get_ID (args[1].value.pdb_int);
  if (layer == NULL)
    success = FALSE;
964
965

  if (success)
966
    success = gimage_lower_layer_to_bottom (gimage, layer) != NULL;
967

968
  return procedural_db_return_args (&image_lower_layer_to_bottom_proc, success);
969
970
}

971
static ProcArg image_lower_layer_to_bottom_inargs[] =
972
{
973
974
  {
    PDB_IMAGE,
975
976
977
    "image",
    "The image"
  },
978
979
  {
    PDB_LAYER,
980
981
982
983
984
    "layer",
    "The layer to lower to bottom"
  }
};

985
static ProcRecord image_lower_layer_to_bottom_proc =
986
987
{
  "gimp_image_lower_layer_to_bottom",
988
989
  "Lower the specified layer in the image's layer stack to bottom of stack",
  "This procedure lowers the specified layer to bottom of the existing layer stack. It will not move the layer if there is no layer below it, or the layer has no alpha channel.",
990
991
992
993
994
  "Wolfgang Hofer, Sven Neumann",
  "Wolfgang Hofer",
  "1998",
  PDB_INTERNAL,
  2,
995
  image_lower_layer_to_bottom_inargs,
996
997
  0,
  NULL,
998
  { { image_lower_layer_to_bottom_invoker } }
999
1000
};

Elliot Lee's avatar
Elliot Lee committed
1001
static Argument *
1002
image_merge_visible_layers_invoker (Argument *args)
Elliot Lee's avatar
Elliot Lee committed
1003
{
1004
  gboolean success = TRUE;
Elliot Lee's avatar
Elliot Lee committed
1005
  Argument *return_args;
1006
1007
1008
  GimpImage *gimage;
  gint32 merge_type;
  GimpLayer *layer = NULL;
Elliot Lee's avatar
Elliot Lee committed
1009

1010
1011
1012
1013
1014
1015
1016
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;

  merge_type = args[1].value.pdb_int;
  if (merge_type < EXPAND_AS_NECESSARY || merge_type > CLIP_TO_BOTTOM_LAYER)
    success = FALSE;
Elliot Lee's avatar
Elliot Lee committed
1017
1018
1019

  if (success)
    {
1020
1021
      layer = gimage_merge_visible_layers (gimage, merge_type);
      success = layer != NULL;
Elliot Lee's avatar
Elliot Lee committed
1022
1023
    }

1024
  return_args = procedural_db_return_args (&image_merge_visible_layers_proc, success);
Elliot Lee's avatar
Elliot Lee committed
1025
1026

  if (success)
1027
    return_args[1].value.pdb_int = drawable_ID (GIMP_DRAWABLE (layer));
Elliot Lee's avatar
Elliot Lee committed
1028
1029
1030
1031

  return return_args;
}

1032
static ProcArg image_merge_visible_layers_inargs[] =
Elliot Lee's avatar
Elliot Lee committed
1033
{
1034
1035
  {
    PDB_IMAGE,
Elliot Lee's avatar
Elliot Lee committed
1036
1037
1038
    "image",
    "The image"
  },
1039
1040
  {
    PDB_INT32,
Elliot Lee's avatar
Elliot Lee committed
1041
    "merge_type",
1042
    "The type of merge: { EXPAND_AS_NECESSARY (0), CLIP_TO_IMAGE (1), CLIP_TO_BOTTOM_LAYER (2) }"
Elliot Lee's avatar
Elliot Lee committed
1043
1044
1045
  }
};

1046
static ProcArg image_merge_visible_layers_outargs[] =
Elliot Lee's avatar
Elliot Lee committed
1047
{
1048
1049
  {
    PDB_LAYER,
Elliot Lee's avatar
Elliot Lee committed
1050
1051
1052
1053
1054
    "layer",
    "The resulting layer"
  }
};

1055
static ProcRecord image_merge_visible_layers_proc =
Elliot Lee's avatar
Elliot Lee committed
1056
1057
{
  "gimp_image_merge_visible_layers",
1058
1059
  "Merge the visible image layers into one.",
  "This procedure combines the visible layers into a single layer using the specified merge type. A merge type of EXPAND_AS_NECESSARY expands the final layer to encompass the areas of the visible layers. A merge type of CLIP_TO_IMAGE clips the final layer to the extents of the image. A merge type of CLIP_TO_BOTTOM_LAYER clips the final layer to the size of the bottommost layer.",
Elliot Lee's avatar
Elliot Lee committed
1060
1061
1062
1063
1064
  "Spencer Kimball & Peter Mattis",
  "Spencer Kimball & Peter Mattis",
  "1995-1996",
  PDB_INTERNAL,
  2,
1065
  image_merge_visible_layers_inargs,
Elliot Lee's avatar
Elliot Lee committed
1066
  1,
1067
1068
  image_merge_visible_layers_outargs,
  { { image_merge_visible_layers_invoker } }
Elliot Lee's avatar
Elliot Lee committed
1069
1070
};

1071
static Argument *
1072
image_merge_down_invoker (Argument *args)
1073
{
1074
  gboolean success = TRUE;
1075
  Argument *return_args;
1076
1077
1078
1079
  GimpImage *gimage;
  GimpLayer *merge_layer;
  gint32 merge_type;
  GimpLayer *layer = NULL;
1080

1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
  gimage = pdb_id_to_image (args[0].value.pdb_int);
  if (gimage == NULL)
    success = FALSE;

  merge_layer = layer_get_ID (args[