[gimp] Add functions to count the items in an image
- From: Michael Natterer <mitch src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gimp] Add functions to count the items in an image
- Date: Sun, 2 Aug 2009 10:14:17 +0000 (UTC)
commit 6be068ceab39bb8f8ea1a6a5d0adbda267a4499b
Author: Michael Natterer <mitch gimp org>
Date: Sun Aug 2 12:12:01 2009 +0200
Add functions to count the items in an image
* app/core/gimpitemstack.[ch]: add gimp_item_stack_get_n_items()
which counts a stack's items recursively.
* app/core/gimpimage.[ch]: add get_n_layers(), get_n_channels()
and get_n_vectors().
app/core/gimpimage.c | 24 ++++++++++++++++++++++++
app/core/gimpimage.h | 4 ++++
app/core/gimpitemstack.c | 24 ++++++++++++++++++++++++
app/core/gimpitemstack.h | 1 +
4 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 30fe046..c71fca2 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -2649,6 +2649,30 @@ gimp_image_get_vectors (const GimpImage *image)
return image->vectors;
}
+gint
+gimp_image_get_n_layers (const GimpImage *image)
+{
+ g_return_val_if_fail (GIMP_IS_IMAGE (image), 0);
+
+ return gimp_item_stack_get_n_items (GIMP_ITEM_STACK (image->layers));
+}
+
+gint
+gimp_image_get_n_channels (const GimpImage *image)
+{
+ g_return_val_if_fail (GIMP_IS_IMAGE (image), 0);
+
+ return gimp_item_stack_get_n_items (GIMP_ITEM_STACK (image->channels));
+}
+
+gint
+gimp_image_get_n_vectors (const GimpImage *image)
+{
+ g_return_val_if_fail (GIMP_IS_IMAGE (image), 0);
+
+ return gimp_item_stack_get_n_items (GIMP_ITEM_STACK (image->vectors));
+}
+
GList *
gimp_image_get_layer_iter (const GimpImage *image)
{
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index 5b00135..eae1124 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -421,6 +421,10 @@ GimpContainer * gimp_image_get_layers (const GimpImage *image);
GimpContainer * gimp_image_get_channels (const GimpImage *image);
GimpContainer * gimp_image_get_vectors (const GimpImage *image);
+gint gimp_image_get_n_layers (const GimpImage *image);
+gint gimp_image_get_n_channels (const GimpImage *image);
+gint gimp_image_get_n_vectors (const GimpImage *image);
+
GList * gimp_image_get_layer_iter (const GimpImage *image);
GList * gimp_image_get_channel_iter (const GimpImage *image);
GList * gimp_image_get_vectors_iter (const GimpImage *image);
diff --git a/app/core/gimpitemstack.c b/app/core/gimpitemstack.c
index 112b89a..5d6c8de 100644
--- a/app/core/gimpitemstack.c
+++ b/app/core/gimpitemstack.c
@@ -116,6 +116,30 @@ gimp_item_stack_new (GType item_type)
NULL);
}
+gint
+gimp_item_stack_get_n_items (GimpItemStack *stack)
+{
+ GList *list;
+ gint n_items = 0;
+
+ g_return_val_if_fail (GIMP_IS_ITEM_STACK (stack), 0);
+
+ for (list = GIMP_LIST (stack)->list; list; list = g_list_next (list))
+ {
+ GimpItem *item = list->data;
+ GimpContainer *children;
+
+ n_items++;
+
+ children = gimp_viewable_get_children (GIMP_VIEWABLE (item));
+
+ if (children)
+ n_items += gimp_item_stack_get_n_items (GIMP_ITEM_STACK (children));
+ }
+
+ return n_items;
+}
+
GList *
gimp_item_stack_get_item_list (GimpItemStack *stack)
{
diff --git a/app/core/gimpitemstack.h b/app/core/gimpitemstack.h
index 29cc91e..da3cb19 100644
--- a/app/core/gimpitemstack.h
+++ b/app/core/gimpitemstack.h
@@ -47,6 +47,7 @@ struct _GimpItemStackClass
GType gimp_item_stack_get_type (void) G_GNUC_CONST;
GimpContainer * gimp_item_stack_new (GType item_type);
+gint gimp_item_stack_get_n_items (GimpItemStack *stack);
GList * gimp_item_stack_get_item_list (GimpItemStack *stack);
GimpItem * gimp_item_stack_get_item_by_tattoo (GimpItemStack *stack,
GimpTattoo tattoo);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]