[gthumb] negative: load the original image using a GthImageViewerTask
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] negative: load the original image using a GthImageViewerTask
- Date: Sat, 9 Nov 2013 19:58:01 +0000 (UTC)
commit 71c846c8fd5962b184b91b891abc462fb191f2d9
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sat Sep 21 16:48:24 2013 +0200
negative: load the original image using a GthImageViewerTask
extensions/file_tools/gth-file-tool-negative.c | 106 +++++++-----------------
1 files changed, 31 insertions(+), 75 deletions(-)
---
diff --git a/extensions/file_tools/gth-file-tool-negative.c b/extensions/file_tools/gth-file-tool-negative.c
index 71d69ba..e16cba8 100644
--- a/extensions/file_tools/gth-file-tool-negative.c
+++ b/extensions/file_tools/gth-file-tool-negative.c
@@ -21,20 +21,13 @@
#include <config.h>
#include <gthumb.h>
-#include <extensions/image_viewer/gth-image-viewer-page.h>
+#include <extensions/image_viewer/image-viewer.h>
#include "gth-file-tool-negative.h"
G_DEFINE_TYPE (GthFileToolNegative, gth_file_tool_negative, GTH_TYPE_FILE_TOOL)
-typedef struct {
- GtkWidget *viewer_page;
- cairo_surface_t *source;
- cairo_surface_t *destination;
-} NegativeData;
-
-
static void
gth_file_tool_negative_update_sensitivity (GthFileTool *base)
{
@@ -50,34 +43,16 @@ gth_file_tool_negative_update_sensitivity (GthFileTool *base)
}
-static void
-negative_data_free (gpointer user_data)
-{
- NegativeData *negative_data = user_data;
-
- cairo_surface_destroy (negative_data->destination);
- cairo_surface_destroy (negative_data->source);
- g_free (negative_data);
-}
-
-
-static void
-negative_init (GthAsyncTask *task,
- gpointer user_data)
-{
- gth_task_progress (GTH_TASK (task), _("Applying changes"), NULL, TRUE, 0.0);
-}
-
-
static gpointer
negative_exec (GthAsyncTask *task,
gpointer user_data)
{
- NegativeData *negative_data = user_data;
+ cairo_surface_t *source;
cairo_format_t format;
int width;
int height;
int source_stride;
+ cairo_surface_t *destination;
int destination_stride;
unsigned char *p_source_line;
unsigned char *p_destination_line;
@@ -85,19 +60,19 @@ negative_exec (GthAsyncTask *task,
unsigned char *p_destination;
gboolean cancelled;
double progress;
- gboolean terminated;
int x, y;
unsigned char red, green, blue, alpha;
- format = cairo_image_surface_get_format (negative_data->source);
- width = cairo_image_surface_get_width (negative_data->source);
- height = cairo_image_surface_get_height (negative_data->source);
- source_stride = cairo_image_surface_get_stride (negative_data->source);
+ source = gth_image_task_get_source_surface (GTH_IMAGE_TASK (task));
+ format = cairo_image_surface_get_format (source);
+ width = cairo_image_surface_get_width (source);
+ height = cairo_image_surface_get_height (source);
+ source_stride = cairo_image_surface_get_stride (source);
- negative_data->destination = cairo_image_surface_create (format, width, height);
- destination_stride = cairo_image_surface_get_stride (negative_data->destination);
- p_source_line = _cairo_image_surface_flush_and_get_data (negative_data->source);
- p_destination_line = _cairo_image_surface_flush_and_get_data (negative_data->destination);
+ destination = cairo_image_surface_create (format, width, height);
+ destination_stride = cairo_image_surface_get_stride (destination);
+ p_source_line = _cairo_image_surface_flush_and_get_data (source);
+ p_destination_line = _cairo_image_surface_flush_and_get_data (destination);
for (y = 0; y < height; y++) {
gth_async_task_get_data (task, NULL, &cancelled, NULL);
if (cancelled)
@@ -123,59 +98,40 @@ negative_exec (GthAsyncTask *task,
p_destination_line += destination_stride;
}
- cairo_surface_mark_dirty (negative_data->destination);
- terminated = TRUE;
- gth_async_task_set_data (task, &terminated, NULL, NULL);
-
- return NULL;
-}
+ cairo_surface_mark_dirty (destination);
+ gth_image_task_set_destination_surface (GTH_IMAGE_TASK (task), destination);
+ cairo_surface_destroy (destination);
+ cairo_surface_destroy (source);
-static void
-negative_after (GthAsyncTask *task,
- GError *error,
- gpointer user_data)
-{
- NegativeData *negative_data = user_data;
-
- if (error == NULL)
- gth_image_viewer_page_set_image (GTH_IMAGE_VIEWER_PAGE (negative_data->viewer_page),
- negative_data->destination,
- TRUE);
+ return NULL;
}
static void
gth_file_tool_negative_activate (GthFileTool *base)
{
- GtkWidget *window;
- GtkWidget *viewer_page;
- GtkWidget *viewer;
- cairo_surface_t *image;
- NegativeData *negative_data;
- GthTask *task;
+ GtkWidget *window;
+ GtkWidget *viewer_page;
+ 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));
- image = gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER (viewer));
- if (image == NULL)
- return;
-
- negative_data = g_new0 (NegativeData, 1);
- negative_data->viewer_page = viewer_page;
- negative_data->source = cairo_surface_reference (image);
- task = gth_async_task_new (negative_init,
- negative_exec,
- negative_after,
- negative_data,
- negative_data_free);
+ task = gth_image_viewer_task_new (GTH_IMAGE_VIEWER_PAGE (viewer_page),
+ _("Applying changes"),
+ NULL,
+ negative_exec,
+ NULL,
+ NULL,
+ NULL);
+ g_signal_connect (task,
+ "completed",
+ G_CALLBACK (gth_image_viewer_task_set_destination),
+ NULL);
gth_browser_exec_task (GTH_BROWSER (window), task, FALSE);
-
- g_object_unref (task);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]