[gimp] app: keep GimpImage's profile around as GimpColorProfile



commit 1715e1e60bfbe22f19c808efdbf146f646216384
Author: Michael Natterer <mitch gimp org>
Date:   Sun Aug 16 19:38:11 2015 +0200

    app: keep GimpImage's profile around as GimpColorProfile
    
    not only as parasite. This way we avoid having to create the profile
    in each call to gimp_image_get_color_profile(). Also keep the built-in
    profiles around in gimp_image_get_builtin_color_profile(). Add/remove
    refs and unrefs as needed in all users of these functions.

 app/actions/image-actions.c              |    2 +-
 app/core/gimpimage-color-profile.c       |   46 ++++++++++++++++++++----------
 app/core/gimpimage-private.h             |    1 +
 app/core/gimpimage.c                     |   34 +++++++++++++++++++--
 app/dialogs/color-profile-dialog.c       |    6 +++-
 app/pdb/image-color-profile-cmds.c       |    2 -
 tools/pdbgen/pdb/image_color_profile.pdb |    2 -
 7 files changed, 68 insertions(+), 25 deletions(-)
---
diff --git a/app/actions/image-actions.c b/app/actions/image-actions.c
index 0de3c4a..be9ea41 100644
--- a/app/actions/image-actions.c
+++ b/app/actions/image-actions.c
@@ -414,7 +414,7 @@ image_actions_update (GimpActionGroup *group,
 
       groups = ! gimp_item_stack_is_flat (GIMP_ITEM_STACK (layers));
 
-      profile = (gimp_image_get_icc_parasite (image) != NULL);
+      profile = (gimp_image_get_color_profile (image) != NULL);
     }
 
 #define SET_SENSITIVE(action,condition) \
diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c
index c5b9aac..982d08a 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -43,6 +43,7 @@
 #include "gimpimage.h"
 #include "gimpimage-color-profile.h"
 #include "gimpimage-colormap.h"
+#include "gimpimage-private.h"
 #include "gimpimage-undo.h"
 #include "gimpprogress.h"
 
@@ -248,18 +249,9 @@ gimp_image_validate_color_profile (GimpImage        *image,
 GimpColorProfile *
 gimp_image_get_color_profile (GimpImage *image)
 {
-  const GimpParasite *parasite;
-
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
-  parasite = gimp_image_get_icc_parasite (image);
-
-  if (parasite)
-    return gimp_color_profile_new_from_icc_profile (gimp_parasite_data (parasite),
-                                                    gimp_parasite_data_size (parasite),
-                                                    NULL);
-
-  return NULL;
+  return GIMP_IMAGE_GET_PRIVATE (image)->color_profile;
 }
 
 gboolean
@@ -284,16 +276,42 @@ gimp_image_set_color_profile (GimpImage         *image,
 GimpColorProfile *
 gimp_image_get_builtin_color_profile (GimpImage *image)
 {
-  const Babl *format;
+  static GimpColorProfile *srgb_profile       = NULL;
+  static GimpColorProfile *linear_rgb_profile = NULL;
+  const  Babl             *format;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
+  if (! srgb_profile)
+    {
+      srgb_profile       = gimp_color_profile_new_srgb ();
+      linear_rgb_profile = gimp_color_profile_new_linear_rgb ();
+    }
+
   format = gimp_image_get_layer_format (image, FALSE);
 
   if (gimp_babl_format_get_linear (format))
-    return gimp_color_profile_new_linear_rgb ();
+    {
+      if (! srgb_profile)
+        {
+          srgb_profile = gimp_color_profile_new_srgb ();
+          g_object_add_weak_pointer (G_OBJECT (srgb_profile),
+                                     (gpointer) &srgb_profile);
+        }
+
+      return linear_rgb_profile;
+    }
   else
-    return gimp_color_profile_new_srgb ();
+    {
+      if (! linear_rgb_profile)
+        {
+          linear_rgb_profile = gimp_color_profile_new_linear_rgb ();
+          g_object_add_weak_pointer (G_OBJECT (linear_rgb_profile),
+                                     (gpointer) &linear_rgb_profile);
+        }
+
+      return srgb_profile;
+    }
 }
 
 gboolean
@@ -344,8 +362,6 @@ gimp_image_convert_color_profile (GimpImage                *image,
       gimp_image_set_color_profile (image, dest_profile, NULL);
     }
 
-  g_object_unref (builtin_profile);
-
   /*  omg...  */
   gimp_image_parasite_detach (image, "icc-profile-name");
 
diff --git a/app/core/gimpimage-private.h b/app/core/gimpimage-private.h
index 6cec1c1..bfc85d1 100644
--- a/app/core/gimpimage-private.h
+++ b/app/core/gimpimage-private.h
@@ -55,6 +55,7 @@ struct _GimpImagePrivate
   GimpPalette       *palette;               /*  palette of colormap          */
   const Babl        *babl_palette_rgb;      /*  palette's RGB Babl format    */
   const Babl        *babl_palette_rgba;     /*  palette's RGBA Babl format   */
+  GimpColorProfile  *color_profile;         /*  image's color profile        */
 
   GimpMetadata      *metadata;              /*  image's metadata             */
 
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 59ff32e..256cecb 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -966,6 +966,12 @@ gimp_image_finalize (GObject *object)
   if (private->colormap)
     gimp_image_colormap_free (image);
 
+  if (private->color_profile)
+    {
+      g_object_unref (private->color_profile);
+      private->color_profile = NULL;
+    }
+
   if (private->metadata)
     {
       g_object_unref (private->metadata);
@@ -1376,6 +1382,8 @@ gimp_image_color_managed_get_color_profile (GimpColorManaged *managed)
   GimpColorProfile *profile;
 
   profile = gimp_image_get_color_profile (image);
+  if (profile)
+    g_object_ref (profile);
 
   if (! profile)
     {
@@ -1385,7 +1393,10 @@ gimp_image_color_managed_get_color_profile (GimpColorManaged *managed)
     }
 
   if (! profile)
-    profile = gimp_image_get_builtin_color_profile (image);
+    {
+      profile = gimp_image_get_builtin_color_profile (image);
+      g_object_ref (profile);
+    }
 
   return profile;
 }
@@ -3308,11 +3319,14 @@ void
 gimp_image_parasite_attach (GimpImage          *image,
                             const GimpParasite *parasite)
 {
-  GimpParasite  copy;
+  GimpImagePrivate *priv;
+  GimpParasite      copy;
 
   g_return_if_fail (GIMP_IS_IMAGE (image));
   g_return_if_fail (parasite != NULL);
 
+  priv = GIMP_IMAGE_GET_PRIVATE (image);
+
   /*  make a temporary copy of the GimpParasite struct because
    *  gimp_parasite_shift_parent() changes it
    */
@@ -3332,7 +3346,7 @@ gimp_image_parasite_attach (GimpImage          *image,
    *  Now we simply attach the parasite without pushing an undo. That way
    *  it's undoable but does not block the undo system.   --Sven
    */
-  gimp_parasite_list_add (GIMP_IMAGE_GET_PRIVATE (image)->parasites, &copy);
+  gimp_parasite_list_add (priv->parasites, &copy);
 
   if (gimp_parasite_has_flag (&copy, GIMP_PARASITE_ATTACH_PARENT))
     {
@@ -3344,7 +3358,19 @@ gimp_image_parasite_attach (GimpImage          *image,
                  gimp_parasite_name (parasite));
 
   if (strcmp (gimp_parasite_name (parasite), GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
-    gimp_color_managed_profile_changed (GIMP_COLOR_MANAGED (image));
+    {
+      GimpColorProfile *profile =
+        gimp_color_profile_new_from_icc_profile (gimp_parasite_data (parasite),
+                                                 gimp_parasite_data_size (parasite),
+                                                 NULL);
+
+      if (priv->color_profile)
+        g_object_unref (priv->color_profile);
+
+      priv->color_profile = profile;
+
+      gimp_color_managed_profile_changed (GIMP_COLOR_MANAGED (image));
+    }
 }
 
 void
diff --git a/app/dialogs/color-profile-dialog.c b/app/dialogs/color-profile-dialog.c
index a8242ce..8c36148 100644
--- a/app/dialogs/color-profile-dialog.c
+++ b/app/dialogs/color-profile-dialog.c
@@ -301,7 +301,10 @@ color_profile_combo_box_new (ProfileDialog *dialog)
     }
 
   if (! profile)
-    profile = gimp_image_get_builtin_color_profile (dialog->image);
+    {
+      profile = gimp_image_get_builtin_color_profile (dialog->image);
+      g_object_ref (profile);
+    }
 
   label = g_strdup_printf (_("RGB workspace (%s)"),
                            gimp_color_profile_get_label (profile));
@@ -360,6 +363,7 @@ color_profile_dialog_response (GtkWidget     *widget,
               else
                 {
                   dest_profile = gimp_image_get_builtin_color_profile (dialog->image);
+                  g_object_ref (dest_profile);
                 }
             }
         }
diff --git a/app/pdb/image-color-profile-cmds.c b/app/pdb/image-color-profile-cmds.c
index 359adf4..53e5b2e 100644
--- a/app/pdb/image-color-profile-cmds.c
+++ b/app/pdb/image-color-profile-cmds.c
@@ -73,8 +73,6 @@ image_get_color_profile_invoker (GimpProcedure         *procedure,
 
           profile_data = g_memdup (data, length);
           num_bytes = length;
-
-          g_object_unref (profile);
         }
     }
 
diff --git a/tools/pdbgen/pdb/image_color_profile.pdb b/tools/pdbgen/pdb/image_color_profile.pdb
index 4ea21df..a489b04 100644
--- a/tools/pdbgen/pdb/image_color_profile.pdb
+++ b/tools/pdbgen/pdb/image_color_profile.pdb
@@ -54,8 +54,6 @@ HELP
 
       profile_data = g_memdup (data, length);
       num_bytes = length;
-
-      g_object_unref (profile);
     }
 }
 CODE


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