[gthumb/ext] make the GthPixbufTask API more generic and consistent
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gthumb/ext] make the GthPixbufTask API more generic and consistent
- Date: Sun, 4 Oct 2009 16:38:21 +0000 (UTC)
commit 4ef8c09711b73654e26458eb216a07540fd051a4
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Oct 4 18:32:25 2009 +0200
make the GthPixbufTask API more generic and consistent
.../file_tools/gth-file-tool-adjust-colors.c | 29 +++++--
extensions/file_tools/gth-file-tool-desaturate.c | 32 +++++---
extensions/file_tools/gth-file-tool-enhance.c | 19 +++--
extensions/file_tools/gth-file-tool-equalize.c | 19 +++--
extensions/file_tools/gth-file-tool-negative.c | 12 +--
extensions/rename_series/dlg-rename-series.c | 1 +
gthumb/gth-pixbuf-task.c | 87 +++++++++++---------
gthumb/gth-pixbuf-task.h | 22 +++--
8 files changed, 135 insertions(+), 86 deletions(-)
---
diff --git a/extensions/file_tools/gth-file-tool-adjust-colors.c b/extensions/file_tools/gth-file-tool-adjust-colors.c
index 1f6f1cd..5660375 100644
--- a/extensions/file_tools/gth-file-tool-adjust-colors.c
+++ b/extensions/file_tools/gth-file-tool-adjust-colors.c
@@ -71,6 +71,7 @@ adjust_colors_init (GthPixbufTask *pixop)
AdjustData *data = pixop->data;
int i;
+ copy_source_to_destination (pixop);
data->cache = pixbuf_cache_new ();
for (i = 0; i < 256; i++)
data->midtone_distance[i] = 0.667 * (1 - SQR (((double) i - 127.0) / 127.0));
@@ -174,8 +175,16 @@ adjust_colors_release (GthPixbufTask *pixop,
{
AdjustData *data = pixop->data;
- g_object_unref (data->viewer_page);
pixbuf_cache_free (data->cache);
+}
+
+
+static void
+adjust_colors_destroy_data (gpointer user_data)
+{
+ AdjustData *data = user_data;
+
+ g_object_unref (data->viewer_page);
g_free (data);
}
@@ -250,17 +259,21 @@ task_completed_cb (GthTask *task,
{
if (self->priv->pixbuf_task == task)
self->priv->pixbuf_task = NULL;
- g_object_unref (task);
if (error == NULL) {
GtkWidget *window;
GtkWidget *viewer_page;
+ _g_object_unref (self->priv->dest_pixbuf);
+ self->priv->dest_pixbuf = g_object_ref (GTH_PIXBUF_TASK (task)->dest);
+
window = gth_file_tool_get_window (GTH_FILE_TOOL (self));
viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (window));
gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), self->priv->dest_pixbuf, FALSE);
gth_histogram_calculate (self->priv->histogram, self->priv->dest_pixbuf);
}
+
+ g_object_unref (task);
}
@@ -293,12 +306,14 @@ apply_cb (gpointer user_data)
data->color_level[2] = gtk_adjustment_get_value (self->priv->yellow_blue_adj);
self->priv->pixbuf_task = gth_pixbuf_task_new (_("Applying changes"),
- self->priv->src_pixbuf,
- self->priv->dest_pixbuf,
+ FALSE,
adjust_colors_init,
adjust_colors_step,
adjust_colors_release,
- data);
+ data,
+ adjust_colors_destroy_data);
+ gth_pixbuf_task_set_source (GTH_PIXBUF_TASK (self->priv->pixbuf_task),
+ self->priv->src_pixbuf);
g_signal_connect (self->priv->pixbuf_task,
"completed",
G_CALLBACK (task_completed_cb),
@@ -384,7 +399,7 @@ gth_file_tool_adjust_colors_get_options (GthFileTool *base)
return NULL;
self->priv->src_pixbuf = g_object_ref (self->priv->src_pixbuf);
- self->priv->dest_pixbuf = gdk_pixbuf_copy (self->priv->src_pixbuf);
+ self->priv->dest_pixbuf = NULL;
self->priv->builder = _gtk_builder_new_from_file ("adjust-colors-options.ui", "file_tools");
options = _gtk_builder_get_widget (self->priv->builder, "options");
@@ -443,7 +458,7 @@ gth_file_tool_adjust_colors_get_options (GthFileTool *base)
G_CALLBACK (value_changed_cb),
self);
- gth_histogram_calculate (self->priv->histogram, self->priv->dest_pixbuf);
+ gth_histogram_calculate (self->priv->histogram, self->priv->src_pixbuf);
return options;
}
diff --git a/extensions/file_tools/gth-file-tool-desaturate.c b/extensions/file_tools/gth-file-tool-desaturate.c
index fd74532..c6bf542 100644
--- a/extensions/file_tools/gth-file-tool-desaturate.c
+++ b/extensions/file_tools/gth-file-tool-desaturate.c
@@ -62,11 +62,20 @@ desaturate_step (GthPixbufTask *pixop)
static void
-desaturate_release (GthPixbufTask *pixop,
- GError *error)
+task_completed_cb (GthTask *task,
+ GError *error,
+ gpointer user_data)
{
- if (error == NULL)
- gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (pixop->data), pixop->dest, TRUE);
+ GthFileTool *base = user_data;
+
+ if (error == NULL) {
+ GthPixbufTask *pixbuf_task;
+ GtkWidget *viewer_page;
+
+ pixbuf_task = GTH_PIXBUF_TASK (task);
+ viewer_page = gth_browser_get_viewer_page (GTH_BROWSER (gth_file_tool_get_window (base)));
+ gth_image_viewer_page_set_pixbuf (GTH_IMAGE_VIEWER_PAGE (viewer_page), pixbuf_task->dest, TRUE);
+ }
}
@@ -77,7 +86,6 @@ gth_file_tool_desaturate_activate (GthFileTool *base)
GtkWidget *viewer_page;
GtkWidget *viewer;
GdkPixbuf *src_pixbuf;
- GdkPixbuf *dest_pixbuf;
GthTask *task;
window = gth_file_tool_get_window (base);
@@ -90,18 +98,18 @@ gth_file_tool_desaturate_activate (GthFileTool *base)
if (src_pixbuf == NULL)
return;
- dest_pixbuf = gdk_pixbuf_copy (src_pixbuf);
task = gth_pixbuf_task_new (_("Desaturating image"),
- src_pixbuf,
- dest_pixbuf,
- NULL,
+ FALSE,
+ copy_source_to_destination,
desaturate_step,
- desaturate_release,
- viewer_page);
+ NULL,
+ NULL,
+ NULL);
+ gth_pixbuf_task_set_source (GTH_PIXBUF_TASK (task), src_pixbuf);
+ g_signal_connect (task, "completed", G_CALLBACK (task_completed_cb), base);
gth_browser_exec_task (GTH_BROWSER (window), task, FALSE);
g_object_unref (task);
- g_object_unref (dest_pixbuf);
}
diff --git a/extensions/file_tools/gth-file-tool-enhance.c b/extensions/file_tools/gth-file-tool-enhance.c
index a4d7da7..6c3cf59 100644
--- a/extensions/file_tools/gth-file-tool-enhance.c
+++ b/extensions/file_tools/gth-file-tool-enhance.c
@@ -114,6 +114,7 @@ adjust_levels_init (GthPixbufTask *pixop)
EnhanceData *data = pixop->data;
int channel;
+ copy_source_to_destination (pixop);
data->hist = gth_histogram_new ();
gth_histogram_calculate (data->hist, pixop->src);
@@ -210,6 +211,14 @@ adjust_levels_release (GthPixbufTask *pixop,
g_object_unref (data->hist);
g_free (data->levels);
+}
+
+
+static void
+adjust_levels_destroy_data (gpointer user_data)
+{
+ EnhanceData *data = user_data;
+
g_object_unref (data->viewer_page);
g_free (data);
}
@@ -222,7 +231,6 @@ gth_file_tool_enhance_activate (GthFileTool *base)
GtkWidget *viewer_page;
GtkWidget *viewer;
GdkPixbuf *src_pixbuf;
- GdkPixbuf *dest_pixbuf;
EnhanceData *data;
GthTask *task;
@@ -236,20 +244,19 @@ gth_file_tool_enhance_activate (GthFileTool *base)
if (src_pixbuf == NULL)
return;
- dest_pixbuf = gdk_pixbuf_copy (src_pixbuf);
data = g_new0 (EnhanceData, 1);
data->viewer_page = g_object_ref (viewer_page);
task = gth_pixbuf_task_new (_("White balance correction"),
- src_pixbuf,
- dest_pixbuf,
+ FALSE,
adjust_levels_init,
adjust_levels_step,
adjust_levels_release,
- data);
+ data,
+ adjust_levels_destroy_data);
+ gth_pixbuf_task_set_source (GTH_PIXBUF_TASK (task), src_pixbuf);
gth_browser_exec_task (GTH_BROWSER (window), task, FALSE);
g_object_unref (task);
- g_object_unref (dest_pixbuf);
}
diff --git a/extensions/file_tools/gth-file-tool-equalize.c b/extensions/file_tools/gth-file-tool-equalize.c
index c4aaf7c..5bced40 100644
--- a/extensions/file_tools/gth-file-tool-equalize.c
+++ b/extensions/file_tools/gth-file-tool-equalize.c
@@ -81,6 +81,7 @@ equalize_init (GthPixbufTask *pixop)
EqualizeData *data = pixop->data;
int i;
+ copy_source_to_destination (pixop);
data->histogram = gth_histogram_new ();
gth_histogram_calculate (data->histogram, pixop->src);
@@ -130,6 +131,14 @@ equalize_release (GthPixbufTask *pixop,
g_free (data->part[i]);
g_free (data->part);
g_object_unref (data->histogram);
+}
+
+
+static void
+equalize_destroy_data (gpointer user_data)
+{
+ EqualizeData *data = user_data;
+
g_object_unref (data->viewer_page);
g_free (data);
}
@@ -142,7 +151,6 @@ gth_file_tool_equalize_activate (GthFileTool *base)
GtkWidget *viewer_page;
GtkWidget *viewer;
GdkPixbuf *src_pixbuf;
- GdkPixbuf *dest_pixbuf;
EqualizeData *data;
GthTask *task;
@@ -156,20 +164,19 @@ gth_file_tool_equalize_activate (GthFileTool *base)
if (src_pixbuf == NULL)
return;
- dest_pixbuf = gdk_pixbuf_copy (src_pixbuf);
data = g_new0 (EqualizeData, 1);
data->viewer_page = g_object_ref (viewer_page);
task = gth_pixbuf_task_new (_("Equalizing image histogram"),
- src_pixbuf,
- dest_pixbuf,
+ FALSE,
equalize_init,
equalize_step,
equalize_release,
- data);
+ data,
+ equalize_destroy_data);
+ gth_pixbuf_task_set_source (GTH_PIXBUF_TASK (task), src_pixbuf);
gth_browser_exec_task (GTH_BROWSER (window), task, FALSE);
g_object_unref (task);
- g_object_unref (dest_pixbuf);
}
diff --git a/extensions/file_tools/gth-file-tool-negative.c b/extensions/file_tools/gth-file-tool-negative.c
index 85f6888..8a3171a 100644
--- a/extensions/file_tools/gth-file-tool-negative.c
+++ b/extensions/file_tools/gth-file-tool-negative.c
@@ -69,7 +69,6 @@ gth_file_tool_negative_activate (GthFileTool *base)
GtkWidget *viewer_page;
GtkWidget *viewer;
GdkPixbuf *src_pixbuf;
- GdkPixbuf *dest_pixbuf;
GthTask *task;
window = gth_file_tool_get_window (base);
@@ -82,18 +81,17 @@ gth_file_tool_negative_activate (GthFileTool *base)
if (src_pixbuf == NULL)
return;
- dest_pixbuf = gdk_pixbuf_copy (src_pixbuf);
task = gth_pixbuf_task_new (_("Applying changes"),
- src_pixbuf,
- dest_pixbuf,
- NULL,
+ FALSE,
+ copy_source_to_destination,
negative_step,
negative_release,
- viewer_page);
+ viewer_page,
+ NULL);
+ gth_pixbuf_task_set_source (GTH_PIXBUF_TASK (task), src_pixbuf);
gth_browser_exec_task (GTH_BROWSER (window), task, FALSE);
g_object_unref (task);
- g_object_unref (dest_pixbuf);
}
diff --git a/extensions/rename_series/dlg-rename-series.c b/extensions/rename_series/dlg-rename-series.c
index 94a632f..81e69b9 100644
--- a/extensions/rename_series/dlg-rename-series.c
+++ b/extensions/rename_series/dlg-rename-series.c
@@ -116,6 +116,7 @@ ok_clicked_cb (GtkWidget *widget,
task = gth_rename_task_new (old_files, new_files);
gth_browser_exec_task (data->browser, task, FALSE);
+ g_object_unref (task);
gtk_widget_destroy (data->dialog);
}
diff --git a/gthumb/gth-pixbuf-task.c b/gthumb/gth-pixbuf-task.c
index a414d44..db16e93 100644
--- a/gthumb/gth-pixbuf-task.c
+++ b/gthumb/gth-pixbuf-task.c
@@ -21,6 +21,7 @@
*/
#include <glib.h>
+#include "glib-utils.h"
#include "gth-pixbuf-task.h"
@@ -29,7 +30,8 @@ struct _GthPixbufTaskPrivate {
PixbufOpFunc init_func;
PixbufOpFunc step_func;
PixbufDataFunc release_func;
- PixbufOpFunc free_data_func;
+ gboolean single_step;
+ GDestroyNotify destroy_data_func;
};
@@ -60,8 +62,8 @@ gth_pixbuf_task_finalize (GObject *object)
self = GTH_PIXBUF_TASK (object);
release_pixbufs (self);
- if (self->priv->free_data_func != NULL)
- (*self->priv->free_data_func) (self);
+ if (self->priv->destroy_data_func != NULL)
+ (*self->priv->destroy_data_func) (self->data);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@@ -139,8 +141,20 @@ execute_pixbuf_task (gpointer user_data)
if (self->priv->init_func != NULL)
(*self->priv->init_func) (self);
- while (execute_step (self))
- /* void */;
+ if (self->dest != NULL)
+ self->dest_line = gdk_pixbuf_get_pixels (self->dest);
+
+ if (self->priv->single_step) {
+ gboolean terminated;
+
+ (*self->priv->step_func) (self);
+ terminated = TRUE;
+ gth_async_task_set_data (GTH_ASYNC_TASK (self), &terminated, NULL, NULL);
+ }
+ else {
+ while (execute_step (self))
+ /* void */;
+ }
return NULL;
}
@@ -177,7 +191,8 @@ gth_pixbuf_task_init (GthPixbufTask *self)
self->priv->init_func = NULL;
self->priv->step_func = NULL;
self->priv->release_func = NULL;
- self->priv->free_data_func = NULL;
+ self->priv->destroy_data_func = NULL;
+ self->dest = NULL;
self->data = NULL;
self->src = NULL;
@@ -220,13 +235,13 @@ gth_pixbuf_task_get_type (void)
GthTask *
-gth_pixbuf_task_new (const char *description,
- GdkPixbuf *src,
- GdkPixbuf *dest,
- PixbufOpFunc init_func,
- PixbufOpFunc step_func,
- PixbufDataFunc release_func,
- gpointer data)
+gth_pixbuf_task_new (const char *description,
+ gboolean single_step,
+ PixbufOpFunc init_func,
+ PixbufOpFunc step_func,
+ PixbufDataFunc release_func,
+ gpointer data,
+ GDestroyNotify destroy_data_func)
{
GthPixbufTask *self;
@@ -237,51 +252,47 @@ gth_pixbuf_task_new (const char *description,
NULL);
self->priv->description = description;
+ self->priv->single_step = single_step;
self->priv->init_func = init_func;
self->priv->step_func = step_func;
self->priv->release_func = release_func;
self->data = data;
-
- gth_pixbuf_task_set_pixbufs (self, src, dest);
+ self->priv->destroy_data_func = destroy_data_func;
return (GthTask *) self;
}
void
-gth_pixbuf_task_set_pixbufs (GthPixbufTask *self,
- GdkPixbuf *src,
- GdkPixbuf *dest)
+gth_pixbuf_task_set_source (GthPixbufTask *self,
+ GdkPixbuf *src)
{
- if (src == NULL)
- return;
-
- /* NOTE that src and dest MAY be the same pixbuf! */
-
g_return_if_fail (GDK_IS_PIXBUF (src));
- if (dest != NULL) {
- g_return_if_fail (GDK_IS_PIXBUF (dest));
- g_return_if_fail (gdk_pixbuf_get_has_alpha (src) == gdk_pixbuf_get_has_alpha (dest));
- g_return_if_fail (gdk_pixbuf_get_width (src) == gdk_pixbuf_get_width (dest));
- g_return_if_fail (gdk_pixbuf_get_height (src) == gdk_pixbuf_get_height (dest));
- g_return_if_fail (gdk_pixbuf_get_colorspace (src) == gdk_pixbuf_get_colorspace (dest));
- }
-
- release_pixbufs (self);
g_object_ref (src);
+ release_pixbufs (self);
self->src = src;
-
self->has_alpha = gdk_pixbuf_get_has_alpha (src);
self->bytes_per_pixel = self->has_alpha ? 4 : 3;
self->width = gdk_pixbuf_get_width (src);
self->height = gdk_pixbuf_get_height (src);
self->rowstride = gdk_pixbuf_get_rowstride (src);
self->src_line = gdk_pixbuf_get_pixels (src);
+}
- if (dest != NULL) {
- g_object_ref (dest);
- self->dest = dest;
- self->dest_line = gdk_pixbuf_get_pixels (dest);
- }
+
+GdkPixbuf *
+gth_pixbuf_task_get_destination (GthPixbufTask *self)
+{
+ return self->dest;
+}
+
+
+void
+copy_source_to_destination (GthPixbufTask *pixbuf_task)
+{
+ g_return_if_fail (pixbuf_task->src != NULL);
+
+ _g_object_unref (pixbuf_task->dest);
+ pixbuf_task->dest = gdk_pixbuf_copy (pixbuf_task->src);
}
diff --git a/gthumb/gth-pixbuf-task.h b/gthumb/gth-pixbuf-task.h
index 83ab90f..6c63dc8 100644
--- a/gthumb/gth-pixbuf-task.h
+++ b/gthumb/gth-pixbuf-task.h
@@ -77,16 +77,18 @@ struct _GthPixbufTaskClass {
};
GType gth_pixbuf_task_get_type (void);
-GthTask * gth_pixbuf_task_new (const char *description,
- GdkPixbuf *src,
- GdkPixbuf *dest,
- PixbufOpFunc init_func,
- PixbufOpFunc step_func,
- PixbufDataFunc release_func,
- gpointer data);
-void gth_pixbuf_task_set_pixbufs (GthPixbufTask *pixbuf_task,
- GdkPixbuf *src,
- GdkPixbuf *dest);
+GthTask * gth_pixbuf_task_new (const char *description,
+ gboolean single_step,
+ PixbufOpFunc init_func,
+ PixbufOpFunc step_func,
+ PixbufDataFunc release_func,
+ gpointer data,
+ GDestroyNotify destroy_data_func);
+void gth_pixbuf_task_set_source (GthPixbufTask *self,
+ GdkPixbuf *src);
+GdkPixbuf * gth_pixbuf_task_get_destination (GthPixbufTask *self);
+
+void copy_source_to_destination (GthPixbufTask *pixbuf_task);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]