[gimp/blend-tool-fun: 152/163] app: add progress reporting to gimp_drawable_convert_type()



commit 7e9deb5283d6878d2aca744f8e1117dde95fd7cf
Author: Michael Natterer <mitch gimp org>
Date:   Wed Oct 21 22:22:30 2015 +0200

    app: add progress reporting to gimp_drawable_convert_type()
    
    so it doesn't sit there appearing to do nothing while converting an
    image with profile to gamma/linear.

 app/core/gimpchannel.c                 |    8 +++++---
 app/core/gimpdrawable.c                |   16 ++++++++++++----
 app/core/gimpdrawable.h                |    6 ++++--
 app/core/gimpgrouplayer.c              |    8 +++++---
 app/core/gimpgrouplayerundo.c          |    2 +-
 app/core/gimpimage-convert-precision.c |   29 ++++++++++++++++++++---------
 app/core/gimpimage-convert-type.c      |    2 +-
 app/core/gimplayer.c                   |   12 +++++++-----
 app/core/gimplayermask.c               |    9 ++++++---
 app/core/gimpselection.c               |    9 ++++++---
 app/text/gimptextlayer.c               |    9 ++++++---
 app/text/gimptextundo.c                |    2 +-
 12 files changed, 74 insertions(+), 38 deletions(-)
---
diff --git a/app/core/gimpchannel.c b/app/core/gimpchannel.c
index f5506a0..8fb1957 100644
--- a/app/core/gimpchannel.c
+++ b/app/core/gimpchannel.c
@@ -143,7 +143,8 @@ static void       gimp_channel_convert_type  (GimpDrawable      *drawable,
                                               gint               layer_dither_type,
                                               gint               mask_dither_type,
                                               gboolean           convert_profile,
-                                              gboolean           push_undo);
+                                              gboolean           push_undo,
+                                              GimpProgress      *progress);
 static void gimp_channel_invalidate_boundary   (GimpDrawable       *drawable);
 static void gimp_channel_get_active_components (const GimpDrawable *drawable,
                                                 gboolean           *active);
@@ -556,7 +557,7 @@ gimp_channel_convert (GimpItem  *item,
       gimp_drawable_convert_type (drawable, dest_image, GIMP_GRAY,
                                   gimp_image_get_precision (dest_image),
                                   0, 0, FALSE,
-                                  FALSE);
+                                  FALSE, NULL);
     }
 
   if (gimp_drawable_has_alpha (drawable))
@@ -899,7 +900,8 @@ gimp_channel_convert_type (GimpDrawable      *drawable,
                            gint               layer_dither_type,
                            gint               mask_dither_type,
                            gboolean           convert_profile,
-                           gboolean           push_undo)
+                           gboolean           push_undo,
+                           GimpProgress      *progress)
 {
   GeglBuffer *dest_buffer;
 
diff --git a/app/core/gimpdrawable.c b/app/core/gimpdrawable.c
index 360463c..fb1294c 100644
--- a/app/core/gimpdrawable.c
+++ b/app/core/gimpdrawable.c
@@ -155,7 +155,8 @@ static void       gimp_drawable_real_convert_type  (GimpDrawable      *drawable,
                                                     gint               layer_dither_type,
                                                     gint               mask_dither_type,
                                                     gboolean           convert_profile,
-                                                    gboolean           push_undo);
+                                                    gboolean           push_undo,
+                                                    GimpProgress      *progress);
 
 static GeglBuffer * gimp_drawable_real_get_buffer  (GimpDrawable      *drawable);
 static void       gimp_drawable_real_set_buffer    (GimpDrawable      *drawable,
@@ -791,7 +792,8 @@ gimp_drawable_real_convert_type (GimpDrawable      *drawable,
                                  gint               layer_dither_type,
                                  gint               mask_dither_type,
                                  gboolean           convert_type,
-                                 gboolean           push_undo)
+                                 gboolean           push_undo,
+                                 GimpProgress      *progress)
 {
   GeglBuffer *dest_buffer;
 
@@ -1259,7 +1261,8 @@ gimp_drawable_convert_type (GimpDrawable      *drawable,
                             gint               layer_dither_type,
                             gint               mask_dither_type,
                             gboolean           convert_profile,
-                            gboolean           push_undo)
+                            gboolean           push_undo,
+                            GimpProgress      *progress)
 {
   const Babl *new_format;
 
@@ -1268,6 +1271,7 @@ gimp_drawable_convert_type (GimpDrawable      *drawable,
   g_return_if_fail (new_base_type != gimp_drawable_get_base_type (drawable) ||
                     new_precision != gimp_drawable_get_precision (drawable) ||
                     convert_profile);
+  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
 
   if (! gimp_item_is_attached (GIMP_ITEM (drawable)))
     push_undo = FALSE;
@@ -1284,7 +1288,11 @@ gimp_drawable_convert_type (GimpDrawable      *drawable,
                                                     layer_dither_type,
                                                     mask_dither_type,
                                                     convert_profile,
-                                                    push_undo);
+                                                    push_undo,
+                                                    progress);
+
+  if (progress)
+    gimp_progress_set_value (progress, 1.0);
 }
 
 void
diff --git a/app/core/gimpdrawable.h b/app/core/gimpdrawable.h
index 2016d80..a0ad15b 100644
--- a/app/core/gimpdrawable.h
+++ b/app/core/gimpdrawable.h
@@ -69,7 +69,8 @@ struct _GimpDrawableClass
                                            gint                  layer_dither_type,
                                            gint                  mask_dither_type,
                                            gboolean              convert_profile,
-                                           gboolean              push_undo);
+                                           gboolean              push_undo,
+                                           GimpProgress         *progress);
   void          (* apply_buffer)          (GimpDrawable         *drawable,
                                            GeglBuffer           *buffer,
                                            const GeglRectangle  *buffer_region,
@@ -146,7 +147,8 @@ void            gimp_drawable_convert_type       (GimpDrawable       *drawable,
                                                   gint                layer_dither_type,
                                                   gint                mask_dither_type,
                                                   gboolean            convert_profile,
-                                                  gboolean            push_undo);
+                                                  gboolean            push_undo,
+                                                  GimpProgress       *progress);
 
 void            gimp_drawable_apply_buffer       (GimpDrawable        *drawable,
                                                   GeglBuffer          *buffer,
diff --git a/app/core/gimpgrouplayer.c b/app/core/gimpgrouplayer.c
index 8ddb4b9..b47f7ff 100644
--- a/app/core/gimpgrouplayer.c
+++ b/app/core/gimpgrouplayer.c
@@ -144,7 +144,8 @@ static void            gimp_group_layer_convert_type (GimpDrawable      *drawabl
                                                       gint               layer_dither_type,
                                                       gint               mask_dither_type,
                                                       gboolean           convert_profile,
-                                                      gboolean           push_undo);
+                                                      gboolean           push_undo,
+                                                      GimpProgress      *progress);
 
 static const Babl    * gimp_group_layer_get_format   (GimpProjectable *projectable);
 static GeglNode      * gimp_group_layer_get_graph    (GimpProjectable *projectable);
@@ -883,7 +884,8 @@ gimp_group_layer_convert_type (GimpDrawable      *drawable,
                                gint               layer_dither_type,
                                gint               mask_dither_type,
                                gboolean           convert_profile,
-                               gboolean           push_undo)
+                               gboolean           push_undo,
+                               GimpProgress      *progress)
 {
   GimpGroupLayer        *group   = GIMP_GROUP_LAYER (drawable);
   GimpGroupLayerPrivate *private = GET_PRIVATE (drawable);
@@ -927,7 +929,7 @@ gimp_group_layer_convert_type (GimpDrawable      *drawable,
                                   GIMP_GRAY, new_precision,
                                   layer_dither_type, mask_dither_type,
                                   convert_profile,
-                                  push_undo);
+                                  push_undo, progress);
     }
 }
 
diff --git a/app/core/gimpgrouplayerundo.c b/app/core/gimpgrouplayerundo.c
index 9703afa..ee46313 100644
--- a/app/core/gimpgrouplayerundo.c
+++ b/app/core/gimpgrouplayerundo.c
@@ -129,7 +129,7 @@ gimp_group_layer_undo_pop (GimpUndo            *undo,
                                     group_layer_undo->prev_type,
                                     group_layer_undo->prev_precision,
                                     0, 0, FALSE,
-                                    FALSE);
+                                    FALSE, NULL);
 
         group_layer_undo->prev_type      = type;
         group_layer_undo->prev_precision = precision;
diff --git a/app/core/gimpimage-convert-precision.c b/app/core/gimpimage-convert-precision.c
index e2c67b8..fbd6f88 100644
--- a/app/core/gimpimage-convert-precision.c
+++ b/app/core/gimpimage-convert-precision.c
@@ -37,6 +37,7 @@
 #include "gimpimage-undo.h"
 #include "gimpimage-undo-push.h"
 #include "gimpprogress.h"
+#include "gimpsubprogress.h"
 
 #include "text/gimptextlayer.h"
 
@@ -56,7 +57,8 @@ gimp_image_convert_precision (GimpImage     *image,
   const Babl       *new_format;
   GList            *all_drawables;
   GList            *list;
-  const gchar      *undo_desc = NULL;
+  const gchar      *undo_desc    = NULL;
+  GimpProgress     *sub_progress = NULL;
   gint              nth_drawable, n_drawables;
 
   g_return_if_fail (GIMP_IS_IMAGE (image));
@@ -70,6 +72,9 @@ gimp_image_convert_precision (GimpImage     *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:
@@ -141,17 +146,17 @@ gimp_image_convert_precision (GimpImage     *image,
       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,
                                   dither_type,
                                   mask_dither_type,
                                   old_profile != NULL,
-                                  TRUE);
-
-      if (progress)
-        gimp_progress_set_value (progress,
-                                 (gdouble) nth_drawable / (gdouble) n_drawables);
+                                  TRUE, sub_progress);
     }
 
   g_list_free (all_drawables);
@@ -187,6 +192,10 @@ gimp_image_convert_precision (GimpImage     *image,
     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,
@@ -203,9 +212,8 @@ gimp_image_convert_precision (GimpImage     *image,
 
     nth_drawable++;
 
-    if (progress)
-      gimp_progress_set_value (progress,
-                               (gdouble) nth_drawable / (gdouble) n_drawables);
+    if (sub_progress)
+      gimp_progress_set_value (sub_progress, 1.0);
   }
 
   gimp_image_undo_group_end (image);
@@ -213,6 +221,9 @@ gimp_image_convert_precision (GimpImage     *image,
   gimp_image_precision_changed (image);
   g_object_thaw_notify (G_OBJECT (image));
 
+  if (sub_progress)
+    g_object_unref (sub_progress);
+
   if (progress)
     gimp_progress_end (progress);
 }
diff --git a/app/core/gimpimage-convert-type.c b/app/core/gimpimage-convert-type.c
index 1cc8e07..bb8fad4 100644
--- a/app/core/gimpimage-convert-type.c
+++ b/app/core/gimpimage-convert-type.c
@@ -1022,7 +1022,7 @@ gimp_image_convert_type (GimpImage               *image,
           gimp_drawable_convert_type (GIMP_DRAWABLE (layer), image, new_type,
                                       gimp_drawable_get_precision (GIMP_DRAWABLE (layer)),
                                       0, 0, FALSE,
-                                      TRUE);
+                                      TRUE, NULL);
         }
     }
 
diff --git a/app/core/gimplayer.c b/app/core/gimplayer.c
index 3e30dae..d0d5905 100644
--- a/app/core/gimplayer.c
+++ b/app/core/gimplayer.c
@@ -174,7 +174,8 @@ static void       gimp_layer_convert_type       (GimpDrawable       *drawable,
                                                  gint                layer_dither_type,
                                                  gint                mask_dither_type,
                                                  gboolean            convert_type,
-                                                 gboolean            push_undo);
+                                                 gboolean            push_undo,
+                                                 GimpProgress       *progress);
 static void    gimp_layer_invalidate_boundary   (GimpDrawable       *drawable);
 static void    gimp_layer_get_active_components (const GimpDrawable *drawable,
                                                  gboolean           *active);
@@ -812,7 +813,7 @@ gimp_layer_convert (GimpItem  *item,
                                   new_base_type, new_precision,
                                   0, 0,
                                   convert_profile,
-                                  FALSE);
+                                  FALSE, NULL);
     }
 
   if (layer->mask)
@@ -1067,7 +1068,8 @@ gimp_layer_convert_type (GimpDrawable      *drawable,
                          gint               layer_dither_type,
                          gint               mask_dither_type,
                          gboolean           convert_profile,
-                         gboolean           push_undo)
+                         gboolean           push_undo,
+                         GimpProgress      *progress)
 {
   GimpLayer        *layer = GIMP_LAYER (drawable);
   GeglBuffer       *src_buffer;
@@ -1161,7 +1163,7 @@ gimp_layer_convert_type (GimpDrawable      *drawable,
       gimp_gegl_convert_color_profile (src_buffer,  NULL, src_profile,
                                        dest_buffer, NULL, dest_profile,
                                        GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
-                                       TRUE, NULL);
+                                       TRUE, progress);
     }
   else
     {
@@ -1183,7 +1185,7 @@ gimp_layer_convert_type (GimpDrawable      *drawable,
                                   GIMP_GRAY, new_precision,
                                   layer_dither_type, mask_dither_type,
                                   convert_profile,
-                                  push_undo);
+                                  push_undo, NULL);
     }
 }
 
diff --git a/app/core/gimplayermask.c b/app/core/gimplayermask.c
index f5dc8cd..0dd516e 100644
--- a/app/core/gimplayermask.c
+++ b/app/core/gimplayermask.c
@@ -57,7 +57,8 @@ static void            gimp_layer_mask_convert_type       (GimpDrawable      *dr
                                                            gint               layer_dither_type,
                                                            gint               mask_dither_type,
                                                            gboolean           convert_profile,
-                                                           gboolean           push_undo);
+                                                           gboolean           push_undo,
+                                                           GimpProgress      *progress);
 
 
 G_DEFINE_TYPE (GimpLayerMask, gimp_layer_mask, GIMP_TYPE_CHANNEL)
@@ -170,7 +171,8 @@ gimp_layer_mask_convert_type (GimpDrawable      *drawable,
                               gint               layer_dither_type,
                               gint               mask_dither_type,
                               gboolean           convert_profile,
-                              gboolean           push_undo)
+                              gboolean           push_undo,
+                              GimpProgress      *progress)
 {
   new_format = gimp_babl_mask_format (new_precision);
 
@@ -181,7 +183,8 @@ gimp_layer_mask_convert_type (GimpDrawable      *drawable,
                                                     layer_dither_type,
                                                     mask_dither_type,
                                                     convert_profile,
-                                                    push_undo);
+                                                    push_undo,
+                                                    progress);
 }
 
 GimpLayerMask *
diff --git a/app/core/gimpselection.c b/app/core/gimpselection.c
index 071991e..dc2a375 100644
--- a/app/core/gimpselection.c
+++ b/app/core/gimpselection.c
@@ -89,7 +89,8 @@ static void       gimp_selection_convert_type  (GimpDrawable        *drawable,
                                                 gint                 layer_dither_type,
                                                 gint                 mask_dither_type,
                                                 gboolean             convert_profile,
-                                                gboolean             push_undo);
+                                                gboolean             push_undo,
+                                                GimpProgress        *progress);
 static void gimp_selection_invalidate_boundary (GimpDrawable        *drawable);
 
 static gboolean   gimp_selection_boundary      (GimpChannel         *channel,
@@ -311,7 +312,8 @@ gimp_selection_convert_type (GimpDrawable      *drawable,
                              gint               layer_dither_type,
                              gint               mask_dither_type,
                              gboolean           convert_profile,
-                             gboolean           push_undo)
+                             gboolean           push_undo,
+                             GimpProgress      *progress)
 {
   new_format = gimp_babl_mask_format (new_precision);
 
@@ -322,7 +324,8 @@ gimp_selection_convert_type (GimpDrawable      *drawable,
                                                     layer_dither_type,
                                                     mask_dither_type,
                                                     convert_profile,
-                                                    push_undo);
+                                                    push_undo,
+                                                    progress);
 }
 
 static void
diff --git a/app/text/gimptextlayer.c b/app/text/gimptextlayer.c
index 9d2cf07..be973b9 100644
--- a/app/text/gimptextlayer.c
+++ b/app/text/gimptextlayer.c
@@ -92,7 +92,8 @@ static void       gimp_text_layer_convert_type   (GimpDrawable      *drawable,
                                                   gint               layer_dither_type,
                                                   gint               mask_dither_type,
                                                   gboolean           convert_profile,
-                                                  gboolean           push_undo);
+                                                  gboolean           push_undo,
+                                                  GimpProgress      *progress);
 static void       gimp_text_layer_set_buffer     (GimpDrawable      *drawable,
                                                   gboolean           push_undo,
                                                   const gchar       *undo_desc,
@@ -320,7 +321,8 @@ gimp_text_layer_convert_type (GimpDrawable      *drawable,
                               gint               layer_dither_type,
                               gint               mask_dither_type,
                               gboolean           convert_profile,
-                              gboolean           push_undo)
+                              gboolean           push_undo,
+                              GimpProgress      *progress)
 {
   GimpTextLayer *layer = GIMP_TEXT_LAYER (drawable);
   GimpImage     *image = gimp_item_get_image (GIMP_ITEM (layer));
@@ -334,7 +336,8 @@ gimp_text_layer_convert_type (GimpDrawable      *drawable,
                                                         layer_dither_type,
                                                         mask_dither_type,
                                                         convert_profile,
-                                                        push_undo);
+                                                        push_undo,
+                                                        progress);
     }
   else
     {
diff --git a/app/text/gimptextundo.c b/app/text/gimptextundo.c
index 56cbdde..af551b8 100644
--- a/app/text/gimptextundo.c
+++ b/app/text/gimptextundo.c
@@ -274,7 +274,7 @@ gimp_text_undo_pop (GimpUndo            *undo,
                                     gimp_babl_format_get_base_type (text_undo->format),
                                     gimp_babl_format_get_precision (text_undo->format),
                                     0, 0, FALSE,
-                                    FALSE);
+                                    FALSE, NULL);
         text_undo->format = format;
       }
       break;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]