libgimp: again, redo all APIs returning list of images, items, children

We now have both variants, one returning a GList, and another
returning an array. Turns out that while a list is often nicer,
sometimes a random-access array really keeps the code much simpler.

Adapt all plug-ins, and clean up a bit (like use g_list_reverse() once
instead of iterating the list reversed).
This commit is contained in:
Michael Natterer 2019-08-27 13:26:27 +02:00
parent 6391b2bcff
commit 0b3e02be10
23 changed files with 414 additions and 181 deletions

View File

@ -299,6 +299,7 @@ EXPORTS
gimp_get_color_configuration
gimp_get_default_comment
gimp_get_default_unit
gimp_get_images
gimp_get_module_load_inhibit
gimp_get_monitor_resolution
gimp_get_parasite
@ -449,8 +450,10 @@ EXPORTS
gimp_image_insert_vectors
gimp_image_is_dirty
gimp_image_is_valid
gimp_image_list
gimp_image_list_channels
gimp_image_list_deprecated
gimp_image_list_layers
gimp_image_list_vectors
gimp_image_lower_item
gimp_image_lower_item_to_bottom
gimp_image_merge_down
@ -537,6 +540,7 @@ EXPORTS
gimp_item_is_text_layer
gimp_item_is_valid
gimp_item_is_vectors
gimp_item_list_children
gimp_item_set_color_tag
gimp_item_set_expanded
gimp_item_set_linked
@ -603,6 +607,7 @@ EXPORTS
gimp_layer_set_offsets
gimp_layer_set_opacity
gimp_layer_set_show_mask
gimp_list_images
gimp_load_procedure_get_handles_raw
gimp_load_procedure_get_thumbnail_loader
gimp_load_procedure_get_type

View File

@ -76,8 +76,9 @@ export_merge (GimpImage *image,
GList *iter;
gint32 nvisible = 0;
layers = gimp_image_get_layers (image);
for (iter = layers; iter; iter = iter->next)
layers = gimp_image_list_layers (image);
for (iter = layers; iter; iter = g_list_next (iter))
{
if (gimp_item_get_visible (GIMP_ITEM (iter->data)))
nvisible++;
@ -119,11 +120,14 @@ export_merge (GimpImage *image,
}
g_list_free (layers);
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
/* make sure that the merged drawable matches the image size */
if (gimp_drawable_width (GIMP_DRAWABLE (merged)) != gimp_image_width (image) ||
gimp_drawable_height (GIMP_DRAWABLE (merged)) != gimp_image_height (image))
if (gimp_drawable_width (GIMP_DRAWABLE (merged)) !=
gimp_image_width (image) ||
gimp_drawable_height (GIMP_DRAWABLE (merged)) !=
gimp_image_height (image))
{
gint off_x, off_y;
@ -138,9 +142,10 @@ export_merge (GimpImage *image,
/* remove any remaining (invisible) layers */
for (iter = layers; iter; iter = iter->next)
{
if (gimp_item_get_id (iter->data) != gimp_item_get_id (GIMP_ITEM (*drawable)))
if (iter->data != *drawable)
gimp_image_remove_layer (image, iter->data);
}
g_list_free (layers);
}
@ -163,7 +168,7 @@ export_remove_alpha (GimpImage *image,
GList *layers;
GList *iter;
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
for (iter = layers; iter; iter = iter->next)
{
@ -181,7 +186,7 @@ export_apply_masks (GimpImage *image,
GList *layers;
GList *iter;
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
for (iter = layers; iter; iter = iter->next)
{
@ -216,7 +221,8 @@ export_convert_indexed (GimpImage *image,
GList *layers;
/* check alpha */
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
if (layers || gimp_drawable_has_alpha (*drawable))
gimp_image_convert_indexed (image,
GIMP_CONVERT_DITHER_NONE,
@ -250,12 +256,14 @@ export_add_alpha (GimpImage *image,
GList *layers;
GList *iter;
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
for (iter = layers; iter; iter = iter->next)
{
if (! gimp_drawable_has_alpha (GIMP_DRAWABLE (iter->data)))
gimp_layer_add_alpha (GIMP_LAYER (iter->data));
}
g_list_free (layers);
}
@ -791,7 +799,7 @@ gimp_export_image (GimpImage **image,
/* check alpha and layer masks */
layers = gimp_image_get_layers (*image);
layers = gimp_image_list_layers (*image);
for (iter = layers; iter; iter = iter->next)
{
@ -844,7 +852,7 @@ gimp_export_image (GimpImage **image,
GimpLayer *layer = GIMP_LAYER (layers->data);
GList *children;
children = gimp_item_get_children (GIMP_ITEM (layer));
children = gimp_item_list_children (GIMP_ITEM (layer));
/* check if layer size != canvas size, opacity != 100%, or offsets != 0 */
if (g_list_length (layers) == 1 &&

View File

@ -168,7 +168,41 @@ gimp_image_get_by_id (gint32 image_id)
}
/**
* gimp_image_list:
* gimp_get_images:
* @num_images: (out): The number of images in the returned array.
*
* Returns the list of images currently open.
*
* This procedure returns the list of images currently open in GIMP.
*
* Returns: (array length=num_images) (transfer container):
* The list of images currently open.
* The returned array must be freed with g_free(). Image
* elements belong to libgimp and must not be freed.
*
* Since: 3.0
**/
GimpImage **
gimp_get_images (gint *num_images)
{
GimpImage **images;
gint *ids;
gint i;
ids = _gimp_image_list (num_images);
images = g_new (GimpImage *, *num_images);
for (i = 0; i < *num_images; i++)
images[i] = gimp_image_get_by_id (ids[i]);
g_free (ids);
return images;
}
/**
* gimp_list_images:
*
* Returns the list of images currently open.
*
@ -176,11 +210,13 @@ gimp_image_get_by_id (gint32 image_id)
*
* Returns: (element-type GimpImage) (transfer container):
* The list of images currently open.
* The returned value must be freed with g_list_free(). Image
* The returned list must be freed with g_list_free(). Image
* elements belong to libgimp and must not be freed.
*
* Since: 3.0
**/
GList *
gimp_image_list (void)
gimp_list_images (void)
{
GList *images = NULL;
gint *ids;
@ -201,32 +237,33 @@ gimp_image_list (void)
/**
* gimp_image_get_layers:
* @image: The image.
* @num_layers: (out): The number of layers in the returned array.
*
* 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.
*
* Returns: (element-type GimpImage) (transfer container):
* Returns: (array length=num_layers) (transfer container):
* The list of layers contained in the image.
* The returned value must be freed with g_list_free(). Layer
* The returned array must be freed with g_free(). Layer
* elements belong to libgimp and must not be freed.
*
* Since: 3.0
**/
GList *
gimp_image_get_layers (GimpImage *image)
GimpLayer **
gimp_image_get_layers (GimpImage *image,
gint *num_layers)
{
GList *layers = NULL;
GimpLayer **layers;
gint *ids;
gint num_layers;
gint i;
ids = _gimp_image_get_layers (image, &num_layers);
for (i = 0; i < num_layers; i++)
layers = g_list_prepend (layers,
GIMP_LAYER (gimp_item_get_by_id (ids[i])));
layers = g_list_reverse (layers);
ids = _gimp_image_get_layers (image, num_layers);
layers = g_new (GimpLayer *, *num_layers);
for (i = 0; i < *num_layers; i++)
layers[i] = GIMP_LAYER (gimp_item_get_by_id (ids[i]));
g_free (ids);
return layers;
@ -235,35 +272,36 @@ gimp_image_get_layers (GimpImage *image)
/**
* gimp_image_get_channels:
* @image: The image.
* @num_channels: (out): The number of channels in the returned array.
*
* 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. Note that
* \"channels\" are custom channels and do not include the image's
* color components.
* "channels" are custom channels and do not include the image's color
* components.
*
* Returns: (element-type GimpChannel) (transfer container):
* Returns: (array length=num_channels) (transfer container):
* The list of channels contained in the image.
* The returned value must be freed with g_list_free(). Channel
* The returned array must be freed with g_free(). Channel
* elements belong to libgimp and must not be freed.
*
* Since: 3.0
**/
GList *
gimp_image_get_channels (GimpImage *image)
GimpChannel **
gimp_image_get_channels (GimpImage *image,
gint *num_channels)
{
GList *channels = NULL;
GimpChannel **channels;
gint *ids;
gint num_channels;
gint i;
ids = _gimp_image_get_channels (image, &num_channels);
for (i = 0; i < num_channels; i++)
channels = g_list_prepend (channels,
GIMP_CHANNEL (gimp_item_get_by_id (ids[i])));
channels = g_list_reverse (channels);
ids = _gimp_image_get_channels (image, num_channels);
channels = g_new (GimpChannel *, *num_channels);
for (i = 0; i < *num_channels; i++)
channels[i] = GIMP_CHANNEL (gimp_item_get_by_id (ids[i]));
g_free (ids);
return channels;
@ -272,6 +310,114 @@ gimp_image_get_channels (GimpImage *image)
/**
* gimp_image_get_vectors:
* @image: The image.
* @num_vectors: (out): The number of vectors in the returned array.
*
* Returns the list of vectors contained in the specified image.
*
* This procedure returns the list of vectors contained in the
* specified image.
*
* Returns: (array length=num_vectors) (transfer container):
* The list of vectors contained in the image.
* The returned array must be freed with g_free(). Vectors
* elements belong to libgimp and must not be freed.
**/
GimpVectors **
gimp_image_get_vectors (GimpImage *image,
gint *num_vectors)
{
GimpVectors **vectors;
gint *ids;
gint i;
ids = _gimp_image_get_vectors (image, num_vectors);
vectors = g_new (GimpVectors *, *num_vectors);
for (i = 0; i < *num_vectors; i++)
vectors[i] = GIMP_VECTORS (gimp_item_get_by_id (ids[i]));
g_free (ids);
return vectors;
}
/**
* gimp_image_list_layers:
* @image: The image.
*
* 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.
*
* Returns: (element-type GimpImage) (transfer container):
* The list of layers contained in the image.
* The returned list must be freed with g_list_free(). Layer
* elements belong to libgimp and must not be freed.
*
* Since: 3.0
**/
GList *
gimp_image_list_layers (GimpImage *image)
{
GList *layers = NULL;
gint *ids;
gint num_layers;
gint i;
ids = _gimp_image_get_layers (image, &num_layers);
for (i = 0; i < num_layers; i++)
layers = g_list_prepend (layers,
GIMP_LAYER (gimp_item_get_by_id (ids[i])));
g_free (ids);
return g_list_reverse (layers);
}
/**
* gimp_image_list_channels:
* @image: The image.
*
* 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. Note that
* "channels" are custom channels and do not include the image's
* color components.
*
* Returns: (element-type GimpChannel) (transfer container):
* The list of channels contained in the image.
* The returned list must be freed with g_list_free(). Channel
* elements belong to libgimp and must not be freed.
*
* Since: 3.0
**/
GList *
gimp_image_list_channels (GimpImage *image)
{
GList *channels = NULL;
gint *ids;
gint num_channels;
gint i;
ids = _gimp_image_get_channels (image, &num_channels);
for (i = 0; i < num_channels; i++)
channels = g_list_prepend (channels,
GIMP_CHANNEL (gimp_item_get_by_id (ids[i])));
g_free (ids);
return g_list_reverse (channels);
}
/**
* gimp_image_list_vectors:
* @image: The image.
*
* Returns the list of vectors contained in the specified image.
*
@ -286,7 +432,7 @@ gimp_image_get_channels (GimpImage *image)
* Since: 3.0
**/
GList *
gimp_image_get_vectors (GimpImage *image)
gimp_image_list_vectors (GimpImage *image)
{
GList *vectors = NULL;
gint *ids;
@ -294,13 +440,14 @@ gimp_image_get_vectors (GimpImage *image)
gint i;
ids = _gimp_image_get_vectors (image, &num_vectors);
for (i = 0; i < num_vectors; i++)
vectors = g_list_prepend (vectors,
GIMP_VECTORS (gimp_item_get_by_id (ids[i])));
vectors = g_list_reverse (vectors);
g_free (ids);
return vectors;
return g_list_reverse (vectors);
}
/**
@ -340,9 +487,9 @@ gimp_image_get_colormap (GimpImage *image,
* Sets the entries in the image's colormap.
*
* This procedure sets the entries in the specified image's colormap.
* The number of colors is specified by the \"num_colors\" parameter
* The number of colors is specified by the "num_colors" parameter
* and corresponds to the number of INT8 triples that must be contained
* in the \"cmap\" array.
* in the "cmap" array.
*
* Returns: TRUE on success.
*/
@ -551,7 +698,7 @@ gimp_image_get_layers_deprecated (gint32 image_id,
* 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. Note that
* \"channels\" are custom channels and do not include the image's
* "channels" are custom channels and do not include the image's
* color components.
*
* Returns: (array length=num_channels):
@ -620,9 +767,9 @@ gimp_image_get_colormap_deprecated (gint32 image_id,
* Sets the entries in the image's colormap.
*
* This procedure sets the entries in the specified image's colormap.
* The number of colors is specified by the \"num_colors\" parameter
* The number of colors is specified by the "num_colors" parameter
* and corresponds to the number of INT8 triples that must be contained
* in the \"cmap\" array.
* in the "cmap" array.
*
* Returns: TRUE on success.
*/

View File

@ -68,13 +68,21 @@ GType gimp_image_get_type (void) G_GNUC_CONST;
gint32 gimp_image_get_id (GimpImage *image);
GimpImage * gimp_image_get_by_id (gint32 image_id);
GList * gimp_image_list (void);
GimpImage ** gimp_get_images (gint *num_images);
GList * gimp_list_images (void);
#ifndef GIMP_DEPRECATED_REPLACE_NEW_API
GList * gimp_image_get_layers (GimpImage *image);
GList * gimp_image_get_channels (GimpImage *image);
GList * gimp_image_get_vectors (GimpImage *image);
GimpLayer ** gimp_image_get_layers (GimpImage *image,
gint *num_layers);
GimpChannel ** gimp_image_get_channels (GimpImage *image,
gint *num_channels);
GimpVectors ** gimp_image_get_vectors (GimpImage *image,
gint *num_vectors);
GList * gimp_image_list_layers (GimpImage *image);
GList * gimp_image_list_channels (GimpImage *image);
GList * gimp_image_list_vectors (GimpImage *image);
guchar * gimp_image_get_colormap (GimpImage *image,
gint *num_colors);

View File

@ -184,7 +184,7 @@ gimp_image_combo_box_populate (GimpImageComboBox *combo_box)
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
images = gimp_image_list ();
images = gimp_list_images ();
gimp_image_combo_box_model_add (GTK_LIST_STORE (model), images,
combo_box->constraint,
@ -208,7 +208,7 @@ gimp_image_combo_box_model_add (GtkListStore *store,
GtkTreeIter iter;
GList *list;
for (list = images; list; list = list->next)
for (list = images; list; list = g_list_next (list))
{
GimpImage *image = list->data;
gint32 image_id = gimp_image_get_id (image);

View File

@ -175,6 +175,41 @@ gimp_item_get_by_id (gint32 item_id)
/**
* gimp_item_get_children:
* @item: The item.
* @num_children: (out): The number of items in the returned array.
*
* Returns the item's list of children.
*
* This procedure returns the list of items which are children of the
* specified item. The order is topmost to bottommost.
*
* Returns: (array length=num_children) (transfer container):
* The item's list of children.
* The returned array must be freed with g_free(). Item
* elements belong to libgimp and must not be unrefed.
**/
GimpItem **
gimp_item_get_children (GimpItem *item,
gint *num_children)
{
GimpItem **children;
gint *ids;
gint i;
ids = _gimp_item_get_children (item, num_children);
children = g_new (GimpItem *, *num_children);
for (i = 0; i < *num_children; i++)
children[i] = gimp_item_get_by_id (ids[i]);
g_free (ids);
return children;
}
/**
* gimp_item_list_children:
* @item: The item.
*
* Returns the item's list of children.
*
@ -183,13 +218,13 @@ gimp_item_get_by_id (gint32 item_id)
*
* Returns: (element-type GimpItem) (transfer container):
* The item's list of children.
* The returned value must be freed with g_list_free(). Item
* The returned ist must be freed with g_list_free(). Item
* elements belong to libgimp and must not be unrefed.
*
* Since: 3.0
**/
GList *
gimp_item_get_children (GimpItem *item)
gimp_item_list_children (GimpItem *item)
{
GList *children = NULL;
gint *ids;

View File

@ -71,7 +71,9 @@ GimpItem * gimp_item_get_by_id (gint32 item_id);
#ifndef GIMP_DEPRECATED_REPLACE_NEW_API
GList * gimp_item_get_children (GimpItem *item);
GimpItem ** gimp_item_get_children (GimpItem *item,
gint *num_children);
GList * gimp_item_list_children (GimpItem *item);
#else /* GIMP_DEPRECATED_REPLACE_NEW_API */

View File

@ -393,9 +393,9 @@ gimp_item_combo_box_populate (GimpIntComboBox *combo_box)
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
images = gimp_image_list ();
images = gimp_list_images ();
for (list = images; list; list = list->next)
for (list = images; list; list = g_list_next (list))
{
GimpImage *image = list->data;
GList *items;
@ -403,7 +403,7 @@ gimp_item_combo_box_populate (GimpIntComboBox *combo_box)
if (GIMP_IS_DRAWABLE_COMBO_BOX (combo_box) ||
GIMP_IS_LAYER_COMBO_BOX (combo_box))
{
items = gimp_image_get_layers (image);
items = gimp_image_list_layers (image);
gimp_item_combo_box_model_add (combo_box, GTK_LIST_STORE (model),
image, items, 0);
g_list_free (items);
@ -412,7 +412,7 @@ gimp_item_combo_box_populate (GimpIntComboBox *combo_box)
if (GIMP_IS_DRAWABLE_COMBO_BOX (combo_box) ||
GIMP_IS_CHANNEL_COMBO_BOX (combo_box))
{
items = gimp_image_get_channels (image);
items = gimp_image_list_channels (image);
gimp_item_combo_box_model_add (combo_box, GTK_LIST_STORE (model),
image, items, 0);
g_list_free (items);
@ -420,7 +420,7 @@ gimp_item_combo_box_populate (GimpIntComboBox *combo_box)
if (GIMP_IS_VECTORS_COMBO_BOX (combo_box))
{
items = gimp_image_get_vectors (image);
items = gimp_image_list_vectors (image);
gimp_item_combo_box_model_add (combo_box, GTK_LIST_STORE (model),
image, items, 0);
g_list_free (items);
@ -457,7 +457,7 @@ gimp_item_combo_box_model_add (GimpIntComboBox *combo_box,
indent = g_strdup ("");
}
for (list = items; list; list = list->next)
for (list = items; list; list = g_list_next (list))
{
GimpItem *item = list->data;
gint32 item_id = gimp_item_get_id (item);
@ -503,7 +503,7 @@ gimp_item_combo_box_model_add (GimpIntComboBox *combo_box,
{
GList *children;
children = gimp_item_get_children (item);
children = gimp_item_list_children (item);
gimp_item_combo_box_model_add (combo_box, store,
image, children,
tree_level + 1);

View File

@ -937,16 +937,21 @@ build_dialog (gchar *imagename)
/* Set up the frame disposal combo. */
frame_disposal_combo = gtk_combo_box_text_new ();
/* 2 styles of default frame disposals: cumulative layers and one frame per layer. */
/* 2 styles of default frame disposals: cumulative layers and one
* frame per layer.
*/
text = g_strdup (_("Cumulative layers (combine)"));
gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (frame_disposal_combo), DISPOSE_COMBINE, text);
gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (frame_disposal_combo),
DISPOSE_COMBINE, text);
g_free (text);
text = g_strdup (_("One frame per layer (replace)"));
gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (frame_disposal_combo), DISPOSE_REPLACE, text);
gtk_combo_box_text_insert_text (GTK_COMBO_BOX_TEXT (frame_disposal_combo),
DISPOSE_REPLACE, text);
g_free (text);
gtk_combo_box_set_active (GTK_COMBO_BOX (frame_disposal_combo), settings.default_frame_disposal);
gtk_combo_box_set_active (GTK_COMBO_BOX (frame_disposal_combo),
settings.default_frame_disposal);
g_signal_connect (frame_disposal_combo, "changed",
G_CALLBACK (framecombo_changed),
@ -1040,14 +1045,19 @@ init_frames (void)
gimp_quit ();
return;
}
/* We only use RGB images for display because indexed images would somehow
render terrible colors. Layers from other types will be automatically
converted. */
/* We only use RGB images for display because indexed images would
* somehow render terrible colors. Layers from other types will be
* automatically converted.
*/
frames_image = gimp_image_new (width, height, GIMP_RGB);
/* Save processing time and memory by not saving history and merged frames. */
gimp_image_undo_disable (frames_image);
for (iter = g_list_last (layers), i = 0; iter; iter = iter->prev, i++)
for (iter = layers, i = 0;
iter;
iter = g_list_next (iter), i++)
{
layer_name = gimp_item_get_name (iter->data);
if (layer_name)
@ -1066,7 +1076,8 @@ init_frames (void)
new_layer = gimp_layer_new_from_drawable (iter->data, frames_image);
gimp_image_insert_layer (frames_image, new_layer, NULL, -1);
gimp_item_set_visible (GIMP_ITEM (new_layer), TRUE);
new_frame = gimp_image_merge_visible_layers (frames_image, GIMP_CLIP_TO_IMAGE);
new_frame = gimp_image_merge_visible_layers (frames_image,
GIMP_CLIP_TO_IMAGE);
frames[i] = new_frame;
gimp_item_set_visible (GIMP_ITEM (new_frame), FALSE);
@ -1114,7 +1125,9 @@ initialize (void)
width = gimp_image_width (image);
height = gimp_image_height (image);
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
layers = g_list_reverse (layers);
if (!window)
build_dialog (gimp_image_get_name (image));

View File

@ -370,7 +370,7 @@ remap (GimpImage *image,
/* There is no needs to process the layers recursively, because
* indexed images cannot have layer groups.
*/
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
for (list = layers; list; list = list->next)
pixels +=

View File

@ -688,7 +688,7 @@ sanity_check (GFile *file,
/*** within the bounds of the image ***/
*image = gimp_image_duplicate (*image);
layers = gimp_image_get_layers (*image);
layers = gimp_image_list_layers (*image);
for (list = layers; list; list = g_list_next (list))
{
@ -802,8 +802,7 @@ save_image (GFile *file,
}
/* get a list of layers for this image */
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
nlayers = g_list_length (layers);
drawable_type = gimp_drawable_type (layers->data);
@ -963,9 +962,11 @@ save_image (GFile *file,
cur_progress = 0;
max_progress = nlayers * rows;
for (list = g_list_last (layers),i = nlayers - 1;
layers = g_list_reverse (layers);
for (list = layers, i = nlayers - 1;
list && i >= 0;
list = g_list_previous (list), i--, cur_progress = (nlayers - i) * rows)
list = g_list_next (list), i--, cur_progress = (nlayers - i) * rows)
{
GimpDrawable *drawable = list->data;
@ -1251,14 +1252,11 @@ save_dialog (GimpImage *image)
GtkWidget *toggle;
GtkWidget *frame;
GimpParasite *GIF2_CMNT;
GList *layers;
gint32 nlayers;
gboolean animation_supported = FALSE;
gboolean run;
layers = gimp_image_get_layers (image);
nlayers = g_list_length (layers);
g_list_free (layers);
g_free (gimp_image_get_layers (image, &nlayers));
animation_supported = nlayers > 1;

View File

@ -272,7 +272,6 @@ gih_save (GimpProcedure *procedure,
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GimpParasite *parasite;
GList *layers;
GimpImage *orig_image;
GError *error = NULL;
gint i;
@ -338,9 +337,7 @@ gih_save (GimpProcedure *procedure,
break;
}
layers = gimp_image_get_layers (image);
num_layers = g_list_length (layers);
g_list_free_full (layers, g_object_unref);
g_free (gimp_image_get_layers (image, &num_layers));
gimp_pixpipe_params_init (&gihparams);
@ -653,10 +650,11 @@ gih_save_dialog (GimpImage *image)
gtk_box_pack_start (GTK_BOX (box), spinbutton, FALSE, FALSE, 0);
gtk_widget_show (spinbutton);
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
cellw_adjust.orientation = GIMP_ORIENTATION_VERTICAL;
cellw_adjust.image = image;
cellw_adjust.toplayer = g_object_ref (g_list_last (layers)->data);
cellw_adjust.toplayer = g_list_last (layers)->data;
cellw_adjust.nguides = 0;
cellw_adjust.guides = NULL;
cellw_adjust.value = &gihparams.cellwidth;
@ -678,7 +676,7 @@ gih_save_dialog (GimpImage *image)
cellh_adjust.orientation = GIMP_ORIENTATION_HORIZONTAL;
cellh_adjust.image = image;
cellh_adjust.toplayer = g_object_ref (g_list_last (layers)->data);
cellh_adjust.toplayer = g_list_last (layers)->data;
cellh_adjust.nguides = 0;
cellh_adjust.guides = NULL;
cellh_adjust.value = &gihparams.cellheight;
@ -695,7 +693,7 @@ gih_save_dialog (GimpImage *image)
_("Cell size:"), 0.0, 0.5,
box, 1);
g_list_free_full (layers, g_object_unref);
g_list_free (layers);
/*
* Number of cells: ___

View File

@ -1565,9 +1565,12 @@ save_image (const gchar *filename,
return FALSE;
}
/* get layers */
orig_layers = gimp_image_get_layers (orig_image);
layers = gimp_image_get_layers (image);
/* get layers, in bottom-to-top order */
orig_layers = gimp_image_list_layers (orig_image);
layers = gimp_image_list_layers (image);
orig_layers = g_list_reverse (orig_layers);
layers = g_list_reverse (layers);
/* create new XcursorImages. */
imagesp = XcursorImagesCreate (g_list_length (layers));
@ -1585,11 +1588,9 @@ save_image (const gchar *filename,
/*
* Now we start to convert each layer to a XcurosrImage one by one.
*/
for (list = g_list_last (layers),
orig_list = g_list_last (orig_layers), i = 0;
for (list = layers, orig_list = orig_layers, i = 0;
list && orig_list;
list = g_list_previous (layers),
orig_list = g_list_previous (orig_list), i++)
list = g_list_next (layers), orig_list = g_list_next (orig_list), i++)
{
GimpDrawable *drawable = list->data;
GeglBuffer *buffer;
@ -2473,7 +2474,7 @@ get_intersection_of_frames (GimpImage *image)
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
for (list = layers; list; list = g_list_next (list))
{

View File

@ -470,16 +470,17 @@ film (void)
/* Calculate total film width */
film_width = 0;
num_pictures = 0;
for (iter = images_src; iter; iter = iter->next)
for (iter = images_src; iter; iter = g_list_next (iter))
{
layers = gimp_image_get_layers (iter->data);
layers = gimp_image_list_layers (iter->data);
/* Get scaled image size */
width = gimp_image_width (iter->data);
height = gimp_image_height (iter->data);
f = ((double)picture_height) / (double)height;
picture_width = width * f;
for (iter2 = layers; iter2; iter2 = iter2->next)
for (iter2 = layers; iter2; iter2 = g_list_next (iter2))
{
if (gimp_layer_is_floating_sel (iter2->data))
continue;
@ -563,8 +564,9 @@ film (void)
gimp_image_convert_rgb (image_tmp);
gimp_image_scale (image_tmp, picture_width, picture_height);
layers = gimp_image_get_layers (image_tmp);
for (iter2 = layers; iter2; iter2 = iter2->next)
layers = gimp_image_list_layers (image_tmp);
for (iter2 = layers; iter2; iter2 = g_list_next (iter2))
{
if (gimp_layer_is_floating_sel (iter2->data))
continue;
@ -604,8 +606,10 @@ film (void)
}
g_list_free (layers);
gimp_image_delete (image_tmp);
}
gimp_progress_update (1.0);
gimp_image_flatten (image_dst);
@ -985,7 +989,7 @@ create_selection_tab (GtkWidget *notebook,
GtkAdjustment *adj;
GtkWidget *button;
GtkWidget *font_button;
GList *image_id_list;
GList *image_list;
gint j;
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
@ -1151,14 +1155,14 @@ create_selection_tab (GtkWidget *notebook,
gtk_container_add (GTK_CONTAINER (frame), hbox);
/* Get a list of all image names */
image_id_list = gimp_image_list ();
filmint.image_list_all = add_image_list (TRUE, image_id_list, hbox);
g_list_free (image_id_list);
image_list = gimp_list_images ();
filmint.image_list_all = add_image_list (TRUE, image_list, hbox);
g_list_free (image_list);
/* Get a list of the images used for the film */
image_id_list = g_list_prepend (NULL, image);
filmint.image_list_film = add_image_list (FALSE, image_id_list, hbox);
g_list_free (image_id_list);
image_list = g_list_prepend (NULL, image);
filmint.image_list_film = add_image_list (FALSE, image_list, hbox);
g_list_free (image_list);
gtk_widget_show (hbox);
}

View File

@ -622,7 +622,7 @@ save_image (const gchar *filename,
{
FILE *file;
GList *framelist;
GList *list;
GList *iter;
gint nframes;
gint colors, i;
guchar *cmap;
@ -638,7 +638,8 @@ save_image (const gchar *filename,
s_fli_header fli_header;
gint cnt;
framelist = gimp_image_get_layers (image);
framelist = gimp_image_list_layers (image);
framelist = g_list_reverse (framelist);
nframes = g_list_length (framelist);
if ((from_frame == -1) && (to_frame == -1))
@ -764,11 +765,11 @@ save_image (const gchar *filename,
/*
* Now write all frames
*/
for (cnt = from_frame, list = g_list_nth (framelist, nframes - cnt);
cnt <= to_frame && list;
cnt++, list = g_list_previous (list))
for (iter = g_list_nth (framelist, from_frame - 1), cnt = from_frame;
iter && cnt <= to_frame;
iter = g_list_next (iter), cnt++)
{
GimpDrawable *drawable = list->data;
GimpDrawable *drawable = iter->data;
GeglBuffer *buffer;
const Babl *format = NULL;
@ -841,7 +842,7 @@ save_image (const gchar *filename,
g_free (fb);
g_free (ofb);
g_list_free (framelist);
g_free (framelist);
gimp_progress_update (1.0);
@ -930,13 +931,10 @@ save_dialog (GimpImage *image)
GtkWidget *grid;
GtkWidget *spinbutton;
GtkAdjustment *adj;
GList *frames;
gint nframes;
gboolean run;
frames = gimp_image_get_layers (image);
nframes = g_list_length (frames);
g_list_free (frames);
g_free (gimp_image_get_layers (image, &nframes));
from_frame = 1;
to_frame = nframes;

View File

@ -159,24 +159,25 @@ static void
ico_save_init (GimpImage *image,
IcoSaveInfo *info)
{
GList *layers;
GList *iter;
gint num_colors;
gint i;
gboolean uses_alpha_values = FALSE;
layers = gimp_image_get_layers (image);
info->num_icons = g_list_length (layers);
info->layers = layers;
info->layers = gimp_image_list_layers (image);
info->num_icons = g_list_length (info->layers);
info->depths = g_new (gint, info->num_icons);
info->default_depths = g_new (gint, info->num_icons);
info->compress = g_new (gboolean, info->num_icons);
/* Limit the color depths to values that don't cause any color loss --
the user should pick these anyway, so we can save her some time.
If the user wants to lose some colors, the settings can always be changed
in the dialog: */
for (iter = layers, i = 0; iter; iter = iter->next, i++)
/* Limit the color depths to values that don't cause any color loss
* -- the user should pick these anyway, so we can save her some
* time. If the user wants to lose some colors, the settings can
* always be changed in the dialog:
*/
for (iter = info->layers, i = 0;
iter;
iter = g_list_next (iter), i++)
{
num_colors = ico_get_layer_num_colors (iter->data, &uses_alpha_values);
@ -210,8 +211,8 @@ ico_save_init (GimpImage *image,
}
/* vista icons */
if (gimp_drawable_width (iter->data) > 255
|| gimp_drawable_height (iter->data) > 255 )
if (gimp_drawable_width (iter->data) > 255 ||
gimp_drawable_height (iter->data) > 255)
{
info->compress[i] = TRUE;
}
@ -240,7 +241,9 @@ ico_save_dialog (GimpImage *image,
gimp_ui_init (PLUG_IN_BINARY, TRUE);
dialog = ico_dialog_new (info);
for (iter = info->layers, i = 0; iter; iter = iter->next, i++)
for (iter = info->layers, i = 0;
iter;
iter = g_list_next (iter), i++)
{
/* if (gimp_layer_get_visible(layers[i])) */
ico_dialog_add_icon (dialog, iter->data, i);
@ -1053,7 +1056,7 @@ ico_save_info_free (IcoSaveInfo *info)
g_free (info->depths);
g_free (info->default_depths);
g_free (info->compress);
g_list_free_full (info->layers, g_object_unref);
g_list_free (info->layers);
memset (info, 0, sizeof (IcoSaveInfo));
}
@ -1117,7 +1120,9 @@ ico_save_image (const gchar *filename,
return GIMP_PDB_EXECUTION_ERROR;
}
for (iter = info.layers, i = 0; iter; iter = iter->next, i++)
for (iter = info.layers, i = 0;
iter;
iter = g_list_next (iter), i++)
{
gimp_progress_update ((gdouble)i / (gdouble)info.num_icons);

View File

@ -780,11 +780,12 @@ destroy_preview (void)
}
if (gimp_image_is_valid (preview_image) &&
gimp_item_is_valid (preview_layer))
gimp_item_is_valid (GIMP_ITEM (preview_layer)))
{
/* assuming that reference counting is working correctly,
we do not need to delete the layer, removing it from
the image should be sufficient */
/* assuming that reference counting is working correctly, we do
* not need to delete the layer, removing it from the image
* should be sufficient
*/
gimp_image_remove_layer (preview_image, preview_layer);
preview_layer = NULL;

View File

@ -627,16 +627,21 @@ save_resources (FILE *fd,
/* Get the active layer number id */
ActLayer = gimp_image_get_active_layer (image);
IFDBG printf ("\tCurrent layer id: %d\n", gimp_item_get_id (GIMP_ITEM (ActLayer)));
IFDBG printf ("\tCurrent layer id: %d\n",
gimp_item_get_id (GIMP_ITEM (ActLayer)));
ActiveLayerPresent = FALSE;
for (iter = PSDImageData.lLayers, i = 0; iter; iter = iter->next, i++)
for (iter = PSDImageData.lLayers, i = 0;
iter;
iter = g_list_next (iter), i++)
{
if (ActLayer == ((PSD_Layer *) iter->data)->layer)
{
nActiveLayer = PSDImageData.nLayers - i - 1;
ActiveLayerPresent = TRUE;
break;
}
}
if (ActiveLayerPresent)
{
@ -917,14 +922,17 @@ save_layer_and_mask (FILE *fd,
/* Layer records section */
/* GIMP layers must be written in reverse order */
for (iter = g_list_last (PSDImageData.lLayers), i = PSDImageData.nLayers; iter; iter = iter->prev, i--)
for (iter = g_list_last (PSDImageData.lLayers), i = PSDImageData.nLayers;
iter;
iter = g_list_previous (iter), i--)
{
PSD_Layer *psd_layer = (PSD_Layer *) iter->data;
gint hasMask = 0;
if (psd_layer->type == PSD_LAYER_TYPE_LAYER)
{
gimp_drawable_offsets (GIMP_DRAWABLE (psd_layer->layer), &offset_x, &offset_y);
gimp_drawable_offsets (GIMP_DRAWABLE (psd_layer->layer),
&offset_x, &offset_y);
layerWidth = gimp_drawable_width (GIMP_DRAWABLE (psd_layer->layer));
layerHeight = gimp_drawable_height (GIMP_DRAWABLE (psd_layer->layer));
}
@ -1149,7 +1157,9 @@ save_layer_and_mask (FILE *fd,
/* Channel image data section */
/* Gimp layers must be written in reverse order */
for (iter = g_list_last (PSDImageData.lLayers), i = PSDImageData.nLayers; iter; iter = iter->prev, i--)
for (iter = g_list_last (PSDImageData.lLayers), i = PSDImageData.nLayers;
iter;
iter = g_list_previous (iter), i--)
{
PSD_Layer *psd_layer = (PSD_Layer *) iter->data;
@ -1530,7 +1540,7 @@ get_image_data (GimpImage *image)
PSDImageData.merged_layer = create_merged_image (image);
PSDImageData.lChannels = gimp_image_get_channels (image);
PSDImageData.lChannels = gimp_image_list_channels (image);
PSDImageData.nChannels = g_list_length (PSDImageData.lChannels);
IFDBG printf ("\tGot number of channels: %d\n", PSDImageData.nChannels);
@ -1586,7 +1596,9 @@ save_image (const gchar *filename,
if (layer->type == PSD_LAYER_TYPE_LAYER)
{
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer->layer));
if (gegl_buffer_get_width (buffer) > 30000 || gegl_buffer_get_height (buffer) > 30000)
if (gegl_buffer_get_width (buffer) > 30000 ||
gegl_buffer_get_height (buffer) > 30000)
{
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Unable to export '%s'. The PSD file format does not "
@ -1596,6 +1608,7 @@ save_image (const gchar *filename,
clear_image_data ();
return FALSE;
}
g_object_unref (buffer);
}
}
@ -1730,7 +1743,7 @@ append_layers (GList *layers)
PSD_Layer *end_layer = g_new0 (PSD_Layer, 1);
GList *group_layers;
group_layers = gimp_item_get_children (iter->data);
group_layers = gimp_item_list_children (iter->data);
psd_layers = g_list_concat (psd_layers,
append_layers (group_layers));
g_list_free (group_layers);
@ -1751,7 +1764,7 @@ image_get_all_layers (GimpImage *image,
GList *psd_layers = NULL;
GList *layers;
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
psd_layers = append_layers (layers);
g_list_free (layers);

View File

@ -120,7 +120,7 @@ save_paths (TIFF *tif,
gint num_strokes, *strokes, s;
GString *ps_tag;
vectors = gimp_image_get_vectors (image);
vectors = gimp_image_list_vectors (image);
if (! vectors)
return FALSE;
@ -128,7 +128,9 @@ save_paths (TIFF *tif,
ps_tag = g_string_new ("");
/* Only up to 1000 paths supported */
for (iter = vectors, v = 0; iter && v < 1000; iter = iter->next, v++)
for (iter = vectors, v = 0;
iter && v < 1000;
iter = g_list_next (iter), v++)
{
GString *data;
gchar *name, *nameend;
@ -960,10 +962,12 @@ save_image (GFile *file,
gboolean out_linear = FALSE;
gint number_of_sub_IFDs = 1;
toff_t sub_IFDs_offsets[1] = { 0UL };
gint32 num_layers, current_layer = 0;
gint32 num_layers;
gint32 current_layer = 0;
GList *layers;
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
layers = g_list_reverse (layers);
num_layers = g_list_length (layers);
gimp_progress_init_printf (_("Exporting '%s'"),
@ -1059,7 +1063,7 @@ save_image (GFile *file,
/* write last layer as first page. */
if (! save_layer (tif, tsvals, space, image,
g_list_nth_data (layers, num_layers - current_layer - 1),
g_list_nth_data (layers, current_layer),
current_layer, num_layers,
orig_image, saved_bpp, out_linear, error))
{
@ -1099,23 +1103,26 @@ save_image (GFile *file,
for (; current_layer < num_layers; current_layer++)
{
gint tmp_saved_bpp;
if (! save_layer (tif, tsvals, space, image,
g_list_nth_data (layers, num_layers - current_layer - 1),
g_list_nth_data (layers, current_layer),
current_layer, num_layers, orig_image,
&tmp_saved_bpp, out_linear, error))
{
goto out;
}
if (tmp_saved_bpp != *saved_bpp)
{
/* this should never happen.
* if it does, decide if it's really an error.
/* this should never happen. if it does, decide if it's
* really an error.
*/
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Writing pages with different bit depth "
"is strange."));
goto out;
}
gimp_progress_update ((gdouble) (current_layer + 1) / num_layers);
}
}

View File

@ -491,12 +491,9 @@ image_is_monochrome (GimpImage *image)
static gboolean
image_is_multi_layer (GimpImage *image)
{
GList *layers;
gint32 n_layers;
layers = gimp_image_get_layers (image);
n_layers = g_list_length (layers);
g_list_free (layers);
g_free (gimp_image_get_layers (image, &n_layers));
return (n_layers > 1);
}

View File

@ -95,16 +95,13 @@ save_dialog (WebPSaveParams *params,
GtkWidget *combo;
GtkAdjustment *quality_scale;
GtkAdjustment *alpha_quality_scale;
GList *list;
gint32 nlayers;
gboolean animation_supported = FALSE;
gboolean run;
gchar *text;
gint row = 0;
list = gimp_image_get_layers (image);
nlayers = g_list_length (list);
g_list_free (list);
g_free (gimp_image_get_layers (image, &nlayers));
animation_supported = nlayers > 1;

View File

@ -594,9 +594,9 @@ save_animation (const gchar *filename,
enc_options.kmin = params->kf_distance - 1;
}
for (list = g_list_last (layers), loop = 0;
list && loop < nLayers;
list = g_list_previous (list), loop++)
for (list = layers, loop = 0;
list;
list = g_list_next (list), loop++)
{
GeglBuffer *geglbuffer;
GeglBuffer *current_frame;
@ -819,7 +819,8 @@ save_image (const gchar *filename,
gboolean status = FALSE;
GList *layers;
layers = gimp_image_get_layers (image);
layers = gimp_image_list_layers (image);
layers = g_list_reverse (layers);
if (! layers)
return FALSE;
@ -840,7 +841,7 @@ save_image (const gchar *filename,
image, drawable, params, error);
}
g_free (layers);
g_list_free (layers);
if (metadata)
{

View File

@ -691,21 +691,16 @@ init_calculation (GimpDrawable *drawable)
gdouble alpha, beta;
gdouble angle;
GimpVector2 v1, v2;
GList *image_layers;
GList *iter;
GList *layers;
gimp_layer_add_alpha (GIMP_LAYER (drawable));
/* Image parameters */
/* Determine Position of original Layer in the Layer stack. */
image_layers = gimp_image_get_layers (image);
iter = image_layers;
drawable_position = 0;
while (iter && iter->data != drawable)
drawable_position++;
g_list_free (image_layers);
layers = gimp_image_list_layers (image);
drawable_position = g_list_index (layers, drawable);
g_list_free (layers);
switch (curl.orientation)
{