[gimp/alxsa-save-intent-bpc-xcf] Switch to guint8 for parasite data



commit 6ecf55ce29c6130544abebbc454a2ffefe104e63
Author: Alx Sa <cmyk student gmail com>
Date:   Fri Aug 19 18:59:39 2022 +0000

    Switch to guint8 for parasite data

 app/core/gimpimage-color-profile.c | 16 ++++++------
 app/xcf/xcf-load.c                 | 51 ++++++++++++++++++++++----------------
 2 files changed, 37 insertions(+), 30 deletions(-)
---
diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c
index c7acd6d1be..a3b067b897 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -478,16 +478,16 @@ gimp_image_set_simulation_intent (GimpImage               *image,
   if (intent != private->simulation_intent)
     {
       GimpParasite *parasite;
-      gchar        *str;
+      gchar         i;
 
       private->simulation_intent = intent;
       gimp_color_managed_simulation_intent_changed (GIMP_COLOR_MANAGED (image));
 
-      str = g_strdup_printf ("%d", intent);
+      i = (gchar) intent;
       parasite = gimp_parasite_new ("image-simulation-intent",
                                     GIMP_PARASITE_PERSISTENT,
-                                    strlen (str) + 1, (gpointer) str);
-      g_free (str);
+                                    1, (gpointer) &i);
+
       gimp_image_parasite_attach (image, parasite, FALSE);
       gimp_parasite_free (parasite);
     }
@@ -514,16 +514,16 @@ gimp_image_set_simulation_bpc (GimpImage *image,
   if (bpc != private->simulation_bpc)
     {
       GimpParasite *parasite;
-      gchar        *str;
+      gchar         i;
 
       private->simulation_bpc = bpc;
       gimp_color_managed_simulation_bpc_changed (GIMP_COLOR_MANAGED (image));
 
-      str = g_strdup_printf ("%i", bpc ? 1 : 0);
+      i = (gchar) bpc;
       parasite = gimp_parasite_new ("image-simulation-bpc",
                                     GIMP_PARASITE_PERSISTENT,
-                                    strlen (str) + 1, (gpointer) str);
-      g_free (str);
+                                    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 66275bb99e..eb72fd3d91 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -275,73 +275,80 @@ xcf_load_image (Gimp     *gimp,
                                        "image-simulation-intent");
   if (parasite)
     {
-      gchar            *parasite_data;
       guint32           parasite_size;
-      gint              intent;
+      const guint8     *intent;
       GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
 
-      parasite_data = (gchar *) gimp_parasite_get_data (parasite, &parasite_size);
-      parasite_data = g_strndup (parasite_data, parasite_size);
+      intent = (const guint8 *) gimp_parasite_get_data (parasite, &parasite_size);
 
-      if (sscanf (parasite_data, "%i", &intent) == 1)
+      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)
+          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",
-                            (gint) intent);
+                            *intent);
             }
           else
             {
               gimp_image_set_simulation_intent (image,
-                                                (GimpColorRenderingIntent) intent);
+                                                (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));
-      g_free (parasite_data);
     }
 
-/* check for simulation intent parasite */
+
+/* check for simulation bpc parasite */
   parasite = gimp_image_parasite_find (GIMP_IMAGE (image),
                                        "image-simulation-bpc");
   if (parasite)
     {
-      gchar            *parasite_data;
       guint32           parasite_size;
-      gint              bpc;
+      const guint8     *bpc;
       gboolean          status  = FALSE;
       GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
 
-      parasite_data = (gchar *) gimp_parasite_get_data (parasite, &parasite_size);
-      parasite_data = g_strndup (parasite_data, parasite_size);
+      bpc = (const guint8 *) gimp_parasite_get_data (parasite, &parasite_size);
 
-      if (sscanf (parasite_data, "%i", &bpc) == 1)
+      if (parasite_size == 1)
         {
-          if (bpc < 0)
+          if (*bpc < 0)
             {
               gimp_message (info->gimp, G_OBJECT (info->progress),
                             GIMP_MESSAGE_ERROR,
                             "Unknown simulation bpc status: %d",
-                            (gint) bpc);
+                            *bpc);
             }
           else
             {
-              if (bpc)
+              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));
-      g_free (parasite_data);
     }
 
   /* check for a GimpGrid parasite */


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