[gnome-photos/wip/rishi/edit-mode: 18/27] Add PhotosToolSharpen
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/wip/rishi/edit-mode: 18/27] Add PhotosToolSharpen
- Date: Wed, 24 Jun 2015 08:07:09 +0000 (UTC)
commit 799e01f0439699dff5e2fa66adab07950ec125e7
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 | 179 +++++++++++++++++++++++++++++++++++++++++++++
src/photos-tool-sharpen.h | 45 +++++++++++
src/photos-utils.c | 3 +
6 files changed, 232 insertions(+), 0 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a7c91b4..9ea50f8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -35,4 +35,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 5ca0a43..91788fd 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -218,6 +218,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 9e2eafa..9ce2226 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_OBJECT_SELECT_SYMBOLIC "object-select-symbolic"
diff --git a/src/photos-tool-sharpen.c b/src/photos-tool-sharpen.c
new file mode 100644
index 0000000..2597f18
--- /dev/null
+++ b/src/photos-tool-sharpen.c
@@ -0,0 +1,179 @@
+/*
+ * 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 const gchar *
+photos_tool_sharpen_get_icon_name (PhotosTool *tool)
+{
+ return PHOTOS_ICON_IMAGE_SHARPEN_SYMBOLIC;
+}
+
+
+static const gchar *
+photos_tool_sharpen_get_name (PhotosTool *tool)
+{
+ return _("Sharpen");
+}
+
+
+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);
+
+ object_class->dispose = photos_tool_sharpen_dispose;
+ object_class->finalize = photos_tool_sharpen_finalize;
+ tool_class->activate = photos_tool_sharpen_activate;
+ tool_class->get_icon_name = photos_tool_sharpen_get_icon_name;
+ tool_class->get_name = photos_tool_sharpen_get_name;
+ 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 a027b21..8c37ba7 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-queue.h"
#include "photos-utils.h"
@@ -536,6 +537,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_once_init_leave (&once_init_value, 1);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]