[gthumb] simplified the code, added some sanity checks



commit bcf37c9c0e67d7fc9ecf9dc7e3dcb623d4a4ea43
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Mon Dec 22 16:18:53 2014 +0100

    simplified the code, added some sanity checks

 .../file_tools/gth-file-tool-adjust-contrast.c     |    9 ++++--
 extensions/file_tools/gth-file-tool-grayscale.c    |   10 +++---
 gthumb/gth-filter-grid.c                           |   27 +++++++++----------
 3 files changed, 24 insertions(+), 22 deletions(-)
---
diff --git a/extensions/file_tools/gth-file-tool-adjust-contrast.c 
b/extensions/file_tools/gth-file-tool-adjust-contrast.c
index c1be9cb..4c81ebd 100644
--- a/extensions/file_tools/gth-file-tool-adjust-contrast.c
+++ b/extensions/file_tools/gth-file-tool-adjust-contrast.c
@@ -74,6 +74,9 @@ value_map_free (long **value_map)
 {
        int c;
 
+       if (value_map == NULL)
+               return;
+
        for (c = 0; c < GTH_HISTOGRAM_N_CHANNELS; c++)
                g_free (value_map[c]);
        g_free (value_map);
@@ -581,10 +584,10 @@ gth_file_tool_adjust_contrast_destroy_options (GthFileTool *base)
        gth_image_viewer_page_reset_viewer_tool (GTH_IMAGE_VIEWER_PAGE (viewer_page));
        gth_viewer_page_update_sensitivity (GTH_VIEWER_PAGE (viewer_page));
 
-       _cairo_clear_surface (&self->priv->preview);
-       _cairo_clear_surface (&self->priv->destination);
        _g_clear_object (&self->priv->builder);
 
+       _cairo_clear_surface (&self->priv->preview);
+       _cairo_clear_surface (&self->priv->destination);
        self->priv->method = -1;
        self->priv->last_applied_method = -1;
 }
@@ -600,9 +603,9 @@ gth_file_tool_adjust_contrast_finalize (GObject *object)
 
        self = (GthFileToolAdjustContrast *) object;
 
+       _g_clear_object (&self->priv->builder);
        _cairo_clear_surface (&self->priv->preview);
        _cairo_clear_surface (&self->priv->destination);
-       _g_clear_object (&self->priv->builder);
 
        G_OBJECT_CLASS (gth_file_tool_adjust_contrast_parent_class)->finalize (object);
 }
diff --git a/extensions/file_tools/gth-file-tool-grayscale.c b/extensions/file_tools/gth-file-tool-grayscale.c
index ea26c94..2f2d066 100644
--- a/extensions/file_tools/gth-file-tool-grayscale.c
+++ b/extensions/file_tools/gth-file-tool-grayscale.c
@@ -434,10 +434,10 @@ gth_file_tool_grayscale_destroy_options (GthFileTool *base)
        gth_image_viewer_page_reset_viewer_tool (GTH_IMAGE_VIEWER_PAGE (viewer_page));
        gth_viewer_page_update_sensitivity (GTH_VIEWER_PAGE (viewer_page));
 
-       _cairo_clear_surface (&self->priv->preview);
-       _cairo_clear_surface (&self->priv->destination);
        _g_clear_object (&self->priv->builder);
 
+       _cairo_clear_surface (&self->priv->preview);
+       _cairo_clear_surface (&self->priv->destination);
        self->priv->method = -1;
        self->priv->last_applied_method = -1;
 }
@@ -453,9 +453,9 @@ gth_file_tool_grayscale_finalize (GObject *object)
 
        self = (GthFileToolGrayscale *) object;
 
-       cairo_surface_destroy (self->priv->preview);
-       cairo_surface_destroy (self->priv->destination);
-       _g_object_unref (self->priv->builder);
+       _g_clear_object (&self->priv->builder);
+       _cairo_clear_surface (&self->priv->preview);
+       _cairo_clear_surface (&self->priv->destination);
 
        G_OBJECT_CLASS (gth_file_tool_grayscale_parent_class)->finalize (object);
 }
diff --git a/gthumb/gth-filter-grid.c b/gthumb/gth-filter-grid.c
index b6e96fe..1d02405 100644
--- a/gthumb/gth-filter-grid.c
+++ b/gthumb/gth-filter-grid.c
@@ -349,7 +349,9 @@ gth_filter_grid_activate (GthFilterGrid     *self,
 static void
 preview_task_free (PreviewTask *task)
 {
-       g_object_unref (task->image_task);
+       if (task == NULL)
+               return;
+       _g_object_unref (task->image_task);
        g_free (task);
 }
 
@@ -357,12 +359,13 @@ preview_task_free (PreviewTask *task)
 static void
 generate_preview_data_free (GeneratePreviewData *data)
 {
-       cairo_surface_destroy (data->original);
        if (data->self != NULL) {
                if (data->self->priv->gp_data == data)
                        data->self->priv->gp_data = NULL;
                g_object_remove_weak_pointer (G_OBJECT (data->self), (gpointer *) &data->self);
        }
+       if (data->original != NULL)
+               cairo_surface_destroy (data->original);
        g_list_free_full (data->tasks, (GDestroyNotify) preview_task_free);
        _g_object_unref (data->cancellable);
        _g_object_unref (data->resize_task);
@@ -387,8 +390,12 @@ image_preview_completed_cb (GthTask    *task,
                            gpointer    user_data)
 {
        GeneratePreviewData *data = user_data;
+       PreviewTask         *current_task;
        cairo_surface_t     *preview;
 
+       current_task = (PreviewTask *) data->current_task->data;
+       g_return_if_fail (task == current_task->image_task);
+
        if ((error != NULL) || (data->self == NULL)) {
                generate_preview_data_free (data);
                return;
@@ -396,8 +403,8 @@ image_preview_completed_cb (GthTask    *task,
 
        preview = gth_image_task_get_destination_surface (GTH_IMAGE_TASK (task));
        if (preview != NULL) {
-               PreviewTask *task = (PreviewTask *) data->current_task->data;
-               gth_filter_grid_set_filter_preview (data->self, task->filter_id, preview);
+               gth_filter_grid_set_filter_preview (data->self, current_task->filter_id, preview);
+               cairo_surface_destroy (preview);
        }
 
        data->current_task = g_list_next (data->current_task);
@@ -416,15 +423,13 @@ generate_preview (GeneratePreviewData *data)
        }
 
        task = (PreviewTask *) data->current_task->data;
-
        g_signal_connect (task->image_task,
                          "completed",
                          G_CALLBACK (image_preview_completed_cb),
                          data);
        gth_image_task_set_source_surface (GTH_IMAGE_TASK (task->image_task), data->original);
 
-       _g_object_unref (data->cancellable);
-       data->cancellable = g_cancellable_new ();
+       g_cancellable_reset (data->cancellable);
        gth_task_exec (task->image_task, data->cancellable);
 }
 
@@ -436,16 +441,11 @@ resize_task_completed_cb (GthTask  *task,
 {
        GeneratePreviewData *data = user_data;
 
-       _g_object_unref (data->resize_task);
-       data->resize_task = NULL;
-
        if ((error != NULL) || (data->self == NULL)) {
                generate_preview_data_free (data);
                return;
        }
 
-       if (data->original != NULL)
-               cairo_surface_destroy (data->original);
        data->original = gth_image_task_get_destination_surface (GTH_IMAGE_TASK (task));
        if (data->original == NULL) {
                generate_preview_data_free (data);
@@ -499,7 +499,7 @@ gth_filter_grid_generate_previews (GthFilterGrid    *self,
        data = g_new (GeneratePreviewData, 1);
        data->self = self;
        data->tasks = NULL;
-       data->cancellable = NULL;
+       data->cancellable = g_cancellable_new ();;
        data->original = NULL;
 
        g_object_add_weak_pointer (G_OBJECT (self), (gpointer *) &data->self);
@@ -539,6 +539,5 @@ gth_filter_grid_generate_previews (GthFilterGrid    *self,
                          G_CALLBACK (resize_task_completed_cb),
                          data);
 
-       data->cancellable = g_cancellable_new ();
        gth_task_exec (data->resize_task, data->cancellable);
 }


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