From b1736a6736c50ac1a63eb7f22f4dbc402163c45c Mon Sep 17 00:00:00 2001 From: Jehan Date: Sat, 6 Jul 2024 17:24:11 +0200 Subject: [PATCH] app, libgimp, pdb, plug-ins: new GimpGroupLayer class in libgimp. Also: - renaming gimp_layer_group_new() to gimp_group_layer_new() in order to keep the same name as in core code (i.e. GimpGroupLayer, not GimpLayerGroup). - renaming gimp_image_merge_layer_group() to gimp_group_layer_merge() - new functions: gimp_procedure_add_group_layer_argument(), gimp_procedure_add_group_layer_aux_argument() and gimp_procedure_add_group_layer_return_value(). This can be tested, e.g. in Python with these calls: ```py i = Gimp.get_images()[0] g = Gimp.GroupLayer.new(i, "hello") i.insert_layer(g, None, 1) g2 = Gimp.GroupLayer.new(i, "world") i.insert_layer(g2, g, 1) g.merge() ``` This was work started long ago, stored in an old stash which I finally finish now! :-) --- app/core/gimpparamspecs.c | 1 + app/pdb/group-layer-cmds.c | 187 +++++++++++++++++++++++++++ app/pdb/image-cmds.c | 77 ----------- app/pdb/internal-procs.c | 3 +- app/pdb/internal-procs.h | 1 + app/pdb/item-cmds.c | 61 +++++++++ app/pdb/layer-cmds.c | 63 --------- app/pdb/meson.build | 1 + libgimp/gimp.def | 13 +- libgimp/gimp.h | 1 + libgimp/gimp_pdb_headers.h | 1 + libgimp/gimpexport.c | 2 +- libgimp/gimpgpparams-body.c | 5 + libgimp/gimpgrouplayer.c | 109 ++++++++++++++++ libgimp/gimpgrouplayer.h | 49 +++++++ libgimp/gimpgrouplayer_pdb.c | 117 +++++++++++++++++ libgimp/gimpgrouplayer_pdb.h | 41 ++++++ libgimp/gimpimage_pdb.c | 40 ------ libgimp/gimpimage_pdb.h | 2 - libgimp/gimpitem.c | 19 +++ libgimp/gimpitem.h | 21 +-- libgimp/gimpitem_pdb.c | 37 ++++++ libgimp/gimpitem_pdb.h | 1 + libgimp/gimplayer_pdb.c | 42 ------ libgimp/gimplayer_pdb.h | 1 - libgimp/gimpparamspecs-body.c | 80 ++++++++++++ libgimp/gimpparamspecs.h | 28 ++++ libgimp/gimpplugin.c | 6 + libgimp/gimpprocedure-params.c | 78 +++++++++++ libgimp/gimpprocedure-params.h | 31 +++++ libgimp/gimptypes.h | 1 + libgimp/meson.build | 4 + libgimp/tests/test-selection-float.c | 2 +- pdb/app.pl | 10 ++ pdb/groups.pl | 1 + pdb/groups/group_layer.pdb | 114 ++++++++++++++++ pdb/groups/image.pdb | 43 ------ pdb/groups/item.pdb | 34 ++++- pdb/groups/layer.pdb | 38 ------ pdb/meson.build | 1 + pdb/pdb.pl | 12 ++ plug-ins/common/wavelet-decompose.c | 3 +- plug-ins/file-psd/psd-load.c | 5 +- 43 files changed, 1059 insertions(+), 327 deletions(-) create mode 100644 app/pdb/group-layer-cmds.c create mode 100644 libgimp/gimpgrouplayer.c create mode 100644 libgimp/gimpgrouplayer.h create mode 100644 libgimp/gimpgrouplayer_pdb.c create mode 100644 libgimp/gimpgrouplayer_pdb.h create mode 100644 pdb/groups/group_layer.pdb diff --git a/app/core/gimpparamspecs.c b/app/core/gimpparamspecs.c index 40d2a25657..5f155a3d86 100644 --- a/app/core/gimpparamspecs.c +++ b/app/core/gimpparamspecs.c @@ -28,6 +28,7 @@ #include "gimpbrush.h" #include "gimpdisplay.h" #include "gimpgradient.h" +#include "gimpgrouplayer.h" #include "gimpimage.h" #include "gimplayer.h" #include "gimplayermask.h" diff --git a/app/pdb/group-layer-cmds.c b/app/pdb/group-layer-cmds.c new file mode 100644 index 0000000000..12b722268e --- /dev/null +++ b/app/pdb/group-layer-cmds.c @@ -0,0 +1,187 @@ +/* GIMP - The GNU Image Manipulation Program + * Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis + * + * 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 3 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, see . + */ + +/* NOTE: This file is auto-generated by pdbgen.pl. */ + +#include "config.h" + +#include "stamp-pdbgen.h" + +#include + +#include + +#include + +#include "libgimpbase/gimpbase.h" + +#include "libgimpbase/gimpbase.h" + +#include "pdb-types.h" + +#include "core/gimp.h" +#include "core/gimpgrouplayer.h" +#include "core/gimpimage-merge.h" +#include "core/gimpimage.h" +#include "core/gimplayer.h" +#include "core/gimpparamspecs.h" + +#include "gimppdb.h" +#include "gimppdb-utils.h" +#include "gimpprocedure.h" +#include "internal-procs.h" + +#include "gimp-intl.h" + + +static GimpValueArray * +group_layer_new_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpValueArray *return_vals; + GimpImage *image; + GimpGroupLayer *group_layer = NULL; + + image = g_value_get_object (gimp_value_array_index (args, 0)); + + if (success) + { + group_layer = GIMP_GROUP_LAYER (gimp_group_layer_new (image)); + + if (! group_layer) + 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), group_layer); + + return return_vals; +} + +static GimpValueArray * +group_layer_merge_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpValueArray *return_vals; + GimpGroupLayer *group_layer; + GimpLayer *layer = NULL; + + group_layer = g_value_get_object (gimp_value_array_index (args, 0)); + + if (success) + { + if (gimp_pdb_item_is_attached (GIMP_ITEM (group_layer), NULL, 0, error) && + gimp_pdb_item_is_group (GIMP_ITEM (group_layer), error)) + { + GimpImage *image = gimp_item_get_image (GIMP_ITEM (group_layer)); + + layer = gimp_image_merge_group_layer (image, group_layer); + + 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; +} + +void +register_group_layer_procs (GimpPDB *pdb) +{ + GimpProcedure *procedure; + + /* + * gimp-group-layer-new + */ + procedure = gimp_procedure_new (group_layer_new_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-group-layer-new"); + gimp_procedure_set_static_help (procedure, + "Create a new group layer.", + "This procedure creates a new group layer. Attributes such as layer mode and opacity should be set with explicit procedure calls. Add the new group layer (which is a kind of layer) with [method@image.insert_layer].\n" + "Other procedures useful with group layers: [method@image_reorder_item], [method@item.get_parent], [method@item.get_children], [method@item.is_group].", + NULL); + gimp_procedure_set_static_attribution (procedure, + "Barak Itkin ", + "Barak Itkin", + "2010"); + gimp_procedure_add_argument (procedure, + gimp_param_spec_image ("image", + "image", + "The image to which to add the layer group", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + gimp_param_spec_group_layer ("group-layer", + "group layer", + "The newly created group layer", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + + /* + * gimp-group-layer-merge + */ + procedure = gimp_procedure_new (group_layer_merge_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-group-layer-merge"); + gimp_procedure_set_static_help (procedure, + "Merge the passed group layer's layers into one normal layer.", + "This procedure combines the layers of the passed group layer into a single normal layer, replacing the group.\n" + "The group layer is expected to be attached to an image.", + NULL); + gimp_procedure_set_static_attribution (procedure, + "Ell", + "Ell", + "2019"); + gimp_procedure_add_argument (procedure, + gimp_param_spec_group_layer ("group-layer", + "group layer", + "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); +} diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c index 33b10fac81..4b7b9de289 100644 --- a/app/pdb/image-cmds.c +++ b/app/pdb/image-cmds.c @@ -39,7 +39,6 @@ #include "core/gimpchannel.h" #include "core/gimpcontainer.h" #include "core/gimpdrawable.h" -#include "core/gimpgrouplayer.h" #include "core/gimpimage-color-profile.h" #include "core/gimpimage-colormap.h" #include "core/gimpimage-duplicate.h" @@ -1472,47 +1471,6 @@ 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, @@ -4287,41 +4245,6 @@ 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_help (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.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Ell", - "Ell", - "2019"); - 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 */ diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index 7aa6e697ae..725ef3de8a 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -30,7 +30,7 @@ #include "internal-procs.h" -/* 785 procedures registered total */ +/* 786 procedures registered total */ void internal_procs_init (GimpPDB *pdb) @@ -61,6 +61,7 @@ internal_procs_init (GimpPDB *pdb) register_gradient_procs (pdb); register_gradient_select_procs (pdb); register_gradients_procs (pdb); + register_group_layer_procs (pdb); register_help_procs (pdb); register_image_procs (pdb); register_image_color_profile_procs (pdb); diff --git a/app/pdb/internal-procs.h b/app/pdb/internal-procs.h index 807d6ffae0..b6826d3aa5 100644 --- a/app/pdb/internal-procs.h +++ b/app/pdb/internal-procs.h @@ -48,6 +48,7 @@ void register_gimprc_procs (GimpPDB *pdb); void register_gradient_procs (GimpPDB *pdb); void register_gradient_select_procs (GimpPDB *pdb); void register_gradients_procs (GimpPDB *pdb); +void register_group_layer_procs (GimpPDB *pdb); void register_help_procs (GimpPDB *pdb); void register_image_procs (GimpPDB *pdb); void register_image_color_profile_procs (GimpPDB *pdb); diff --git a/app/pdb/item-cmds.c b/app/pdb/item-cmds.c index 1b2e17f16e..61021bd7ac 100644 --- a/app/pdb/item-cmds.c +++ b/app/pdb/item-cmds.c @@ -31,6 +31,7 @@ #include "pdb-types.h" +#include "core/gimpgrouplayer.h" #include "core/gimpimage.h" #include "core/gimpitem.h" #include "core/gimplayermask.h" @@ -178,6 +179,37 @@ item_id_is_text_layer_invoker (GimpProcedure *procedure, return return_vals; } +static GimpValueArray * +item_id_is_group_layer_invoker (GimpProcedure *procedure, + Gimp *gimp, + GimpContext *context, + GimpProgress *progress, + const GimpValueArray *args, + GError **error) +{ + gboolean success = TRUE; + GimpValueArray *return_vals; + gint item_id; + gboolean group_layer = FALSE; + + item_id = g_value_get_int (gimp_value_array_index (args, 0)); + + if (success) + { + GimpItem *item = gimp_item_get_by_id (gimp, item_id); + + group_layer = (GIMP_IS_GROUP_LAYER (item) && ! gimp_item_is_removed (item)); + } + + return_vals = gimp_procedure_get_return_values (procedure, success, + error ? *error : NULL); + + if (success) + g_value_set_boolean (gimp_value_array_index (return_vals, 1), group_layer); + + return return_vals; +} + static GimpValueArray * item_id_is_channel_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -1145,6 +1177,35 @@ register_item_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); + /* + * gimp-item-id-is-group-layer + */ + procedure = gimp_procedure_new (item_id_is_group_layer_invoker); + gimp_object_set_static_name (GIMP_OBJECT (procedure), + "gimp-item-id-is-group-layer"); + gimp_procedure_set_static_help (procedure, + "Returns whether the item ID is a group layer.", + "This procedure returns TRUE if the specified item ID is a group layer.", + NULL); + gimp_procedure_set_static_attribution (procedure, + "Jehan", + "Jehan", + "2024"); + gimp_procedure_add_argument (procedure, + g_param_spec_int ("item-id", + "item id", + "The item ID", + G_MININT32, G_MAXINT32, 0, + GIMP_PARAM_READWRITE)); + gimp_procedure_add_return_value (procedure, + g_param_spec_boolean ("group-layer", + "group layer", + "TRUE if the item is a group layer, FALSE otherwise.", + FALSE, + GIMP_PARAM_READWRITE)); + gimp_pdb_register_procedure (pdb, procedure); + g_object_unref (procedure); + /* * gimp-item-id-is-channel */ diff --git a/app/pdb/layer-cmds.c b/app/pdb/layer-cmds.c index c4d05a24fa..22427249d0 100644 --- a/app/pdb/layer-cmds.c +++ b/app/pdb/layer-cmds.c @@ -36,7 +36,6 @@ #include "core/gimp.h" #include "core/gimpdrawable.h" -#include "core/gimpgrouplayer.h" #include "core/gimpimage-color-profile.h" #include "core/gimpimage-undo.h" #include "core/gimpimage.h" @@ -249,38 +248,6 @@ layer_new_from_drawable_invoker (GimpProcedure *procedure, return return_vals; } -static GimpValueArray * -layer_group_new_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 = NULL; - - image = g_value_get_object (gimp_value_array_index (args, 0)); - - if (success) - { - layer_group = gimp_group_layer_new (image); - - if (! layer_group) - 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_group); - - return return_vals; -} - static GimpValueArray * layer_copy_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -1394,36 +1361,6 @@ register_layer_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); - /* - * gimp-layer-group-new - */ - procedure = gimp_procedure_new (layer_group_new_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-layer-group-new"); - gimp_procedure_set_static_help (procedure, - "Create a new layer group.", - "This procedure creates a new layer group. Attributes such as layer mode and opacity should be set with explicit procedure calls. Add the new layer group (which is a kind of layer) with the 'gimp-image-insert-layer' command.\n" - "Other procedures useful with layer groups: 'gimp-image-reorder-item', 'gimp-item-get-parent', 'gimp-item-get-children', 'gimp-item-is-group'.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Barak Itkin ", - "Barak Itkin", - "2010"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_image ("image", - "image", - "The image to which to add the layer group", - FALSE, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_return_value (procedure, - gimp_param_spec_layer ("layer-group", - "layer group", - "The newly created layer group", - FALSE, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - /* * gimp-layer-copy */ diff --git a/app/pdb/meson.build b/app/pdb/meson.build index 125e2f9d66..bc0852bef4 100644 --- a/app/pdb/meson.build +++ b/app/pdb/meson.build @@ -32,6 +32,7 @@ libappinternalprocs_sources = [ 'gradient-cmds.c', 'gradient-select-cmds.c', 'gradients-cmds.c', + 'group-layer-cmds.c', 'help-cmds.c', 'image-cmds.c', 'image-color-profile-cmds.c', diff --git a/libgimp/gimp.def b/libgimp/gimp.def index 8305856b2b..88723167ff 100644 --- a/libgimp/gimp.def +++ b/libgimp/gimp.def @@ -368,6 +368,10 @@ EXPORTS gimp_gradients_popup gimp_gradients_refresh gimp_gradients_set_popup + gimp_group_layer_get_by_id + gimp_group_layer_get_type + gimp_group_layer_merge + gimp_group_layer_new gimp_heal gimp_heal_default gimp_help @@ -474,7 +478,6 @@ 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_metadata_load_finish gimp_image_metadata_load_prepare @@ -559,6 +562,7 @@ EXPORTS gimp_item_get_visible gimp_item_id_is_channel gimp_item_id_is_drawable + gimp_item_id_is_group_layer gimp_item_id_is_layer gimp_item_id_is_layer_mask gimp_item_id_is_selection @@ -568,6 +572,7 @@ EXPORTS gimp_item_is_channel gimp_item_is_drawable gimp_item_is_group + gimp_item_is_group_layer gimp_item_is_layer gimp_item_is_layer_mask gimp_item_is_selection @@ -613,7 +618,6 @@ EXPORTS gimp_layer_get_opacity gimp_layer_get_show_mask gimp_layer_get_type - gimp_layer_group_new gimp_layer_is_floating_sel gimp_layer_mask_get_by_id gimp_layer_mask_get_type @@ -675,6 +679,7 @@ EXPORTS gimp_param_drawable_get_type gimp_param_font_get_type gimp_param_gradient_get_type + gimp_param_group_layer_get_type gimp_param_image_get_type gimp_param_item_get_type gimp_param_layer_get_type @@ -690,6 +695,7 @@ EXPORTS gimp_param_spec_font gimp_param_spec_get_desc gimp_param_spec_gradient + gimp_param_spec_group_layer gimp_param_spec_image gimp_param_spec_item gimp_param_spec_layer @@ -779,6 +785,9 @@ EXPORTS gimp_procedure_add_gradient_argument gimp_procedure_add_gradient_aux_argument gimp_procedure_add_gradient_return_value + gimp_procedure_add_group_layer_argument + gimp_procedure_add_group_layer_aux_argument + gimp_procedure_add_group_layer_return_value gimp_procedure_add_image_argument gimp_procedure_add_image_aux_argument gimp_procedure_add_image_return_value diff --git a/libgimp/gimp.h b/libgimp/gimp.h index 83ea7c7bb4..4204c44f91 100644 --- a/libgimp/gimp.h +++ b/libgimp/gimp.h @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include diff --git a/libgimp/gimp_pdb_headers.h b/libgimp/gimp_pdb_headers.h index fab957311e..51b546aada 100644 --- a/libgimp/gimp_pdb_headers.h +++ b/libgimp/gimp_pdb_headers.h @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include diff --git a/libgimp/gimpexport.c b/libgimp/gimpexport.c index 9b0c588a2c..6760785a5c 100644 --- a/libgimp/gimpexport.c +++ b/libgimp/gimpexport.c @@ -242,7 +242,7 @@ export_apply_masks (GimpImage *image, * first */ if (gimp_item_is_group (iter->data)) - iter->data = gimp_image_merge_layer_group (image, iter->data); + iter->data = gimp_group_layer_merge (iter->data); gimp_layer_remove_mask (iter->data, GIMP_MASK_APPLY); } diff --git a/libgimp/gimpgpparams-body.c b/libgimp/gimpgpparams-body.c index d80b55bcc2..025e82fba0 100644 --- a/libgimp/gimpgpparams-body.c +++ b/libgimp/gimpgpparams-body.c @@ -238,6 +238,11 @@ _gimp_gp_param_def_to_param_spec (const GPParamDef *param_def) param_def->meta.m_id.none_ok, flags); + if (! strcmp (param_def->type_name, "GimpParamGroupLayer")) + return gimp_param_spec_group_layer (name, nick, blurb, + param_def->meta.m_id.none_ok, + flags); + if (! strcmp (param_def->type_name, "GimpParamChannel")) return gimp_param_spec_channel (name, nick, blurb, param_def->meta.m_id.none_ok, diff --git a/libgimp/gimpgrouplayer.c b/libgimp/gimpgrouplayer.c new file mode 100644 index 0000000000..5a5b7c59cc --- /dev/null +++ b/libgimp/gimpgrouplayer.c @@ -0,0 +1,109 @@ +/* LIBGIMP - The GIMP Library + * Copyright (C) 1995-2000 Peter Mattis and Spencer Kimball + * + * gimpgrouplayer.c + * Copyright (C) 2022 Jehan + * + * This library is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include "config.h" + +#include "gimp.h" + + +struct _GimpGroupLayer +{ + GimpLayer parent_instance; +}; + + +G_DEFINE_TYPE (GimpGroupLayer, gimp_group_layer, GIMP_TYPE_LAYER) + +#define parent_class gimp_group_layer_parent_class + + +static void +gimp_group_layer_class_init (GimpGroupLayerClass *klass) +{ +} + +static void +gimp_group_layer_init (GimpGroupLayer *layer) +{ +} + + +/* Public API. */ + +/** + * gimp_group_layer_get_by_id: + * @layer_id: The layer id. + * + * Returns a #GimpGroupLayer representing @layer_id. This function calls + * gimp_item_get_by_id() and returns the item if it is a group layer or + * %NULL otherwise. + * + * Returns: (nullable) (transfer none): a #GimpGroupLayer for @layer_id or + * %NULL if @layer_id does not represent a valid group layer. + * The object belongs to libgimp and you must not modify or + * unref it. + * + * Since: 3.0 + **/ +GimpGroupLayer * +gimp_group_layer_get_by_id (gint32 layer_id) +{ + GimpItem *item = gimp_item_get_by_id (layer_id); + + if (GIMP_IS_GROUP_LAYER (item)) + return (GimpGroupLayer *) item; + + return NULL; +} + +/** + * gimp_group_layer_new: + * @image: The image to which to add the layer. + * @name: (nullable): The group layer name. + * + * Create a new group layer. + * + * This procedure creates a new group layer with a given @name. If @name is + * %NULL, GIMP will choose a name using its default layer name algorithm. + * + * The new group layer still needs to be added to the image, as this is + * not automatic. Add the new layer with the [method@Image.insert_layer] + * method. + * + * Other attributes such as layer mask modes, and offsets should be set + * with explicit procedure calls. + * + * Returns: (transfer none): The newly created group layer. + * The object belongs to libgimp and you should not free it. + * + * Since: 3.0 + */ +GimpGroupLayer * +gimp_group_layer_new (GimpImage *image, + const gchar *name) +{ + GimpGroupLayer *layer = _gimp_group_layer_new (image); + + if (name != NULL) + gimp_item_set_name (GIMP_ITEM (layer), name); + + return layer; +} diff --git a/libgimp/gimpgrouplayer.h b/libgimp/gimpgrouplayer.h new file mode 100644 index 0000000000..04a7e347f2 --- /dev/null +++ b/libgimp/gimpgrouplayer.h @@ -0,0 +1,49 @@ +/* LIBGIMP - The GIMP Library + * Copyright (C) 1995-2000 Peter Mattis and Spencer Kimball + * + * gimpgrouplayer.h + * Copyright (C) 2022 Jehan + * + * This library is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#if !defined (__GIMP_H_INSIDE__) && !defined (GIMP_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef __GIMP_GROUP_LAYER_H__ +#define __GIMP_GROUP_LAYER_H__ + +G_BEGIN_DECLS + +/* For information look into the C source or the html documentation */ + + +#include + + +#define GIMP_TYPE_GROUP_LAYER (gimp_group_layer_get_type ()) +G_DECLARE_FINAL_TYPE (GimpGroupLayer, gimp_group_layer, GIMP, GROUP_LAYER, GimpLayer) + + +GimpGroupLayer * gimp_group_layer_get_by_id (gint32 layer_id); + +GimpGroupLayer * gimp_group_layer_new (GimpImage *image, + const gchar *name); + + +G_END_DECLS + +#endif /* __GIMP_GROUP_LAYER_H__ */ diff --git a/libgimp/gimpgrouplayer_pdb.c b/libgimp/gimpgrouplayer_pdb.c new file mode 100644 index 0000000000..3319d2556f --- /dev/null +++ b/libgimp/gimpgrouplayer_pdb.c @@ -0,0 +1,117 @@ +/* LIBGIMP - The GIMP Library + * Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball + * + * gimpgrouplayer_pdb.c + * + * This library is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +/* NOTE: This file is auto-generated by pdbgen.pl */ + +#include "config.h" + +#include "stamp-pdbgen.h" + +#include "gimp.h" + + +/** + * SECTION: gimpgrouplayer + * @title: gimpgrouplayer + * @short_description: Operations on a group layer. + * + * Operations on a group layer. + **/ + + +/** + * _gimp_group_layer_new: + * @image: The image to which to add the layer group. + * + * Create a new group layer. + * + * This procedure creates a new group layer. Attributes such as layer + * mode and opacity should be set with explicit procedure calls. Add + * the new group layer (which is a kind of layer) with + * [method@image.insert_layer]. + * Other procedures useful with group layers: + * [method@image_reorder_item], [method@item.get_parent], + * [method@item.get_children], [method@item.is_group]. + * + * Returns: (transfer none): The newly created group layer. + * + * Since: 2.8 + **/ +GimpGroupLayer * +_gimp_group_layer_new (GimpImage *image) +{ + GimpValueArray *args; + GimpValueArray *return_vals; + GimpGroupLayer *group_layer = NULL; + + args = gimp_value_array_new_from_types (NULL, + GIMP_TYPE_IMAGE, image, + G_TYPE_NONE); + + return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), + "gimp-group-layer-new", + args); + gimp_value_array_unref (args); + + if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) + group_layer = GIMP_VALUES_GET_GROUP_LAYER (return_vals, 1); + + gimp_value_array_unref (return_vals); + + return group_layer; +} + +/** + * gimp_group_layer_merge: + * @group_layer: The layer group to merge. + * + * Merge the passed group layer's layers into one normal layer. + * + * This procedure combines the layers of the passed group layer into a + * single normal layer, replacing the group. + * The group layer is expected to be attached to an image. + * + * Returns: (transfer none): The resulting layer. + * + * Since: 2.10.14 + **/ +GimpLayer * +gimp_group_layer_merge (GimpGroupLayer *group_layer) +{ + GimpValueArray *args; + GimpValueArray *return_vals; + GimpLayer *layer = NULL; + + args = gimp_value_array_new_from_types (NULL, + GIMP_TYPE_GROUP_LAYER, group_layer, + G_TYPE_NONE); + + return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), + "gimp-group-layer-merge", + 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; +} diff --git a/libgimp/gimpgrouplayer_pdb.h b/libgimp/gimpgrouplayer_pdb.h new file mode 100644 index 0000000000..04c7a83a5a --- /dev/null +++ b/libgimp/gimpgrouplayer_pdb.h @@ -0,0 +1,41 @@ +/* LIBGIMP - The GIMP Library + * Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball + * + * gimpgrouplayer_pdb.h + * + * This library is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +/* NOTE: This file is auto-generated by pdbgen.pl */ + +#if !defined (__GIMP_H_INSIDE__) && !defined (GIMP_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef __GIMP_GROUP_LAYER_PDB_H__ +#define __GIMP_GROUP_LAYER_PDB_H__ + +G_BEGIN_DECLS + +/* For information look into the C source or the html documentation */ + + +G_GNUC_INTERNAL GimpGroupLayer* _gimp_group_layer_new (GimpImage *image); +GimpLayer* gimp_group_layer_merge (GimpGroupLayer *group_layer); + + +G_END_DECLS + +#endif /* __GIMP_GROUP_LAYER_PDB_H__ */ diff --git a/libgimp/gimpimage_pdb.c b/libgimp/gimpimage_pdb.c index 2bec8b54e9..606cb57105 100644 --- a/libgimp/gimpimage_pdb.c +++ b/libgimp/gimpimage_pdb.c @@ -1705,46 +1705,6 @@ 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. - * - * Since: 2.10.14 - **/ -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. diff --git a/libgimp/gimpimage_pdb.h b/libgimp/gimpimage_pdb.h index 7ce2a7e443..6e25b4dc63 100644 --- a/libgimp/gimpimage_pdb.h +++ b/libgimp/gimpimage_pdb.h @@ -113,8 +113,6 @@ 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 GBytes* _gimp_image_get_colormap (GimpImage *image); G_GNUC_INTERNAL gboolean _gimp_image_set_colormap (GimpImage *image, GBytes *colormap); diff --git a/libgimp/gimpitem.c b/libgimp/gimpitem.c index 558a028a4a..9602d75c0d 100644 --- a/libgimp/gimpitem.c +++ b/libgimp/gimpitem.c @@ -256,6 +256,25 @@ gimp_item_is_text_layer (GimpItem *item) return gimp_item_id_is_text_layer (gimp_item_get_id (item)); } +/** + * gimp_item_is_group_layer: + * @item: The item. + * + * Returns whether the item is a group layer. + * + * This procedure returns TRUE if the specified item is a group + * layer. + * + * Returns: TRUE if the item is a group layer, FALSE otherwise. + * + * Since: 3.0 + **/ +gboolean +gimp_item_is_group_layer (GimpItem *item) +{ + return gimp_item_id_is_group_layer (gimp_item_get_id (item)); +} + /** * gimp_item_is_channel: * @item: The item. diff --git a/libgimp/gimpitem.h b/libgimp/gimpitem.h index 9bc1508b59..7ecb75241d 100644 --- a/libgimp/gimpitem.h +++ b/libgimp/gimpitem.h @@ -51,17 +51,18 @@ struct _GimpItemClass }; -gint32 gimp_item_get_id (GimpItem *item); -GimpItem * gimp_item_get_by_id (gint32 item_id); +gint32 gimp_item_get_id (GimpItem *item); +GimpItem * gimp_item_get_by_id (gint32 item_id); -gboolean gimp_item_is_valid (GimpItem *item); -gboolean gimp_item_is_drawable (GimpItem *item); -gboolean gimp_item_is_layer (GimpItem *item); -gboolean gimp_item_is_text_layer (GimpItem *item); -gboolean gimp_item_is_channel (GimpItem *item); -gboolean gimp_item_is_layer_mask (GimpItem *item); -gboolean gimp_item_is_selection (GimpItem *item); -gboolean gimp_item_is_vectors (GimpItem *item); +gboolean gimp_item_is_valid (GimpItem *item); +gboolean gimp_item_is_drawable (GimpItem *item); +gboolean gimp_item_is_layer (GimpItem *item); +gboolean gimp_item_is_text_layer (GimpItem *item); +gboolean gimp_item_is_group_layer (GimpItem *item); +gboolean gimp_item_is_channel (GimpItem *item); +gboolean gimp_item_is_layer_mask (GimpItem *item); +gboolean gimp_item_is_selection (GimpItem *item); +gboolean gimp_item_is_vectors (GimpItem *item); GList * gimp_item_list_children (GimpItem *item); diff --git a/libgimp/gimpitem_pdb.c b/libgimp/gimpitem_pdb.c index b26055d7fb..ebab01b572 100644 --- a/libgimp/gimpitem_pdb.c +++ b/libgimp/gimpitem_pdb.c @@ -182,6 +182,43 @@ gimp_item_id_is_text_layer (gint item_id) return text_layer; } +/** + * gimp_item_id_is_group_layer: + * @item_id: The item ID. + * + * Returns whether the item ID is a group layer. + * + * This procedure returns TRUE if the specified item ID is a group + * layer. + * + * Returns: TRUE if the item is a group layer, FALSE otherwise. + * + * Since: 3.0 + **/ +gboolean +gimp_item_id_is_group_layer (gint item_id) +{ + GimpValueArray *args; + GimpValueArray *return_vals; + gboolean group_layer = FALSE; + + args = gimp_value_array_new_from_types (NULL, + G_TYPE_INT, item_id, + G_TYPE_NONE); + + return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), + "gimp-item-id-is-group-layer", + args); + gimp_value_array_unref (args); + + if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) + group_layer = GIMP_VALUES_GET_BOOLEAN (return_vals, 1); + + gimp_value_array_unref (return_vals); + + return group_layer; +} + /** * gimp_item_id_is_channel: * @item_id: The item ID. diff --git a/libgimp/gimpitem_pdb.h b/libgimp/gimpitem_pdb.h index 5dff0d8263..c6820e0649 100644 --- a/libgimp/gimpitem_pdb.h +++ b/libgimp/gimpitem_pdb.h @@ -36,6 +36,7 @@ gboolean gimp_item_id_is_valid (gint item_id); gboolean gimp_item_id_is_drawable (gint item_id); gboolean gimp_item_id_is_layer (gint item_id); gboolean gimp_item_id_is_text_layer (gint item_id); +gboolean gimp_item_id_is_group_layer (gint item_id); gboolean gimp_item_id_is_channel (gint item_id); gboolean gimp_item_id_is_layer_mask (gint item_id); gboolean gimp_item_id_is_selection (gint item_id); diff --git a/libgimp/gimplayer_pdb.c b/libgimp/gimplayer_pdb.c index 5b388b48f5..49d78959f2 100644 --- a/libgimp/gimplayer_pdb.c +++ b/libgimp/gimplayer_pdb.c @@ -181,48 +181,6 @@ gimp_layer_new_from_drawable (GimpDrawable *drawable, return layer_copy; } -/** - * gimp_layer_group_new: - * @image: The image to which to add the layer group. - * - * Create a new layer group. - * - * This procedure creates a new layer group. Attributes such as layer - * mode and opacity should be set with explicit procedure calls. Add - * the new layer group (which is a kind of layer) with the - * gimp_image_insert_layer() command. - * Other procedures useful with layer groups: - * gimp_image_reorder_item(), gimp_item_get_parent(), - * gimp_item_get_children(), gimp_item_is_group(). - * - * Returns: (transfer none): The newly created layer group. - * - * Since: 2.8 - **/ -GimpLayer * -gimp_layer_group_new (GimpImage *image) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - GimpLayer *layer_group = NULL; - - args = gimp_value_array_new_from_types (NULL, - GIMP_TYPE_IMAGE, image, - G_TYPE_NONE); - - return_vals = _gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-layer-group-new", - args); - gimp_value_array_unref (args); - - if (GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS) - layer_group = GIMP_VALUES_GET_LAYER (return_vals, 1); - - gimp_value_array_unref (return_vals); - - return layer_group; -} - /** * _gimp_layer_copy: * @layer: The layer to copy. diff --git a/libgimp/gimplayer_pdb.h b/libgimp/gimplayer_pdb.h index a1efa07004..1b6579fe02 100644 --- a/libgimp/gimplayer_pdb.h +++ b/libgimp/gimplayer_pdb.h @@ -44,7 +44,6 @@ GimpLayer* gimp_layer_new_from_visible (GimpImage const gchar *name); GimpLayer* gimp_layer_new_from_drawable (GimpDrawable *drawable, GimpImage *dest_image); -GimpLayer* gimp_layer_group_new (GimpImage *image); G_GNUC_INTERNAL GimpLayer* _gimp_layer_copy (GimpLayer *layer, gboolean add_alpha); gboolean gimp_layer_add_alpha (GimpLayer *layer); diff --git a/libgimp/gimpparamspecs-body.c b/libgimp/gimpparamspecs-body.c index 3604d3b726..2949b16994 100644 --- a/libgimp/gimpparamspecs-body.c +++ b/libgimp/gimpparamspecs-body.c @@ -478,6 +478,86 @@ gimp_param_spec_text_layer (const gchar *name, } +/* + * GIMP_TYPE_PARAM_GROUP_LAYER + */ + +static void gimp_param_group_layer_class_init (GParamSpecClass *klass); +static void gimp_param_group_layer_init (GParamSpec *pspec); + +GType +gimp_param_group_layer_get_type (void) +{ + static GType type = 0; + + if (! type) + { + const GTypeInfo info = + { + sizeof (GParamSpecClass), + NULL, NULL, + (GClassInitFunc) gimp_param_group_layer_class_init, + NULL, NULL, + sizeof (GimpParamSpecGroupLayer), + 0, + (GInstanceInitFunc) gimp_param_group_layer_init + }; + + type = g_type_register_static (GIMP_TYPE_PARAM_LAYER, + "GimpParamGroupLayer", &info, 0); + } + + return type; +} + +static void +gimp_param_group_layer_class_init (GParamSpecClass *klass) +{ + klass->value_type = GIMP_TYPE_GROUP_LAYER; +} + +static void +gimp_param_group_layer_init (GParamSpec *pspec) +{ +} + +/** + * gimp_param_spec_group_layer: + * @name: Canonical name of the property specified. + * @nick: Nick name of the property specified. + * @blurb: Description of the property specified. + * @none_ok: Whether %NULL is a valid value. + * @flags: Flags for the property specified. + * + * Creates a new #GimpParamSpecGroupLayer specifying a + * [type@GroupLayer] property. + * + * See g_param_spec_internal() for details on property names. + * + * Returns: (transfer full): The newly created #GimpParamSpecGroupLayer. + * + * Since: 3.0 + **/ +GParamSpec * +gimp_param_spec_group_layer (const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean none_ok, + GParamFlags flags) +{ + GimpParamSpecItem *ispec; + + ispec = g_param_spec_internal (GIMP_TYPE_PARAM_GROUP_LAYER, + name, nick, blurb, flags); + + g_return_val_if_fail (ispec, NULL); + + ispec->none_ok = none_ok ? TRUE : FALSE; + + return G_PARAM_SPEC (ispec); +} + + /* * GIMP_TYPE_PARAM_CHANNEL */ diff --git a/libgimp/gimpparamspecs.h b/libgimp/gimpparamspecs.h index bda8ef3dee..2eb938a764 100644 --- a/libgimp/gimpparamspecs.h +++ b/libgimp/gimpparamspecs.h @@ -168,6 +168,34 @@ GParamSpec * gimp_param_spec_text_layer (const gchar *name, gboolean none_ok, GParamFlags flags); + +/* + * GIMP_TYPE_PARAM_GROUP_LAYER + */ + +#define GIMP_VALUE_HOLDS_GROUP_LAYER(value) (G_TYPE_CHECK_VALUE_TYPE ((value),\ + GIMP_TYPE_GROUP_LAYER)) + +#define GIMP_TYPE_PARAM_GROUP_LAYER (gimp_param_group_layer_get_type ()) +#define GIMP_PARAM_SPEC_GROUP_LAYER(pspec) (G_TYPE_CHECK_INSTANCE_CAST ((pspec), GIMP_TYPE_PARAM_GROUP_LAYER, GimpParamSpecGroupLayer)) +#define GIMP_IS_PARAM_SPEC_GROUP_LAYER(pspec) (G_TYPE_CHECK_INSTANCE_TYPE ((pspec), GIMP_TYPE_PARAM_GROUP_LAYER)) + +typedef struct _GimpParamSpecGroupLayer GimpParamSpecGroupLayer; + +struct _GimpParamSpecGroupLayer +{ + GimpParamSpecLayer parent_instance; +}; + +GType gimp_param_group_layer_get_type (void) G_GNUC_CONST; + +GParamSpec * gimp_param_spec_group_layer (const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean none_ok, + GParamFlags flags); + + /* * GIMP_TYPE_PARAM_CHANNEL */ diff --git a/libgimp/gimpplugin.c b/libgimp/gimpplugin.c index 665a054091..502d0a5ae0 100644 --- a/libgimp/gimpplugin.c +++ b/libgimp/gimpplugin.c @@ -1570,6 +1570,12 @@ _gimp_plug_in_get_item (GimpPlugIn *plug_in, "id", item_id, NULL); } + else if (gimp_item_id_is_group_layer (item_id)) + { + item = g_object_new (GIMP_TYPE_GROUP_LAYER, + "id", item_id, + NULL); + } else if (gimp_item_id_is_layer (item_id)) { item = g_object_new (GIMP_TYPE_LAYER, diff --git a/libgimp/gimpprocedure-params.c b/libgimp/gimpprocedure-params.c index 0500eff44b..0abdc702aa 100644 --- a/libgimp/gimpprocedure-params.c +++ b/libgimp/gimpprocedure-params.c @@ -1884,6 +1884,84 @@ gimp_procedure_add_text_layer_return_value (GimpProcedure *procedure, none_ok, flags)); } +/** + * gimp_procedure_add_group_layer_argument: + * @procedure: the #GimpProcedure. + * @name: the name of the argument to be created. + * @nick: the label used in #GimpProcedureDialog. + * @blurb: a more detailed help description. + * @none_ok: Whether no is a valid value. + * @flags: argument flags. + * + * Add a new [class@GroupLayer] argument to @procedure. + * + * Since: 3.0 + **/ +void +gimp_procedure_add_group_layer_argument (GimpProcedure *procedure, + const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean none_ok, + GParamFlags flags) +{ + _gimp_procedure_add_argument (procedure, + gimp_param_spec_group_layer (name, nick, blurb, + none_ok, flags)); +} + +/** + * gimp_procedure_add_group_layer_aux_argument: + * @procedure: the #GimpProcedure. + * @name: the name of the argument to be created. + * @nick: the label used in #GimpProcedureDialog. + * @blurb: a more detailed help description. + * @none_ok: Whether no is a valid value. + * @flags: argument flags. + * + * Add a new [class@GroupLayer] auxiliary argument to @procedure. + * + * Since: 3.0 + **/ +void +gimp_procedure_add_group_layer_aux_argument (GimpProcedure *procedure, + const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean none_ok, + GParamFlags flags) +{ + _gimp_procedure_add_aux_argument (procedure, + gimp_param_spec_group_layer (name, nick, blurb, + none_ok, flags)); +} + +/** + * gimp_procedure_add_group_layer_return_value: + * @procedure: the #GimpProcedure. + * @name: the name of the argument to be created. + * @nick: the label used in #GimpProcedureDialog. + * @blurb: a more detailed help description. + * @none_ok: Whether no is a valid value. + * @flags: argument flags. + * + * Add a new [class@GroupLayer] return value to @procedure. + * + * Since: 3.0 + **/ +void +gimp_procedure_add_group_layer_return_value (GimpProcedure *procedure, + const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean none_ok, + GParamFlags flags) +{ + _gimp_procedure_add_return_value (procedure, + gimp_param_spec_group_layer (name, nick, blurb, + none_ok, flags)); +} + /** * gimp_procedure_add_channel_argument: * @procedure: the #GimpProcedure. diff --git a/libgimp/gimpprocedure-params.h b/libgimp/gimpprocedure-params.h index f3e65fcf25..616fed5389 100644 --- a/libgimp/gimpprocedure-params.h +++ b/libgimp/gimpprocedure-params.h @@ -315,6 +315,18 @@ G_BEGIN_DECLS g_value_set_object (gimp_value_array_index (args, n), value) +/* group layer */ + +#define GIMP_VALUES_GET_GROUP_LAYER(args, n) \ + g_value_get_object (gimp_value_array_index (args, n)) + +#define GIMP_VALUES_GET_GROUP_LAYER_ID(args, n) \ + gimp_item_get_id (g_value_get_object (gimp_value_array_index (args, n))) + +#define GIMP_VALUES_SET_GROUP_LAYER(args, n, value) \ + g_value_set_object (gimp_value_array_index (args, n), value) + + /* channel */ #define GIMP_VALUES_GET_CHANNEL(args, n) \ @@ -868,6 +880,25 @@ void gimp_procedure_add_text_layer_return_value (GimpProcedure *procedure gboolean none_ok, GParamFlags flags); +void gimp_procedure_add_group_layer_argument (GimpProcedure *procedure, + const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean none_ok, + GParamFlags flags); +void gimp_procedure_add_group_layer_aux_argument (GimpProcedure *procedure, + const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean none_ok, + GParamFlags flags); +void gimp_procedure_add_group_layer_return_value (GimpProcedure *procedure, + const gchar *name, + const gchar *nick, + const gchar *blurb, + gboolean none_ok, + GParamFlags flags); + void gimp_procedure_add_channel_argument (GimpProcedure *procedure, const gchar *name, const gchar *nick, diff --git a/libgimp/gimptypes.h b/libgimp/gimptypes.h index 606f0109cd..e376c17c87 100644 --- a/libgimp/gimptypes.h +++ b/libgimp/gimptypes.h @@ -36,6 +36,7 @@ typedef struct _GimpProcedureConfig GimpProcedureConfig; typedef struct _GimpImage GimpImage; typedef struct _GimpItem GimpItem; typedef struct _GimpDrawable GimpDrawable; +typedef struct _GimpGroupLayer GimpGroupLayer; typedef struct _GimpLayer GimpLayer; typedef struct _GimpChannel GimpChannel; typedef struct _GimpLayerMask GimpLayerMask; diff --git a/libgimp/meson.build b/libgimp/meson.build index 96a3d1752c..06cff7ef2f 100644 --- a/libgimp/meson.build +++ b/libgimp/meson.build @@ -84,6 +84,7 @@ pdb_wrappers_sources = [ 'gimpgradient_pdb.c', 'gimpgradients_pdb.c', 'gimpgradientselect_pdb.c', + 'gimpgrouplayer_pdb.c', 'gimphelp_pdb.c', 'gimpimage_pdb.c', 'gimpimagecolorprofile_pdb.c', @@ -139,6 +140,7 @@ pdb_wrappers_headers = [ 'gimpgradient_pdb.h', 'gimpgradients_pdb.h', 'gimpgradientselect_pdb.h', + 'gimpgrouplayer_pdb.h', 'gimphelp_pdb.h', 'gimpimage_pdb.h', 'gimpimagecolorprofile_pdb.h', @@ -179,6 +181,7 @@ libgimp_sources_introspectable = [ 'gimpfont.c', 'gimpgimprc.c', 'gimpgradient.c', + 'gimpgrouplayer.c', 'gimpimage.c', 'gimpimagecolorprofile.c', 'gimpimagemetadata.c', @@ -240,6 +243,7 @@ libgimp_headers_introspectable = [ 'gimpfont.h', 'gimpgimprc.h', 'gimpgradient.h', + 'gimpgrouplayer.h', 'gimpimage.h', 'gimpimagecolorprofile.h', 'gimpimagemetadata.h', diff --git a/libgimp/tests/test-selection-float.c b/libgimp/tests/test-selection-float.c index 7dc18fa096..c9ea9f0f18 100644 --- a/libgimp/tests/test-selection-float.c +++ b/libgimp/tests/test-selection-float.c @@ -24,7 +24,7 @@ gimp_c_test_run (GimpProcedure *procedure, GIMP_RGBA_IMAGE, 100.0, GIMP_LAYER_MODE_NORMAL)); layer2 = GIMP_DRAWABLE (gimp_layer_new (img, "layer2", 10, 20, GIMP_RGBA_IMAGE, 100.0, GIMP_LAYER_MODE_NORMAL)); - group1 = GIMP_DRAWABLE (gimp_layer_group_new (img)); + group1 = GIMP_DRAWABLE (gimp_group_layer_new (img, NULL)); GIMP_TEST_START("insert layer") GIMP_TEST_END(gimp_image_insert_layer (img, GIMP_LAYER (layer1), NULL, 0)) diff --git a/pdb/app.pl b/pdb/app.pl index 2378e591a9..18309617e4 100644 --- a/pdb/app.pl +++ b/pdb/app.pl @@ -317,6 +317,16 @@ gimp_param_spec_drawable ("$name", "$blurb", $none_ok, $flags) +CODE + } + elsif ($pdbtype eq 'group_layer') { + $none_ok = exists $arg->{none_ok} ? 'TRUE' : 'FALSE'; + $pspec = <. + + +sub group_layer_new { + $blurb = 'Create a new group layer.'; + + $help = <<'HELP'; +This procedure creates a new group layer. Attributes such as layer mode +and opacity should be set with explicit procedure calls. Add the new +group layer (which is a kind of layer) with [method@image.insert_layer]. + +Other procedures useful with group layers: [method@image_reorder_item], +[method@item.get_parent], [method@item.get_children], [method@item.is_group]. +HELP + + &barak_pdb_misc('2010', '2.8'); + + $lib_private = 1; + + @inargs = ( + { name => 'image', type => 'image', + desc => 'The image to which to add the group layer' } + ); + + @outargs = ( + { name => 'group_layer', type => 'group_layer', + desc => 'The newly created group layer' } + ); + %invoke = ( + code => <<'CODE' +{ + group_layer = GIMP_GROUP_LAYER (gimp_group_layer_new (image)); + + if (! group_layer) + success = FALSE; +} +CODE + ); +} + +sub group_layer_merge { + $blurb = 'Merge the passed group layer\'s layers into one normal layer.'; + + $help = <<'HELP'; +This procedure combines the layers of the passed group layer into +a single normal layer, replacing the group. + +The group layer is expected to be attached to an image. +HELP + + &ell_pdb_misc('2019', '2.10.14'); + + @inargs = ( + { name => 'group_layer', type => 'group_layer', + desc => 'The group layer to merge' }, + ); + + @outargs = ( + { name => 'layer', type => 'layer', + desc => 'The resulting layer' } + ); + + %invoke = ( + headers => [ qw("core/gimpimage-merge.h") ], + code => <<'CODE' +{ + if (gimp_pdb_item_is_attached (GIMP_ITEM (group_layer), NULL, 0, error) && + gimp_pdb_item_is_group (GIMP_ITEM (group_layer), error)) + { + GimpImage *image = gimp_item_get_image (GIMP_ITEM (group_layer)); + + layer = gimp_image_merge_group_layer (image, group_layer); + + if (! layer) + success = FALSE; + } + else + success = FALSE; +} +CODE + ); +} +@headers = qw( + "libgimpbase/gimpbase.h" + "core/gimp.h" + "core/gimpgrouplayer.h" + "gimppdb-utils.h" + "gimp-intl.h"); + +@procs = qw(group_layer_new + group_layer_merge); + +%exports = (app => [@procs], lib => [@procs]); + +$desc = 'Group Layer'; +$doc_title = 'gimpgrouplayer'; +$doc_short_desc = 'Operations on a group layer.'; +$doc_long_desc = 'Operations on a group layer.'; + +1; diff --git a/pdb/groups/image.pdb b/pdb/groups/image.pdb index 7ba1e5a7bc..7ca44937ad 100644 --- a/pdb/groups/image.pdb +++ b/pdb/groups/image.pdb @@ -855,48 +855,6 @@ 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', '2.10.14'); - - @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. @@ -3219,7 +3177,6 @@ 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_palette image_get_metadata image_set_metadata diff --git a/pdb/groups/item.pdb b/pdb/groups/item.pdb index aac3c20f77..643ad96dfc 100644 --- a/pdb/groups/item.pdb +++ b/pdb/groups/item.pdb @@ -144,6 +144,36 @@ CODE ); } +sub item_id_is_group_layer { + $blurb = 'Returns whether the item ID is a group layer.'; + + $help = <<'HELP'; +This procedure returns TRUE if the specified item ID is a group layer. +HELP + + &jehan_pdb_misc('2024', '3.0'); + + @inargs = ( + { name => 'item_id', type => 'int32', + desc => 'The item ID' } + ); + + @outargs = ( + { name => 'group_layer', type => 'boolean', + desc => 'TRUE if the item is a group layer, FALSE otherwise.' } + ); + + %invoke = ( + code => <<'CODE' +{ + GimpItem *item = gimp_item_get_by_id (gimp, item_id); + + group_layer = (GIMP_IS_GROUP_LAYER (item) && ! gimp_item_is_removed (item)); +} +CODE + ); +} + sub item_id_is_channel { $blurb = 'Returns whether the item ID is a channel.'; @@ -974,7 +1004,8 @@ CODE ); } -@headers = qw("core/gimplayermask.h" +@headers = qw("core/gimpgrouplayer.h" + "core/gimplayermask.h" "core/gimplist.h" "core/gimpselection.h" "text/gimptextlayer.h" @@ -987,6 +1018,7 @@ CODE item_id_is_drawable item_id_is_layer item_id_is_text_layer + item_id_is_group_layer item_id_is_channel item_id_is_layer_mask item_id_is_selection diff --git a/pdb/groups/layer.pdb b/pdb/groups/layer.pdb index 28901f1415..1a7d6278cc 100644 --- a/pdb/groups/layer.pdb +++ b/pdb/groups/layer.pdb @@ -222,42 +222,6 @@ CODE ); } -sub layer_group_new { - $blurb = 'Create a new layer group.'; - - $help = <<'HELP'; -This procedure creates a new layer group. Attributes such as layer mode -and opacity should be set with explicit procedure calls. Add the new -layer group (which is a kind of layer) with the -gimp_image_insert_layer() command. - -Other procedures useful with layer groups: gimp_image_reorder_item(), -gimp_item_get_parent(), gimp_item_get_children(), gimp_item_is_group(). -HELP - - &barak_pdb_misc('2010', '2.8'); - - @inargs = ( - { name => 'image', type => 'image', - desc => 'The image to which to add the layer group' } - ); - - @outargs = ( - { name => 'layer_group', type => 'layer', - desc => 'The newly created layer group' } - ); - %invoke = ( - code => <<'CODE' -{ - layer_group = gimp_group_layer_new (image); - - if (! layer_group) - success = FALSE; -} -CODE - ); -} - sub layer_copy { $blurb = 'Copy a layer.'; @@ -1285,7 +1249,6 @@ CODE "core/gimp.h" "core/gimpimage-color-profile.h" "core/gimpimage-undo.h" - "core/gimpgrouplayer.h" "core/gimplayer-new.h" "core/gimppickable.h" "core/gimpprogress.h" @@ -1297,7 +1260,6 @@ CODE @procs = qw(layer_new layer_new_from_visible layer_new_from_drawable - layer_group_new layer_copy layer_add_alpha layer_flatten diff --git a/pdb/meson.build b/pdb/meson.build index ad71945392..e21b00b6c4 100644 --- a/pdb/meson.build +++ b/pdb/meson.build @@ -26,6 +26,7 @@ pdb_names = [ 'gradient_select', 'gradient', 'gradients', + 'group_layer', 'help', 'image_color_profile', 'image_convert', diff --git a/pdb/pdb.pl b/pdb/pdb.pl index 35c6288313..cfd3ee89da 100644 --- a/pdb/pdb.pl +++ b/pdb/pdb.pl @@ -335,6 +335,18 @@ package Gimp::CodeGen::pdb; take_value_func => 'g_value_set_object ($value, $var)', headers => [ qw("text/gimptextlayer.h") ] }, + group_layer => { name => 'GROUP_LAYER', + gtype => 'GIMP_TYPE_GROUP_LAYER', + type => 'GimpGroupLayer *', + const_type => 'GimpGroupLayer *', + init_value => 'NULL', + out_annotate => '(transfer none)', + get_value_func => '$var = g_value_get_object ($value)', + dup_value_func => '$var = GIMP_VALUES_GET_GROUP_LAYER ($value)', + set_value_func => 'g_value_set_object ($value, $var)', + take_value_func => 'g_value_set_object ($value, $var)', + headers => [ qw("core/gimpgrouplayer.h") ] }, + channel => { name => 'CHANNEL', gtype => 'GIMP_TYPE_CHANNEL', type => 'GimpChannel *', diff --git a/plug-ins/common/wavelet-decompose.c b/plug-ins/common/wavelet-decompose.c index 36a959f3a3..40ff381508 100644 --- a/plug-ins/common/wavelet-decompose.c +++ b/plug-ins/common/wavelet-decompose.c @@ -209,9 +209,8 @@ wavelet_run (GimpProcedure *procedure, if (create_group) { - parent = gimp_layer_group_new (image); + parent = GIMP_LAYER (gimp_group_layer_new (image, _("Decomposition"))); - gimp_item_set_name (GIMP_ITEM (parent), _("Decomposition")); gimp_item_set_visible (GIMP_ITEM (parent), FALSE); gimp_image_insert_layer (image, parent, GIMP_LAYER (gimp_item_get_parent (GIMP_ITEM (drawable))), diff --git a/plug-ins/file-psd/psd-load.c b/plug-ins/file-psd/psd-load.c index 06f6498ece..6caef8f92c 100644 --- a/plug-ins/file-psd/psd-load.c +++ b/plug-ins/file-psd/psd-load.c @@ -2365,7 +2365,7 @@ add_layers (GimpImage *image, * assemble the layer structure in a single pass */ IFDBG(2) g_debug ("Create placeholder group layer"); - layer = gimp_layer_group_new (image); + layer = GIMP_LAYER (gimp_group_layer_new (image, NULL)); /* add this group layer as the new parent */ g_array_append_val (parent_group_stack, layer); } @@ -3180,9 +3180,8 @@ add_clipping_group (GimpImage *image, * composition mode in a different manner than PS. */ IFDBG(2) g_debug ("Creating a layer group to handle PS transparency clipping correctly."); - clipping_group = gimp_layer_group_new (image); + clipping_group = GIMP_LAYER (gimp_group_layer_new (image, "Group added by GIMP")); - gimp_item_set_name (GIMP_ITEM (clipping_group), "Group added by GIMP"); gimp_layer_set_blend_space (clipping_group, GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL); gimp_layer_set_composite_space (clipping_group, GIMP_LAYER_COLOR_SPACE_RGB_PERCEPTUAL); gimp_layer_set_composite_mode (clipping_group, GIMP_LAYER_COMPOSITE_UNION);