Iterate over all an image's items recursively

Use gimp_image_get_layer,channel,vectors_list() instead of
gimp_image_get_layer,channel,vectors_iter(). As a side-effect,
simplified some code that was making sure we don't modify the list
returned by the old functions (the new functions return newly
allocated lists so we can safely remove items from the image while
iterating it). Some places will need adjusting once we really have
item trees.
This commit is contained in:
Michael Natterer 2009-08-02 17:44:05 +02:00
parent ec21c2880c
commit 87d463aed0
8 changed files with 167 additions and 111 deletions

View File

@ -766,6 +766,7 @@ gimp_image_convert (GimpImage *image,
{ {
QuantizeObj *quantobj = NULL; QuantizeObj *quantobj = NULL;
GimpImageBaseType old_type; GimpImageBaseType old_type;
GList *all_layers;
GList *list; GList *list;
const gchar *undo_desc = NULL; const gchar *undo_desc = NULL;
gint nth_layer, n_layers; gint nth_layer, n_layers;
@ -797,7 +798,9 @@ gimp_image_convert (GimpImage *image,
gimp_set_busy (image->gimp); gimp_set_busy (image->gimp);
n_layers = gimp_container_get_n_children (GIMP_CONTAINER (image->layers)); all_layers = gimp_image_get_layer_list (image);
n_layers = g_list_length (all_layers);
switch (new_type) switch (new_type)
{ {
@ -866,7 +869,7 @@ gimp_image_convert (GimpImage *image,
num_found_cols = 0; num_found_cols = 0;
/* Build the histogram */ /* Build the histogram */
for (list = gimp_image_get_layer_iter (image), nth_layer = 0; for (list = all_layers, nth_layer = 0;
list; list;
list = g_list_next (list), nth_layer++) list = g_list_next (list), nth_layer++)
{ {
@ -951,7 +954,7 @@ gimp_image_convert (GimpImage *image,
if (quantobj) if (quantobj)
quantobj->n_layers = n_layers; quantobj->n_layers = n_layers;
for (list = gimp_image_get_layer_iter (image), nth_layer = 0; for (list = all_layers, nth_layer = 0;
list; list;
list = g_list_next (list), nth_layer++) list = g_list_next (list), nth_layer++)
{ {
@ -1025,9 +1028,7 @@ gimp_image_convert (GimpImage *image,
remap_table, &num_entries); remap_table, &num_entries);
/* Convert all layers */ /* Convert all layers */
for (list = gimp_image_get_layer_iter (image); for (list = all_layers; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
remap_indexed_layer (list->data, remap_table, num_entries); remap_indexed_layer (list->data, remap_table, num_entries);
} }
@ -1086,6 +1087,8 @@ gimp_image_convert (GimpImage *image,
gimp_image_mode_changed (image); gimp_image_mode_changed (image);
g_object_thaw_notify (G_OBJECT (image)); g_object_thaw_notify (G_OBJECT (image));
g_list_free (all_layers);
gimp_unset_busy (image->gimp); gimp_unset_busy (image->gimp);
return TRUE; return TRUE;

View File

@ -118,9 +118,16 @@ gimp_image_crop (GimpImage *image,
} }
else else
{ {
GList *all_layers;
GList *all_channels;
GList *all_vectors;
GimpItem *item; GimpItem *item;
GList *list; GList *list;
all_layers = gimp_image_get_layer_list (image);
all_channels = gimp_image_get_channel_list (image);
all_vectors = gimp_image_get_vectors_list (image);
g_object_freeze_notify (G_OBJECT (image)); g_object_freeze_notify (G_OBJECT (image));
if (crop_layers) if (crop_layers)
@ -145,9 +152,7 @@ gimp_image_crop (GimpImage *image,
NULL); NULL);
/* Resize all channels */ /* Resize all channels */
for (list = gimp_image_get_channel_iter (image); for (list = all_channels; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
item = (GimpItem *) list->data; item = (GimpItem *) list->data;
@ -155,9 +160,7 @@ gimp_image_crop (GimpImage *image,
} }
/* Resize all vectors */ /* Resize all vectors */
for (list = gimp_image_get_vectors_iter (image); for (list = all_vectors; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
item = (GimpItem *) list->data; item = (GimpItem *) list->data;
@ -169,14 +172,10 @@ gimp_image_crop (GimpImage *image,
width, height, -x1, -y1); width, height, -x1, -y1);
/* crop all layers */ /* crop all layers */
list = gimp_image_get_layer_iter (image); for (list = all_layers; list; list = g_list_next (list))
while (list)
{ {
item = (GimpItem *) list->data; item = (GimpItem *) list->data;
list = g_list_next (list);
gimp_item_translate (item, -x1, -y1, TRUE); gimp_item_translate (item, -x1, -y1, TRUE);
if (crop_layers) if (crop_layers)
@ -281,6 +280,10 @@ gimp_image_crop (GimpImage *image,
previous_height); previous_height);
g_object_thaw_notify (G_OBJECT (image)); g_object_thaw_notify (G_OBJECT (image));
g_list_free (all_layers);
g_list_free (all_channels);
g_list_free (all_vectors);
} }
gimp_unset_busy (image->gimp); gimp_unset_busy (image->gimp);

View File

@ -202,6 +202,7 @@ gimp_image_duplicate_layers (GimpImage *image,
{ {
GimpLayer *active_layer = NULL; GimpLayer *active_layer = NULL;
GimpLayer *floating_selection; GimpLayer *floating_selection;
GList *all_layers;
GList *list; GList *list;
gint count; gint count;
@ -209,11 +210,11 @@ gimp_image_duplicate_layers (GimpImage *image,
floating_selection = gimp_image_get_floating_selection (image); floating_selection = gimp_image_get_floating_selection (image);
if (floating_selection) if (floating_selection)
{ *floating_sel_drawable = gimp_layer_get_floating_sel_drawable (floating_selection);
*floating_sel_drawable = gimp_layer_get_floating_sel_drawable (floating_selection);
}
for (list = gimp_image_get_layer_iter (image), count = 0; all_layers = gimp_image_get_layer_list (image);
for (list = all_layers, count = 0;
list; list;
list = g_list_next (list)) list = g_list_next (list))
{ {
@ -248,6 +249,8 @@ gimp_image_duplicate_layers (GimpImage *image,
gimp_image_add_layer (new_image, new_layer, count++, FALSE); gimp_image_add_layer (new_image, new_layer, count++, FALSE);
} }
g_list_free (all_layers);
return active_layer; return active_layer;
} }
@ -258,10 +261,13 @@ gimp_image_duplicate_channels (GimpImage *image,
GimpDrawable **new_floating_sel_drawable) GimpDrawable **new_floating_sel_drawable)
{ {
GimpChannel *active_channel = NULL; GimpChannel *active_channel = NULL;
GList *all_channels;
GList *list; GList *list;
gint count; gint count;
for (list = gimp_image_get_channel_iter (image), count = 0; all_channels = gimp_image_get_channel_list (image);
for (list = all_channels, count = 0;
list; list;
list = g_list_next (list)) list = g_list_next (list))
{ {
@ -277,7 +283,7 @@ gimp_image_duplicate_channels (GimpImage *image,
gimp_object_get_name (GIMP_OBJECT (channel))); gimp_object_get_name (GIMP_OBJECT (channel)));
if (gimp_image_get_active_channel (image) == channel) if (gimp_image_get_active_channel (image) == channel)
active_channel = (new_channel); active_channel = new_channel;
if (floating_sel_drawable == GIMP_DRAWABLE (channel)) if (floating_sel_drawable == GIMP_DRAWABLE (channel))
*new_floating_sel_drawable = GIMP_DRAWABLE (new_channel); *new_floating_sel_drawable = GIMP_DRAWABLE (new_channel);
@ -285,6 +291,8 @@ gimp_image_duplicate_channels (GimpImage *image,
gimp_image_add_channel (new_image, new_channel, count++, FALSE); gimp_image_add_channel (new_image, new_channel, count++, FALSE);
} }
g_list_free (all_channels);
return active_channel; return active_channel;
} }
@ -293,10 +301,13 @@ gimp_image_duplicate_vectors (GimpImage *image,
GimpImage *new_image) GimpImage *new_image)
{ {
GimpVectors *active_vectors = NULL; GimpVectors *active_vectors = NULL;
GList *all_vectors;
GList *list; GList *list;
gint count; gint count;
for (list = gimp_image_get_vectors_iter (image), count = 0; all_vectors = gimp_image_get_vectors_list (image);
for (list = all_vectors, count = 0;
list; list;
list = g_list_next (list)) list = g_list_next (list))
{ {
@ -317,6 +328,8 @@ gimp_image_duplicate_vectors (GimpImage *image,
gimp_image_add_vectors (new_image, new_vectors, count++, FALSE); gimp_image_add_vectors (new_image, new_vectors, count++, FALSE);
} }
g_list_free (all_vectors);
return active_vectors; return active_vectors;
} }
@ -369,7 +382,9 @@ gimp_image_duplicate_guides (GimpImage *image,
{ {
GList *list; GList *list;
for (list = gimp_image_get_guides (image); list; list = g_list_next (list)) for (list = gimp_image_get_guides (image);
list;
list = g_list_next (list))
{ {
GimpGuide *guide = list->data; GimpGuide *guide = list->data;
gint position = gimp_guide_get_position (guide); gint position = gimp_guide_get_position (guide);

View File

@ -42,6 +42,9 @@ gimp_image_flip (GimpImage *image,
GimpOrientationType flip_type, GimpOrientationType flip_type,
GimpProgress *progress) GimpProgress *progress)
{ {
GList *all_layers;
GList *all_channels;
GList *all_vectors;
GList *list; GList *list;
gdouble axis; gdouble axis;
gdouble progress_max; gdouble progress_max;
@ -68,17 +71,19 @@ gimp_image_flip (GimpImage *image,
return; return;
} }
progress_max = (gimp_container_get_n_children (image->channels) + all_layers = gimp_image_get_layer_list (image);
gimp_container_get_n_children (image->layers) + all_channels = gimp_image_get_channel_list (image);
gimp_container_get_n_children (image->vectors) + all_vectors = gimp_image_get_vectors_list (image);
progress_max = (g_list_length (all_layers) +
g_list_length (all_channels) +
g_list_length (all_vectors) +
1 /* selection */); 1 /* selection */);
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_FLIP, NULL); gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_FLIP, NULL);
/* Flip all channels */ /* Flip all channels */
for (list = gimp_image_get_channel_iter (image); for (list = all_channels; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
@ -89,9 +94,7 @@ gimp_image_flip (GimpImage *image,
} }
/* Flip all vectors */ /* Flip all vectors */
for (list = gimp_image_get_vectors_iter (image); for (list = all_vectors; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
@ -109,9 +112,7 @@ gimp_image_flip (GimpImage *image,
gimp_progress_set_value (progress, progress_current++ / progress_max); gimp_progress_set_value (progress, progress_current++ / progress_max);
/* Flip all layers */ /* Flip all layers */
for (list = gimp_image_get_layer_iter (image); for (list = all_layers; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
@ -122,7 +123,9 @@ gimp_image_flip (GimpImage *image,
} }
/* Flip all Guides */ /* Flip all Guides */
for (list = gimp_image_get_guides (image); list; list = g_list_next (list)) for (list = gimp_image_get_guides (image);
list;
list = g_list_next (list))
{ {
GimpGuide *guide = list->data; GimpGuide *guide = list->data;
gint position = gimp_guide_get_position (guide); gint position = gimp_guide_get_position (guide);
@ -149,7 +152,9 @@ gimp_image_flip (GimpImage *image,
} }
/* Flip all sample points */ /* Flip all sample points */
for (list = gimp_image_get_sample_points (image); list; list = g_list_next (list)) for (list = gimp_image_get_sample_points (image);
list;
list = g_list_next (list))
{ {
GimpSamplePoint *sample_point = list->data; GimpSamplePoint *sample_point = list->data;
@ -170,5 +175,9 @@ gimp_image_flip (GimpImage *image,
gimp_image_undo_group_end (image); gimp_image_undo_group_end (image);
g_list_free (all_layers);
g_list_free (all_channels);
g_list_free (all_vectors);
gimp_unset_busy (image->gimp); gimp_unset_busy (image->gimp);
} }

View File

@ -162,6 +162,7 @@ gimp_image_item_list_get_list (const GimpImage *image,
GimpItemTypeMask type, GimpItemTypeMask type,
GimpItemSet set) GimpItemSet set)
{ {
GList *all_items;
GList *list; GList *list;
GList *return_list = NULL; GList *return_list = NULL;
@ -170,41 +171,47 @@ gimp_image_item_list_get_list (const GimpImage *image,
if (type & GIMP_ITEM_TYPE_LAYERS) if (type & GIMP_ITEM_TYPE_LAYERS)
{ {
for (list = gimp_image_get_layer_iter (image); all_items = gimp_image_get_layer_list (image);
list;
list = g_list_next (list)) for (list = all_items; list; list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
if (item != exclude && gimp_item_is_in_set (item, set)) if (item != exclude && gimp_item_is_in_set (item, set))
return_list = g_list_prepend (return_list, item); return_list = g_list_prepend (return_list, item);
} }
g_list_free (all_items);
} }
if (type & GIMP_ITEM_TYPE_CHANNELS) if (type & GIMP_ITEM_TYPE_CHANNELS)
{ {
for (list = gimp_image_get_channel_iter (image); all_items = gimp_image_get_channel_list (image);
list;
list = g_list_next (list)) for (list = all_items; list; list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
if (item != exclude && gimp_item_is_in_set (item, set)) if (item != exclude && gimp_item_is_in_set (item, set))
return_list = g_list_prepend (return_list, item); return_list = g_list_prepend (return_list, item);
} }
g_list_free (all_items);
} }
if (type & GIMP_ITEM_TYPE_VECTORS) if (type & GIMP_ITEM_TYPE_VECTORS)
{ {
for (list = gimp_image_get_vectors_iter (image); all_items = gimp_image_get_vectors_list (image);
list;
list = g_list_next (list)) for (list = all_items; list; list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
if (item != exclude && gimp_item_is_in_set (item, set)) if (item != exclude && gimp_item_is_in_set (item, set))
return_list = g_list_prepend (return_list, item); return_list = g_list_prepend (return_list, item);
} }
g_list_free (all_items);
} }
return g_list_reverse (return_list); return g_list_reverse (return_list);

View File

@ -65,6 +65,9 @@ gimp_image_resize_with_layers (GimpImage *image,
GimpItemSet layer_set, GimpItemSet layer_set,
GimpProgress *progress) GimpProgress *progress)
{ {
GList *all_layers;
GList *all_channels;
GList *all_vectors;
GList *list; GList *list;
GList *resize_layers; GList *resize_layers;
gdouble progress_max; gdouble progress_max;
@ -78,9 +81,13 @@ gimp_image_resize_with_layers (GimpImage *image,
gimp_set_busy (image->gimp); gimp_set_busy (image->gimp);
progress_max = (gimp_container_get_n_children (image->channels) + all_layers = gimp_image_get_layer_list (image);
gimp_container_get_n_children (image->layers) + all_channels = gimp_image_get_channel_list (image);
gimp_container_get_n_children (image->vectors) + all_vectors = gimp_image_get_vectors_list (image);
progress_max = (g_list_length (all_layers) +
g_list_length (all_channels) +
g_list_length (all_vectors) +
1 /* selection */); 1 /* selection */);
g_object_freeze_notify (G_OBJECT (image)); g_object_freeze_notify (G_OBJECT (image));
@ -110,9 +117,7 @@ gimp_image_resize_with_layers (GimpImage *image,
NULL); NULL);
/* Resize all channels */ /* Resize all channels */
for (list = gimp_image_get_channel_iter (image); for (list = all_channels; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
@ -124,9 +129,7 @@ gimp_image_resize_with_layers (GimpImage *image,
} }
/* Resize all vectors */ /* Resize all vectors */
for (list = gimp_image_get_vectors_iter (image); for (list = all_vectors; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
@ -145,9 +148,7 @@ gimp_image_resize_with_layers (GimpImage *image,
gimp_progress_set_value (progress, progress_current++ / progress_max); gimp_progress_set_value (progress, progress_current++ / progress_max);
/* Reposition all layers */ /* Reposition all layers */
for (list = gimp_image_get_layer_iter (image); for (list = all_layers; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
gint old_offset_x; gint old_offset_x;
@ -169,7 +170,9 @@ gimp_image_resize_with_layers (GimpImage *image,
g_list_free (resize_layers); g_list_free (resize_layers);
/* Reposition or remove all guides */ /* Reposition or remove all guides */
for (list = gimp_image_get_guides (image); list; list = g_list_next (list)) for (list = gimp_image_get_guides (image);
list;
list = g_list_next (list))
{ {
GimpGuide *guide = list->data; GimpGuide *guide = list->data;
gboolean remove_guide = FALSE; gboolean remove_guide = FALSE;
@ -200,7 +203,9 @@ gimp_image_resize_with_layers (GimpImage *image,
} }
/* Reposition or remove sample points */ /* Reposition or remove sample points */
for (list = gimp_image_get_sample_points (image); list; list = g_list_next (list)) for (list = gimp_image_get_sample_points (image);
list;
list = g_list_next (list))
{ {
GimpSamplePoint *sample_point = list->data; GimpSamplePoint *sample_point = list->data;
gboolean remove_sample_point = FALSE; gboolean remove_sample_point = FALSE;
@ -232,6 +237,10 @@ gimp_image_resize_with_layers (GimpImage *image,
g_object_thaw_notify (G_OBJECT (image)); g_object_thaw_notify (G_OBJECT (image));
g_list_free (all_layers);
g_list_free (all_channels);
g_list_free (all_vectors);
gimp_unset_busy (image->gimp); gimp_unset_busy (image->gimp);
} }
@ -240,25 +249,33 @@ gimp_image_resize_to_layers (GimpImage *image,
GimpContext *context, GimpContext *context,
GimpProgress *progress) GimpProgress *progress)
{ {
GList *list = gimp_image_get_layer_iter (image); GList *all_layers;
GList *list;
GimpItem *item; GimpItem *item;
gint min_x, max_x; gint min_x, max_x;
gint min_y, max_y; gint min_y, max_y;
if (!list) g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (GIMP_IS_CONTEXT (context));
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
all_layers = gimp_image_get_layer_list (image);
if (! all_layers)
return; return;
list = all_layers;
/* figure out starting values */ /* figure out starting values */
item = list->data; item = list->data;
min_x = gimp_item_get_offset_x (item); min_x = gimp_item_get_offset_x (item);
min_y = gimp_item_get_offset_y (item); min_y = gimp_item_get_offset_y (item);
max_x = gimp_item_get_offset_x (item) + gimp_item_get_width (item); max_x = gimp_item_get_offset_x (item) + gimp_item_get_width (item);
max_y = gimp_item_get_offset_y (item) + gimp_item_get_height (item); max_y = gimp_item_get_offset_y (item) + gimp_item_get_height (item);
/* Respect all layers */ /* Respect all layers */
for (list = g_list_next (list); for (list = g_list_next (list); list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
item = list->data; item = list->data;

View File

@ -53,6 +53,9 @@ gimp_image_rotate (GimpImage *image,
GimpRotationType rotate_type, GimpRotationType rotate_type,
GimpProgress *progress) GimpProgress *progress)
{ {
GList *all_layers;
GList *all_channels;
GList *all_vectors;
GList *list; GList *list;
gdouble center_x; gdouble center_x;
gdouble center_y; gdouble center_y;
@ -78,9 +81,13 @@ gimp_image_rotate (GimpImage *image,
center_x = previous_image_width / 2.0; center_x = previous_image_width / 2.0;
center_y = previous_image_height / 2.0; center_y = previous_image_height / 2.0;
progress_max = (gimp_container_get_n_children (image->channels) + all_layers = gimp_image_get_layer_list (image);
gimp_container_get_n_children (image->layers) + all_channels = gimp_image_get_channel_list (image);
gimp_container_get_n_children (image->vectors) + all_vectors = gimp_image_get_vectors_list (image);
progress_max = (g_list_length (all_layers) +
g_list_length (all_channels) +
g_list_length (all_vectors) +
1 /* selection */); 1 /* selection */);
g_object_freeze_notify (G_OBJECT (image)); g_object_freeze_notify (G_OBJECT (image));
@ -113,9 +120,7 @@ gimp_image_rotate (GimpImage *image,
} }
/* Rotate all channels */ /* Rotate all channels */
for (list = gimp_image_get_channel_iter (image); for (list = all_channels; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
@ -128,9 +133,7 @@ gimp_image_rotate (GimpImage *image,
} }
/* Rotate all vectors */ /* Rotate all vectors */
for (list = gimp_image_get_vectors_iter (image); for (list = all_vectors; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
@ -167,9 +170,7 @@ gimp_image_rotate (GimpImage *image,
} }
/* Rotate all layers */ /* Rotate all layers */
for (list = gimp_image_get_layer_iter (image); for (list = all_layers; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
gint off_x; gint off_x;
@ -226,6 +227,10 @@ gimp_image_rotate (GimpImage *image,
g_object_thaw_notify (G_OBJECT (image)); g_object_thaw_notify (G_OBJECT (image));
g_list_free (all_layers);
g_list_free (all_channels);
g_list_free (all_vectors);
gimp_unset_busy (image->gimp); gimp_unset_busy (image->gimp);
} }

View File

@ -51,8 +51,10 @@ gimp_image_scale (GimpImage *image,
GimpProgress *progress) GimpProgress *progress)
{ {
GimpProgress *sub_progress; GimpProgress *sub_progress;
GList *all_layers;
GList *all_channels;
GList *all_vectors;
GList *list; GList *list;
GList *remove = NULL;
gint old_width; gint old_width;
gint old_height; gint old_height;
gint offset_x; gint offset_x;
@ -70,9 +72,13 @@ gimp_image_scale (GimpImage *image,
sub_progress = gimp_sub_progress_new (progress); sub_progress = gimp_sub_progress_new (progress);
progress_steps = (gimp_container_get_n_children (image->channels) + all_layers = gimp_image_get_layer_list (image);
gimp_container_get_n_children (image->layers) + all_channels = gimp_image_get_channel_list (image);
gimp_container_get_n_children (image->vectors) + all_vectors = gimp_image_get_vectors_list (image);
progress_steps = (g_list_length (all_layers) +
g_list_length (all_channels) +
g_list_length (all_vectors) +
1 /* selection */); 1 /* selection */);
g_object_freeze_notify (G_OBJECT (image)); g_object_freeze_notify (G_OBJECT (image));
@ -103,9 +109,7 @@ gimp_image_scale (GimpImage *image,
NULL); NULL);
/* Scale all channels */ /* Scale all channels */
for (list = gimp_image_get_channel_iter (image); for (list = all_channels; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
@ -118,9 +122,7 @@ gimp_image_scale (GimpImage *image,
} }
/* Scale all vectors */ /* Scale all vectors */
for (list = gimp_image_get_vectors_iter (image); for (list = all_vectors; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
@ -141,9 +143,7 @@ gimp_image_scale (GimpImage *image,
interpolation_type, sub_progress); interpolation_type, sub_progress);
/* Scale all layers */ /* Scale all layers */
for (list = gimp_image_get_layer_iter (image); for (list = all_layers; list; list = g_list_next (list))
list;
list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
@ -159,24 +159,10 @@ gimp_image_scale (GimpImage *image,
* here. Upstream warning implemented in resize_check_layer_scaling(), * here. Upstream warning implemented in resize_check_layer_scaling(),
* which offers the user the chance to bail out. * which offers the user the chance to bail out.
*/ */
remove = g_list_prepend (remove, item); gimp_image_remove_layer (image, GIMP_LAYER (item), TRUE, NULL);
} }
} }
/* We defer removing layers lost to scaling until now so as not to mix
* the operations of iterating over and removal from image->layers.
*/
remove = g_list_reverse (remove);
for (list = remove; list; list = g_list_next (list))
{
GimpLayer *layer = list->data;
gimp_image_remove_layer (image, layer, TRUE, NULL);
}
g_list_free (remove);
/* Scale all Guides */ /* Scale all Guides */
for (list = gimp_image_get_guides (image); list; list = g_list_next (list)) for (list = gimp_image_get_guides (image); list; list = g_list_next (list))
{ {
@ -214,6 +200,10 @@ gimp_image_scale (GimpImage *image,
gimp_image_undo_group_end (image); gimp_image_undo_group_end (image);
g_list_free (all_layers);
g_list_free (all_channels);
g_list_free (all_vectors);
g_object_unref (sub_progress); g_object_unref (sub_progress);
gimp_image_size_changed_detailed (image, gimp_image_size_changed_detailed (image,
@ -254,6 +244,7 @@ gimp_image_scale_check (const GimpImage *image,
gint64 *new_memsize) gint64 *new_memsize)
{ {
GList *drawables; GList *drawables;
GList *all_layers;
GList *list; GList *list;
gint64 current_size; gint64 current_size;
gint64 scalable_size; gint64 scalable_size;
@ -330,15 +321,21 @@ gimp_image_scale_check (const GimpImage *image,
if (new_size > current_size && new_size > max_memsize) if (new_size > current_size && new_size > max_memsize)
return GIMP_IMAGE_SCALE_TOO_BIG; return GIMP_IMAGE_SCALE_TOO_BIG;
for (list = gimp_image_get_layer_iter (image); all_layers = gimp_image_get_layer_list (image);
list;
list = g_list_next (list)) for (list = all_layers; list; list = g_list_next (list))
{ {
GimpItem *item = list->data; GimpItem *item = list->data;
if (! gimp_item_check_scaling (item, new_width, new_height)) if (! gimp_item_check_scaling (item, new_width, new_height))
return GIMP_IMAGE_SCALE_TOO_SMALL; {
g_list_free (all_layers);
return GIMP_IMAGE_SCALE_TOO_SMALL;
}
} }
g_list_free (all_layers);
return GIMP_IMAGE_SCALE_OK; return GIMP_IMAGE_SCALE_OK;
} }