[gimp] Bug 735895 - Precision Conversion "Dithering" dialog



commit 98232c25a5eff91b7348749e753038af07eee8dd
Author: Michael Natterer <mitch gimp org>
Date:   Mon Sep 26 17:38:26 2016 +0200

    Bug 735895 - Precision Conversion "Dithering" dialog
    
    Remember the convert precision dialog's dithering options in
    GimpDialogConfig. Also addresses bug 599573.

 app/config/gimpdialogconfig.c          |   57 +++++++++++++++++++++
 app/config/gimpdialogconfig.h          |    4 ++
 app/config/gimppluginconfig.c          |    1 +
 app/config/gimprc-blurbs.h             |    9 +++
 app/config/gimprc-serialize.c          |    1 +
 app/config/gimprc.c                    |    1 +
 app/dialogs/convert-precision-dialog.c |   87 +++++++++++++++++---------------
 app/dialogs/preferences-dialog.c       |   21 ++++++++
 8 files changed, 141 insertions(+), 40 deletions(-)
---
diff --git a/app/config/gimpdialogconfig.c b/app/config/gimpdialogconfig.c
index ae6ab82..f9aceb8 100644
--- a/app/config/gimpdialogconfig.c
+++ b/app/config/gimpdialogconfig.c
@@ -51,6 +51,10 @@ enum
   PROP_IMAGE_CONVERT_PROFILE_INTENT,
   PROP_IMAGE_CONVERT_PROFILE_BPC,
 
+  PROP_IMAGE_CONVERT_PRECISION_LAYER_DITHER_METHOD,
+  PROP_IMAGE_CONVERT_PRECISION_TEXT_LAYER_DITHER_METHOD,
+  PROP_IMAGE_CONVERT_PRECISION_CHANNEL_DITHER_METHOD,
+
   PROP_LAYER_NEW_NAME,
   PROP_LAYER_NEW_FILL_TYPE,
 
@@ -168,6 +172,33 @@ gimp_dialog_config_class_init (GimpDialogConfigClass *klass)
                             TRUE,
                             GIMP_PARAM_STATIC_STRINGS);
 
+  GIMP_CONFIG_PROP_ENUM (object_class,
+                         PROP_IMAGE_CONVERT_PRECISION_LAYER_DITHER_METHOD,
+                         "image-convert-precision-layer-dither-method",
+                         "Default layer dither type for precision conversion",
+                         IMAGE_CONVERT_PRECISION_LAYER_DITHER_METHOD_BLURB,
+                         GEGL_TYPE_DITHER_METHOD,
+                         GEGL_DITHER_NONE,
+                         GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_PROP_ENUM (object_class,
+                         PROP_IMAGE_CONVERT_PRECISION_TEXT_LAYER_DITHER_METHOD,
+                         "image-convert-precision-text-layer-dither-method",
+                         "Default text layer dither type for precision conversion",
+                         IMAGE_CONVERT_PRECISION_TEXT_LAYER_DITHER_METHOD_BLURB,
+                         GEGL_TYPE_DITHER_METHOD,
+                         GEGL_DITHER_NONE,
+                         GIMP_PARAM_STATIC_STRINGS);
+
+  GIMP_CONFIG_PROP_ENUM (object_class,
+                         PROP_IMAGE_CONVERT_PRECISION_CHANNEL_DITHER_METHOD,
+                         "image-convert-precision-channel-dither-method",
+                         "Default channel dither type for precision conversion",
+                         IMAGE_CONVERT_PRECISION_CHANNEL_DITHER_METHOD_BLURB,
+                         GEGL_TYPE_DITHER_METHOD,
+                         GEGL_DITHER_NONE,
+                         GIMP_PARAM_STATIC_STRINGS);
+
   GIMP_CONFIG_PROP_STRING (object_class, PROP_LAYER_NEW_NAME,
                            "layer-new-name",
                            "Default new layer name",
@@ -447,6 +478,19 @@ gimp_dialog_config_set_property (GObject      *object,
       config->image_convert_profile_bpc = g_value_get_boolean (value);
       break;
 
+    case PROP_IMAGE_CONVERT_PRECISION_LAYER_DITHER_METHOD:
+      config->image_convert_precision_layer_dither_method =
+        g_value_get_enum (value);
+      break;
+    case PROP_IMAGE_CONVERT_PRECISION_TEXT_LAYER_DITHER_METHOD:
+      config->image_convert_precision_text_layer_dither_method =
+        g_value_get_enum (value);
+      break;
+    case PROP_IMAGE_CONVERT_PRECISION_CHANNEL_DITHER_METHOD:
+      config->image_convert_precision_channel_dither_method =
+        g_value_get_enum (value);
+      break;
+
     case PROP_LAYER_NEW_NAME:
       if (config->layer_new_name)
         g_free (config->layer_new_name);
@@ -577,6 +621,19 @@ gimp_dialog_config_get_property (GObject    *object,
       g_value_set_boolean (value, config->image_convert_profile_bpc);
       break;
 
+    case PROP_IMAGE_CONVERT_PRECISION_LAYER_DITHER_METHOD:
+      g_value_set_enum (value,
+                        config->image_convert_precision_layer_dither_method);
+      break;
+    case PROP_IMAGE_CONVERT_PRECISION_TEXT_LAYER_DITHER_METHOD:
+      g_value_set_enum (value,
+                        config->image_convert_precision_text_layer_dither_method);
+      break;
+    case PROP_IMAGE_CONVERT_PRECISION_CHANNEL_DITHER_METHOD:
+      g_value_set_enum (value,
+                        config->image_convert_precision_channel_dither_method);
+      break;
+
     case PROP_LAYER_NEW_NAME:
       g_value_set_string (value, config->layer_new_name);
       break;
diff --git a/app/config/gimpdialogconfig.h b/app/config/gimpdialogconfig.h
index 99e2d7f..02eae0b 100644
--- a/app/config/gimpdialogconfig.h
+++ b/app/config/gimpdialogconfig.h
@@ -49,6 +49,10 @@ struct _GimpDialogConfig
   GimpColorRenderingIntent  image_convert_profile_intent;
   gboolean                  image_convert_profile_bpc;
 
+  GeglDitherMethod          image_convert_precision_layer_dither_method;
+  GeglDitherMethod          image_convert_precision_text_layer_dither_method;
+  GeglDitherMethod          image_convert_precision_channel_dither_method;
+
   gchar                    *layer_new_name;
   GimpFillType              layer_new_fill_type;
 
diff --git a/app/config/gimppluginconfig.c b/app/config/gimppluginconfig.c
index 4e69a59..acb9bfb 100644
--- a/app/config/gimppluginconfig.c
+++ b/app/config/gimppluginconfig.c
@@ -21,6 +21,7 @@
 #include "config.h"
 
 #include <gio/gio.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
 #include "libgimpconfig/gimpconfig.h"
diff --git a/app/config/gimprc-blurbs.h b/app/config/gimprc-blurbs.h
index 2feb2da..aa68025 100644
--- a/app/config/gimprc-blurbs.h
+++ b/app/config/gimprc-blurbs.h
@@ -427,6 +427,15 @@ _("Sets the default rendering intent for the 'Convert to Color Profile' dialog."
 _("Sets the default 'Black Point Compensation' state for the " \
   "'Convert to Color Profile' dialog.")
 
+#define IMAGE_CONVERT_PRECISION_LAYER_DITHER_METHOD_BLURB \
+_("Sets the default layer dithering method for the 'Convert Precision' dialog.")
+
+#define IMAGE_CONVERT_PRECISION_TEXT_LAYER_DITHER_METHOD_BLURB \
+_("Sets the default text layer dithering method for the 'Convert Precision' dialog.")
+
+#define IMAGE_CONVERT_PRECISION_CHANNEL_DITHER_METHOD_BLURB \
+_("Sets the default channel dithering method for the 'Convert Precision' dialog.")
+
 #define LAYER_NEW_NAME_BLURB \
 _("Sets the default layer name for the 'New Layer' dialog.")
 
diff --git a/app/config/gimprc-serialize.c b/app/config/gimprc-serialize.c
index d35ca36..bb75caa 100644
--- a/app/config/gimprc-serialize.c
+++ b/app/config/gimprc-serialize.c
@@ -21,6 +21,7 @@
 #include "config.h"
 
 #include <gio/gio.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
 #include "libgimpconfig/gimpconfig.h"
diff --git a/app/config/gimprc.c b/app/config/gimprc.c
index ce6fdd0..e68816b 100644
--- a/app/config/gimprc.c
+++ b/app/config/gimprc.c
@@ -23,6 +23,7 @@
 #include <string.h>
 
 #include <gio/gio.h>
+#include <gegl.h>
 
 #include "libgimpbase/gimpbase.h"
 #include "libgimpconfig/gimpconfig.h"
diff --git a/app/dialogs/convert-precision-dialog.c b/app/dialogs/convert-precision-dialog.c
index 8492b8d..cfe88ea 100644
--- a/app/dialogs/convert-precision-dialog.c
+++ b/app/dialogs/convert-precision-dialog.c
@@ -28,6 +28,8 @@
 #include "gegl/gimp-babl.h"
 #include "gegl/gimp-gegl-utils.h"
 
+#include "config/gimpdialogconfig.h"
+
 #include "core/gimp.h"
 #include "core/gimpcontext.h"
 #include "core/gimpimage.h"
@@ -47,17 +49,17 @@
 
 typedef struct
 {
-  GtkWidget         *dialog;
+  GtkWidget          *dialog;
 
-  GimpImage         *image;
-  GimpProgress      *progress;
+  GimpImage          *image;
+  GimpProgress       *progress;
 
-  GimpComponentType  component_type;
-  gboolean           linear;
-  gint               bits;
-  gint               layer_dither_type;
-  gint               text_layer_dither_type;
-  gint               mask_dither_type;
+  GimpComponentType   component_type;
+  gboolean            linear;
+  gint                bits;
+  GeglDitherMethod    layer_dither_method;
+  GeglDitherMethod    text_layer_dither_method;
+  GeglDitherMethod    mask_dither_method;
 } ConvertDialog;
 
 
@@ -67,13 +69,6 @@ static void   convert_precision_dialog_response (GtkWidget        *widget,
 static void   convert_precision_dialog_free     (ConvertDialog    *dialog);
 
 
-/*  defaults  */
-
-static gint   saved_layer_dither_type      = 0;
-static gint   saved_text_layer_dither_type = 0;
-static gint   saved_mask_dither_type       = 0;
-
-
 /*  public functions  */
 
 GtkWidget *
@@ -94,7 +89,6 @@ convert_precision_dialog_new (GimpImage         *image,
   GtkSizeGroup  *size_group;
   const gchar   *enum_desc;
   gchar         *blurb;
-  GType          dither_type;
   const Babl    *format;
   gint           bits;
   gboolean       linear;
@@ -107,8 +101,9 @@ convert_precision_dialog_new (GimpImage         *image,
   dialog = g_slice_new0 (ConvertDialog);
 
   /* a random format with precision */
-  format = gimp_babl_format (GIMP_RGB, gimp_babl_precision (component_type,
-                                                            FALSE), FALSE);
+  format = gimp_babl_format (GIMP_RGB,
+                             gimp_babl_precision (component_type, FALSE),
+                             FALSE);
   bits   = (babl_format_get_bytes_per_pixel (format) * 8 /
             babl_format_get_n_components (format));
 
@@ -124,9 +119,16 @@ convert_precision_dialog_new (GimpImage         *image,
   /* gegl:color-reduction only does 16 bits */
   if (bits <= 16)
     {
-      dialog->layer_dither_type      = saved_layer_dither_type;
-      dialog->text_layer_dither_type = saved_text_layer_dither_type;
-      dialog->mask_dither_type       = saved_mask_dither_type;
+      GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
+
+      dialog->layer_dither_method =
+        config->image_convert_precision_layer_dither_method;
+
+      dialog->text_layer_dither_method =
+        config->image_convert_precision_text_layer_dither_method;
+
+      dialog->mask_dither_method =
+        config->image_convert_precision_channel_dither_method;
     }
 
   gimp_enum_get_value (GIMP_TYPE_COMPONENT_TYPE, component_type,
@@ -179,9 +181,6 @@ convert_precision_dialog_new (GimpImage         *image,
 
   /*  dithering  */
 
-  dither_type = gimp_gegl_get_op_enum_type ("gegl:color-reduction",
-                                            "dither-strategy");
-
   frame = gimp_frame_new (_("Dithering"));
   gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
   gtk_widget_show (frame);
@@ -207,15 +206,15 @@ convert_precision_dialog_new (GimpImage         *image,
   gtk_size_group_add_widget (size_group, label);
   gtk_widget_show (label);
 
-  combo = gimp_enum_combo_box_new (dither_type);
+  combo = gimp_enum_combo_box_new (GEGL_TYPE_DITHER_METHOD);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
   gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
   gtk_widget_show (combo);
 
   gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
-                              dialog->layer_dither_type,
+                              dialog->layer_dither_method,
                               G_CALLBACK (gimp_int_combo_box_get_active),
-                              &dialog->layer_dither_type);
+                              &dialog->layer_dither_method);
 
   /*  text layers  */
 
@@ -229,15 +228,15 @@ convert_precision_dialog_new (GimpImage         *image,
   gtk_size_group_add_widget (size_group, label);
   gtk_widget_show (label);
 
-  combo = gimp_enum_combo_box_new (dither_type);
+  combo = gimp_enum_combo_box_new (GEGL_TYPE_DITHER_METHOD);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
   gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
   gtk_widget_show (combo);
 
   gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
-                              dialog->text_layer_dither_type,
+                              dialog->text_layer_dither_method,
                               G_CALLBACK (gimp_int_combo_box_get_active),
-                              &dialog->text_layer_dither_type);
+                              &dialog->text_layer_dither_method);
 
   gimp_help_set_help_data (combo,
                            _("Dithering text layers will make them uneditable"),
@@ -255,15 +254,15 @@ convert_precision_dialog_new (GimpImage         *image,
   gtk_size_group_add_widget (size_group, label);
   gtk_widget_show (label);
 
-  combo = gimp_enum_combo_box_new (dither_type);
+  combo = gimp_enum_combo_box_new (GEGL_TYPE_DITHER_METHOD);
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
   gtk_box_pack_start (GTK_BOX (hbox), combo, TRUE, TRUE, 0);
   gtk_widget_show (combo);
 
   gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
-                              dialog->mask_dither_type,
+                              dialog->mask_dither_method,
                               G_CALLBACK (gimp_int_combo_box_get_active),
-                              &dialog->mask_dither_type);
+                              &dialog->mask_dither_method);
 
   g_object_unref (size_group);
 
@@ -318,9 +317,9 @@ convert_precision_dialog_response (GtkWidget     *widget,
 
       gimp_image_convert_precision (dialog->image,
                                     precision,
-                                    dialog->layer_dither_type,
-                                    dialog->text_layer_dither_type,
-                                    dialog->mask_dither_type,
+                                    dialog->layer_dither_method,
+                                    dialog->text_layer_dither_method,
+                                    dialog->mask_dither_method,
                                     progress);
 
       if (progress)
@@ -331,10 +330,18 @@ convert_precision_dialog_response (GtkWidget     *widget,
        /* gegl:color-reduction only does 16 bits */
       if (dialog->bits <= 16)
         {
+          GimpDialogConfig *config =
+            GIMP_DIALOG_CONFIG (dialog->image->gimp->config);
+
           /* Save defaults for next time */
-          saved_layer_dither_type      = dialog->layer_dither_type;
-          saved_text_layer_dither_type = dialog->text_layer_dither_type;
-          saved_mask_dither_type       = dialog->mask_dither_type;
+          g_object_set (config,
+                        "image-convert-precision-layer-dither-method",
+                        dialog->layer_dither_method,
+                        "image-convert-precision-text-layer-dither-method",
+                        dialog->text_layer_dither_method,
+                        "image-convert-precision-channel-dither-method",
+                        dialog->mask_dither_method,
+                        NULL);
         }
     }
 
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index 37213e2..3b88e66 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -1838,6 +1838,27 @@ prefs_dialog_new (Gimp       *gimp,
                           _("Black point compensation"),
                           GTK_BOX (vbox2));
 
+  /*  Convert Precision Dialog  */
+  vbox2 = prefs_frame_new (_("Precision Conversion Dialog"),
+                           GTK_CONTAINER (vbox), FALSE);
+  table = prefs_table_new (3, GTK_CONTAINER (vbox2));
+
+  prefs_enum_combo_box_add (object,
+                            "image-convert-precision-layer-dither-method",
+                            0, 0,
+                            _("Dither layers:"),
+                            GTK_TABLE (table), 0, size_group);
+  prefs_enum_combo_box_add (object,
+                            "image-convert-precision-text-layer-dither-method",
+                            0, 0,
+                            _("Dither text layers:"),
+                            GTK_TABLE (table), 1, size_group);
+  prefs_enum_combo_box_add (object,
+                            "image-convert-precision-channel-dither-method",
+                            0, 0,
+                            _("Dither channels/masks:"),
+                            GTK_TABLE (table), 2, size_group);
+
   /*  New Layer Dialog  */
   vbox2 = prefs_frame_new (_("New Layer Dialog"),
                            GTK_CONTAINER (vbox), FALSE);


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