[gimp/alxsa-save-intent-bpc-xcf: 6/6] app: Save simulation intent and bpc in XCF file




commit ea6576987ec2d6d6cbf21b9d49758c026db7e2de
Author: Alx Sa <cmyk student gmail com>
Date:   Thu Aug 18 22:30:04 2022 +0000

    app: Save simulation intent and bpc in XCF file
    
    Creates two new parasites to save the black point compensation status
    and rendering intent simulation settings in GimpImage.
    The parasites are saved and loaded as part of the image in the
    .xcf file.

 app/core/gimpimage-color-profile.c | 22 ++++++++++
 app/xcf/xcf-load.c                 | 82 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+)
---
diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c
index 9bd1f8f22f..a3b067b897 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -477,8 +477,19 @@ gimp_image_set_simulation_intent (GimpImage               *image,
 
   if (intent != private->simulation_intent)
     {
+      GimpParasite *parasite;
+      gchar         i;
+
       private->simulation_intent = intent;
       gimp_color_managed_simulation_intent_changed (GIMP_COLOR_MANAGED (image));
+
+      i = (gchar) intent;
+      parasite = gimp_parasite_new ("image-simulation-intent",
+                                    GIMP_PARASITE_PERSISTENT,
+                                    1, (gpointer) &i);
+
+      gimp_image_parasite_attach (image, parasite, FALSE);
+      gimp_parasite_free (parasite);
     }
 }
 
@@ -502,8 +513,19 @@ gimp_image_set_simulation_bpc (GimpImage *image,
 
   if (bpc != private->simulation_bpc)
     {
+      GimpParasite *parasite;
+      gchar         i;
+
       private->simulation_bpc = bpc;
       gimp_color_managed_simulation_bpc_changed (GIMP_COLOR_MANAGED (image));
+
+      i = (gchar) bpc;
+      parasite = gimp_parasite_new ("image-simulation-bpc",
+                                    GIMP_PARASITE_PERSISTENT,
+                                    1, (gpointer) &i);
+
+      gimp_image_parasite_attach (image, parasite, FALSE);
+      gimp_parasite_free (parasite);
     }
 }
 
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index 95bcd83f59..eb72fd3d91 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -40,6 +40,7 @@
 #include "core/gimpgrid.h"
 #include "core/gimpgrouplayer.h"
 #include "core/gimpimage.h"
+#include "core/gimpimage-color-profile.h"
 #include "core/gimpimage-colormap.h"
 #include "core/gimpimage-grid.h"
 #include "core/gimpimage-guides.h"
@@ -269,6 +270,87 @@ xcf_load_image (Gimp     *gimp,
   info->layer_sets = g_list_reverse (info->layer_sets);
   info->channel_sets = g_list_reverse (info->channel_sets);
 
+  /* check for simulation intent parasite */
+  parasite = gimp_image_parasite_find (GIMP_IMAGE (image),
+                                       "image-simulation-intent");
+  if (parasite)
+    {
+      guint32           parasite_size;
+      const guint8     *intent;
+      GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
+
+      intent = (const guint8 *) gimp_parasite_get_data (parasite, &parasite_size);
+
+      if (parasite_size == 1)
+        {
+          if (*intent != GIMP_COLOR_RENDERING_INTENT_PERCEPTUAL            &&
+              *intent != GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC &&
+              *intent != GIMP_COLOR_RENDERING_INTENT_SATURATION            &&
+              *intent != GIMP_COLOR_RENDERING_INTENT_ABSOLUTE_COLORIMETRIC)
+            {
+              gimp_message (info->gimp, G_OBJECT (info->progress),
+                            GIMP_MESSAGE_ERROR,
+                            "Unknown simulation rendering intent: %d",
+                            *intent);
+            }
+          else
+            {
+              gimp_image_set_simulation_intent (image,
+                                                (GimpColorRenderingIntent) *intent);
+            }
+        }
+      else
+        {
+          gimp_message (info->gimp, G_OBJECT (info->progress),
+                        GIMP_MESSAGE_ERROR,
+                        "Invalid simulation intent data");
+        }
+
+      gimp_parasite_list_remove (private->parasites,
+                                 gimp_parasite_get_name (parasite));
+    }
+
+
+/* check for simulation bpc parasite */
+  parasite = gimp_image_parasite_find (GIMP_IMAGE (image),
+                                       "image-simulation-bpc");
+  if (parasite)
+    {
+      guint32           parasite_size;
+      const guint8     *bpc;
+      gboolean          status  = FALSE;
+      GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
+
+      bpc = (const guint8 *) gimp_parasite_get_data (parasite, &parasite_size);
+
+      if (parasite_size == 1)
+        {
+          if (*bpc < 0)
+            {
+              gimp_message (info->gimp, G_OBJECT (info->progress),
+                            GIMP_MESSAGE_ERROR,
+                            "Unknown simulation bpc status: %d",
+                            *bpc);
+            }
+          else
+            {
+              if (*bpc)
+                status = TRUE;
+
+              gimp_image_set_simulation_bpc (image, status);
+            }
+        }
+      else
+        {
+          gimp_message (info->gimp, G_OBJECT (info->progress),
+                        GIMP_MESSAGE_ERROR,
+                        "Invalid simulation bpc data");
+        }
+
+      gimp_parasite_list_remove (private->parasites,
+                                 gimp_parasite_get_name (parasite));
+    }
+
   /* check for a GimpGrid parasite */
   parasite = gimp_image_parasite_find (GIMP_IMAGE (image),
                                        gimp_grid_parasite_name ());


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