Commit 62a6023b authored by Ell's avatar Ell

pdb: add gimp-image-merge-layer-group procedure

Oddly, we didn't have this one yet :P
parent 184762cd
......@@ -37,6 +37,7 @@
#include "core/gimpchannel.h"
#include "core/gimpcontainer.h"
#include "core/gimpdrawable.h"
#include "core/gimpgrouplayer.h"
#include "core/gimpimage-colormap.h"
#include "core/gimpimage-duplicate.h"
#include "core/gimpimage-merge.h"
......@@ -1461,6 +1462,47 @@ image_merge_down_invoker (GimpProcedure *procedure,
return return_vals;
}
static GimpValueArray *
image_merge_layer_group_invoker (GimpProcedure *procedure,
Gimp *gimp,
GimpContext *context,
GimpProgress *progress,
const GimpValueArray *args,
GError **error)
{
gboolean success = TRUE;
GimpValueArray *return_vals;
GimpImage *image;
GimpLayer *layer_group;
GimpLayer *layer = NULL;
image = g_value_get_object (gimp_value_array_index (args, 0));
layer_group = g_value_get_object (gimp_value_array_index (args, 1));
if (success)
{
if (gimp_pdb_item_is_attached (GIMP_ITEM (layer_group), image, 0, error) &&
gimp_pdb_item_is_group (GIMP_ITEM (layer_group), error))
{
layer = gimp_image_merge_group_layer (image,
GIMP_GROUP_LAYER (layer_group));
if (! layer)
success = FALSE;
}
else
success = FALSE;
}
return_vals = gimp_procedure_get_return_values (procedure, success,
error ? *error : NULL);
if (success)
g_value_set_object (gimp_value_array_index (return_vals, 1), layer);
return return_vals;
}
static GimpValueArray *
image_get_colormap_invoker (GimpProcedure *procedure,
Gimp *gimp,
......@@ -4066,6 +4108,40 @@ register_image_procs (GimpPDB *pdb)
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-merge-layer-group
*/
procedure = gimp_procedure_new (image_merge_layer_group_invoker);
gimp_object_set_static_name (GIMP_OBJECT (procedure),
"gimp-image-merge-layer-group");
gimp_procedure_set_static_strings (procedure,
"Merge the passed layer group's layers into one normal layer.",
"This procedure combines the layers of the passed layer group into a single normal layer, replacing the group.",
"Ell",
"Ell",
"2019",
NULL);
gimp_procedure_add_argument (procedure,
gimp_param_spec_image ("image",
"image",
"The image",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_argument (procedure,
gimp_param_spec_layer ("layer-group",
"layer group",
"The layer group to merge",
FALSE,
GIMP_PARAM_READWRITE));
gimp_procedure_add_return_value (procedure,
gimp_param_spec_layer ("layer",
"layer",
"The resulting layer",
FALSE,
GIMP_PARAM_READWRITE));
gimp_pdb_register_procedure (pdb, procedure);
g_object_unref (procedure);
/*
* gimp-image-get-colormap
*/
......
......@@ -28,7 +28,7 @@
#include "internal-procs.h"
/* 745 procedures registered total */
/* 746 procedures registered total */
void
internal_procs_init (GimpPDB *pdb)
......
......@@ -437,6 +437,7 @@ EXPORTS
gimp_image_lower_item
gimp_image_lower_item_to_bottom
gimp_image_merge_down
gimp_image_merge_layer_group
gimp_image_merge_visible_layers
gimp_image_new
gimp_image_new_with_precision
......
......@@ -1726,6 +1726,44 @@ gimp_image_merge_down (GimpImage *image,
return layer;
}
/**
* gimp_image_merge_layer_group:
* @image: The image.
* @layer_group: The layer group to merge.
*
* Merge the passed layer group's layers into one normal layer.
*
* This procedure combines the layers of the passed layer group into a
* single normal layer, replacing the group.
*
* Returns: (transfer none): The resulting layer.
**/
GimpLayer *
gimp_image_merge_layer_group (GimpImage *image,
GimpLayer *layer_group)
{
GimpValueArray *args;
GimpValueArray *return_vals;
GimpLayer *layer = NULL;
args = gimp_value_array_new_from_types (NULL,
GIMP_TYPE_IMAGE, image,
GIMP_TYPE_LAYER, layer_group,
G_TYPE_NONE);
return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (),
"gimp-image-merge-layer-group",
args);
gimp_value_array_unref (args);
if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS)
layer = GIMP_VALUES_GET_LAYER (return_vals, 1);
gimp_value_array_unref (return_vals);
return layer;
}
/**
* _gimp_image_get_colormap:
* @image: The image.
......
......@@ -113,6 +113,8 @@ GimpLayer* gimp_image_merge_visible_layers (GimpImage
GimpLayer* gimp_image_merge_down (GimpImage *image,
GimpLayer *merge_layer,
GimpMergeType merge_type);
GimpLayer* gimp_image_merge_layer_group (GimpImage *image,
GimpLayer *layer_group);
G_GNUC_INTERNAL guint8* _gimp_image_get_colormap (GimpImage *image,
gint *num_bytes);
G_GNUC_INTERNAL gboolean _gimp_image_set_colormap (GimpImage *image,
......
......@@ -797,6 +797,48 @@ CODE
);
}
sub image_merge_layer_group {
$blurb = 'Merge the passed layer group\'s layers into one normal layer.';
$help = <<'HELP';
This procedure combines the layers of the passed layer group into
a single normal layer, replacing the group.
HELP
&ell_pdb_misc('2019');
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' },
{ name => 'layer_group', type => 'layer',
desc => 'The layer group to merge' },
);
@outargs = (
{ name => 'layer', type => 'layer',
desc => 'The resulting layer' }
);
%invoke = (
headers => [ qw("core/gimpgrouplayer.h" "core/gimpimage-merge.h") ],
code => <<'CODE'
{
if (gimp_pdb_item_is_attached (GIMP_ITEM (layer_group), image, 0, error) &&
gimp_pdb_item_is_group (GIMP_ITEM (layer_group), error))
{
layer = gimp_image_merge_group_layer (image,
GIMP_GROUP_LAYER (layer_group));
if (! layer)
success = FALSE;
}
else
success = FALSE;
}
CODE
);
}
sub image_flatten {
$blurb = <<'BLURB';
Flatten all visible layers into a single layer. Discard all invisible layers.
......@@ -2972,6 +3014,7 @@ CODE
image_raise_item_to_top image_lower_item_to_bottom
image_reorder_item
image_flatten image_merge_visible_layers image_merge_down
image_merge_layer_group
image_get_colormap image_set_colormap
image_get_metadata image_set_metadata
image_clean_all image_is_dirty
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment