[gthumb] rotate image: load the original image using a GthImageViewerTask



commit 474d631802989f4a038d5dc2b227ef01e12f0952
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Tue Sep 24 23:07:41 2013 +0200

    rotate image: load the original image using a GthImageViewerTask

 extensions/file_tools/gth-file-tool-rotate.c |   45 ++++++++++++++++++++-----
 extensions/file_tools/gth-image-rotator.c    |   37 ++++++++++++++-------
 extensions/file_tools/gth-image-rotator.h    |    3 +-
 3 files changed, 62 insertions(+), 23 deletions(-)
---
diff --git a/extensions/file_tools/gth-file-tool-rotate.c b/extensions/file_tools/gth-file-tool-rotate.c
index b3c57a1..d820728 100644
--- a/extensions/file_tools/gth-file-tool-rotate.c
+++ b/extensions/file_tools/gth-file-tool-rotate.c
@@ -22,7 +22,7 @@
 #include <math.h>
 #include <config.h>
 #include <gthumb.h>
-#include <extensions/image_viewer/gth-image-viewer-page.h>
+#include <extensions/image_viewer/image-viewer.h>
 #include "cairo-rotate.h"
 #include "enum-types.h"
 #include "gth-file-tool-rotate.h"
@@ -232,22 +232,49 @@ reset_button_clicked_cb (GtkButton         *button,
 }
 
 
+static gpointer
+rotate_exec (GthAsyncTask *task,
+            gpointer      user_data)
+{
+       GthImageViewerTool *rotator = user_data;
+       cairo_surface_t    *source;
+       cairo_surface_t    *destination;
+
+       source = gth_image_task_get_source_surface (GTH_IMAGE_TASK (task));
+       destination = gth_image_rotator_get_result (GTH_IMAGE_ROTATOR (rotator), source, task);
+       gth_image_task_set_destination_surface (GTH_IMAGE_TASK (task), destination);
+
+       cairo_surface_destroy (destination);
+       cairo_surface_destroy (source);
+
+       return NULL;
+}
+
+
 static void
 apply_button_clicked_cb (GtkButton         *button,
                         GthFileToolRotate *self)
 {
-       cairo_surface_t *image;
-       GtkWidget       *window;
-       GtkWidget       *viewer_page;
-
-       image = gth_image_rotator_get_result (GTH_IMAGE_ROTATOR (self->priv->rotator), FALSE);
+       GtkWidget   *window;
+       GtkWidget   *viewer_page;
+       GthTask     *task;
 
        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_image (GTH_IMAGE_VIEWER_PAGE (viewer_page), image, TRUE);
-       gth_file_tool_hide_options (GTH_FILE_TOOL (self));
+       task = gth_image_viewer_task_new (GTH_IMAGE_VIEWER_PAGE (viewer_page),
+                                         _("Applying changes"),
+                                         NULL,
+                                         rotate_exec,
+                                         NULL,
+                                         g_object_ref (self->priv->rotator),
+                                         g_object_unref);
+       g_signal_connect (task,
+                         "completed",
+                         G_CALLBACK (gth_image_viewer_task_set_destination),
+                         NULL);
+       gth_browser_exec_task (GTH_BROWSER (window), task, FALSE);
 
-       cairo_surface_destroy (image);
+       gth_file_tool_hide_options (GTH_FILE_TOOL (self));
 }
 
 
diff --git a/extensions/file_tools/gth-image-rotator.c b/extensions/file_tools/gth-image-rotator.c
index 7ec4b22..5767cc5 100644
--- a/extensions/file_tools/gth-image-rotator.c
+++ b/extensions/file_tools/gth-image-rotator.c
@@ -850,7 +850,7 @@ gth_image_rotator_get_background (GthImageRotator *self,
 }
 
 
-static cairo_surface_t *
+G_GNUC_UNUSED static cairo_surface_t *
 gth_image_rotator_get_result_fast (GthImageRotator *self)
 {
        double                 tx, ty;
@@ -925,15 +925,19 @@ gth_image_rotator_get_result_fast (GthImageRotator *self)
 
 
 static cairo_surface_t *
-gth_image_rotator_get_result_high_quality (GthImageRotator *self)
+gth_image_rotator_get_result_high_quality (GthImageRotator *self,
+                                          cairo_surface_t *image,
+                                          GthAsyncTask    *task)
 {
        cairo_surface_t *rotated;
        cairo_surface_t *result;
+       double           zoom;
 
-       rotated = _cairo_image_surface_rotate (gth_image_viewer_get_current_image (GTH_IMAGE_VIEWER 
(self->priv->viewer)),
+       rotated = _cairo_image_surface_rotate (image,
                                               self->priv->angle / G_PI * 180.0,
                                               TRUE,
-                                              &self->priv->background_color);
+                                              &self->priv->background_color,
+                                              task);
 
        switch (self->priv->resize) {
        case GTH_TRANSFORM_RESIZE_BOUNDING_BOX:
@@ -944,14 +948,23 @@ gth_image_rotator_get_result_high_quality (GthImageRotator *self)
                break;
 
        case GTH_TRANSFORM_RESIZE_CLIP:
-               self->priv->crop_region.x = MAX (((double) cairo_image_surface_get_width (rotated) - 
self->priv->original_width) / 2.0, 0);
-               self->priv->crop_region.y = MAX (((double) cairo_image_surface_get_height (rotated) - 
self->priv->original_height) / 2.0, 0);
-               self->priv->crop_region.width = self->priv->original_width;
-               self->priv->crop_region.height = self->priv->original_height;
+               self->priv->crop_region.x = MAX (((double) cairo_image_surface_get_width (rotated) - 
cairo_image_surface_get_width (image)) / 2.0, 0);
+               self->priv->crop_region.y = MAX (((double) cairo_image_surface_get_height (rotated) - 
cairo_image_surface_get_height (image)) / 2.0, 0);
+               self->priv->crop_region.width = cairo_image_surface_get_width (image);
+               self->priv->crop_region.height = cairo_image_surface_get_height (image);
                break;
 
        case GTH_TRANSFORM_RESIZE_CROP:
                /* set by the user */
+
+               zoom = (double) cairo_image_surface_get_width (image) / self->priv->original_width;
+               self->priv->crop_region.x *= zoom;
+               self->priv->crop_region.width *= zoom;
+
+               zoom = (double) cairo_image_surface_get_height (image) / self->priv->original_height;
+               self->priv->crop_region.y *= zoom;
+               self->priv->crop_region.height *= zoom;
+
                break;
        }
 
@@ -969,10 +982,8 @@ gth_image_rotator_get_result_high_quality (GthImageRotator *self)
 
 cairo_surface_t *
 gth_image_rotator_get_result (GthImageRotator *self,
-                             gboolean         high_quality)
+                             cairo_surface_t *image,
+                             GthAsyncTask    *task)
 {
-       if (high_quality)
-               return gth_image_rotator_get_result_high_quality (self);
-       else
-               return gth_image_rotator_get_result_fast (self);
+       return gth_image_rotator_get_result_high_quality (self, image, task);
 }
diff --git a/extensions/file_tools/gth-image-rotator.h b/extensions/file_tools/gth-image-rotator.h
index 4300be0..06136f3 100644
--- a/extensions/file_tools/gth-image-rotator.h
+++ b/extensions/file_tools/gth-image-rotator.h
@@ -89,7 +89,8 @@ void                  gth_image_rotator_set_background  (GthImageRotator       *
 void                  gth_image_rotator_get_background  (GthImageRotator       *self,
                                                         GdkRGBA               *color);
 cairo_surface_t *     gth_image_rotator_get_result      (GthImageRotator       *self,
-                                                        gboolean               high_quality);
+                                                        cairo_surface_t       *image,
+                                                        GthAsyncTask          *task);
 
 G_END_DECLS
 


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