# HG changeset patch
# User nadvornik
# Date 1240736495 0
# Node ID c776b1310ca668ff74157ad8f9bdea9392d0a18c
# Parent 3d9f5c0785215ddd04b947aef9720fd3d66511cf
added an option to write image orientation to the metadata
diff -r 3d9f5c078521 -r c776b1310ca6 src/bar.c
--- a/src/bar.c Sat Apr 25 22:08:09 2009 +0000
+++ b/src/bar.c Sun Apr 26 09:01:35 2009 +0000
@@ -95,7 +95,7 @@
" "
" "
" "
-" "
+" "
" "
" "
" "
diff -r 3d9f5c078521 -r c776b1310ca6 src/exif.c
--- a/src/exif.c Sat Apr 25 22:08:09 2009 +0000
+++ b/src/exif.c Sun Apr 26 09:01:35 2009 +0000
@@ -1605,6 +1605,9 @@
if (!key) return NULL;
+ /* convert xmp key to exif key */
+ if (strcmp(key, ORIENTATION_KEY) == 0) key = "Exif.Image.Orientation";
+
if (format == METADATA_FORMATTED)
{
gchar *text;
diff -r 3d9f5c078521 -r c776b1310ca6 src/image.c
--- a/src/image.c Sat Apr 25 22:08:09 2009 +0000
+++ b/src/image.c Sun Apr 26 09:01:35 2009 +0000
@@ -401,10 +401,18 @@
break;
}
- if (type != ALTER_NONE)
+ if (imd->orientation != imd->image_fd->exif_orientation ? imd->image_fd->exif_orientation : 1)
{
- if (imd->image_fd->user_orientation == 0) file_data_ref(imd->image_fd);
- imd->image_fd->user_orientation = imd->orientation;
+ if (!options->metadata.write_orientation)
+ {
+ /* user_orientation does not work together with options->metadata.write_orientation,
+ use either one or the other.
+ we must however handle switching metadata.write_orientation on and off, therefore
+ we just disable referencing new fd's, not unreferencing the old ones
+ */
+ if (imd->image_fd->user_orientation == 0) file_data_ref(imd->image_fd);
+ imd->image_fd->user_orientation = imd->orientation;
+ }
}
else
{
@@ -412,6 +420,18 @@
imd->image_fd->user_orientation = 0;
}
+ if (options->metadata.write_orientation)
+ {
+ if (type == ALTER_NONE)
+ {
+ metadata_write_revert(imd->image_fd, ORIENTATION_KEY);
+ }
+ else
+ {
+ metadata_write_int(imd->image_fd, ORIENTATION_KEY, imd->orientation);
+ }
+ }
+
pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation);
}
@@ -1079,7 +1099,7 @@
}
else if (options->image.exif_rotate_enable)
{
- imd->orientation = metadata_read_int(imd->image_fd, "Exif.Image.Orientation", EXIF_ORIENTATION_TOP_LEFT);
+ imd->orientation = metadata_read_int(imd->image_fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
imd->image_fd->exif_orientation = imd->orientation;
}
}
diff -r 3d9f5c078521 -r c776b1310ca6 src/metadata.c
--- a/src/metadata.c Sat Apr 25 22:08:09 2009 +0000
+++ b/src/metadata.c Sun Apr 26 09:01:35 2009 +0000
@@ -189,6 +189,24 @@
return FALSE;
}
+gboolean metadata_write_revert(FileData *fd, const gchar *key)
+{
+ if (!fd->modified_xmp) return FALSE;
+
+ g_hash_table_remove(fd->modified_xmp, key);
+
+ if (g_hash_table_size(fd->modified_xmp) == 0)
+ {
+ metadata_write_queue_remove(fd);
+ }
+ else
+ {
+ /* reread the metadata to restore the original value */
+ file_data_increment_version(fd);
+ file_data_send_notification(fd, NOTIFY_REREAD);
+ }
+}
+
gboolean metadata_write_list(FileData *fd, const gchar *key, const GList *values)
{
if (!fd->modified_xmp)
@@ -231,6 +249,13 @@
return ret;
}
+gboolean metadata_write_int(FileData *fd, const gchar *key, guint64 value)
+{
+ gchar string[50];
+
+ g_snprintf(string, sizeof(string), "%ld", value);
+ return metadata_write_string(fd, key, string);
+}
/*
*-------------------------------------------------------------------
diff -r 3d9f5c078521 -r c776b1310ca6 src/metadata.h
--- a/src/metadata.h Sat Apr 25 22:08:09 2009 +0000
+++ b/src/metadata.h Sun Apr 26 09:01:35 2009 +0000
@@ -16,6 +16,7 @@
#define COMMENT_KEY "Xmp.dc.description"
#define KEYWORD_KEY "Xmp.dc.subject"
+#define ORIENTATION_KEY "Xmp.tiff.Orientation"
gboolean metadata_write_queue_remove(FileData *fd);
gboolean metadata_write_queue_remove_list(GList *list);
@@ -24,8 +25,10 @@
gint metadata_queue_length(void);
+gboolean metadata_write_revert(FileData *fd, const gchar *key);
gboolean metadata_write_list(FileData *fd, const gchar *key, const GList *values);
gboolean metadata_write_string(FileData *fd, const gchar *key, const char *value);
+gboolean metadata_write_int(FileData *fd, const gchar *key, guint64 value);
GList *metadata_read_list(FileData *fd, const gchar *key, MetadataFormat format);
gchar *metadata_read_string(FileData *fd, const gchar *key, MetadataFormat format);
diff -r 3d9f5c078521 -r c776b1310ca6 src/options.c
--- a/src/options.c Sat Apr 25 22:08:09 2009 +0000
+++ b/src/options.c Sun Apr 26 09:01:35 2009 +0000
@@ -104,6 +104,7 @@
options->metadata.confirm_on_image_change = FALSE;
options->metadata.confirm_on_dir_change = TRUE;
options->metadata.tags_case_sensitive = FALSE;
+ options->metadata.write_orientation = TRUE;
options->show_icon_names = TRUE;
diff -r 3d9f5c078521 -r c776b1310ca6 src/options.h
--- a/src/options.h Sat Apr 25 22:08:09 2009 +0000
+++ b/src/options.h Sun Apr 26 09:01:35 2009 +0000
@@ -178,6 +178,7 @@
gboolean confirm_on_image_change;
gboolean confirm_on_dir_change;
gboolean tags_case_sensitive;
+ gboolean write_orientation;
} metadata;
};
diff -r 3d9f5c078521 -r c776b1310ca6 src/preferences.c
--- a/src/preferences.c Sat Apr 25 22:08:09 2009 +0000
+++ b/src/preferences.c Sun Apr 26 09:01:35 2009 +0000
@@ -325,6 +325,7 @@
options->metadata.confirm_on_image_change = c_options->metadata.confirm_on_image_change;
options->metadata.confirm_on_dir_change = c_options->metadata.confirm_on_dir_change;
options->metadata.tags_case_sensitive = c_options->metadata.tags_case_sensitive;
+ options->metadata.write_orientation = c_options->metadata.write_orientation;
#ifdef DEBUG
set_debug_level(debug_c);
@@ -1369,6 +1370,9 @@
pref_checkbox_new_int(group, _("Allow keywords to differ only in case"),
options->metadata.tags_case_sensitive, &c_options->metadata.tags_case_sensitive);
+
+ pref_checkbox_new_int(group, _("Write altered image orientation to the metadata"),
+ options->metadata.write_orientation, &c_options->metadata.write_orientation);
}
/* metadata tab */
diff -r 3d9f5c078521 -r c776b1310ca6 src/rcfile.c
--- a/src/rcfile.c Sat Apr 25 22:08:09 2009 +0000
+++ b/src/rcfile.c Sun Apr 26 09:01:35 2009 +0000
@@ -438,6 +438,7 @@
WRITE_NL(); WRITE_BOOL(*options, metadata.confirm_on_image_change);
WRITE_NL(); WRITE_BOOL(*options, metadata.confirm_on_dir_change);
WRITE_NL(); WRITE_BOOL(*options, metadata.tags_case_sensitive);
+ WRITE_NL(); WRITE_BOOL(*options, metadata.write_orientation);
}
@@ -697,6 +698,7 @@
if (READ_BOOL(*options, metadata.confirm_on_image_change)) continue;
if (READ_BOOL(*options, metadata.confirm_on_dir_change)) continue;
if (READ_BOOL(*options, metadata.tags_case_sensitive)) continue;
+ if (READ_BOOL(*options, metadata.write_orientation)) continue;
log_printf("unknown attribute %s = %s\n", option, value);
}
diff -r 3d9f5c078521 -r c776b1310ca6 src/thumb.c
--- a/src/thumb.c Sat Apr 25 22:08:09 2009 +0000
+++ b/src/thumb.c Sun Apr 26 09:01:35 2009 +0000
@@ -142,7 +142,7 @@
{
if (!tl->fd->exif_orientation)
{
- tl->fd->exif_orientation = metadata_read_int(tl->fd, "Exif.Image.Orientation", EXIF_ORIENTATION_TOP_LEFT);
+ tl->fd->exif_orientation = metadata_read_int(tl->fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
}
if (tl->fd->exif_orientation != EXIF_ORIENTATION_TOP_LEFT)
diff -r 3d9f5c078521 -r c776b1310ca6 src/thumb_standard.c
--- a/src/thumb_standard.c Sat Apr 25 22:08:09 2009 +0000
+++ b/src/thumb_standard.c Sun Apr 26 09:01:35 2009 +0000
@@ -388,7 +388,7 @@
{
if (!tl->fd->exif_orientation)
{
- tl->fd->exif_orientation = metadata_read_int(tl->fd, "Exif.Image.Orientation", EXIF_ORIENTATION_TOP_LEFT);
+ tl->fd->exif_orientation = metadata_read_int(tl->fd, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
}
if (tl->fd->exif_orientation != EXIF_ORIENTATION_TOP_LEFT)