[gimp] app: make image and projection size estimations precision-aware



commit 101a9b9887902a573f03150a960f46b691ca6bce
Author: Michael Natterer <mitch gimp org>
Date:   Fri Aug 24 22:16:02 2012 +0200

    app: make image and projection size estimations precision-aware
    
    GimpProjection estimation was still assuming 8 bit, so was
    GimpTemplate. Also, calculate GIMP_PROJECTION_IDLE_PRIORITY
    inatead of hardcoding it.

 app/core/gimpgrouplayer.c  |    4 +++-
 app/core/gimpimage-scale.c |    2 ++
 app/core/gimpprojection.c  |   31 +++++++++++++++----------------
 app/core/gimpprojection.h  |    1 +
 app/core/gimptemplate.c    |   22 ++++++++++++++++------
 5 files changed, 37 insertions(+), 23 deletions(-)
---
diff --git a/app/core/gimpgrouplayer.c b/app/core/gimpgrouplayer.c
index 8d3bc3e..c833b05 100644
--- a/app/core/gimpgrouplayer.c
+++ b/app/core/gimpgrouplayer.c
@@ -811,7 +811,9 @@ gimp_group_layer_estimate_memsize (const GimpDrawable *drawable,
 
   base_type = gimp_drawable_get_base_type (drawable);
 
-  memsize += gimp_projection_estimate_memsize (base_type, width, height);
+  memsize += gimp_projection_estimate_memsize (base_type,
+                                               gimp_drawable_get_precision (drawable),
+                                               width, height);
 
   return memsize + GIMP_DRAWABLE_CLASS (parent_class)->estimate_memsize (drawable,
                                                                          width,
diff --git a/app/core/gimpimage-scale.c b/app/core/gimpimage-scale.c
index 8ab7c6d..2e8b129 100644
--- a/app/core/gimpimage-scale.c
+++ b/app/core/gimpimage-scale.c
@@ -304,11 +304,13 @@ gimp_image_scale_check (const GimpImage *image,
 
   scalable_size +=
     gimp_projection_estimate_memsize (gimp_image_get_base_type (image),
+                                      gimp_image_get_precision (image),
                                       gimp_image_get_width (image),
                                       gimp_image_get_height (image));
 
   scaled_size +=
     gimp_projection_estimate_memsize (gimp_image_get_base_type (image),
+                                      gimp_image_get_precision (image),
                                       new_width, new_height);
 
   GIMP_LOG (IMAGE_SCALE,
diff --git a/app/core/gimpprojection.c b/app/core/gimpprojection.c
index b8cee63..83f32fd 100644
--- a/app/core/gimpprojection.c
+++ b/app/core/gimpprojection.c
@@ -22,6 +22,7 @@
 
 #include "core-types.h"
 
+#include "gegl/gimp-babl.h"
 #include "gegl/gimp-gegl-utils.h"
 #include "gegl/gimptilehandlerprojection.h"
 
@@ -36,7 +37,8 @@
 
 
 /*  halfway between G_PRIORITY_HIGH_IDLE and G_PRIORITY_DEFAULT_IDLE  */
-#define  GIMP_PROJECTION_IDLE_PRIORITY  150
+#define GIMP_PROJECTION_IDLE_PRIORITY \
+        ((G_PRIORITY_HIGH_IDLE + G_PRIORITY_DEFAULT_IDLE) / 2)
 
 
 enum
@@ -192,9 +194,10 @@ gimp_projection_get_memsize (GimpObject *object,
 
 /**
  * gimp_projection_estimate_memsize:
- * @type:   the image base type
- * @width:  projection width
- * @height: projection height
+ * @type:      the projectable's base type
+ * @precision: the projectable's precision
+ * @width:     projection width
+ * @height:    projection height
  *
  * Calculates a rough estimate of the memory that is required for the
  * projection of an image with the given @width and @height.
@@ -203,22 +206,18 @@ gimp_projection_get_memsize (GimpObject *object,
  **/
 gint64
 gimp_projection_estimate_memsize (GimpImageBaseType type,
+                                  GimpPrecision     precision,
                                   gint              width,
                                   gint              height)
 {
-  gint64 bytes = 0;
+  const Babl *format;
+  gint64      bytes;
 
-  switch (type)
-    {
-    case GIMP_RGB:
-    case GIMP_INDEXED:
-      bytes = 4;
-      break;
-
-    case GIMP_GRAY:
-      bytes = 2;
-      break;
-    }
+  if (type == GIMP_INDEXED)
+    type = GIMP_RGB;
+
+  format = gimp_babl_format (type, precision, TRUE);
+  bytes  = babl_format_get_bytes_per_pixel (format);
 
   /* The pyramid levels constitute a geometric sum with a ratio of 1/4. */
   return bytes * (gint64) width * (gint64) height * 1.33;
diff --git a/app/core/gimpprojection.h b/app/core/gimpprojection.h
index 95040d7..d6af5dc 100644
--- a/app/core/gimpprojection.h
+++ b/app/core/gimpprojection.h
@@ -85,6 +85,7 @@ void             gimp_projection_flush_now        (GimpProjection    *proj);
 void             gimp_projection_finish_draw      (GimpProjection    *proj);
 
 gint64           gimp_projection_estimate_memsize (GimpImageBaseType  type,
+                                                   GimpPrecision      precision,
                                                    gint               width,
                                                    gint               height);
 
diff --git a/app/core/gimptemplate.c b/app/core/gimptemplate.c
index d2d5c6a..adb6d09 100644
--- a/app/core/gimptemplate.c
+++ b/app/core/gimptemplate.c
@@ -30,6 +30,8 @@
 
 #include "core-types.h"
 
+#include "gegl/gimp-babl.h"
+
 #include "gimpimage.h"
 #include "gimpprojection.h"
 #include "gimptemplate.h"
@@ -316,23 +318,31 @@ gimp_template_notify (GObject    *object,
                       GParamSpec *pspec)
 {
   GimpTemplatePrivate *private = GET_PRIVATE (object);
-  gint                 channels;
+  const Babl          *format;
+  gint                 bytes;
 
   if (G_OBJECT_CLASS (parent_class)->notify)
     G_OBJECT_CLASS (parent_class)->notify (object, pspec);
 
-  channels = ((private->base_type == GIMP_RGB ? 3 : 1)      /* color      */ +
-              (private->fill_type == GIMP_TRANSPARENT_FILL) /* alpha      */ +
-              1                                             /* selection  */);
+  /* the initial layer */
+  format = gimp_babl_format (private->base_type,
+                             private->precision,
+                             private->fill_type == GIMP_TRANSPARENT_FILL);
+  bytes = babl_format_get_bytes_per_pixel (format);
 
-  /* XXX todo honor precision */
+  /* the selection */
+  format = gimp_babl_format (GIMP_GRAY,
+                             private->precision,
+                             FALSE);
+  bytes += babl_format_get_bytes_per_pixel (format);
 
-  private->initial_size = ((guint64) channels       *
+  private->initial_size = ((guint64) bytes          *
                            (guint64) private->width *
                            (guint64) private->height);
 
   private->initial_size +=
     gimp_projection_estimate_memsize (private->base_type,
+                                      private->precision,
                                       private->width, private->height);
 
   if (! strcmp (pspec->name, "stock-id"))



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