[gimp/alxsa-simulation-profile-new-image] core: Add "Simulation Profile" to Create New Image




commit e90a5a96921447986caafa7f8732d04b31c78938
Author: Alx Sa <cmyk student gmail com>
Date:   Sat Aug 6 04:42:46 2022 +0000

    core: Add "Simulation Profile" to Create New Image
    
    Adds a dropdown for Simulation Profile to the Create a New Image dialog.
    This allows users to assign a soft-proofing profile when the image is
    first created. It defaults to "None", however.

 app/core/gimpimage-new.c         |  5 ++++
 app/core/gimptemplate.c          | 34 +++++++++++++++++++++++
 app/core/gimptemplate.h          |  2 ++
 app/dialogs/preferences-dialog.c |  8 ------
 app/widgets/gimptemplateeditor.c | 59 ++++++++++++++++++++++++++++++++++++++--
 5 files changed, 98 insertions(+), 10 deletions(-)
---
diff --git a/app/core/gimpimage-new.c b/app/core/gimpimage-new.c
index bd442d1072..b6ae7ceab5 100644
--- a/app/core/gimpimage-new.c
+++ b/app/core/gimpimage-new.c
@@ -136,6 +136,11 @@ gimp_image_new_from_template (Gimp         *gimp,
   if (profile)
     g_object_unref (profile);
 
+  profile = gimp_template_get_simulation_profile (template);
+  gimp_image_set_simulation_profile (image, profile);
+  if (profile)
+    g_object_unref (profile);
+
   width  = gimp_image_get_width (image);
   height = gimp_image_get_height (image);
 
diff --git a/app/core/gimptemplate.c b/app/core/gimptemplate.c
index 71a75ff578..58658eedac 100644
--- a/app/core/gimptemplate.c
+++ b/app/core/gimptemplate.c
@@ -59,6 +59,7 @@ enum
   PROP_LINEAR,
   PROP_TRC,
   PROP_COLOR_PROFILE,
+  PROP_SIMULATION_PROFILE,
   PROP_FILL_TYPE,
   PROP_COMMENT,
   PROP_FILENAME,
@@ -84,6 +85,7 @@ struct _GimpTemplatePrivate
   GimpPrecision      precision;
 
   GFile             *color_profile;
+  GFile             *simulation_profile;
 
   GimpFillType       fill_type;
 
@@ -217,6 +219,13 @@ gimp_template_class_init (GimpTemplateClass *klass)
                            G_TYPE_FILE,
                            GIMP_PARAM_STATIC_STRINGS);
 
+  GIMP_CONFIG_PROP_OBJECT (object_class, PROP_SIMULATION_PROFILE,
+                           "simulation-profile",
+                           _("Simulation profile"),
+                           NULL,
+                           G_TYPE_FILE,
+                           GIMP_PARAM_STATIC_STRINGS);
+
   GIMP_CONFIG_PROP_ENUM (object_class, PROP_FILL_TYPE,
                          "fill-type",
                          _("Fill type"),
@@ -258,6 +267,7 @@ gimp_template_finalize (GObject *object)
   GimpTemplatePrivate *private = GET_PRIVATE (object);
 
   g_clear_object (&private->color_profile);
+  g_clear_object (&private->simulation_profile);
   g_clear_pointer (&private->comment,  g_free);
   g_clear_pointer (&private->filename, g_free);
 
@@ -317,6 +327,11 @@ gimp_template_set_property (GObject      *object,
         g_object_unref (private->color_profile);
       private->color_profile = g_value_dup_object (value);
       break;
+    case PROP_SIMULATION_PROFILE:
+      if (private->simulation_profile)
+        g_object_unref (private->simulation_profile);
+      private->simulation_profile = g_value_dup_object (value);
+      break;
     case PROP_FILL_TYPE:
       private->fill_type = g_value_get_enum (value);
       break;
@@ -384,6 +399,9 @@ gimp_template_get_property (GObject    *object,
     case PROP_COLOR_PROFILE:
       g_value_set_object (value, private->color_profile);
       break;
+    case PROP_SIMULATION_PROFILE:
+      g_value_set_object (value, private->simulation_profile);
+      break;
     case PROP_FILL_TYPE:
       g_value_set_enum (value, private->fill_type);
       break;
@@ -573,6 +591,22 @@ gimp_template_get_color_profile (GimpTemplate *template)
   return NULL;
 }
 
+GimpColorProfile *
+gimp_template_get_simulation_profile (GimpTemplate *template)
+{
+  GimpTemplatePrivate *private;
+
+  g_return_val_if_fail (GIMP_IS_TEMPLATE (template), FALSE);
+
+  private = GET_PRIVATE (template);
+
+  if (private->simulation_profile)
+    return gimp_color_profile_new_from_file (private->simulation_profile,
+                                             NULL);
+
+  return NULL;
+}
+
 GimpFillType
 gimp_template_get_fill_type (GimpTemplate *template)
 {
diff --git a/app/core/gimptemplate.h b/app/core/gimptemplate.h
index d2bc35be9a..81ed29e621 100644
--- a/app/core/gimptemplate.h
+++ b/app/core/gimptemplate.h
@@ -85,6 +85,8 @@ GimpImageBaseType   gimp_template_get_base_type       (GimpTemplate *template);
 GimpPrecision       gimp_template_get_precision       (GimpTemplate *template);
 
 GimpColorProfile  * gimp_template_get_color_profile   (GimpTemplate *template);
+GimpColorProfile  * gimp_template_get_simulation_profile
+                                                      (GimpTemplate *template);
 
 GimpFillType        gimp_template_get_fill_type       (GimpTemplate *template);
 
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index 35a6f7e552..0e06218ddb 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -1423,14 +1423,6 @@ prefs_dialog_new (Gimp       *gimp,
     grid = prefs_grid_new (GTK_CONTAINER (vbox2));
     row = 0;
 
-    prefs_profile_combo_box_add (color_config,
-                                 "simulation-profile",
-                                 store,
-                                 _("Select Soft-Proofing Color Profile"),
-                                 _("_Soft-proofing profile:"),
-                                 GTK_GRID (grid), row++, size_group,
-                                 object, "color-profile-path");
-
     prefs_enum_combo_box_add (color_config,
                               "simulation-rendering-intent", 0, 0,
                               _("Re_ndering intent:"),
diff --git a/app/widgets/gimptemplateeditor.c b/app/widgets/gimptemplateeditor.c
index 75e9e8f6b4..010f3dad49 100644
--- a/app/widgets/gimptemplateeditor.c
+++ b/app/widgets/gimptemplateeditor.c
@@ -24,6 +24,7 @@
 
 #include "libgimpmath/gimpmath.h"
 #include "libgimpbase/gimpbase.h"
+#include "libgimpcolor/gimpcolor.h"
 #include "libgimpconfig/gimpconfig.h"
 #include "libgimpwidgets/gimpwidgets.h"
 
@@ -76,6 +77,7 @@ struct _GimpTemplateEditorPrivate
   GtkWidget     *chain_button;
   GtkWidget     *precision_combo;
   GtkWidget     *profile_combo;
+  GtkWidget     *simulation_profile_combo;
 };
 
 #define GET_PRIVATE(editor) \
@@ -435,6 +437,17 @@ gimp_template_editor_constructed (GObject *object)
                             _("Co_lor profile:"), 0.0, 0.5,
                             private->profile_combo, 1);
 
+  private->simulation_profile_combo =
+    gimp_prop_profile_combo_box_new (G_OBJECT (template),
+                                     "simulation-profile",
+                                     NULL,
+                                     _("Choose A Soft-Proofing Color Profile"),
+                                     G_OBJECT (private->gimp->config),
+                                     "color-profile-path");
+  gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
+                            _("_Soft-proofing color profile:"), 0.0, 0.5,
+                            private->simulation_profile_combo, 1);
+
   combo = gimp_prop_enum_combo_box_new (G_OBJECT (template),
                                         "fill-type",
                                         0, 0);
@@ -798,8 +811,10 @@ gimp_template_editor_template_notify (GimpTemplate       *template,
       ! strcmp (param_spec->name, "image-type") ||
       ! strcmp (param_spec->name, "precision"))
     {
-      GtkListStore *profile_store;
-      GFile        *file;
+      GimpColorProfile *profile;
+      GtkListStore     *profile_store;
+      GFile            *file;
+      gchar            *path;
 
       file = gimp_directory_file ("profilerc", NULL);
       profile_store = gimp_color_profile_store_new (file);
@@ -813,6 +828,36 @@ gimp_template_editor_template_notify (GimpTemplate       *template,
 
       gtk_combo_box_set_model (GTK_COMBO_BOX (private->profile_combo),
                                GTK_TREE_MODEL (profile_store));
+
+      /* Simulation Profile should not be set by default */
+      file = gimp_directory_file ("profilerc", NULL);
+      profile_store = gimp_color_profile_store_new (file);
+      g_object_unref (file);
+
+      gimp_color_profile_store_add_file (GIMP_COLOR_PROFILE_STORE (profile_store),
+                                         NULL, NULL);
+      /* Add Preferred CMYK profile if it exists */
+      profile =
+        gimp_color_config_get_cmyk_color_profile (GIMP_COLOR_CONFIG 
(private->gimp->config->color_management),
+                                                  NULL);
+      if (profile)
+        {
+          g_object_get (G_OBJECT (private->gimp->config->color_management),
+                        "cmyk-profile", &path, NULL);
+          file = gimp_file_new_for_config_path (path, NULL);
+          g_free (path);
+          text = g_strdup_printf (_("Preferred CMYK (%s)"),
+                                  gimp_color_profile_get_label (profile));
+          g_object_unref (profile);
+          gimp_color_profile_store_add_file (GIMP_COLOR_PROFILE_STORE (profile_store),
+                                             file, text);
+          g_object_unref (file);
+          g_free (text);
+        }
+
+      gtk_combo_box_set_model (GTK_COMBO_BOX (private->simulation_profile_combo),
+                               GTK_TREE_MODEL (profile_store));
+
       g_object_unref (profile_store);
 
       g_object_get (template,
@@ -824,5 +869,15 @@ gimp_template_editor_template_notify (GimpTemplate       *template,
 
       if (file)
         g_object_unref (file);
+
+      g_object_get (template,
+                    "simulation-profile", &file,
+                    NULL);
+
+      gimp_color_profile_combo_box_set_active_file (GIMP_COLOR_PROFILE_COMBO_BOX 
(private->simulation_profile_combo),
+                                                    file, NULL);
+
+      if (file)
+        g_object_unref (file);
     }
 }


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