Commit 139a2345 authored by Ell's avatar Ell

app: use GimpObjectQueue in lots of places

Use GimpObjectQueue, added in the previous commit, in various
instances where we perform an action on a set of objects.  This
improves progress reporting, by using a single progress for the
entire operation, rather than reporting the progress of each object
individually, and by taking the relative cost of each object into
account, instead of assuming a uniform cost for all objects.

In particular, this affects the various whole-image operations
(i.e., transformations and color conversions), operations on linked
items, and operations on layer groups.  This also affects layers
with masks, whose progress is now reported together instead of
individually.

Additionally, this commit fixes erroneous group-layer mask cropping
during undo when resizing the image, by properly calling
{start,end}_move() on all the resized layers before starting the
operation, and when scaling the image, by only scaling top-level
layers, and letting group layers scale their children themselves.
parent 3ee5054e
......@@ -38,7 +38,9 @@
#include "gimpimage-undo.h"
#include "gimpimage-undo-push.h"
#include "gimplayerstack.h"
#include "gimpobjectqueue.h"
#include "gimppickable.h"
#include "gimpprogress.h"
#include "gimpprojectable.h"
#include "gimpprojection.h"
......@@ -780,6 +782,7 @@ gimp_group_layer_scale (GimpLayer *layer,
GimpGroupLayer *group = GIMP_GROUP_LAYER (layer);
GimpGroupLayerPrivate *private = GET_PRIVATE (layer);
GimpItem *item = GIMP_ITEM (layer);
GimpObjectQueue *queue = NULL;
GList *list;
gdouble width_factor;
gdouble height_factor;
......@@ -792,6 +795,14 @@ gimp_group_layer_scale (GimpLayer *layer,
old_offset_x = gimp_item_get_offset_x (item);
old_offset_y = gimp_item_get_offset_y (item);
if (progress)
{
queue = gimp_object_queue_new (progress);
progress = GIMP_PROGRESS (queue);
gimp_object_queue_push_container (queue, private->children);
}
gimp_group_layer_suspend_resize (group, TRUE);
list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
......@@ -806,6 +817,9 @@ gimp_group_layer_scale (GimpLayer *layer,
list = g_list_next (list);
if (queue)
gimp_object_queue_pop (queue);
child_width = ROUND (width_factor * gimp_item_get_width (child));
child_height = ROUND (height_factor * gimp_item_get_height (child));
child_offset_x = ROUND (width_factor * (gimp_item_get_offset_x (child) -
......@@ -836,6 +850,8 @@ gimp_group_layer_scale (GimpLayer *layer,
}
gimp_group_layer_resume_resize (group, TRUE);
g_clear_object (&queue);
}
static void
......@@ -902,8 +918,17 @@ gimp_group_layer_transform (GimpLayer *layer,
{
GimpGroupLayer *group = GIMP_GROUP_LAYER (layer);
GimpGroupLayerPrivate *private = GET_PRIVATE (layer);
GimpObjectQueue *queue = NULL;
GList *list;
if (progress)
{
queue = gimp_object_queue_new (progress);
progress = GIMP_PROGRESS (queue);
gimp_object_queue_push_container (queue, private->children);
}
gimp_group_layer_suspend_resize (group, TRUE);
for (list = gimp_item_stack_get_item_iter (GIMP_ITEM_STACK (private->children));
......@@ -912,6 +937,9 @@ gimp_group_layer_transform (GimpLayer *layer,
{
GimpItem *child = list->data;
if (queue)
gimp_object_queue_pop (queue);
gimp_item_transform (child, context,
matrix, direction,
interpolation_type,
......@@ -919,6 +947,8 @@ gimp_group_layer_transform (GimpLayer *layer,
}
gimp_group_layer_resume_resize (group, TRUE);
g_clear_object (&queue);
}
static const Babl *
......
......@@ -47,8 +47,8 @@
#include "gimpimage-private.h"
#include "gimpimage-undo.h"
#include "gimpimage-undo-push.h"
#include "gimpobjectqueue.h"
#include "gimpprogress.h"
#include "gimpsubprogress.h"
#include "gimp-intl.h"
......@@ -676,36 +676,26 @@ gimp_image_convert_profile_layers (GimpImage *image,
gboolean bpc,
GimpProgress *progress)
{
GList *layers;
GList *list;
gint n_drawables = 0;
gint nth_drawable = 0;
GimpObjectQueue *queue;
GList *layers;
GList *list;
GimpDrawable *drawable;
queue = gimp_object_queue_new (progress);
progress = GIMP_PROGRESS (queue);
layers = gimp_image_get_layer_list (image);
for (list = layers; list; list = g_list_next (list))
{
if (! gimp_viewable_get_children (list->data))
n_drawables++;
gimp_object_queue_push (queue, list->data);
}
for (list = layers; list; list = g_list_next (list))
{
GimpDrawable *drawable = list->data;
GimpProgress *sub_progress = NULL;
if (gimp_viewable_get_children (GIMP_VIEWABLE (drawable)))
continue;
if (progress)
{
sub_progress = gimp_sub_progress_new (progress);
gimp_sub_progress_set_step (GIMP_SUB_PROGRESS (sub_progress),
nth_drawable, n_drawables);
}
nth_drawable++;
g_list_free (layers);
while ((drawable = gimp_object_queue_pop (queue)))
{
gimp_drawable_push_undo (drawable, NULL, NULL,
0, 0,
gimp_item_get_width (GIMP_ITEM (drawable)),
......@@ -718,15 +708,12 @@ gimp_image_convert_profile_layers (GimpImage *image,
NULL,
dest_profile,
intent, bpc,
sub_progress);
progress);
gimp_drawable_update (drawable, 0, 0, -1, -1);
if (sub_progress)
g_object_unref (sub_progress);
}
g_list_free (layers);
g_object_unref (queue);
}
static void
......
......@@ -155,6 +155,7 @@
#include "gimpimage-undo.h"
#include "gimpimage-undo-push.h"
#include "gimplayer.h"
#include "gimpobjectqueue.h"
#include "gimppalette.h"
#include "gimpprogress.h"
......@@ -486,8 +487,6 @@ struct _QuantizeObj
gint error_freedom; /* 0=much bleed, 1=controlled bleed */
GimpProgress *progress;
gint nth_layer;
gint n_layers;
};
typedef struct
......@@ -525,9 +524,7 @@ static void generate_histogram_rgb (CFHistogram histogram,
GimpLayer *layer,
gint col_limit,
gboolean dither_alpha,
GimpProgress *progress,
gint nth_layer,
gint n_layers);
GimpProgress *progress);
static QuantizeObj * initialize_median_cut (GimpImageBaseType old_type,
gint max_colors,
......@@ -760,13 +757,13 @@ gimp_image_convert_indexed (GimpImage *image,
GimpProgress *progress,
GError **error)
{
QuantizeObj *quantobj = NULL;
QuantizeObj *quantobj = NULL;
GimpObjectQueue *queue = NULL;
GimpProgress *sub_progress = NULL;
GimpImageBaseType old_type;
GList *all_layers;
GList *list;
GimpColorProfile *dest_profile = NULL;
gint nth_layer;
gint n_layers;
g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
g_return_val_if_fail (gimp_image_get_base_type (image) != GIMP_INDEXED, FALSE);
......@@ -795,8 +792,6 @@ gimp_image_convert_indexed (GimpImage *image,
all_layers = gimp_image_get_layer_list (image);
n_layers = g_list_length (all_layers);
g_object_freeze_notify (G_OBJECT (image));
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CONVERT,
......@@ -835,10 +830,18 @@ gimp_image_convert_indexed (GimpImage *image,
dither_type = GIMP_CONVERT_DITHER_NONE;
}
if (progress)
{
queue = gimp_object_queue_new (progress);
sub_progress = GIMP_PROGRESS (queue);
gimp_object_queue_push_list (queue, all_layers);
}
quantobj = initialize_median_cut (old_type, max_colors, dither_type,
palette_type, custom_palette,
dither_alpha,
progress);
sub_progress);
if (palette_type == GIMP_CONVERT_PALETTE_GENERATE)
{
......@@ -855,12 +858,15 @@ gimp_image_convert_indexed (GimpImage *image,
num_found_cols = 0;
/* Build the histogram */
for (list = all_layers, nth_layer = 0;
for (list = all_layers;
list;
list = g_list_next (list), nth_layer++)
list = g_list_next (list))
{
GimpLayer *layer = list->data;
if (queue)
gimp_object_queue_pop (queue);
if (old_type == GIMP_GRAY)
{
generate_histogram_gray (quantobj->histogram,
......@@ -874,7 +880,7 @@ gimp_image_convert_indexed (GimpImage *image,
*/
generate_histogram_rgb (quantobj->histogram,
layer, max_colors, dither_alpha,
progress, nth_layer, n_layers);
sub_progress);
}
}
}
......@@ -906,7 +912,7 @@ gimp_image_convert_indexed (GimpImage *image,
palette_type,
custom_palette,
dither_alpha,
progress);
sub_progress);
/* We can skip the first pass (palette creation) */
quantobj->actual_number_of_colors = num_found_cols;
......@@ -928,8 +934,13 @@ gimp_image_convert_indexed (GimpImage *image,
color_quicksort);
if (progress)
gimp_progress_set_text_literal (progress,
_("Converting to indexed colors (stage 3)"));
{
gimp_progress_set_text_literal (progress,
_("Converting to indexed colors (stage 3)"));
gimp_object_queue_clear (queue);
gimp_object_queue_push_list (queue, all_layers);
}
/* Initialise data which must persist across indexed layer iterations */
if (quantobj->second_pass_init)
......@@ -955,16 +966,16 @@ gimp_image_convert_indexed (GimpImage *image,
}
/* Convert all layers */
if (quantobj)
quantobj->n_layers = n_layers;
for (list = all_layers, nth_layer = 0;
for (list = all_layers;
list;
list = g_list_next (list), nth_layer++)
list = g_list_next (list))
{
GimpLayer *layer = list->data;
gboolean quantize;
if (queue)
gimp_object_queue_pop (queue);
if (gimp_item_is_text_layer (GIMP_ITEM (layer)))
quantize = dither_text_layers;
else
......@@ -984,7 +995,6 @@ gimp_image_convert_indexed (GimpImage *image,
gimp_image_get_layer_format (image,
has_alpha));
quantobj->nth_layer = nth_layer;
quantobj->second_pass (quantobj, layer, new_buffer);
gimp_drawable_set_buffer (GIMP_DRAWABLE (layer), TRUE, NULL,
......@@ -999,7 +1009,7 @@ gimp_image_convert_indexed (GimpImage *image,
gimp_drawable_has_alpha (GIMP_DRAWABLE (layer)),
dest_profile,
GEGL_DITHER_NONE, GEGL_DITHER_NONE,
TRUE, NULL);
TRUE, sub_progress);
}
}
......@@ -1062,6 +1072,8 @@ gimp_image_convert_indexed (GimpImage *image,
gimp_image_mode_changed (image);
g_object_thaw_notify (G_OBJECT (image));
g_clear_object (&queue);
g_list_free (all_layers);
gimp_unset_busy (image->gimp);
......@@ -1146,9 +1158,7 @@ generate_histogram_rgb (CFHistogram histogram,
GimpLayer *layer,
gint col_limit,
gboolean dither_alpha,
GimpProgress *progress,
gint nth_layer,
gint n_layers)
GimpProgress *progress)
{
GeglBufferIterator *iter;
const Babl *format;
......@@ -1340,8 +1350,7 @@ generate_histogram_rgb (CFHistogram histogram,
if (progress && (count % 16 == 0))
gimp_progress_set_value (progress,
(nth_layer + ((gdouble) total_size)/
layer_size) / (gdouble) n_layers);
(gdouble) total_size / (gdouble) layer_size);
}
/* g_print ("O: col_limit = %d, nfc = %d\n", col_limit, num_found_cols);*/
......@@ -3098,8 +3107,6 @@ median_cut_pass2_no_dither_rgb (QuantizeObj *quantobj,
glong total_size = 0;
glong layer_size;
gint count = 0;
gint nth_layer = quantobj->nth_layer;
gint n_layers = quantobj->n_layers;
gimp_item_get_offset (GIMP_ITEM (layer), &offsetx, &offsety);
......@@ -3198,8 +3205,7 @@ median_cut_pass2_no_dither_rgb (QuantizeObj *quantobj,
if (quantobj->progress && (count % 16 == 0))
gimp_progress_set_value (quantobj->progress,
(nth_layer + ((gdouble) total_size)/
layer_size) / (gdouble) n_layers);
(gdouble) total_size / (gdouble) layer_size);
}
}
......@@ -3234,8 +3240,6 @@ median_cut_pass2_fixed_dither_rgb (QuantizeObj *quantobj,
glong total_size = 0;
glong layer_size;
gint count = 0;
gint nth_layer = quantobj->nth_layer;
gint n_layers = quantobj->n_layers;
gimp_item_get_offset (GIMP_ITEM (layer), &offsetx, &offsety);
......@@ -3433,8 +3437,7 @@ median_cut_pass2_fixed_dither_rgb (QuantizeObj *quantobj,
if (quantobj->progress && (count % 16 == 0))
gimp_progress_set_value (quantobj->progress,
(nth_layer + ((gdouble) total_size)/
layer_size) / (gdouble) n_layers);
(gdouble) total_size / (gdouble) layer_size);
}
}
......@@ -3946,8 +3949,6 @@ median_cut_pass2_fs_dither_rgb (QuantizeObj *quantobj,
gint global_rmax = 0, global_rmin = G_MAXINT;
gint global_gmax = 0, global_gmin = G_MAXINT;
gint global_bmax = 0, global_bmin = G_MAXINT;
gint nth_layer = quantobj->nth_layer;
gint n_layers = quantobj->n_layers;
src_buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
......@@ -4265,8 +4266,7 @@ median_cut_pass2_fs_dither_rgb (QuantizeObj *quantobj,
if (quantobj->progress && (row % 16 == 0))
gimp_progress_set_value (quantobj->progress,
(nth_layer + ((gdouble) row) /
height) / (gdouble) n_layers);
(gdouble) row / (gdouble) height);
}
g_free (error_limiter - 255);
......
......@@ -30,6 +30,7 @@
#include "gegl/gimp-babl.h"
#include "gimpchannel.h"
#include "gimpdrawable.h"
#include "gimpdrawable-operation.h"
#include "gimpimage.h"
......@@ -37,8 +38,8 @@
#include "gimpimage-convert-precision.h"
#include "gimpimage-undo.h"
#include "gimpimage-undo-push.h"
#include "gimpobjectqueue.h"
#include "gimpprogress.h"
#include "gimpsubprogress.h"
#include "text/gimptextlayer.h"
......@@ -57,11 +58,10 @@ gimp_image_convert_precision (GimpImage *image,
GimpColorProfile *new_profile = NULL;
const Babl *old_format;
const Babl *new_format;
GList *all_drawables;
GList *list;
GimpObjectQueue *queue;
GList *layers;
GimpDrawable *drawable;
const gchar *undo_desc = NULL;
GimpProgress *sub_progress = NULL;
gint nth_drawable, n_drawables;
g_return_if_fail (GIMP_IS_IMAGE (image));
g_return_if_fail (precision != gimp_image_get_precision (image));
......@@ -69,14 +69,6 @@ gimp_image_convert_precision (GimpImage *image,
gimp_image_get_base_type (image) != GIMP_INDEXED);
g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
all_drawables = g_list_concat (gimp_image_get_layer_list (image),
gimp_image_get_channel_list (image));
n_drawables = g_list_length (all_drawables) + 1 /* + selection */;
if (progress)
sub_progress = gimp_sub_progress_new (progress);
switch (precision)
{
case GIMP_PRECISION_U8_LINEAR:
......@@ -120,6 +112,16 @@ gimp_image_convert_precision (GimpImage *image,
if (progress)
gimp_progress_start (progress, FALSE, "%s", undo_desc);
queue = gimp_object_queue_new (progress);
progress = GIMP_PROGRESS (queue);
layers = gimp_image_get_layer_list (image);
gimp_object_queue_push_list (queue, layers);
g_list_free (layers);
gimp_object_queue_push (queue, gimp_image_get_mask (image));
gimp_object_queue_push_container (queue, gimp_image_get_channels (image));
g_object_freeze_notify (G_OBJECT (image));
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_IMAGE_CONVERT,
......@@ -172,33 +174,46 @@ gimp_image_convert_precision (GimpImage *image,
new_profile = g_object_ref (old_profile);
}
for (list = all_drawables, nth_drawable = 0;
list;
list = g_list_next (list), nth_drawable++)
while ((drawable = gimp_object_queue_pop (queue)))
{
GimpDrawable *drawable = list->data;
gint dither_type;
if (drawable == GIMP_DRAWABLE (gimp_image_get_mask (image)))
{
GeglBuffer *buffer;
if (gimp_item_is_text_layer (GIMP_ITEM (drawable)))
dither_type = text_layer_dither_type;
gimp_image_undo_push_mask_precision (image, NULL,
GIMP_CHANNEL (drawable));
buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0,
gimp_image_get_width (image),
gimp_image_get_height (image)),
gimp_image_get_mask_format (image));
gegl_buffer_copy (gimp_drawable_get_buffer (drawable), NULL,
GEGL_ABYSS_NONE,
buffer, NULL);
gimp_drawable_set_buffer (drawable, FALSE, NULL, buffer);
g_object_unref (buffer);
}
else
dither_type = layer_dither_type;
if (sub_progress)
gimp_sub_progress_set_step (GIMP_SUB_PROGRESS (sub_progress),
nth_drawable, n_drawables);
gimp_drawable_convert_type (drawable, image,
gimp_drawable_get_base_type (drawable),
precision,
gimp_drawable_has_alpha (drawable),
new_profile,
dither_type,
mask_dither_type,
TRUE, sub_progress);
}
{
gint dither_type;
g_list_free (all_drawables);
if (gimp_item_is_text_layer (GIMP_ITEM (drawable)))
dither_type = text_layer_dither_type;
else
dither_type = layer_dither_type;
gimp_drawable_convert_type (drawable, image,
gimp_drawable_get_base_type (drawable),
precision,
gimp_drawable_has_alpha (drawable),
new_profile,
dither_type,
mask_dither_type,
TRUE, progress);
}
}
if (new_profile)
{
......@@ -208,42 +223,12 @@ gimp_image_convert_precision (GimpImage *image,
g_object_unref (new_profile);
}
/* convert the selection mask */
{
GimpChannel *mask = gimp_image_get_mask (image);
GeglBuffer *buffer;
if (sub_progress)
gimp_sub_progress_set_step (GIMP_SUB_PROGRESS (sub_progress),
nth_drawable, n_drawables);
gimp_image_undo_push_mask_precision (image, NULL, mask);
buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0,
gimp_image_get_width (image),
gimp_image_get_height (image)),
gimp_image_get_mask_format (image));
gegl_buffer_copy (gimp_drawable_get_buffer (GIMP_DRAWABLE (mask)), NULL,
GEGL_ABYSS_NONE,
buffer, NULL);
gimp_drawable_set_buffer (GIMP_DRAWABLE (mask), FALSE, NULL, buffer);
g_object_unref (buffer);
nth_drawable++;
}
if (sub_progress)
gimp_progress_set_value (sub_progress, 1.0);
gimp_image_undo_group_end (image);
gimp_image_precision_changed (image);
g_object_thaw_notify (G_OBJECT (image));
if (sub_progress)
g_object_unref (sub_progress);
g_object_unref (queue);
if (progress)
gimp_progress_end (progress);
......@@ -270,37 +255,41 @@ gimp_image_convert_dither_u8 (GimpImage *image,
if (dither)
{
GList *drawables;
GList *list;
GimpObjectQueue *queue;
GList *layers;
GList *list;
GimpDrawable *drawable;
if (progress)
gimp_progress_start (progress, FALSE, "%s", _("Dithering"));
drawables = gimp_image_get_layer_list (image);
queue = gimp_object_queue_new (progress);
progress = GIMP_PROGRESS (queue);
for (list = drawables; list; list = g_list_next (list))
layers = gimp_image_get_layer_list (image);
for (list = layers; list; list = g_list_next (list))
{
if (! gimp_viewable_get_children (list->data) &&
! gimp_item_is_text_layer (list->data))
{
gimp_drawable_apply_operation (list->data, progress,
_("Dithering"),
dither);
gimp_object_queue_push (queue, list->data);
}
}
g_list_free (drawables);
g_list_free (layers);
drawables = gimp_image_get_channel_list (image);
gimp_object_queue_push (queue, gimp_image_get_mask (image));
gimp_object_queue_push_container (queue, gimp_image_get_channels (image));
for (list = drawables; list; list = g_list_next (list))
while ((drawable = gimp_object_queue_pop (queue)))
{
if (! gimp_viewable_get_children (list->data))
{
gimp_drawable_apply_operation (list->data, progress,