[gnome-photos/wip/uajain/shadows_highlights: 2/3] WIP



commit ba618c7eb367480f014b97bbcb2e114eab713844
Author: Umang Jain <mailumangjain gmail com>
Date:   Sat Oct 7 17:38:43 2017 +0530

    WIP

 src/photos-application.c  |    8 ++++++
 src/photos-preview-view.c |   44 ++++++++++++++++++++++++++++++++++
 src/photos-tool-colors.c  |   58 +++++++++++++++++++++++++++++++++++---------
 3 files changed, 98 insertions(+), 12 deletions(-)
---
diff --git a/src/photos-application.c b/src/photos-application.c
index 3a4b02c..10bde4c 100644
--- a/src/photos-application.c
+++ b/src/photos-application.c
@@ -109,6 +109,7 @@ struct _PhotosApplication
   GSimpleAction *selection_mode_action;
   GSimpleAction *set_bg_action;
   GSimpleAction *set_ss_action;
+  GSimpleAction *shadows_highlights_action;
   GSimpleAction *share_action;
   GSimpleAction *sharpen_action;
   GSimpleAction *zoom_best_fit_action;
@@ -386,6 +387,7 @@ photos_application_actions_update (PhotosApplication *self)
   g_simple_action_set_enabled (self->edit_done_action, enable);
   g_simple_action_set_enabled (self->insta_action, enable);
   g_simple_action_set_enabled (self->saturation_action, enable);
+  g_simple_action_set_enabled (self->shadows_highlights_action, enable);
   g_simple_action_set_enabled (self->sharpen_action, enable);
 
   enable = FALSE;
@@ -1928,6 +1930,11 @@ photos_application_startup (GApplication *application)
   g_variant_type_free (parameter_type);
 
   parameter_type = g_variant_type_new ("a{sd}");
+  self->shadows_highlights_action = g_simple_action_new ("shadows-highlights-current", parameter_type);
+  g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->shadows_highlights_action));
+  g_variant_type_free (parameter_type);
+
+  parameter_type = g_variant_type_new ("a{sd}");
   self->crop_action = g_simple_action_new ("crop-current", parameter_type);
   g_action_map_add_action (G_ACTION_MAP (self), G_ACTION (self->crop_action));
   g_variant_type_free (parameter_type);
@@ -2169,6 +2176,7 @@ photos_application_dispose (GObject *object)
   g_clear_object (&self->selection_mode_action);
   g_clear_object (&self->set_bg_action);
   g_clear_object (&self->set_ss_action);
+  g_clear_object (&self->shadows_highlights_action);
   g_clear_object (&self->share_action);
   g_clear_object (&self->sharpen_action);
   g_clear_object (&self->zoom_best_fit_action);
diff --git a/src/photos-preview-view.c b/src/photos-preview-view.c
index 15bc98a..9fec11c 100644
--- a/src/photos-preview-view.c
+++ b/src/photos-preview-view.c
@@ -564,6 +564,43 @@ photos_preview_view_brightness_contrast (PhotosPreviewView *self, GVariant *para
 
 
 static void
+photos_preview_view_shadows_highlights (PhotosPreviewView *self, GVariant *parameter)
+{
+  GVariantIter iter;
+  PhotosBaseItem *item;
+  const gchar *key;
+  gdouble shadows = -G_MAXDOUBLE;
+  gdouble highlights = -G_MAXDOUBLE;
+  gdouble value;
+
+  item = PHOTOS_BASE_ITEM (photos_base_manager_get_active_object (self->item_mngr));
+  if (item == NULL)
+    return;
+
+  g_variant_iter_init (&iter, parameter);
+  while (g_variant_iter_next (&iter, "{&sd}", &key, &value))
+    {
+      if (g_strcmp0 (key, "shadows") == 0)
+        shadows = value;
+      else if (g_strcmp0 (key, "highlights") == 0)
+        highlights = value;
+    }
+
+  g_return_if_fail (shadows > -G_MAXDOUBLE);
+  g_return_if_fail (highlights > -G_MAXDOUBLE);
+
+  photos_base_item_operation_add_async (item,
+                                        self->cancellable,
+                                        photos_preview_view_process,
+                                        self,
+                                        "gegl:shadow-highlights",
+                                        "shadows", shadows,
+                                        "highlights", highlights,
+                                        NULL);
+}
+
+
+static void
 photos_preview_view_crop (PhotosPreviewView *self, GVariant *parameter)
 {
   GVariantIter iter;
@@ -1092,6 +1129,13 @@ photos_preview_view_init (PhotosPreviewView *self)
                            self,
                            G_CONNECT_SWAPPED);
 
+  action = g_action_map_lookup_action (G_ACTION_MAP (app), "shadows-highlights-current");
+  g_signal_connect_object (action,
+                           "activate",
+                           G_CALLBACK (photos_preview_view_shadows_highlights),
+                           self,
+                           G_CONNECT_SWAPPED);
+
   action = g_action_map_lookup_action (G_ACTION_MAP (app), "sharpen-current");
   g_signal_connect_object (action, "activate", G_CALLBACK (photos_preview_view_sharpen), self, 
G_CONNECT_SWAPPED);
 
diff --git a/src/photos-tool-colors.c b/src/photos-tool-colors.c
index 7bdd447..e0f0e40 100644
--- a/src/photos-tool-colors.c
+++ b/src/photos-tool-colors.c
@@ -1,6 +1,7 @@
 /*
  * Photos - access, organize and share your photos on GNOME
  * Copyright © 2015 – 2017 Red Hat, Inc.
+ * Copyright © 2017 Umang Jain
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -40,6 +41,7 @@ struct _PhotosToolColors
   GAction *blacks_exposure;
   GAction *brightness_contrast;
   GAction *saturation;
+  GAction *shadows_highlights;
   GtkWidget *blacks_scale;
   GtkWidget *brightness_scale;
   GtkWidget *contrast_scale;
@@ -51,6 +53,7 @@ struct _PhotosToolColors
   guint blacks_exposure_value_changed_id;
   guint brightness_contrast_value_changed_id;
   guint saturation_value_changed_id;
+  guint shadows_highlights_value_changed_id;
 };
 
 
@@ -117,6 +120,30 @@ photos_tool_colors_blacks_exposure_value_changed_timeout (gpointer user_data)
 
 
 static gboolean
+photos_tool_colors_shadows_highlights_value_changed_timeout (gpointer user_data)
+{
+  PhotosToolColors *self = PHOTOS_TOOL_COLORS (user_data);
+  GVariantBuilder parameter;
+  GVariantType *parameter_type;
+  gdouble shadows;
+  gdouble highlights;
+
+  shadows = gtk_range_get_value (GTK_RANGE (self->shadows_scale));
+  highlights = gtk_range_get_value (GTK_RANGE (self->highlights_scale));
+
+  parameter_type = g_variant_type_new ("a{sd}");
+  g_variant_builder_init (&parameter, parameter_type);
+  g_variant_builder_add (&parameter, "{sd}", "shadows", shadows);
+  g_variant_builder_add (&parameter, "{sd}", "highlights", highlights);
+  g_action_activate (self->shadows_highlights, g_variant_builder_end (&parameter));
+
+  g_variant_type_free (parameter_type);
+  self->shadows_highlights_value_changed_id = 0;
+  return G_SOURCE_REMOVE;
+}
+
+
+static gboolean
 photos_tool_colors_brightness_contrast_value_changed_timeout (gpointer user_data)
 {
   PhotosToolColors *self = PHOTOS_TOOL_COLORS (user_data);
@@ -196,13 +223,16 @@ photos_tool_colors_saturation_value_changed (PhotosToolColors *self)
 
 
 static void
-photos_tool_colors_highlights_value_changed (PhotosToolColors *self)
-{}
-
+photos_tool_colors_shadows_highlights_value_changed (PhotosToolColors *self)
+{
+  if (self->shadows_highlights_value_changed_id != 0)
+    g_source_remove (self->shadows_highlights_value_changed_id);
 
-static void
-photos_tool_colors_shadows_value_changed (PhotosToolColors *self)
-{}
+  self->shadows_highlights_value_changed_id
+    = g_timeout_add (150,
+                     photos_tool_colors_shadows_highlights_value_changed_timeout,
+                     self);
+}
 
 
 static void
@@ -267,9 +297,9 @@ photos_tool_colors_activate (PhotosTool *tool, PhotosBaseItem *item, PhotosImage
                                    photos_tool_colors_brightness_contrast_value_changed,
                                    self);
   g_signal_handlers_block_by_func (self->exposure_scale, photos_tool_colors_blacks_exposure_value_changed, 
self);
-  g_signal_handlers_block_by_func (self->highlights_scale, photos_tool_colors_highlights_value_changed, 
self);
+  g_signal_handlers_block_by_func (self->highlights_scale, 
photos_tool_colors_shadows_highlights_value_changed, self);
   g_signal_handlers_block_by_func (self->saturation_scale, photos_tool_colors_saturation_value_changed, 
self);
-  g_signal_handlers_block_by_func (self->shadows_scale, photos_tool_colors_shadows_value_changed, self);
+  g_signal_handlers_block_by_func (self->shadows_scale, photos_tool_colors_shadows_highlights_value_changed, 
self);
   gtk_range_set_value (GTK_RANGE (self->blacks_scale), blacks);
   gtk_range_set_value (GTK_RANGE (self->brightness_scale), brightness);
   gtk_range_set_value (GTK_RANGE (self->contrast_scale), contrast);
@@ -285,9 +315,9 @@ photos_tool_colors_activate (PhotosTool *tool, PhotosBaseItem *item, PhotosImage
                                      photos_tool_colors_brightness_contrast_value_changed,
                                      self);
   g_signal_handlers_unblock_by_func (self->exposure_scale, photos_tool_colors_blacks_exposure_value_changed, 
self);
-  g_signal_handlers_unblock_by_func (self->highlights_scale, photos_tool_colors_highlights_value_changed, 
self);
+  g_signal_handlers_unblock_by_func (self->highlights_scale, 
photos_tool_colors_shadows_highlights_value_changed, self);
   g_signal_handlers_unblock_by_func (self->saturation_scale, photos_tool_colors_saturation_value_changed, 
self);
-  g_signal_handlers_unblock_by_func (self->shadows_scale, photos_tool_colors_shadows_value_changed, self);
+  g_signal_handlers_unblock_by_func (self->shadows_scale, 
photos_tool_colors_shadows_highlights_value_changed, self);
 
   g_signal_emit_by_name (self, "activated");
 }
@@ -326,6 +356,9 @@ photos_tool_colors_finalize (GObject *object)
   if (self->saturation_value_changed_id != 0)
     g_source_remove (self->saturation_value_changed_id);
 
+  if (self->shadows_highlights_value_changed_id != 0)
+    g_source_remove (self->shadows_highlights_value_changed_id);
+
   G_OBJECT_CLASS (photos_tool_colors_parent_class)->dispose (object);
 }
 
@@ -342,6 +375,7 @@ photos_tool_colors_init (PhotosToolColors *self)
   self->blacks_exposure = g_action_map_lookup_action (G_ACTION_MAP (app), "blacks-exposure-current");
   self->brightness_contrast = g_action_map_lookup_action (G_ACTION_MAP (app), "brightness-contrast-current");
   self->saturation = g_action_map_lookup_action (G_ACTION_MAP (app), "saturation-current");
+  self->shadows_highlights = g_action_map_lookup_action (G_ACTION_MAP (app), "shadows-highlights-current");
 
   self->grid = g_object_ref_sink (gtk_grid_new ());
   gtk_orientable_set_orientation (GTK_ORIENTABLE (self->grid), GTK_ORIENTATION_VERTICAL);
@@ -470,7 +504,7 @@ photos_tool_colors_init (PhotosToolColors *self)
   gtk_container_add (GTK_CONTAINER (box), self->shadows_scale);
   g_signal_connect_swapped (self->shadows_scale,
                             "value-changed",
-                            G_CALLBACK (photos_tool_colors_shadows_value_changed),
+                            G_CALLBACK (photos_tool_colors_shadows_highlights_value_changed),
                             self);
 
   label = gtk_label_new (_("Highlights"));
@@ -489,7 +523,7 @@ photos_tool_colors_init (PhotosToolColors *self)
   gtk_container_add (GTK_CONTAINER (box), self->highlights_scale);
   g_signal_connect_swapped (self->highlights_scale,
                             "value-changed",
-                            G_CALLBACK (photos_tool_colors_highlights_value_changed),
+                            G_CALLBACK (photos_tool_colors_shadows_highlights_value_changed),
                             self);
 
 }


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