[gnome-photos/wip/rishi/edit-mode: 20/27] Add PhotosToolSharpen



commit 9531731ef8915c48fa0c2fc1bb07f041114f3eb9
Author: Debarshi Ray <debarshir gnome org>
Date:   Tue Jun 2 21:23:51 2015 +0200

    Add PhotosToolSharpen

 po/POTFILES.in            |    1 +
 src/Makefile.am           |    2 +
 src/photos-icons.h        |    2 +
 src/photos-tool-sharpen.c |  166 +++++++++++++++++++++++++++++++++++++++++++++
 src/photos-tool-sharpen.h |   45 ++++++++++++
 src/photos-utils.c        |    3 +
 6 files changed, 219 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 30437fb..85b6db9 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -31,4 +31,5 @@ src/photos-search-type-manager.c
 src/photos-selection-toolbar.c
 src/photos-source-manager.c
 src/photos-spinner-box.c
+src/photos-tool-sharpen.c
 src/photos-tracker-controller.c
diff --git a/src/Makefile.am b/src/Makefile.am
index f420258..2d1cf72 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -190,6 +190,8 @@ gnome_photos_SOURCES = \
        photos-spinner-box.h \
        photos-tool.c \
        photos-tool.h \
+       photos-tool-sharpen.c \
+       photos-tool-sharpen.h \
        photos-tracker-change-event.c \
        photos-tracker-change-event.h \
        photos-tracker-change-monitor.c \
diff --git a/src/photos-icons.h b/src/photos-icons.h
index e53eb1c..f7fcc2f 100644
--- a/src/photos-icons.h
+++ b/src/photos-icons.h
@@ -40,6 +40,8 @@ G_BEGIN_DECLS
 #define PHOTOS_ICON_GO_NEXT_SYMBOLIC "go-next-symbolic"
 #define PHOTOS_ICON_GO_PREVIOUS_SYMBOLIC "go-previous-symbolic"
 
+#define PHOTOS_ICON_IMAGE_SHARPEN_SYMBOLIC "image-sharpen-symbolic"
+
 #define PHOTOS_ICON_IMAGE_X_GENERIC_SYMBOLIC "image-x-generic-symbolic"
 
 #define PHOTOS_ICON_NOT_FAVORITE "non-starred"
diff --git a/src/photos-tool-sharpen.c b/src/photos-tool-sharpen.c
new file mode 100644
index 0000000..8a6edd8
--- /dev/null
+++ b/src/photos-tool-sharpen.c
@@ -0,0 +1,166 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2015 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+
+#include "config.h"
+
+#include <gio/gio.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "photos-icons.h"
+#include "photos-tool.h"
+#include "photos-tool-sharpen.h"
+#include "photos-utils.h"
+
+
+struct _PhotosToolSharpen
+{
+  PhotosTool parent_instance;
+  GAction *sharpen;
+  GtkWidget *scale;
+  guint value_changed_id;
+};
+
+struct _PhotosToolSharpenClass
+{
+  PhotosToolClass parent_class;
+};
+
+
+G_DEFINE_TYPE_WITH_CODE (PhotosToolSharpen, photos_tool_sharpen, PHOTOS_TYPE_TOOL,
+                         photos_utils_ensure_extension_points ();
+                         g_io_extension_point_implement (PHOTOS_TOOL_EXTENSION_POINT_NAME,
+                                                         g_define_type_id,
+                                                         "sharpen",
+                                                         300));
+
+
+static const gdouble SHARPEN_SCALE_MAXIMUM = 10.0;
+static const gdouble SHARPEN_SCALE_MINIMUM = 0.0;
+static const gdouble SHARPEN_SCALE_STEP = 0.5;
+
+
+static gboolean
+photos_tool_sharpen_value_changed_timeout (gpointer user_data)
+{
+  PhotosToolSharpen *self = PHOTOS_TOOL_SHARPEN (user_data);
+  GVariant *parameter;
+  gdouble value;
+
+  value = gtk_range_get_value (GTK_RANGE (self->scale));
+  parameter = g_variant_new_double (value);
+  g_action_activate (self->sharpen, parameter);
+
+  self->value_changed_id = 0;
+  return G_SOURCE_REMOVE;
+}
+
+
+static void
+photos_tool_sharpen_value_changed (PhotosToolSharpen *self)
+{
+  if (self->value_changed_id != 0)
+    return;
+
+  self->value_changed_id = g_timeout_add (150, photos_tool_sharpen_value_changed_timeout, self);
+}
+
+
+static void
+photos_tool_sharpen_activate (PhotosTool *tool, PhotosBaseItem *item, GeglGtkView *view)
+{
+  PhotosToolSharpen *self = PHOTOS_TOOL_SHARPEN (tool);
+  gdouble value;
+
+  if (!photos_base_item_operation_get (item, "gegl:unsharp-mask", "scale", &value, NULL))
+    value = SHARPEN_SCALE_MINIMUM;
+
+  value = CLAMP (value, SHARPEN_SCALE_MINIMUM, SHARPEN_SCALE_MAXIMUM);
+
+  g_signal_handlers_block_by_func (self->scale, photos_tool_sharpen_value_changed, self);
+  gtk_range_set_value (GTK_RANGE (self->scale), value);
+  g_signal_handlers_unblock_by_func (self->scale, photos_tool_sharpen_value_changed, self);
+}
+
+
+static GtkWidget *
+photos_tool_sharpen_get_widget (PhotosTool *tool)
+{
+  PhotosToolSharpen *self = PHOTOS_TOOL_SHARPEN (tool);
+  return self->scale;
+}
+
+
+static void
+photos_tool_sharpen_dispose (GObject *object)
+{
+  PhotosToolSharpen *self = PHOTOS_TOOL_SHARPEN (object);
+
+  g_clear_object (&self->scale);
+
+  G_OBJECT_CLASS (photos_tool_sharpen_parent_class)->dispose (object);
+}
+
+
+static void
+photos_tool_sharpen_finalize (GObject *object)
+{
+  PhotosToolSharpen *self = PHOTOS_TOOL_SHARPEN (object);
+
+  if (self->value_changed_id != 0)
+    g_source_remove (self->value_changed_id);
+
+  G_OBJECT_CLASS (photos_tool_sharpen_parent_class)->dispose (object);
+}
+
+
+static void
+photos_tool_sharpen_init (PhotosToolSharpen *self)
+{
+  GApplication *app;
+
+  app = g_application_get_default ();
+  self->sharpen = g_action_map_lookup_action (G_ACTION_MAP (app), "sharpen-current");
+
+  self->scale = g_object_ref_sink (gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL,
+                                                             SHARPEN_SCALE_MINIMUM,
+                                                             SHARPEN_SCALE_MAXIMUM,
+                                                             SHARPEN_SCALE_STEP));
+  gtk_scale_set_draw_value (GTK_SCALE (self->scale), FALSE);
+  g_signal_connect_swapped (self->scale, "value-changed", G_CALLBACK (photos_tool_sharpen_value_changed), 
self);
+}
+
+
+static void
+photos_tool_sharpen_class_init (PhotosToolSharpenClass *class)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (class);
+  PhotosToolClass *tool_class = PHOTOS_TOOL_CLASS (class);
+
+  tool_class->icon_name = PHOTOS_ICON_IMAGE_SHARPEN_SYMBOLIC;
+  tool_class->name = _("Sharpen");
+
+  object_class->dispose = photos_tool_sharpen_dispose;
+  object_class->finalize = photos_tool_sharpen_finalize;
+  tool_class->activate = photos_tool_sharpen_activate;
+  tool_class->get_widget = photos_tool_sharpen_get_widget;
+}
diff --git a/src/photos-tool-sharpen.h b/src/photos-tool-sharpen.h
new file mode 100644
index 0000000..689b732
--- /dev/null
+++ b/src/photos-tool-sharpen.h
@@ -0,0 +1,45 @@
+/*
+ * Photos - access, organize and share your photos on GNOME
+ * Copyright © 2015 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef PHOTOS_TOOL_SHARPEN_H
+#define PHOTOS_TOOL_SHARPEN_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PHOTOS_TYPE_TOOL_SHARPEN (photos_tool_sharpen_get_type ())
+
+#define PHOTOS_TOOL_SHARPEN(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+   PHOTOS_TYPE_TOOL_SHARPEN, PhotosToolSharpen))
+
+#define PHOTOS_IS_TOOL_SHARPEN(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+   PHOTOS_TYPE_TOOL_SHARPEN))
+
+typedef struct _PhotosToolSharpen      PhotosToolSharpen;
+typedef struct _PhotosToolSharpenClass PhotosToolSharpenClass;
+
+GType               photos_tool_sharpen_get_type           (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* PHOTOS_TOOL_SHARPEN_H */
diff --git a/src/photos-utils.c b/src/photos-utils.c
index cb6f7bc..2f957e7 100644
--- a/src/photos-utils.c
+++ b/src/photos-utils.c
@@ -46,6 +46,7 @@
 #include "photos-query.h"
 #include "photos-source.h"
 #include "photos-tool.h"
+#include "photos-tool-sharpen.h"
 #include "photos-tracker-collections-controller.h"
 #include "photos-tracker-controller.h"
 #include "photos-tracker-favorites-controller.h"
@@ -524,6 +525,8 @@ photos_utils_ensure_builtins (void)
       g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_CURVE);
       g_type_ensure (PHOTOS_TYPE_OPERATION_INSTA_FILTER);
 
+      g_type_ensure (PHOTOS_TYPE_TOOL_SHARPEN);
+
       g_type_ensure (PHOTOS_TYPE_TRACKER_COLLECTIONS_CONTROLLER);
       g_type_ensure (PHOTOS_TYPE_TRACKER_FAVORITES_CONTROLLER);
       g_type_ensure (PHOTOS_TYPE_TRACKER_OVERVIEW_CONTROLLER);


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