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




commit 0068340cdf05cc916a499eeb19fabfe4f3960824
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         |  24 ++++++--
 app/core/gimptemplate.c          | 113 ++++++++++++++++++++++++++++++++----
 app/core/gimptemplate.h          |   5 ++
 app/dialogs/preferences-dialog.c |  19 ------
 app/widgets/gimptemplateeditor.c | 122 ++++++++++++++++++++++++++++++++++++++-
 5 files changed, 244 insertions(+), 39 deletions(-)
---
diff --git a/app/core/gimpimage-new.c b/app/core/gimpimage-new.c
index bd442d1072..2c89c15661 100644
--- a/app/core/gimpimage-new.c
+++ b/app/core/gimpimage-new.c
@@ -92,12 +92,14 @@ gimp_image_new_from_template (Gimp         *gimp,
                               GimpTemplate *template,
                               GimpContext  *context)
 {
-  GimpImage         *image;
-  GimpLayer         *layer;
-  GimpColorProfile  *profile;
-  gint               width, height;
-  gboolean           has_alpha;
-  const gchar       *comment;
+  GimpImage               *image;
+  GimpLayer               *layer;
+  GimpColorProfile        *profile;
+  GimpColorRenderingIntent intent;
+  gboolean                 bpc;
+  gint                     width, height;
+  gboolean                 has_alpha;
+  const gchar             *comment;
 
   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
   g_return_val_if_fail (GIMP_IS_TEMPLATE (template), NULL);
@@ -136,6 +138,16 @@ 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);
+
+  intent = gimp_template_get_simulation_intent (template);
+  gimp_image_set_simulation_intent (image, intent);
+  bpc = gimp_template_get_simulation_bpc (template);
+  gimp_image_set_simulation_bpc (image, bpc);
+
   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..148a40cf2e 100644
--- a/app/core/gimptemplate.c
+++ b/app/core/gimptemplate.c
@@ -59,6 +59,9 @@ enum
   PROP_LINEAR,
   PROP_TRC,
   PROP_COLOR_PROFILE,
+  PROP_SIMULATION_PROFILE,
+  PROP_SIMULATION_BPC,
+  PROP_SIMULATION_INTENT,
   PROP_FILL_TYPE,
   PROP_COMMENT,
   PROP_FILENAME,
@@ -72,23 +75,26 @@ typedef struct _GimpTemplatePrivate GimpTemplatePrivate;
 
 struct _GimpTemplatePrivate
 {
-  gint               width;
-  gint               height;
-  GimpUnit           unit;
+  gint                     width;
+  gint                     height;
+  GimpUnit                 unit;
 
-  gdouble            xresolution;
-  gdouble            yresolution;
-  GimpUnit           resolution_unit;
+  gdouble                  xresolution;
+  gdouble                  yresolution;
+  GimpUnit                 resolution_unit;
 
-  GimpImageBaseType  base_type;
-  GimpPrecision      precision;
+  GimpImageBaseType        base_type;
+  GimpPrecision            precision;
 
-  GFile             *color_profile;
+  GFile                   *color_profile;
+  GFile                   *simulation_profile;
+  GimpColorRenderingIntent simulation_intent;
+  gboolean                 simulation_bpc;
 
-  GimpFillType       fill_type;
+  GimpFillType             fill_type;
 
-  gchar             *comment;
-  gchar             *filename;
+  gchar                   *comment;
+  gchar                   *filename;
 
   guint64            initial_size;
 };
@@ -217,6 +223,28 @@ 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_SIMULATION_INTENT,
+                         "simulation-intent",
+                         _("Simulation Rendering Intent"),
+                         NULL,
+                         GIMP_TYPE_COLOR_RENDERING_INTENT,
+                         GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC,
+                         GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_PROP_BOOLEAN (object_class, PROP_SIMULATION_BPC,
+                            "simulation-bpc",
+                            _("Use Black Point Compensation for Simulation"),
+                            NULL,
+                            FALSE,
+                            GIMP_PARAM_STATIC_STRINGS);
+
   GIMP_CONFIG_PROP_ENUM (object_class, PROP_FILL_TYPE,
                          "fill-type",
                          _("Fill type"),
@@ -258,6 +286,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 +346,17 @@ 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_SIMULATION_INTENT:
+      private->simulation_intent = g_value_get_enum (value);
+      break;
+    case PROP_SIMULATION_BPC:
+      private->simulation_bpc = g_value_get_boolean (value);
+      break;
     case PROP_FILL_TYPE:
       private->fill_type = g_value_get_enum (value);
       break;
@@ -384,6 +424,15 @@ 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_SIMULATION_INTENT:
+      g_value_set_enum (value, private->simulation_intent);
+      break;
+    case PROP_SIMULATION_BPC:
+      g_value_set_boolean (value, private->simulation_bpc);
+      break;
     case PROP_FILL_TYPE:
       g_value_set_enum (value, private->fill_type);
       break;
@@ -573,6 +622,46 @@ 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;
+}
+
+GimpColorRenderingIntent
+gimp_template_get_simulation_intent (GimpTemplate *template)
+{
+  GimpTemplatePrivate *private;
+
+  g_return_val_if_fail (GIMP_IS_TEMPLATE (template), FALSE);
+
+  private = GET_PRIVATE (template);
+
+  return private->simulation_intent;
+}
+
+gboolean
+gimp_template_get_simulation_bpc (GimpTemplate *template)
+{
+  GimpTemplatePrivate *private;
+
+  g_return_val_if_fail (GIMP_IS_TEMPLATE (template), FALSE);
+
+  private = GET_PRIVATE (template);
+
+  return private->simulation_bpc;
+}
+
 GimpFillType
 gimp_template_get_fill_type (GimpTemplate *template)
 {
diff --git a/app/core/gimptemplate.h b/app/core/gimptemplate.h
index d2bc35be9a..39ee4707e1 100644
--- a/app/core/gimptemplate.h
+++ b/app/core/gimptemplate.h
@@ -85,6 +85,11 @@ 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);
+GimpColorRenderingIntent gimp_template_get_simulation_intent
+                                                      (GimpTemplate *template);
+gboolean            gimp_template_get_simulation_bpc  (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..656b8c7fe9 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -1423,25 +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:"),
-                              GTK_GRID (grid), row++, size_group);
-
-    button = gimp_prop_check_button_new (color_config,
-                                         "simulation-use-black-point-compensation",
-                                         _("Use black _point compensation"));
-    gtk_grid_attach (GTK_GRID (grid), button, 1, row, 1, 1);
-    row++;
-
     prefs_boolean_combo_box_add (color_config,
                                  "simulation-optimize",
                                  _("Speed"),
diff --git a/app/widgets/gimptemplateeditor.c b/app/widgets/gimptemplateeditor.c
index 75e9e8f6b4..503da98a7f 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,9 @@ struct _GimpTemplateEditorPrivate
   GtkWidget     *chain_button;
   GtkWidget     *precision_combo;
   GtkWidget     *profile_combo;
+  GtkWidget     *simulation_profile_combo;
+  GtkWidget     *simulation_intent_combo;
+  GtkWidget     *simulation_bpc_toggle;
 };
 
 #define GET_PRIVATE(editor) \
@@ -95,6 +99,13 @@ static void    gimp_template_editor_get_property   (GObject            *object,
 
 static void gimp_template_editor_precision_changed (GtkWidget          *widget,
                                                     GimpTemplateEditor *editor);
+static void gimp_template_editor_simulation_intent_changed
+                                                   (GtkWidget          *widget,
+                                                    GimpTemplateEditor *editor);
+static void gimp_template_editor_simulation_bpc_toggled
+                                                   (GtkWidget          *widget,
+                                                    GimpTemplateEditor *editor);
+
 static void gimp_template_editor_aspect_callback   (GtkWidget          *widget,
                                                     GimpTemplateEditor *editor);
 static void gimp_template_editor_template_notify   (GimpTemplate       *template,
@@ -435,6 +446,42 @@ 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);
+
+  private->simulation_intent_combo =
+    gimp_enum_combo_box_new (GIMP_TYPE_COLOR_RENDERING_INTENT);
+
+  gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
+                            _("_Soft-proofing rendering intent:"), 0.0, 0.5,
+                            private->simulation_intent_combo, 1);
+
+  gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (private->simulation_intent_combo),
+                                 GIMP_COLOR_RENDERING_INTENT_RELATIVE_COLORIMETRIC);
+
+  g_signal_connect (private->simulation_intent_combo, "changed",
+                    G_CALLBACK (gimp_template_editor_simulation_intent_changed),
+                    editor);
+
+  private->simulation_bpc_toggle =
+    gtk_check_button_new_with_mnemonic (_("_Use Black Point Compensation"));
+
+  gimp_grid_attach_aligned (GTK_GRID (grid), 0, row++,
+                            NULL, 0.0, 0.5,
+                            private->simulation_bpc_toggle, 1);
+
+  g_signal_connect (private->simulation_bpc_toggle, "toggled",
+                    G_CALLBACK (gimp_template_editor_simulation_bpc_toggled),
+                    editor);
+
   combo = gimp_prop_enum_combo_box_new (G_OBJECT (template),
                                         "fill-type",
                                         0, 0);
@@ -648,6 +695,35 @@ gimp_template_editor_precision_changed (GtkWidget          *widget,
                 NULL);
 }
 
+static void
+gimp_template_editor_simulation_intent_changed (GtkWidget          *widget,
+                                                GimpTemplateEditor *editor)
+{
+  GimpTemplateEditorPrivate *private = GET_PRIVATE (editor);
+  GimpColorRenderingIntent   intent;
+
+  gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget),
+                                 (gint *) &intent);
+
+  g_object_set (private->template,
+                "simulation-intent", intent,
+                NULL);
+}
+
+static void
+gimp_template_editor_simulation_bpc_toggled (GtkWidget          *widget,
+                                             GimpTemplateEditor *editor)
+{
+  GimpTemplateEditorPrivate *private = GET_PRIVATE (editor);
+  gboolean                   bpc     = FALSE;
+
+  bpc = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
+
+  g_object_set (private->template,
+                "simulation-bpc", bpc,
+                NULL);
+}
+
 static void
 gimp_template_editor_set_pixels (GimpTemplateEditor *editor,
                                  GimpTemplate       *template)
@@ -798,8 +874,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 +891,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 +932,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]