[gimp] app: cache more lcms transforms in GimpImage



commit 0ee27de4636b7ec5c3fce069abfd55a45c27dfd5
Author: Michael Natterer <mitch gimp org>
Date:   Fri Apr 15 16:49:36 2016 +0100

    app: cache more lcms transforms in GimpImage
    
    Keep around transforms not only to/from the image's pixels to
    "R'G'B'A double" (GimpRGB's format), but also to/from "R'G'B'A u8"
    (GdkPixbuf's format). Also add API to access all cached transforms
    and the Babl formats expected when calling lcms.

 app/core/gimpimage-color-profile.c |  153 +++++++++++++++++++++++++++++++-----
 app/core/gimpimage-color-profile.h |   18 ++++
 app/core/gimpimage-private.h       |   15 +++-
 3 files changed, 162 insertions(+), 24 deletions(-)
---
diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c
index 218ed1d..d682631 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -437,7 +437,7 @@ gimp_image_import_color_profile (GimpImage    *image,
                                  GimpProgress *progress,
                                  gboolean      interactive)
 {
-  GimpColorConfig *config = image->gimp->config->color_management;
+  GimpColorConfig *config;
 
   g_return_if_fail (GIMP_IS_IMAGE (image));
   g_return_if_fail (GIMP_IS_CONTEXT (context));
@@ -607,6 +607,82 @@ gimp_image_convert_profile_colormap (GimpImage                *image,
   g_free (cmap);
 }
 
+GimpColorTransform
+gimp_image_get_color_transform_to_srgb_u8 (GimpImage   *image,
+                                           const Babl **pixel_format,
+                                           const Babl **srgb_u8_format)
+{
+  GimpImagePrivate *private;
+
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+  g_return_val_if_fail (pixel_format != NULL, NULL);
+  g_return_val_if_fail (srgb_u8_format != NULL, NULL);
+
+  private = GIMP_IMAGE_GET_PRIVATE (image);
+
+  *pixel_format   = private->transform_layer_format;
+  *srgb_u8_format = private->transform_srgb_u8_format;
+
+  return private->transform_to_srgb_u8;
+}
+
+GimpColorTransform
+gimp_image_get_color_transform_from_srgb_u8 (GimpImage   *image,
+                                             const Babl **pixel_format,
+                                             const Babl **srgb_u8_format)
+{
+  GimpImagePrivate *private;
+
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+  g_return_val_if_fail (pixel_format != NULL, NULL);
+  g_return_val_if_fail (srgb_u8_format != NULL, NULL);
+
+  private = GIMP_IMAGE_GET_PRIVATE (image);
+
+  *pixel_format   = private->transform_layer_format;
+  *srgb_u8_format = private->transform_srgb_u8_format;
+
+  return private->transform_from_srgb_u8;
+}
+
+GimpColorTransform
+gimp_image_get_color_transform_to_srgb_double (GimpImage   *image,
+                                               const Babl **pixel_format,
+                                               const Babl **srgb_double_format)
+{
+  GimpImagePrivate *private;
+
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+  g_return_val_if_fail (pixel_format != NULL, NULL);
+  g_return_val_if_fail (srgb_double_format != NULL, NULL);
+
+  private = GIMP_IMAGE_GET_PRIVATE (image);
+
+  *pixel_format       = private->transform_layer_format;
+  *srgb_double_format = private->transform_srgb_double_format;
+
+  return private->transform_to_srgb_double;
+}
+
+GimpColorTransform
+gimp_image_get_color_transform_from_srgb_double (GimpImage   *image,
+                                                 const Babl **pixel_format,
+                                                 const Babl **srgb_double_format)
+{
+  GimpImagePrivate *private;
+
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+  g_return_val_if_fail (pixel_format != NULL, NULL);
+  g_return_val_if_fail (srgb_double_format != NULL, NULL);
+
+  private = GIMP_IMAGE_GET_PRIVATE (image);
+
+  *pixel_format       = private->transform_layer_format;
+  *srgb_double_format = private->transform_srgb_double_format;
+
+  return private->transform_from_srgb_double;
+}
+
 void
 gimp_image_color_profile_pixel_to_srgb (GimpImage  *image,
                                         const Babl *pixel_format,
@@ -615,7 +691,7 @@ gimp_image_color_profile_pixel_to_srgb (GimpImage  *image,
 {
   GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
 
-  if (private->transform_to_srgb)
+  if (private->transform_to_srgb_double)
     {
       guchar srgb_pixel[32];
 
@@ -624,7 +700,8 @@ gimp_image_color_profile_pixel_to_srgb (GimpImage  *image,
 
       if (pixel_format == private->transform_layer_format)
         {
-          cmsDoTransform (private->transform_to_srgb, pixel, srgb_pixel, 1);
+          cmsDoTransform (private->transform_to_srgb_double,
+                          pixel, srgb_pixel, 1);
         }
       else
         {
@@ -634,10 +711,12 @@ gimp_image_color_profile_pixel_to_srgb (GimpImage  *image,
                                    private->transform_layer_format),
                         pixel, src_pixel, 1);
 
-          cmsDoTransform (private->transform_to_srgb, src_pixel, srgb_pixel, 1);
+          cmsDoTransform (private->transform_to_srgb_double,
+                          src_pixel, srgb_pixel, 1);
         }
 
-      gimp_rgb_set_pixel (color, private->transform_srgb_format, srgb_pixel);
+      gimp_rgb_set_pixel (color, private->transform_srgb_double_format,
+                          srgb_pixel);
     }
   else
     {
@@ -659,17 +738,33 @@ _gimp_image_free_color_profile (GimpImage *image)
       private->color_profile = NULL;
     }
 
-  if (private->transform_to_srgb)
+  if (private->transform_to_srgb_u8)
+    {
+      cmsDeleteTransform (private->transform_to_srgb_u8);
+      private->transform_to_srgb_u8 = NULL;
+    }
+
+  if (private->transform_from_srgb_u8)
+    {
+      cmsDeleteTransform (private->transform_from_srgb_u8);
+      private->transform_from_srgb_u8 = NULL;
+    }
+
+  if (private->transform_to_srgb_double)
     {
-      cmsDeleteTransform (private->transform_to_srgb);
-      private->transform_to_srgb = NULL;
+      cmsDeleteTransform (private->transform_to_srgb_double);
+      private->transform_to_srgb_double = NULL;
     }
 
-  if (private->transform_from_srgb)
+  if (private->transform_from_srgb_double)
     {
-      cmsDeleteTransform (private->transform_from_srgb);
-      private->transform_from_srgb = NULL;
+      cmsDeleteTransform (private->transform_from_srgb_double);
+      private->transform_from_srgb_double = NULL;
     }
+
+  private->transform_layer_format       = NULL;
+  private->transform_srgb_u8_format     = NULL;
+  private->transform_srgb_double_format = NULL;
 }
 
 void
@@ -693,7 +788,8 @@ _gimp_image_update_color_profile (GimpImage          *image,
           cmsHPROFILE       image_lcms;
           cmsHPROFILE       srgb_lcms;
           cmsUInt32Number   image_lcms_format;
-          cmsUInt32Number   srgb_lcms_format;
+          cmsUInt32Number   srgb_u8_lcms_format;
+          cmsUInt32Number   srgb_double_lcms_format;
           cmsUInt32Number   flags;
 
           srgb_profile = gimp_color_profile_new_rgb_srgb ();
@@ -703,27 +799,44 @@ _gimp_image_update_color_profile (GimpImage          *image,
 
           private->transform_layer_format = gimp_image_get_layer_format (image,
                                                                          TRUE);
-          private->transform_srgb_format  = babl_format ("R'G'B'A double");
+          private->transform_srgb_u8_format     = babl_format ("R'G'B'A u8");
+          private->transform_srgb_double_format = babl_format ("R'G'B'A double");
 
           private->transform_layer_format =
             gimp_color_profile_get_format (private->transform_layer_format,
                                            &image_lcms_format);
 
-          private->transform_srgb_format =
-            gimp_color_profile_get_format (private->transform_srgb_format,
-                                           &srgb_lcms_format);
+          private->transform_srgb_u8_format =
+            gimp_color_profile_get_format (private->transform_srgb_u8_format,
+                                           &srgb_u8_lcms_format);
+
+          private->transform_srgb_double_format =
+            gimp_color_profile_get_format (private->transform_srgb_double_format,
+                                           &srgb_double_lcms_format);
 
           flags = cmsFLAGS_NOOPTIMIZE;
           flags |= cmsFLAGS_BLACKPOINTCOMPENSATION;
 
-          private->transform_to_srgb =
+          private->transform_to_srgb_u8 =
+            cmsCreateTransform (image_lcms, image_lcms_format,
+                                srgb_lcms,  srgb_u8_lcms_format,
+                                GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
+                                flags);
+
+          private->transform_from_srgb_u8 =
+            cmsCreateTransform (srgb_lcms,  srgb_u8_lcms_format,
+                                image_lcms, image_lcms_format,
+                                GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
+                                flags);
+
+          private->transform_to_srgb_double =
             cmsCreateTransform (image_lcms, image_lcms_format,
-                                srgb_lcms,  srgb_lcms_format,
+                                srgb_lcms,  srgb_double_lcms_format,
                                 GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
                                 flags);
 
-          private->transform_from_srgb =
-            cmsCreateTransform (srgb_lcms,  srgb_lcms_format,
+          private->transform_from_srgb_double =
+            cmsCreateTransform (srgb_lcms,  srgb_double_lcms_format,
                                 image_lcms, image_lcms_format,
                                 GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL,
                                 flags);
diff --git a/app/core/gimpimage-color-profile.h b/app/core/gimpimage-color-profile.h
index 818f0c8..e7aaf28 100644
--- a/app/core/gimpimage-color-profile.h
+++ b/app/core/gimpimage-color-profile.h
@@ -69,6 +69,24 @@ void                 gimp_image_import_color_profile   (GimpImage           *ima
                                                         GimpProgress        *progress,
                                                         gboolean             interactive);
 
+GimpColorTransform   gimp_image_get_color_transform_to_srgb_u8
+                                                       (GimpImage           *image,
+                                                        const Babl         **pixel_format,
+                                                        const Babl         **srgb_u8_format);
+GimpColorTransform   gimp_image_get_color_transform_from_srgb_u8
+                                                       (GimpImage           *image,
+                                                        const Babl         **pixel_format,
+                                                        const Babl         **srgb_u8_format);
+
+GimpColorTransform   gimp_image_get_color_transform_to_srgb_double
+                                                       (GimpImage           *image,
+                                                        const Babl         **pixel_format,
+                                                        const Babl         **srgb_double_format);
+GimpColorTransform   gimp_image_get_color_transform_from_srgb_double
+                                                       (GimpImage           *image,
+                                                        const Babl         **pixel_format,
+                                                        const Babl         **srgb_double_format);
+
 void                 gimp_image_color_profile_pixel_to_srgb
                                                        (GimpImage           *image,
                                                         const Babl          *pixel_format,
diff --git a/app/core/gimpimage-private.h b/app/core/gimpimage-private.h
index 6dbfea2..474f4b1 100644
--- a/app/core/gimpimage-private.h
+++ b/app/core/gimpimage-private.h
@@ -57,10 +57,17 @@ struct _GimpImagePrivate
   const Babl        *babl_palette_rgba;     /*  palette's RGBA Babl format   */
 
   GimpColorProfile  *color_profile;         /*  image's color profile        */
-  GimpColorTransform transform_to_srgb;     /*  from layer pixels to sRGB    */
-  GimpColorTransform transform_from_srgb;   /*  from sRGB to layer pixels    */
-  const Babl        *transform_layer_format;/*  layer format for transforms  */
-  const Babl        *transform_srgb_format; /*  sRGB format for transforms   */
+
+  /*  Cached color transforms: from layer to sRGB u8 and double, and back    */
+  GimpColorTransform transform_to_srgb_u8;
+  GimpColorTransform transform_from_srgb_u8;
+  GimpColorTransform transform_to_srgb_double;
+  GimpColorTransform transform_from_srgb_double;
+
+  /*  Babl formats for above transforms: layer, sRGB u8, sRGB double         */
+  const Babl        *transform_layer_format;
+  const Babl        *transform_srgb_u8_format;
+  const Babl        *transform_srgb_double_format;
 
   GimpMetadata      *metadata;              /*  image's metadata             */
 


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