Updating branch refs/heads/ristretto-0.0 to 1f40e6b21f7fcad72dd19442570ccdf12cc8a6a0 (commit) from 35499a94d25bde24f109593fe41b8f04b358202a (commit)
commit 1f40e6b21f7fcad72dd19442570ccdf12cc8a6a0 Author: Stephan Arts <stephan@thor.(none)> Date: Sat May 16 10:49:05 2009 +0200 Re-implement image rotation to work with the new rendering method ChangeLog | 14 ++ src/Makefile.am | 4 +- src/image.c | 152 +++------------------ src/image.h | 12 +- src/image_transform_orientation.c | 278 ------------------------------------- src/image_transform_orientation.h | 67 --------- src/image_transformation.c | 72 ---------- src/image_transformation.h | 64 --------- src/main_window.c | 43 +++++-- src/picture_viewer.c | 217 +++++++++++++++++++++-------- 10 files changed, 229 insertions(+), 694 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9b3d98b..bab5a96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2009-05-16 Stephan Arts <step...@xfce.org> + + * src/image.c + src/image.h + src/main_window.c + src/picture_viewer.c + src/image_transformation.h + src/image_transformation.c + src/image_transform_orientation.h + src/image_transform_orientation.c + src/Makefile.am: Re-implement image-rotation, now it finally works with + the new rendering method. + + 2009-05-15 Stephan Arts <step...@xfce.org> * src/main_window.c: Set current_uri on open_folder dialog diff --git a/src/Makefile.am b/src/Makefile.am index 1fed4dc..8ef558d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -4,8 +4,6 @@ ristretto_SOURCES = \ navigator.c navigator.h \ image.c image.h \ image_cache.c image_cache.h \ - image_transformation.c image_transformation.h \ - image_transform_orientation.c image_transform_orientation.h \ picture_viewer.c picture_viewer.h \ settings.c settings.h \ preferences_dialog.h preferences_dialog.c \ @@ -27,7 +25,7 @@ ristretto_CFLAGS = \ $(LIBXFCEGUI4_CFLAGS) \ -DDATADIR=\"$(datadir)\" \ -DSRCDIR=\"$(top_srcdir)\" \ - -DLOCALEDIR=\"$(localedir)\" + -DLOCALEDIR=\"$(localedir)\" -pg ristretto_LDADD = \ $(GTK_LIBS) \ diff --git a/src/image.c b/src/image.c index 62d3f3a..b175bbd 100644 --- a/src/image.c +++ b/src/image.c @@ -28,8 +28,6 @@ #include "image.h" #include "image_cache.h" -#include "image_transformation.h" -#include "image_transform_orientation.h" #ifndef RSTTO_IMAGE_BUFFER_SIZE /* #define RSTTO_IMAGE_BUFFER_SIZE 1024 */ @@ -108,6 +106,7 @@ struct _RsttoImagePriv /* Image data */ /**************/ + RsttoImageOrientation orientation; GdkPixbufLoader *loader; ExifData *exif_data; GdkPixbuf *thumbnail; @@ -119,8 +118,6 @@ struct _RsttoImagePriv GdkPixbufAnimation *animation; GdkPixbufAnimationIter *iter; gint animation_timeout_id; - - GList *transformations; }; @@ -210,13 +207,6 @@ rstto_image_dispose (GObject *object) image->priv->pixbuf = NULL; } - if (image->priv->transformations) - { - g_list_foreach (image->priv->transformations, (GFunc)g_object_unref, NULL); - g_list_free (image->priv->transformations); - image->priv->transformations = NULL; - } - if (image->priv->buffer) { g_free (image->priv->buffer); @@ -240,7 +230,6 @@ rstto_image_new (GFile *file) RsttoImage *image = g_object_new (RSTTO_TYPE_IMAGE, NULL); gchar *file_path = g_file_get_path (file); ExifEntry *exif_entry = NULL; - RsttoImageTransformation *transformation = NULL; RsttoImageOrientation orientation; image->priv->file = file; @@ -253,40 +242,13 @@ rstto_image_new (GFile *file) } if (exif_entry && exif_entry->data != NULL) { - orientation = exif_get_short (exif_entry->data, exif_data_get_byte_order (exif_entry->parent->parent)); - switch (orientation) - { - default: - case RSTTO_IMAGE_ORIENT_NONE: - transformation = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_NONE); - break; - case RSTTO_IMAGE_ORIENT_90: - transformation = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_CLOCKWISE); - break; - case RSTTO_IMAGE_ORIENT_180: - transformation = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_UPSIDEDOWN); - break; - case RSTTO_IMAGE_ORIENT_270: - transformation = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE); - break; - case RSTTO_IMAGE_ORIENT_FLIP_HORIZONTAL: - transformation = rstto_image_transform_orientation_new ( FALSE, TRUE, GDK_PIXBUF_ROTATE_NONE); - break; - case RSTTO_IMAGE_ORIENT_FLIP_VERTICAL: - transformation = rstto_image_transform_orientation_new ( TRUE, FALSE, GDK_PIXBUF_ROTATE_NONE); - break; - case RSTTO_IMAGE_ORIENT_TRANSPOSE: - transformation = rstto_image_transform_orientation_new ( FALSE, TRUE, GDK_PIXBUF_ROTATE_CLOCKWISE); - break; - case RSTTO_IMAGE_ORIENT_TRANSVERSE: - transformation = rstto_image_transform_orientation_new ( TRUE, FALSE, GDK_PIXBUF_ROTATE_CLOCKWISE); - break; - } + image->priv->orientation = exif_get_short (exif_entry->data, exif_data_get_byte_order (exif_entry->parent->parent)); + if (image->priv->orientation == 0) + image->priv->orientation = RSTTO_IMAGE_ORIENT_NONE; } - - if (transformation) + else { - rstto_image_push_transformation (image, G_OBJECT (transformation), NULL); + image->priv->orientation = RSTTO_IMAGE_ORIENT_NONE; } return image; @@ -470,13 +432,6 @@ rstto_image_unload (RsttoImage *image) image->priv->iter = NULL; } - if (image->priv->transformations) - { - g_list_foreach (image->priv->transformations, (GFunc)g_object_unref, NULL); - g_list_free (image->priv->transformations); - image->priv->transformations = NULL; - } - } @@ -595,59 +550,6 @@ rstto_image_set_pixbuf (RsttoImage *image, GdkPixbuf *pixbuf) } /** - * rstto_image_push_transformation: - * @image : - * @transformation : - * @error : - * - * Return value: TRUE on success. - */ -gboolean -rstto_image_push_transformation (RsttoImage *image, GObject *object, GError **error) -{ - g_return_val_if_fail (RSTTO_IS_IMAGE_TRANSFORMATION (object), FALSE); - RsttoImageTransformation *transformation = RSTTO_IMAGE_TRANSFORMATION (object); - - g_object_ref (transformation); - /* Perform the transformation, on success add it to the stack */ - if (transformation->transform (transformation, image) == TRUE) - { - image->priv->transformations = g_list_prepend (image->priv->transformations, transformation); - return TRUE; - } - g_object_unref (transformation); - return FALSE; -} - - -/** - * rstto_image_pop_transformation: - * @image : - * @error : - * - * Return value: TRUE on success. - */ -gboolean -rstto_image_pop_transformation (RsttoImage *image, GError **error) -{ - if (image->priv->transformations) - { - RsttoImageTransformation *transformation = image->priv->transformations->data; - - if (transformation->revert (transformation, image) == TRUE) - { - /* remove the first item from the list */ - image->priv->transformations = g_list_delete_link (image->priv->transformations, image->priv->transformations); - g_object_unref (transformation); - transformation = NULL; - return TRUE; - } - } - return FALSE; -} - - -/** * PRIVATE CALLBACKS */ @@ -729,7 +631,6 @@ cb_rstto_image_closed (GdkPixbufLoader *loader, RsttoImage *image) g_return_if_fail (loader == image->priv->loader); GdkPixbuf *pixbuf = NULL; - RsttoImageTransformation *transformation = NULL; g_object_unref (image->priv->loader); image->priv->loader = NULL; @@ -737,19 +638,6 @@ cb_rstto_image_closed (GdkPixbufLoader *loader, RsttoImage *image) if (image->priv->pixbuf != NULL) { - /* Get to the bottom of the transformation list */ - GList *transform_iter = g_list_last (image->priv->transformations); - while (transform_iter != NULL) - { - transformation = transform_iter->data; - - /* Transform source image */ - transformation->transform (transformation, image); - - transform_iter = g_list_previous (transform_iter); - } - - g_signal_emit(G_OBJECT(image), rstto_image_signals[RSTTO_IMAGE_SIGNAL_UPDATED], 0, image, NULL); } } @@ -763,7 +651,6 @@ cb_rstto_image_closed (GdkPixbufLoader *loader, RsttoImage *image) static gboolean cb_rstto_image_update(RsttoImage *image) { - RsttoImageTransformation *transformation = NULL; if (image->priv->iter) { @@ -777,20 +664,6 @@ cb_rstto_image_update(RsttoImage *image) } image->priv->pixbuf = gdk_pixbuf_animation_iter_get_pixbuf (image->priv->iter); - if (image->priv->pixbuf) - { - /* Get to the bottom of the transformation list */ - GList *transform_iter = g_list_last (image->priv->transformations); - while (transform_iter != NULL) - { - transformation = transform_iter->data; - - /* Transform source image */ - transformation->transform (transformation, image); - - transform_iter = g_list_previous (transform_iter); - } - } } gint time = gdk_pixbuf_animation_iter_get_delay_time (image->priv->iter); @@ -822,3 +695,16 @@ rstto_image_get_size (RsttoImage *image) } return 0; } + +RsttoImageOrientation +rstto_image_get_orientation (RsttoImage *image) +{ + return image->priv->orientation; +} + +void +rstto_image_set_orientation (RsttoImage *image, RsttoImageOrientation orientation) +{ + image->priv->orientation = orientation; + g_signal_emit (G_OBJECT(image), rstto_image_signals[RSTTO_IMAGE_SIGNAL_UPDATED], 0, image, NULL); +} diff --git a/src/image.h b/src/image.h index 05b0846..87b7c27 100644 --- a/src/image.h +++ b/src/image.h @@ -81,15 +81,13 @@ GFile *rstto_image_get_file (RsttoImage *image); void rstto_image_unload (RsttoImage *image); gboolean rstto_image_load (RsttoImage *image, gboolean empty_cache, guint max_size, gboolean preload, GError **error); -gboolean -rstto_image_push_transformation (RsttoImage *image, GObject *transformation, GError **error); -gboolean -rstto_image_pop_transformation (RsttoImage *image, GError **error); - -/* Should only be used by image-transformation implementations */ -void rstto_image_set_pixbuf (RsttoImage *image, GdkPixbuf *pixbuf); guint rstto_image_get_size (RsttoImage *image); +void +rstto_image_set_orientation (RsttoImage *image, RsttoImageOrientation orientation); +RsttoImageOrientation +rstto_image_get_orientation (RsttoImage *image); + G_END_DECLS #endif /* __RISTRETTO_IMAGE_H__ */ diff --git a/src/image_transform_orientation.c b/src/image_transform_orientation.c deleted file mode 100644 index c984e20..0000000 --- a/src/image_transform_orientation.c +++ /dev/null @@ -1,278 +0,0 @@ -/* - * Copyright (c) 2009 Stephan Arts <step...@xfce.org> - * - * 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 Library 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 Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include <config.h> - -#include <glib.h> -#include <gio/gio.h> -#include <gdk/gdk.h> - -#include <libexif/exif-data.h> - -#include "image.h" -#include "image_transformation.h" -#include "image_transform_orientation.h" - -static void -rstto_image_transform_orientation_init (GObject *); -static void -rstto_image_transform_orientation_class_init (GObjectClass *); - -static void -rstto_image_transform_orientation_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); -static void -rstto_image_transform_orientation_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); - -static gboolean -rstto_image_transform_orientation_transform (RsttoImageTransformation *transformation, RsttoImage *image); -static gboolean -rstto_image_transform_orientation_revert (RsttoImageTransformation *transformation, RsttoImage *image); - -enum -{ - PROP_0, - PROP_TRANSFORM_FLIP_VERTICAL, - PROP_TRANSFORM_FLIP_HORIZONTAL, - PROP_TRANSFORM_ROTATION -}; - -GType -rstto_image_transform_orientation_get_type () -{ - static GType rstto_image_transform_orientation_type = 0; - - if (!rstto_image_transform_orientation_type) - { - static const GTypeInfo rstto_image_transform_orientation_info = - { - sizeof (RsttoImageTransformOrientationClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) rstto_image_transform_orientation_class_init, - (GClassFinalizeFunc) NULL, - NULL, - sizeof (RsttoImageTransformOrientation), - 0, - (GInstanceInitFunc) rstto_image_transform_orientation_init, - NULL - }; - - rstto_image_transform_orientation_type = g_type_register_static (RSTTO_TYPE_IMAGE_TRANSFORMATION, "RsttoImageTransformOrientation", &rstto_image_transform_orientation_info, 0); - } - return rstto_image_transform_orientation_type; -} - - -static void -rstto_image_transform_orientation_init (GObject *object) -{ - RsttoImageTransformation *transformation = RSTTO_IMAGE_TRANSFORMATION (object); - - transformation->transform = rstto_image_transform_orientation_transform; - transformation->revert = rstto_image_transform_orientation_revert; -} - -static void -rstto_image_transform_orientation_class_init (GObjectClass *object_class) -{ - GParamSpec *pspec; - - object_class->set_property = rstto_image_transform_orientation_set_property; - object_class->get_property = rstto_image_transform_orientation_get_property; - - pspec = g_param_spec_boolean ("flip-vertical", - "", - "Indicates if this performs a vertical flip", - FALSE /* default value */, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); - - g_object_class_install_property (object_class, - PROP_TRANSFORM_FLIP_VERTICAL, - pspec); - - pspec = g_param_spec_boolean ("flip-horizontal", - "", - "Indicates if this performs a horizontal flip", - FALSE /* default value */, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); - - g_object_class_install_property (object_class, - PROP_TRANSFORM_FLIP_HORIZONTAL, - pspec); - - - pspec = g_param_spec_uint ("rotation", - "", - "Indicates how it rotates", - 0 /* minimum */, - 360 /* maximum */, - 0 /* default value */, - G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE); - - g_object_class_install_property (object_class, - PROP_TRANSFORM_ROTATION, - pspec); - -} - -RsttoImageTransformation * -rstto_image_transform_orientation_new (gboolean flip_vertical, - gboolean flip_horizontal, - GdkPixbufRotation rotation) -{ - RsttoImageTransformation *transformation = g_object_new (RSTTO_TYPE_IMAGE_TRANSFORM_ORIENTATION, - "flip-vertical", flip_vertical, - "flip-horizontal", flip_horizontal, - "rotation", rotation, - NULL); - - return transformation; -} - -static gboolean -rstto_image_transform_orientation_transform (RsttoImageTransformation *transformation, RsttoImage *image) -{ - RsttoImageTransformOrientation *trans_orientation = RSTTO_IMAGE_TRANSFORM_ORIENTATION (transformation); - GdkPixbuf *tmp_pixbuf = NULL; - - if (trans_orientation->flip_vertical) - { - tmp_pixbuf = rstto_image_get_pixbuf (image); - if (tmp_pixbuf) - { - g_object_ref (tmp_pixbuf); - /* Flip vertically (pass FALSE to gdk_pixbuf_flip) */ - rstto_image_set_pixbuf (image, gdk_pixbuf_flip (tmp_pixbuf, FALSE)); - g_object_unref (tmp_pixbuf); - } - } - - if (trans_orientation->flip_horizontal) - { - tmp_pixbuf = rstto_image_get_pixbuf (image); - if (tmp_pixbuf) - { - g_object_ref (tmp_pixbuf); - /* Flip horizontally (pass TRUE to gdk_pixbuf_flip) */ - rstto_image_set_pixbuf (image, gdk_pixbuf_flip (tmp_pixbuf, TRUE)); - g_object_unref (tmp_pixbuf); - } - } - - - tmp_pixbuf = rstto_image_get_pixbuf (image); - if (tmp_pixbuf) - { - g_object_ref (tmp_pixbuf); - rstto_image_set_pixbuf (image, gdk_pixbuf_rotate_simple (tmp_pixbuf, (360+(trans_orientation->rotation))%360)); - g_object_unref (tmp_pixbuf); - } - - return TRUE; -} - -static gboolean -rstto_image_transform_orientation_revert (RsttoImageTransformation *transformation, RsttoImage *image) -{ - RsttoImageTransformOrientation *trans_orientation = RSTTO_IMAGE_TRANSFORM_ORIENTATION (transformation); - GdkPixbuf *tmp_pixbuf = NULL; - - if (trans_orientation->flip_vertical) - { - tmp_pixbuf = rstto_image_get_pixbuf (image); - if (tmp_pixbuf) - { - /* Flip vertically (pass FALSE to gdk_pixbuf_flip) */ - rstto_image_set_pixbuf (image, gdk_pixbuf_flip (tmp_pixbuf, FALSE)); - g_object_unref (tmp_pixbuf); - } - } - - if (trans_orientation->flip_horizontal) - { - tmp_pixbuf = rstto_image_get_pixbuf (image); - if (tmp_pixbuf) - { - /* Flip horizontally (pass TRUE to gdk_pixbuf_flip) */ - rstto_image_set_pixbuf (image, gdk_pixbuf_flip (tmp_pixbuf, TRUE)); - g_object_unref (tmp_pixbuf); - } - } - - tmp_pixbuf = rstto_image_get_pixbuf (image); - g_object_ref (tmp_pixbuf); - rstto_image_set_pixbuf (image, gdk_pixbuf_rotate_simple (tmp_pixbuf, 360-((360+(trans_orientation->rotation))%360))); - g_object_unref (tmp_pixbuf); - - return TRUE; -} - -static void -rstto_image_transform_orientation_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - RsttoImageTransformOrientation *transformation = RSTTO_IMAGE_TRANSFORM_ORIENTATION (object); - - switch (property_id) - { - case PROP_TRANSFORM_FLIP_VERTICAL: - transformation->flip_vertical = g_value_get_boolean (value); - break; - case PROP_TRANSFORM_FLIP_HORIZONTAL: - transformation->flip_horizontal = g_value_get_boolean (value); - break; - case PROP_TRANSFORM_ROTATION: - transformation->rotation = g_value_get_uint (value); - break; - default: - break; - } -} - - -static void -rstto_image_transform_orientation_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - RsttoImageTransformOrientation *transformation = RSTTO_IMAGE_TRANSFORM_ORIENTATION (object); - - switch (property_id) - { - case PROP_TRANSFORM_FLIP_VERTICAL: - g_value_set_boolean (value, transformation->flip_vertical); - break; - case PROP_TRANSFORM_FLIP_HORIZONTAL: - g_value_set_boolean (value, transformation->flip_horizontal); - break; - case PROP_TRANSFORM_ROTATION: - g_value_set_uint (value, transformation->rotation); - break; - default: - break; - } -} diff --git a/src/image_transform_orientation.h b/src/image_transform_orientation.h deleted file mode 100644 index 6604369..0000000 --- a/src/image_transform_orientation.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 Library 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 Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef __RISTRETTO_IMAGE_TRANSFORM_ORIENTATION_H__ -#define __RISTRETTO_IMAGE_TRANSFORM_ORIENTATION_H__ - -G_BEGIN_DECLS - -#define RSTTO_TYPE_IMAGE_TRANSFORM_ORIENTATION rstto_image_transform_orientation_get_type() - -#define RSTTO_IMAGE_TRANSFORM_ORIENTATION(obj)( \ - G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - RSTTO_TYPE_IMAGE_TRANSFORM_ORIENTATION, \ - RsttoImageTransformOrientation)) - -#define RSTTO_IS_IMAGE_TRANSFORM_ORIENTATION(obj)( \ - G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - RSTTO_TYPE_IMAGE_TRANSFORM_ORIENTATION)) - -#define RSTTO_IMAGE_TRANSFORM_ORIENTATION_CLASS(klass)( \ - G_TYPE_CHECK_CLASS_CAST ((klass), \ - RSTTO_TYPE_IMAGE_TRANSFORM_ORIENTATION, \ - RsttoImageTransformOrientationClass)) - -#define RSTTO_IS_IMAGE_TRANSFORM_ORIENTATION_CLASS(klass)( \ - G_TYPE_CHECK_CLASS_TYPE ((klass), \ - RSTTO_TYPE_IMAGE_TRANSFORM_ORIENTATION())) - -typedef struct _RsttoImageTransformOrientation RsttoImageTransformOrientation; - -struct _RsttoImageTransformOrientation -{ - RsttoImageTransformation parent; - - gboolean flip_horizontal; - gboolean flip_vertical; - GdkPixbufRotation rotation; -}; - -typedef struct _RsttoImageTransformOrientationClass RsttoImageTransformOrientationClass; - -struct _RsttoImageTransformOrientationClass -{ - RsttoImageTransformationClass parent_class; -}; - -RsttoImageTransformation * -rstto_image_transform_orientation_new (gboolean flip_vertical, - gboolean flip_horizontal, - GdkPixbufRotation rotation); - -G_END_DECLS - -#endif /* __RISTRETTO_IMAGE_TRANSFORM_ORIENTATION_H__ */ diff --git a/src/image_transformation.c b/src/image_transformation.c deleted file mode 100644 index b7e350d..0000000 --- a/src/image_transformation.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2009 Stephan Arts <step...@xfce.org> - * - * 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 Library 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 Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include <config.h> - -#include <glib.h> -#include <gio/gio.h> -#include <gdk/gdk.h> - -#include <libexif/exif-data.h> - -#include "image.h" -#include "image_transformation.h" - -static void -rstto_image_transformation_init (GObject *); -static void -rstto_image_transformation_class_init (GObjectClass *); - -GType -rstto_image_transformation_get_type () -{ - static GType rstto_image_transformation_type = 0; - - if (!rstto_image_transformation_type) - { - static const GTypeInfo rstto_image_transformation_info = - { - sizeof (RsttoImageTransformationClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) rstto_image_transformation_class_init, - (GClassFinalizeFunc) NULL, - NULL, - sizeof (RsttoImageTransformation), - 0, - (GInstanceInitFunc) rstto_image_transformation_init, - NULL - }; - - rstto_image_transformation_type = g_type_register_static (G_TYPE_OBJECT, "RsttoImageTransformation", &rstto_image_transformation_info, 0); - } - return rstto_image_transformation_type; -} - - -static void -rstto_image_transformation_init (GObject *object) -{ - -} - -static void -rstto_image_transformation_class_init (GObjectClass *object_class) -{ - -} diff --git a/src/image_transformation.h b/src/image_transformation.h deleted file mode 100644 index 29a1e9c..0000000 --- a/src/image_transformation.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 Library 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 Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef __RISTRETTO_IMAGE_TRANSFORMATION_H__ -#define __RISTRETTO_IMAGE_TRANSFORMATION_H__ - -G_BEGIN_DECLS - -#define RSTTO_TYPE_IMAGE_TRANSFORMATION rstto_image_transformation_get_type() - -#define RSTTO_IMAGE_TRANSFORMATION(obj)( \ - G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - RSTTO_TYPE_IMAGE_TRANSFORMATION, \ - RsttoImageTransformation)) - -#define RSTTO_IS_IMAGE_TRANSFORMATION(obj)( \ - G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - RSTTO_TYPE_IMAGE_TRANSFORMATION)) - -#define RSTTO_IMAGE_TRANSFORMATION_CLASS(klass)( \ - G_TYPE_CHECK_CLASS_CAST ((klass), \ - RSTTO_TYPE_IMAGE_TRANSFORMATION, \ - RsttoImageTransformationClass)) - -#define RSTTO_IS_IMAGE_TRANSFORMATION_CLASS(klass)( \ - G_TYPE_CHECK_CLASS_TYPE ((klass), \ - RSTTO_TYPE_IMAGE_TRANSFORMATION())) - -typedef struct _RsttoImageTransformation RsttoImageTransformation; - -struct _RsttoImageTransformation -{ - GObject parent; - - gboolean (*transform)(RsttoImageTransformation *, RsttoImage *); - gboolean (*revert)(RsttoImageTransformation *, RsttoImage *); -}; - -typedef struct _RsttoImageTransformationClass RsttoImageTransformationClass; - -struct _RsttoImageTransformationClass -{ - GObjectClass parent_class; -}; - -GType -rstto_image_transformation_get_type (); - -G_END_DECLS - -#endif /* __RISTRETTO_IMAGE_TRANSFORMATION_H__ */ diff --git a/src/main_window.c b/src/main_window.c index a0d273b..4e37b7e 100644 --- a/src/main_window.c +++ b/src/main_window.c @@ -28,9 +28,6 @@ #include "image.h" -#include "image_transformation.h" -#include "image_transform_orientation.h" - #include "settings.h" #include "navigator.h" #include "picture_viewer.h" @@ -778,7 +775,6 @@ cb_rstto_main_window_zoom_out (GtkWidget *widget, RsttoMainWindow *window) static void cb_rstto_main_window_rotate_cw (GtkWidget *widget, RsttoMainWindow *window) { - RsttoImageTransformation *transform; RsttoImage *image = NULL; RsttoSettings *settings_manager = rstto_settings_new(); @@ -792,9 +788,23 @@ cb_rstto_main_window_rotate_cw (GtkWidget *widget, RsttoMainWindow *window) if (image) { - transform = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_CLOCKWISE); - rstto_image_push_transformation (image, G_OBJECT (transform), NULL); - rstto_image_load (image, TRUE, g_value_get_uint (&max_size), FALSE, NULL); + switch (rstto_image_get_orientation (image)) + { + case RSTTO_IMAGE_ORIENT_NONE: + rstto_image_set_orientation (image, RSTTO_IMAGE_ORIENT_270); + break; + case RSTTO_IMAGE_ORIENT_90: + rstto_image_set_orientation (image, RSTTO_IMAGE_ORIENT_NONE); + break; + case RSTTO_IMAGE_ORIENT_180: + rstto_image_set_orientation (image, RSTTO_IMAGE_ORIENT_90); + break; + case RSTTO_IMAGE_ORIENT_270: + rstto_image_set_orientation (image, RSTTO_IMAGE_ORIENT_180); + break; + default: + g_debug ("O: %d", rstto_image_get_orientation (image)); + } } g_value_unset (&max_size); @@ -810,7 +820,6 @@ cb_rstto_main_window_rotate_cw (GtkWidget *widget, RsttoMainWindow *window) static void cb_rstto_main_window_rotate_ccw (GtkWidget *widget, RsttoMainWindow *window) { - RsttoImageTransformation *transform; RsttoImage *image = NULL; RsttoSettings *settings_manager = rstto_settings_new(); @@ -824,9 +833,21 @@ cb_rstto_main_window_rotate_ccw (GtkWidget *widget, RsttoMainWindow *window) if (image) { - transform = rstto_image_transform_orientation_new ( FALSE, FALSE, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE); - rstto_image_push_transformation (image, G_OBJECT (transform), NULL); - rstto_image_load (image, TRUE, g_value_get_uint (&max_size), FALSE, NULL); + switch (rstto_image_get_orientation (image)) + { + case RSTTO_IMAGE_ORIENT_NONE: + rstto_image_set_orientation (image, RSTTO_IMAGE_ORIENT_90); + break; + case RSTTO_IMAGE_ORIENT_90: + rstto_image_set_orientation (image, RSTTO_IMAGE_ORIENT_180); + break; + case RSTTO_IMAGE_ORIENT_180: + rstto_image_set_orientation (image, RSTTO_IMAGE_ORIENT_270); + break; + case RSTTO_IMAGE_ORIENT_270: + rstto_image_set_orientation (image, RSTTO_IMAGE_ORIENT_NONE); + break; + } } g_value_unset (&max_size); } diff --git a/src/picture_viewer.c b/src/picture_viewer.c index 59b6f30..c891798 100644 --- a/src/picture_viewer.c +++ b/src/picture_viewer.c @@ -730,8 +730,18 @@ rstto_picture_viewer_calculate_scale (RsttoPictureViewer *viewer) if (viewer->priv->image != NULL) { - width = rstto_image_get_width (viewer->priv->image); - height = rstto_image_get_height (viewer->priv->image); + switch(rstto_image_get_orientation (viewer->priv->image)) + { + default: + width = rstto_image_get_width (viewer->priv->image); + height = rstto_image_get_height (viewer->priv->image); + break; + case RSTTO_IMAGE_ORIENT_270: + case RSTTO_IMAGE_ORIENT_90: + height = rstto_image_get_width (viewer->priv->image); + width = rstto_image_get_height (viewer->priv->image); + break; + } } if (width > 0 && height > 0) @@ -883,42 +893,85 @@ rstto_picture_viewer_calculate_adjustments (RsttoPictureViewer *viewer, gdouble image_scale = pixbuf_width / image_width; - - if(viewer->hadjustment) + switch (rstto_image_get_orientation (viewer->priv->image)) { - viewer->hadjustment->page_size = widget->allocation.width / image_scale; - viewer->hadjustment->upper = image_width * (scale / image_scale); - viewer->hadjustment->lower = 0; - viewer->hadjustment->step_increment = 1; - viewer->hadjustment->page_increment = 100; - if((viewer->hadjustment->value + viewer->hadjustment->page_size) > viewer->hadjustment->upper) - { - viewer->hadjustment->value = viewer->hadjustment->upper - viewer->hadjustment->page_size; - hadjustment_changed = TRUE; - } - if(viewer->hadjustment->value < viewer->hadjustment->lower) - { - viewer->hadjustment->value = viewer->hadjustment->lower; - hadjustment_changed = TRUE; - } - } - if(viewer->vadjustment) - { - viewer->vadjustment->page_size = widget->allocation.height / image_scale; - viewer->vadjustment->upper = image_height * (scale / image_scale); - viewer->vadjustment->lower = 0; - viewer->vadjustment->step_increment = 1; - viewer->vadjustment->page_increment = 100; - if((viewer->vadjustment->value + viewer->vadjustment->page_size) > viewer->vadjustment->upper) - { - viewer->vadjustment->value = viewer->vadjustment->upper - viewer->vadjustment->page_size; - vadjustment_changed = TRUE; - } - if(viewer->vadjustment->value < viewer->vadjustment->lower) - { - viewer->vadjustment->value = viewer->vadjustment->lower; - vadjustment_changed = TRUE; - } + default: + if(viewer->hadjustment) + { + viewer->hadjustment->page_size = widget->allocation.width / image_scale; + viewer->hadjustment->upper = image_width * (scale / image_scale); + viewer->hadjustment->lower = 0; + viewer->hadjustment->step_increment = 1; + viewer->hadjustment->page_increment = 100; + if((viewer->hadjustment->value + viewer->hadjustment->page_size) > viewer->hadjustment->upper) + { + viewer->hadjustment->value = viewer->hadjustment->upper - viewer->hadjustment->page_size; + hadjustment_changed = TRUE; + } + if(viewer->hadjustment->value < viewer->hadjustment->lower) + { + viewer->hadjustment->value = viewer->hadjustment->lower; + hadjustment_changed = TRUE; + } + } + if(viewer->vadjustment) + { + viewer->vadjustment->page_size = widget->allocation.height / image_scale; + viewer->vadjustment->upper = image_height * (scale / image_scale); + viewer->vadjustment->lower = 0; + viewer->vadjustment->step_increment = 1; + viewer->vadjustment->page_increment = 100; + if((viewer->vadjustment->value + viewer->vadjustment->page_size) > viewer->vadjustment->upper) + { + viewer->vadjustment->value = viewer->vadjustment->upper - viewer->vadjustment->page_size; + vadjustment_changed = TRUE; + } + if(viewer->vadjustment->value < viewer->vadjustment->lower) + { + viewer->vadjustment->value = viewer->vadjustment->lower; + vadjustment_changed = TRUE; + } + } + break; + case RSTTO_IMAGE_ORIENT_270: + case RSTTO_IMAGE_ORIENT_90: + if(viewer->hadjustment) + { + viewer->hadjustment->page_size = widget->allocation.width / image_scale; + viewer->hadjustment->upper = image_height * (scale / image_scale); + viewer->hadjustment->lower = 0; + viewer->hadjustment->step_increment = 1; + viewer->hadjustment->page_increment = 100; + if((viewer->hadjustment->value + viewer->hadjustment->page_size) > viewer->hadjustment->upper) + { + viewer->hadjustment->value = viewer->hadjustment->upper - viewer->hadjustment->page_size; + hadjustment_changed = TRUE; + } + if(viewer->hadjustment->value < viewer->hadjustment->lower) + { + viewer->hadjustment->value = viewer->hadjustment->lower; + hadjustment_changed = TRUE; + } + } + if(viewer->vadjustment) + { + viewer->vadjustment->page_size = widget->allocation.height / image_scale; + viewer->vadjustment->upper = image_width * (scale / image_scale); + viewer->vadjustment->lower = 0; + viewer->vadjustment->step_increment = 1; + viewer->vadjustment->page_increment = 100; + if((viewer->vadjustment->value + viewer->vadjustment->page_size) > viewer->vadjustment->upper) + { + viewer->vadjustment->value = viewer->vadjustment->upper - viewer->vadjustment->page_size; + vadjustment_changed = TRUE; + } + if(viewer->vadjustment->value < viewer->vadjustment->lower) + { + viewer->vadjustment->value = viewer->vadjustment->lower; + vadjustment_changed = TRUE; + } + } + break; } if (viewer->vadjustment && viewer->hadjustment) @@ -956,6 +1009,7 @@ cb_rstto_picture_viewer_queued_repaint (RsttoPictureViewer *viewer) { GdkPixbuf *p_src_pixbuf = NULL; GdkPixbuf *p_tmp_pixbuf = NULL; + GdkPixbuf *p_tmp_pixbuf2 = NULL; gdouble *p_scale = NULL; gboolean *p_fit_to_screen= NULL; gdouble scale = 1; @@ -981,17 +1035,6 @@ cb_rstto_picture_viewer_queued_repaint (RsttoPictureViewer *viewer) pixbuf_width = (gdouble)gdk_pixbuf_get_width (p_src_pixbuf); pixbuf_height = (gdouble)gdk_pixbuf_get_height (p_src_pixbuf); - /** HACK HACK HACK - * Because the image-dimensions do not get modified when the image is rotated, - * we have to check here... and fix it ourselves - */ - if ((((pixbuf_width / pixbuf_height) > 1) && ((image_width / image_height < 1))) || - (((pixbuf_width / pixbuf_height) < 1) && ((image_width / image_height > 1)))) - { - gdouble tmp_width = image_width; - image_width = image_height; - image_height = tmp_width; - } image_scale = pixbuf_width / image_width; } break; @@ -1000,17 +1043,6 @@ cb_rstto_picture_viewer_queued_repaint (RsttoPictureViewer *viewer) if (p_src_pixbuf) { thumb_width = (gdouble)gdk_pixbuf_get_width (p_src_pixbuf); - /** HACK HACK HACK - * Because the image-dimensions do not get modified when the image is rotated, - * we have to check here... and fix it ourselves - */ - if ((((pixbuf_width / pixbuf_height) > 1) && ((image_width / image_height < 1))) || - (((pixbuf_width / pixbuf_height) < 1) && ((image_width / image_height > 1)))) - { - gdouble tmp_width = image_width; - image_width = image_height; - image_height = tmp_width; - } thumb_scale = (thumb_width / image_width); } else @@ -1046,10 +1078,76 @@ cb_rstto_picture_viewer_queued_repaint (RsttoPictureViewer *viewer) } if (p_src_pixbuf) { + gdouble x, y; + + switch (rstto_image_get_orientation (viewer->priv->image)) + { + default: + case RSTTO_IMAGE_ORIENT_NONE: + x = viewer->hadjustment->value * image_scale; + y = viewer->vadjustment->value * image_scale; + p_tmp_pixbuf = gdk_pixbuf_new_subpixbuf (p_src_pixbuf, + (gint)(x/scale * thumb_scale * image_scale), + (gint)(y/scale * thumb_scale * image_scale), + (gint)((widget->allocation.width / scale) < image_width? + (widget->allocation.width / scale)*thumb_scale*image_scale:image_width*thumb_scale*image_scale), + (gint)((widget->allocation.height / scale) < image_height? + (widget->allocation.height / scale)*image_scale*thumb_scale:image_height*thumb_scale*image_scale)); + break; + case RSTTO_IMAGE_ORIENT_90: + x = viewer->vadjustment->value * image_scale; + y = (viewer->hadjustment->upper - (viewer->hadjustment->value + viewer->hadjustment->page_size)) * image_scale; + if (y < 0) y = 0; + //y = viewer->hadjustment->value * image_scale; + p_tmp_pixbuf = gdk_pixbuf_new_subpixbuf (p_src_pixbuf, + (gint)(x/scale * thumb_scale * image_scale), + (gint)(y/scale * thumb_scale * image_scale), + (gint)((widget->allocation.height/ scale) < image_width? + (widget->allocation.height/ scale)*thumb_scale*image_scale:image_width*thumb_scale*image_scale), + (gint)((widget->allocation.width/ scale) < image_height? + (widget->allocation.width/ scale)*image_scale*thumb_scale:image_height*thumb_scale*image_scale)); + p_tmp_pixbuf2 = gdk_pixbuf_rotate_simple (p_tmp_pixbuf, GDK_PIXBUF_ROTATE_CLOCKWISE); + g_object_unref (p_tmp_pixbuf); + p_tmp_pixbuf = p_tmp_pixbuf2; + break; + case RSTTO_IMAGE_ORIENT_180: + x = (viewer->vadjustment->upper - (viewer->vadjustment->value + viewer->vadjustment->page_size)) * image_scale; + if (x < 0) x = 0; + y = (viewer->hadjustment->upper - (viewer->hadjustment->value + viewer->hadjustment->page_size)) * image_scale; + if (y < 0) y = 0; + //y = viewer->hadjustment->value * image_scale; + p_tmp_pixbuf = gdk_pixbuf_new_subpixbuf (p_src_pixbuf, + (gint)(x/scale * thumb_scale * image_scale), + (gint)(y/scale * thumb_scale * image_scale), + (gint)((widget->allocation.height/ scale) < image_width? + (widget->allocation.height/ scale)*thumb_scale*image_scale:image_width*thumb_scale*image_scale), + (gint)((widget->allocation.width/ scale) < image_height? + (widget->allocation.width/ scale)*image_scale*thumb_scale:image_height*thumb_scale*image_scale)); + p_tmp_pixbuf2 = gdk_pixbuf_rotate_simple (p_tmp_pixbuf, GDK_PIXBUF_ROTATE_UPSIDEDOWN); + g_object_unref (p_tmp_pixbuf); + p_tmp_pixbuf = p_tmp_pixbuf2; + break; + case RSTTO_IMAGE_ORIENT_270: + x = (viewer->vadjustment->upper - (viewer->vadjustment->value + viewer->vadjustment->page_size)) * image_scale; + if (x < 0) x = 0; + y = viewer->hadjustment->value * image_scale; + p_tmp_pixbuf = gdk_pixbuf_new_subpixbuf (p_src_pixbuf, + (gint)(x/scale * thumb_scale * image_scale), + (gint)(y/scale * thumb_scale * image_scale), + (gint)((widget->allocation.height/ scale) < image_width? + (widget->allocation.height/ scale)*thumb_scale*image_scale:image_width*thumb_scale*image_scale), + (gint)((widget->allocation.width/ scale) < image_height? + (widget->allocation.width/ scale)*image_scale*thumb_scale:image_height*thumb_scale*image_scale)); + p_tmp_pixbuf2 = gdk_pixbuf_rotate_simple (p_tmp_pixbuf, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE); + g_object_unref (p_tmp_pixbuf); + p_tmp_pixbuf = p_tmp_pixbuf2; + break; + } /** * tmp_scale is the factor between the original image and the thumbnail, * when looking at the actual image, tmp_scale == 1.0 */ + /* gdouble x = viewer->hadjustment->value * image_scale; gdouble y = viewer->vadjustment->value * image_scale; @@ -1060,6 +1158,7 @@ cb_rstto_picture_viewer_queued_repaint (RsttoPictureViewer *viewer) (widget->allocation.width / scale)*thumb_scale*image_scale:image_width*thumb_scale*image_scale), (gint)((widget->allocation.height / scale) < image_height? (widget->allocation.height / scale)*image_scale*thumb_scale:image_height*thumb_scale*image_scale)); + */ if(p_tmp_pixbuf) { _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits