[gthumb/ext] [file tools] added the "invert colors" tool
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gthumb/ext] [file tools] added the "invert colors" tool
- Date: Sun, 20 Sep 2009 17:46:17 +0000 (UTC)
commit be50bf57c8d7bdda24f08ec32fd13c11070c113e
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Sep 20 19:45:10 2009 +0200
[file tools] added the "invert colors" tool
extensions/file_tools/Makefile.am | 2 +
extensions/file_tools/gth-file-tool-negative.c | 134 ++++++++++++++++++++++++
extensions/file_tools/gth-file-tool-negative.h | 52 +++++++++
extensions/file_tools/main.c | 2 +
4 files changed, 190 insertions(+), 0 deletions(-)
---
diff --git a/extensions/file_tools/Makefile.am b/extensions/file_tools/Makefile.am
index 4b2a25e..376ef2e 100644
--- a/extensions/file_tools/Makefile.am
+++ b/extensions/file_tools/Makefile.am
@@ -14,6 +14,8 @@ libfile_tools_la_SOURCES = \
gth-file-tool-enhance.h \
gth-file-tool-equalize.c \
gth-file-tool-equalize.h \
+ gth-file-tool-negative.c \
+ gth-file-tool-negative.h \
gth-file-tool-redo.c \
gth-file-tool-redo.h \
gth-file-tool-save.c \
diff --git a/extensions/file_tools/gth-file-tool-negative.c b/extensions/file_tools/gth-file-tool-negative.c
new file mode 100644
index 0000000..85f6888
--- /dev/null
+++ b/extensions/file_tools/gth-file-tool-negative.c
@@ -0,0 +1,134 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2009 Free Software Foundation, 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., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <gthumb.h>
+#include <extensions/image_viewer/gth-image-viewer-page.h>
+#include "gth-file-tool-negative.h"
+
+
+static void
+gth_file_tool_negative_update_sensitivity (GthFileTool *base)
+{
+ GtkWidget *window;
+ GtkWidget *viewer_page;
+
+ window = gth_file_tool_get_window (base);
+ viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+ if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page))
+ gtk_widget_set_sensitive (GTK_WIDGET (base), FALSE);
+ else
+ gtk_widget_set_sensitive (GTK_WIDGET (base), TRUE);
+}
+
+
+static void
+negative_step (GthPixbufTask *pixop)
+{
+ pixop->dest_pixel[RED_PIX] = 255 - pixop->dest_pixel[RED_PIX];
+ pixop->dest_pixel[GREEN_PIX] = 255 - pixop->dest_pixel[GREEN_PIX];
+ pixop->dest_pixel[BLUE_PIX] = 255 - pixop->dest_pixel[BLUE_PIX];
+
+ if (pixop->has_alpha)
+ pixop->dest_pixel[ALPHA_PIX] = pixop->src_pixel[ALPHA_PIX];
+}
+
+
+static void
+negative_release (GthPixbufTask *pixop,
+ GError *error)
+{
+ if (error == NULL)
+ gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (pixop->data), pixop->dest, TRUE);
+}
+
+
+static void
+gth_file_tool_negative_activate (GthFileTool *base)
+{
+ GtkWidget *window;
+ GtkWidget *viewer_page;
+ GtkWidget *viewer;
+ GdkPixbuf *src_pixbuf;
+ GdkPixbuf *dest_pixbuf;
+ GthTask *task;
+
+ window = gth_file_tool_get_window (base);
+ viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
+ if (! GTH_IS_IMAGE_VIEWER_PAGE (viewer_page))
+ return;
+
+ viewer = gth_image_viewer_page_get_image_viewer (GTH_IMAGE_VIEWER_PAGE (viewer_page));
+ src_pixbuf = gth_image_viewer_get_current_pixbuf (GTH_IMAGE_VIEWER (viewer));
+ if (src_pixbuf == NULL)
+ return;
+
+ dest_pixbuf = gdk_pixbuf_copy (src_pixbuf);
+ task = gth_pixbuf_task_new (_("Applying changes"),
+ src_pixbuf,
+ dest_pixbuf,
+ NULL,
+ negative_step,
+ negative_release,
+ viewer_page);
+ gth_browser_exec_task (GTH_BROWSER (window), task, FALSE);
+
+ g_object_unref (task);
+ g_object_unref (dest_pixbuf);
+}
+
+
+static void
+gth_file_tool_negative_instance_init (GthFileToolNegative *self)
+{
+ gth_file_tool_construct (GTH_FILE_TOOL (self), GTK_STOCK_EDIT, _("Negative"), _("Negative"), FALSE);
+}
+
+
+static void
+gth_file_tool_negative_class_init (GthFileToolClass *klass)
+{
+ klass->update_sensitivity = gth_file_tool_negative_update_sensitivity;
+ klass->activate = gth_file_tool_negative_activate;
+}
+
+
+GType
+gth_file_tool_negative_get_type (void) {
+ static GType type_id = 0;
+ if (type_id == 0) {
+ static const GTypeInfo g_define_type_info = {
+ sizeof (GthFileToolNegativeClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) gth_file_tool_negative_class_init,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ sizeof (GthFileToolNegative),
+ 0,
+ (GInstanceInitFunc) gth_file_tool_negative_instance_init,
+ NULL
+ };
+ type_id = g_type_register_static (GTH_TYPE_FILE_TOOL, "GthFileToolNegative", &g_define_type_info, 0);
+ }
+ return type_id;
+}
diff --git a/extensions/file_tools/gth-file-tool-negative.h b/extensions/file_tools/gth-file-tool-negative.h
new file mode 100644
index 0000000..d5816ae
--- /dev/null
+++ b/extensions/file_tools/gth-file-tool-negative.h
@@ -0,0 +1,52 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2009 Free Software Foundation, 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., 59 Temple Street #330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GTH_FILE_TOOL_NEGATIVE_H
+#define GTH_FILE_TOOL_NEGATIVE_H
+
+#include <gthumb.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_FILE_TOOL_NEGATIVE (gth_file_tool_negative_get_type ())
+#define GTH_FILE_TOOL_NEGATIVE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_FILE_TOOL_NEGATIVE, GthFileToolNegative))
+#define GTH_FILE_TOOL_NEGATIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_TYPE_FILE_TOOL_NEGATIVE, GthFileToolNegativeClass))
+#define GTH_IS_FILE_TOOL_NEGATIVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_FILE_TOOL_NEGATIVE))
+#define GTH_IS_FILE_TOOL_NEGATIVE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTH_TYPE_FILE_TOOL_NEGATIVE))
+#define GTH_FILE_TOOL_NEGATIVE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTH_TYPE_FILE_TOOL_NEGATIVE, GthFileToolNegativeClass))
+
+typedef struct _GthFileToolNegative GthFileToolNegative;
+typedef struct _GthFileToolNegativeClass GthFileToolNegativeClass;
+
+struct _GthFileToolNegative {
+ GthFileTool parent_instance;
+};
+
+struct _GthFileToolNegativeClass {
+ GthFileToolClass parent_class;
+};
+
+GType gth_file_tool_negative_get_type (void);
+
+G_END_DECLS
+
+#endif /* GTH_FILE_TOOL_NEGATIVE_H */
diff --git a/extensions/file_tools/main.c b/extensions/file_tools/main.c
index a32f69c..351b6eb 100644
--- a/extensions/file_tools/main.c
+++ b/extensions/file_tools/main.c
@@ -29,6 +29,7 @@
#include "gth-file-tool-desaturate.h"
#include "gth-file-tool-enhance.h"
#include "gth-file-tool-equalize.h"
+#include "gth-file-tool-negative.h"
#include "gth-file-tool-redo.h"
#include "gth-file-tool-save.h"
#include "gth-file-tool-save-as.h"
@@ -46,6 +47,7 @@ gthumb_extension_activate (void)
gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_ADJUST_COLORS);
gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_EQUALIZE);
gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_DESATURATE);
+ gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_NEGATIVE);
gth_main_register_type ("file-tools", GTH_TYPE_FILE_TOOL_CROP);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]