Commit a7e517df authored by Stephan Arts's avatar Stephan Arts

Re-implement exif auto-rotation

parent 39f7d71c
x.x.x
=====
- Re-introduce autorotation based on the exif-orientation tag, a
regression since 0.0.93
- Prevent segmentation fault when an error occurs while loading an image
0.2.0
=====
- Fix bug #6866 (Improve the sorting algorythm for filenames)
......
......@@ -25,6 +25,7 @@
#include <libxfce4util/libxfce4util.h>
#include "util.h"
#include "file.h"
static void
......@@ -100,6 +101,7 @@ struct _RsttoFilePriv
gchar *path;
ExifData *exif_data;
RsttoImageOrientation orientation;
};
......@@ -213,7 +215,6 @@ rstto_file_new ( GFile *file )
o_file->priv->file = file;
g_object_ref (file);
open_files = g_list_append (open_files, o_file);
return o_file;
......@@ -339,10 +340,9 @@ rstto_file_get_modified_time ( RsttoFile *file )
return time_;
}
gchar *
ExifEntry *
rstto_file_get_exif ( RsttoFile *file, ExifTag id )
{
gchar *val = NULL;
ExifEntry *exif_entry = NULL;
/* If there is no exif-data object, try to create it */
......@@ -352,21 +352,42 @@ rstto_file_get_exif ( RsttoFile *file, ExifTag id )
}
if ( NULL != file->priv->exif_data )
{
exif_entry = exif_data_get_entry (
return exif_data_get_entry (
file->priv->exif_data,
id );
if ( NULL != exif_entry )
}
return NULL;
}
RsttoImageOrientation
rstto_file_get_orientation ( RsttoFile *file )
{
ExifEntry *exif_entry = NULL;
if (file->priv->orientation == 0 )
{
exif_entry = rstto_file_get_exif (file, EXIF_TAG_ORIENTATION);
if (NULL != exif_entry)
{
switch ( id )
{
default:
val = g_new0 (gchar, 20);
exif_entry_get_value (exif_entry, val, 20);
break;
}
file->priv->orientation = exif_get_short (
exif_entry->data,
exif_data_get_byte_order (exif_entry->parent->parent));
exif_entry_free (exif_entry);
}
if (file->priv->orientation == 0)
{
/* Default orientation */
file->priv->orientation = RSTTO_IMAGE_ORIENT_NONE;
}
}
return file->priv->orientation;
}
return val;
void
rstto_file_set_orientation (
RsttoFile *file ,
RsttoImageOrientation orientation )
{
file->priv->orientation = orientation;
}
......@@ -86,9 +86,17 @@ rstto_file_get_content_type ( RsttoFile * );
guint64
rstto_file_get_modified_time ( RsttoFile *);
gchar *
ExifEntry *
rstto_file_get_exif ( RsttoFile *, ExifTag );
RsttoImageOrientation
rstto_file_get_orientation ( RsttoFile * );
void
rstto_file_set_orientation (
RsttoFile * ,
RsttoImageOrientation );
G_END_DECLS
......
......@@ -28,6 +28,7 @@
#include <libexif/exif-data.h>
#include "util.h"
#include "file.h"
#include "image_list.h"
#include "settings.h"
......
......@@ -23,6 +23,8 @@
#include <gio/gio.h>
#include <libexif/exif-data.h>
#include "util.h"
#include "file.h"
#include "image_viewer.h"
#include "settings.h"
......@@ -56,7 +58,7 @@ struct _RsttoImageViewerPriv
RsttoImageViewerTransaction *transaction;
GdkPixbuf *pixbuf;
GdkPixbuf *dst_pixbuf;
RsttoImageViewerOrientation orientation;
RsttoImageOrientation orientation;
gdouble quality;
......@@ -112,6 +114,7 @@ struct _RsttoImageViewerTransaction
gint image_height;
gdouble image_scale;
gdouble scale;
RsttoImageOrientation orientation;
/* File I/O data */
/*****************/
......@@ -896,7 +899,7 @@ rstto_image_viewer_set_file (
RsttoImageViewer *viewer,
RsttoFile *file,
gdouble scale,
RsttoImageViewerOrientation orientation)
RsttoImageOrientation orientation)
{
/*
......@@ -1216,13 +1219,15 @@ rstto_image_viewer_set_motion_state (RsttoImageViewer *viewer, RsttoImageViewerM
void
rstto_image_viewer_set_orientation (
RsttoImageViewer *viewer,
RsttoImageViewerOrientation orientation)
RsttoImageOrientation orientation)
{
viewer->priv->orientation = orientation;
rstto_file_set_orientation (viewer->priv->file, orientation);
rstto_image_viewer_queued_repaint (viewer, TRUE);
}
RsttoImageViewerOrientation
RsttoImageOrientation
rstto_image_viewer_get_orientation (RsttoImageViewer *viewer)
{
return viewer->priv->orientation;
......@@ -1420,6 +1425,8 @@ cb_rstto_image_loader_size_prepared (GdkPixbufLoader *loader, gint width, gint h
*/
transaction->image_scale = 1.0;
}
transaction->orientation = rstto_file_get_orientation (transaction->file);
}
static void
......@@ -1434,6 +1441,7 @@ cb_rstto_image_loader_closed (GdkPixbufLoader *loader, RsttoImageViewerTransacti
viewer->priv->image_scale = transaction->image_scale;
viewer->priv->image_width = transaction->image_width;
viewer->priv->image_height = transaction->image_height;
viewer->priv->orientation = transaction->orientation;
viewer->priv->transaction = NULL;
rstto_image_viewer_queued_repaint (viewer, TRUE);
......@@ -1515,8 +1523,17 @@ cb_rstto_image_viewer_queued_repaint (RsttoImageViewer *viewer)
{
switch (viewer->priv->orientation)
{
case RSTTO_IMAGE_VIEWER_ORIENT_NONE:
case RSTTO_IMAGE_VIEWER_ORIENT_180:
case RSTTO_IMAGE_ORIENT_90:
case RSTTO_IMAGE_ORIENT_270:
hadjustment = viewer->vadjustment;
vadjustment = viewer->hadjustment;
v_scale = (gdouble)(GTK_WIDGET (viewer)->allocation.height) / (gdouble)viewer->priv->image_width;
h_scale = (gdouble)(GTK_WIDGET (viewer)->allocation.width) / (gdouble)viewer->priv->image_height;
break;
case RSTTO_IMAGE_ORIENT_NONE:
case RSTTO_IMAGE_ORIENT_180:
default:
hadjustment = viewer->hadjustment;
vadjustment = viewer->vadjustment;
......@@ -1524,14 +1541,6 @@ cb_rstto_image_viewer_queued_repaint (RsttoImageViewer *viewer)
h_scale = (gdouble)(GTK_WIDGET (viewer)->allocation.width) / (gdouble)viewer->priv->image_width;
break;
case RSTTO_IMAGE_VIEWER_ORIENT_90:
case RSTTO_IMAGE_VIEWER_ORIENT_270:
hadjustment = viewer->vadjustment;
vadjustment = viewer->hadjustment;
v_scale = (gdouble)(GTK_WIDGET (viewer)->allocation.height) / (gdouble)viewer->priv->image_width;
h_scale = (gdouble)(GTK_WIDGET (viewer)->allocation.width) / (gdouble)viewer->priv->image_height;
break;
}
width = gdk_pixbuf_get_width (viewer->priv->pixbuf);
......@@ -1611,32 +1620,7 @@ cb_rstto_image_viewer_queued_repaint (RsttoImageViewer *viewer)
*/
switch (viewer->priv->orientation)
{
case RSTTO_IMAGE_VIEWER_ORIENT_NONE:
if ((gtk_adjustment_get_page_size (vadjustment) +
gtk_adjustment_get_value(vadjustment)) > (viewer->priv->image_height*viewer->priv->scale))
{
gtk_adjustment_set_value (vadjustment,
(height*relative_scale) -
gtk_adjustment_get_page_size (vadjustment));
}
if ((gtk_adjustment_get_page_size (hadjustment) +
gtk_adjustment_get_value(hadjustment)) > (viewer->priv->image_width*viewer->priv->scale))
{
gtk_adjustment_set_value (hadjustment,
(width*relative_scale) -
gtk_adjustment_get_page_size (hadjustment));
}
gtk_adjustment_set_upper (hadjustment, (gdouble)width*(viewer->priv->scale/viewer->priv->image_scale));
gtk_adjustment_set_upper (vadjustment, (gdouble)height*(viewer->priv->scale/viewer->priv->image_scale));
subpixbuf_x_offset = (gint)(gtk_adjustment_get_value (hadjustment) / relative_scale);
subpixbuf_y_offset = (gint)(gtk_adjustment_get_value (vadjustment) / relative_scale);
subpixbuf_width = (gint)((gtk_adjustment_get_page_size (hadjustment) / relative_scale) < width)?
(gtk_adjustment_get_page_size (hadjustment) / relative_scale)+1:(width);
subpixbuf_height = (gint)((gtk_adjustment_get_page_size (vadjustment) / relative_scale) < height)?
(gtk_adjustment_get_page_size (vadjustment) / relative_scale)+1:(height);
break;
case RSTTO_IMAGE_VIEWER_ORIENT_180:
case RSTTO_IMAGE_ORIENT_180:
gtk_adjustment_set_upper (hadjustment, (gdouble)width*(viewer->priv->scale/viewer->priv->image_scale));
gtk_adjustment_set_upper (vadjustment, (gdouble)height*(viewer->priv->scale/viewer->priv->image_scale));
subpixbuf_x_offset = (gint)((gtk_adjustment_get_upper(hadjustment) -
......@@ -1650,7 +1634,7 @@ cb_rstto_image_viewer_queued_repaint (RsttoImageViewer *viewer)
subpixbuf_height = (gint)((gtk_adjustment_get_page_size (vadjustment) / relative_scale) < height)?
(gtk_adjustment_get_page_size (vadjustment) / relative_scale)+1:(height);
break;
case RSTTO_IMAGE_VIEWER_ORIENT_270:
case RSTTO_IMAGE_ORIENT_270:
gtk_adjustment_set_upper (hadjustment, (gdouble)width*(viewer->priv->scale/viewer->priv->image_scale));
gtk_adjustment_set_upper (vadjustment, (gdouble)height*(viewer->priv->scale/viewer->priv->image_scale));
......@@ -1678,7 +1662,7 @@ cb_rstto_image_viewer_queued_repaint (RsttoImageViewer *viewer)
subpixbuf_height = (gint)((gtk_adjustment_get_page_size (vadjustment) / relative_scale) < height)?
(gtk_adjustment_get_page_size (vadjustment) / relative_scale)+1:(height);
break;
case RSTTO_IMAGE_VIEWER_ORIENT_90:
case RSTTO_IMAGE_ORIENT_90:
gtk_adjustment_set_upper (hadjustment, (gdouble)width*(viewer->priv->scale/viewer->priv->image_scale));
gtk_adjustment_set_upper (vadjustment, (gdouble)height*(viewer->priv->scale/viewer->priv->image_scale));
......@@ -1706,6 +1690,32 @@ cb_rstto_image_viewer_queued_repaint (RsttoImageViewer *viewer)
subpixbuf_height = (gint)((gtk_adjustment_get_page_size (vadjustment) / relative_scale) < height)?
(gtk_adjustment_get_page_size (vadjustment) / relative_scale)+1:(height);
break;
case RSTTO_IMAGE_ORIENT_NONE:
default:
if ((gtk_adjustment_get_page_size (vadjustment) +
gtk_adjustment_get_value(vadjustment)) > (viewer->priv->image_height*viewer->priv->scale))
{
gtk_adjustment_set_value (vadjustment,
(height*relative_scale) -
gtk_adjustment_get_page_size (vadjustment));
}
if ((gtk_adjustment_get_page_size (hadjustment) +
gtk_adjustment_get_value(hadjustment)) > (viewer->priv->image_width*viewer->priv->scale))
{
gtk_adjustment_set_value (hadjustment,
(width*relative_scale) -
gtk_adjustment_get_page_size (hadjustment));
}
gtk_adjustment_set_upper (hadjustment, (gdouble)width*(viewer->priv->scale/viewer->priv->image_scale));
gtk_adjustment_set_upper (vadjustment, (gdouble)height*(viewer->priv->scale/viewer->priv->image_scale));
subpixbuf_x_offset = (gint)(gtk_adjustment_get_value (hadjustment) / relative_scale);
subpixbuf_y_offset = (gint)(gtk_adjustment_get_value (vadjustment) / relative_scale);
subpixbuf_width = (gint)((gtk_adjustment_get_page_size (hadjustment) / relative_scale) < width)?
(gtk_adjustment_get_page_size (hadjustment) / relative_scale)+1:(width);
subpixbuf_height = (gint)((gtk_adjustment_get_page_size (vadjustment) / relative_scale) < height)?
(gtk_adjustment_get_page_size (vadjustment) / relative_scale)+1:(height);
break;
}
if (subpixbuf_x_offset < 0)
......@@ -1746,22 +1756,23 @@ cb_rstto_image_viewer_queued_repaint (RsttoImageViewer *viewer)
switch (viewer->priv->orientation)
{
case RSTTO_IMAGE_VIEWER_ORIENT_180:
case RSTTO_IMAGE_ORIENT_180:
tmp_pixbuf2 = gdk_pixbuf_rotate_simple (tmp_pixbuf, GDK_PIXBUF_ROTATE_UPSIDEDOWN);
g_object_unref (tmp_pixbuf);
tmp_pixbuf = tmp_pixbuf2;
break;
case RSTTO_IMAGE_VIEWER_ORIENT_270:
case RSTTO_IMAGE_ORIENT_270:
tmp_pixbuf2 = gdk_pixbuf_rotate_simple (tmp_pixbuf, GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE);
g_object_unref (tmp_pixbuf);
tmp_pixbuf = tmp_pixbuf2;
break;
case RSTTO_IMAGE_VIEWER_ORIENT_90:
case RSTTO_IMAGE_ORIENT_90:
tmp_pixbuf2 = gdk_pixbuf_rotate_simple (tmp_pixbuf, GDK_PIXBUF_ROTATE_CLOCKWISE);
g_object_unref (tmp_pixbuf);
tmp_pixbuf = tmp_pixbuf2;
break;
case RSTTO_IMAGE_VIEWER_ORIENT_NONE:
case RSTTO_IMAGE_ORIENT_NONE:
default:
break;
}
......
......@@ -21,13 +21,6 @@
G_BEGIN_DECLS
typedef enum
{
RSTTO_IMAGE_VIEWER_ORIENT_NONE,
RSTTO_IMAGE_VIEWER_ORIENT_90,
RSTTO_IMAGE_VIEWER_ORIENT_180,
RSTTO_IMAGE_VIEWER_ORIENT_270
} RsttoImageViewerOrientation;
#define RSTTO_TYPE_IMAGE_VIEWER rstto_image_viewer_get_type()
......@@ -84,7 +77,7 @@ rstto_image_viewer_set_file (
RsttoImageViewer *viewer,
RsttoFile *file,
gdouble scale,
RsttoImageViewerOrientation orientation);
RsttoImageOrientation orientation);
void
rstto_image_viewer_set_scale (
......@@ -98,9 +91,9 @@ rstto_image_viewer_get_scale (
void
rstto_image_viewer_set_orientation (
RsttoImageViewer *viewer,
RsttoImageViewerOrientation orientation);
RsttoImageOrientation orientation);
RsttoImageViewerOrientation
RsttoImageOrientation
rstto_image_viewer_get_orientation (RsttoImageViewer *viewer);
void
......
......@@ -30,6 +30,7 @@
#include <libxfce4util/libxfce4util.h>
#include <libexif/exif-data.h>
#include "util.h"
#include "file.h"
#include "image_list.h"
#include "settings.h"
......
......@@ -32,6 +32,7 @@
#include <cairo/cairo.h>
#include "settings.h"
#include "util.h"
#include "file.h"
#include "image_list.h"
#include "image_viewer.h"
......@@ -903,7 +904,7 @@ rstto_main_window_image_list_iter_changed (RsttoMainWindow *window)
RSTTO_IMAGE_VIEWER(window->priv->image_viewer),
cur_file,
-1.0,
RSTTO_IMAGE_VIEWER_ORIENT_NONE);
0);
app_list = g_app_info_get_all_for_type (content_type);
......@@ -941,7 +942,7 @@ rstto_main_window_image_list_iter_changed (RsttoMainWindow *window)
gtk_menu_shell_append (GTK_MENU_SHELL (open_with_menu), menu_item);
gtk_widget_set_sensitive (menu_item, FALSE);
rstto_image_viewer_set_file (RSTTO_IMAGE_VIEWER(window->priv->image_viewer), NULL, -1, RSTTO_IMAGE_VIEWER_ORIENT_NONE);
rstto_image_viewer_set_file (RSTTO_IMAGE_VIEWER(window->priv->image_viewer), NULL, -1, 0);
menu_item = gtk_image_menu_item_new_with_label (_("Empty"));
......@@ -2433,17 +2434,17 @@ cb_rstto_main_window_rotate_cw (GtkWidget *widget, RsttoMainWindow *window)
switch (rstto_image_viewer_get_orientation (viewer))
{
default:
case RSTTO_IMAGE_VIEWER_ORIENT_NONE:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_VIEWER_ORIENT_90);
case RSTTO_IMAGE_ORIENT_NONE:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_ORIENT_90);
break;
case RSTTO_IMAGE_VIEWER_ORIENT_90:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_VIEWER_ORIENT_180);
case RSTTO_IMAGE_ORIENT_90:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_ORIENT_180);
break;
case RSTTO_IMAGE_VIEWER_ORIENT_180:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_VIEWER_ORIENT_270);
case RSTTO_IMAGE_ORIENT_180:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_ORIENT_270);
break;
case RSTTO_IMAGE_VIEWER_ORIENT_270:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_VIEWER_ORIENT_NONE);
case RSTTO_IMAGE_ORIENT_270:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_ORIENT_NONE);
break;
}
}
......@@ -2462,17 +2463,17 @@ cb_rstto_main_window_rotate_ccw (GtkWidget *widget, RsttoMainWindow *window)
switch (rstto_image_viewer_get_orientation (viewer))
{
default:
case RSTTO_IMAGE_VIEWER_ORIENT_NONE:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_VIEWER_ORIENT_270);
case RSTTO_IMAGE_ORIENT_NONE:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_ORIENT_270);
break;
case RSTTO_IMAGE_VIEWER_ORIENT_90:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_VIEWER_ORIENT_NONE);
case RSTTO_IMAGE_ORIENT_90:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_ORIENT_NONE);
break;
case RSTTO_IMAGE_VIEWER_ORIENT_180:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_VIEWER_ORIENT_90);
case RSTTO_IMAGE_ORIENT_180:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_ORIENT_90);
break;
case RSTTO_IMAGE_VIEWER_ORIENT_270:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_VIEWER_ORIENT_180);
case RSTTO_IMAGE_ORIENT_270:
rstto_image_viewer_set_orientation (viewer, RSTTO_IMAGE_ORIENT_180);
break;
}
}
......
......@@ -25,6 +25,7 @@
#include <libxfce4util/libxfce4util.h>
#include "settings.h"
#include "util.h"
#include "file.h"
#include "properties_dialog.h"
......
......@@ -23,6 +23,7 @@
#include <libexif/exif-data.h>
#include "util.h"
#include "file.h"
#include "image_list.h"
#include "thumbnail.h"
......
......@@ -24,6 +24,7 @@
#include <libxfce4ui/libxfce4ui.h>
#include <libexif/exif-data.h>
#include "util.h"
#include "file.h"
#include "image_list.h"
#include "thumbnail.h"
......
......@@ -27,6 +27,7 @@
#include <libexif/exif-data.h>
#include "util.h"
#include "file.h"
#include "thumbnail.h"
#include "thumbnailer.h"
......
/*
* Copyright (c) Stephan Arts 2011 <stephan@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.
*/
#ifndef __RISTRETTO_UTIL_H__
#define __RISTRETTO_UTIL_H__
G_BEGIN_DECLS
typedef enum
{
RSTTO_IMAGE_ORIENT_NONE = 1,
RSTTO_IMAGE_ORIENT_FLIP_HORIZONTAL,
RSTTO_IMAGE_ORIENT_180,
RSTTO_IMAGE_ORIENT_FLIP_VERTICAL,
RSTTO_IMAGE_ORIENT_FLIP_TRANSPOSE,
RSTTO_IMAGE_ORIENT_90,
RSTTO_IMAGE_ORIENT_FLIP_TRANSVERSE,
RSTTO_IMAGE_ORIENT_270,
RSTTO_IMAGE_ORIENT_NOT_DETERMINED,
} RsttoImageOrientation;
#endif /* __RSTTO_UTIL_H__ */
......@@ -26,6 +26,7 @@
#include <libexif/exif-data.h>
#include "util.h"
#include "file.h"
#include "wallpaper_manager.h"
......
......@@ -28,6 +28,7 @@
#include <libexif/exif-data.h>
#include "util.h"
#include "file.h"
#include "monitor_chooser.h"
#include "wallpaper_manager.h"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment