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



commit aa63483893a01f1837b5a8a6392755953105f0ba
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/widgets/gimptemplateeditor.c | 34 ++++++++++++++++++++++++++++++++++
 4 files changed, 75 insertions(+)
---
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/widgets/gimptemplateeditor.c b/app/widgets/gimptemplateeditor.c
index 75e9e8f6b4..4e47a4cf0d 100644
--- a/app/widgets/gimptemplateeditor.c
+++ b/app/widgets/gimptemplateeditor.c
@@ -76,6 +76,7 @@ struct _GimpTemplateEditorPrivate
   GtkWidget     *chain_button;
   GtkWidget     *precision_combo;
   GtkWidget     *profile_combo;
+  GtkWidget     *simulation_profile_combo;
 };
 
 #define GET_PRIVATE(editor) \
@@ -435,6 +436,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);
@@ -813,6 +825,18 @@ 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);
+
+      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 +848,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]