Revision: 1664
          http://geeqie.svn.sourceforge.net/geeqie/?rev=1664&view=rev
Author:   nadvornik
Date:     2009-04-26 09:01:35 +0000 (Sun, 26 Apr 2009)

Log Message:
-----------
added an option to write image orientation to the metadata

Modified Paths:
--------------
    trunk/src/bar.c
    trunk/src/exif.c
    trunk/src/image.c
    trunk/src/metadata.c
    trunk/src/metadata.h
    trunk/src/options.c
    trunk/src/options.h
    trunk/src/preferences.c
    trunk/src/rcfile.c
    trunk/src/thumb.c
    trunk/src/thumb_standard.c

Modified: trunk/src/bar.c
===================================================================
--- trunk/src/bar.c     2009-04-25 22:08:09 UTC (rev 1663)
+++ trunk/src/bar.c     2009-04-26 09:01:35 UTC (rev 1664)
@@ -95,7 +95,7 @@
 "                <entry key = 'formatted.ColorProfile' if_set = 'true' 
editable = 'false' />"
 "                <entry key = 'formatted.SubjectDistance' if_set = 'true' 
editable = 'false' />"
 "                <entry key = 'formatted.Resolution' if_set = 'true' editable 
= 'false' />"
-"                <entry key = 'Exif.Image.Orientation' if_set = 'true' 
editable = 'false' />"
+"                <entry key = '" ORIENTATION_KEY "' if_set = 'true' editable = 
'false' />"
 "            </pane_exif>"
 "        </bar>"
 "    </layout>"

Modified: trunk/src/exif.c
===================================================================
--- trunk/src/exif.c    2009-04-25 22:08:09 UTC (rev 1663)
+++ trunk/src/exif.c    2009-04-26 09:01:35 UTC (rev 1664)
@@ -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;

Modified: trunk/src/image.c
===================================================================
--- trunk/src/image.c   2009-04-25 22:08:09 UTC (rev 1663)
+++ trunk/src/image.c   2009-04-26 09:01:35 UTC (rev 1664)
@@ -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;
                        }
                }

Modified: trunk/src/metadata.c
===================================================================
--- trunk/src/metadata.c        2009-04-25 22:08:09 UTC (rev 1663)
+++ trunk/src/metadata.c        2009-04-26 09:01:35 UTC (rev 1664)
@@ -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);
+}
 
 /*
  *-------------------------------------------------------------------

Modified: trunk/src/metadata.h
===================================================================
--- trunk/src/metadata.h        2009-04-25 22:08:09 UTC (rev 1663)
+++ trunk/src/metadata.h        2009-04-26 09:01:35 UTC (rev 1664)
@@ -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);

Modified: trunk/src/options.c
===================================================================
--- trunk/src/options.c 2009-04-25 22:08:09 UTC (rev 1663)
+++ trunk/src/options.c 2009-04-26 09:01:35 UTC (rev 1664)
@@ -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;
 

Modified: trunk/src/options.h
===================================================================
--- trunk/src/options.h 2009-04-25 22:08:09 UTC (rev 1663)
+++ trunk/src/options.h 2009-04-26 09:01:35 UTC (rev 1664)
@@ -178,6 +178,7 @@
                gboolean confirm_on_image_change;
                gboolean confirm_on_dir_change;
                gboolean tags_case_sensitive;
+               gboolean write_orientation;
        } metadata;
 
 };

Modified: trunk/src/preferences.c
===================================================================
--- trunk/src/preferences.c     2009-04-25 22:08:09 UTC (rev 1663)
+++ trunk/src/preferences.c     2009-04-26 09:01:35 UTC (rev 1664)
@@ -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 */

Modified: trunk/src/rcfile.c
===================================================================
--- trunk/src/rcfile.c  2009-04-25 22:08:09 UTC (rev 1663)
+++ trunk/src/rcfile.c  2009-04-26 09:01:35 UTC (rev 1664)
@@ -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);
                }

Modified: trunk/src/thumb.c
===================================================================
--- trunk/src/thumb.c   2009-04-25 22:08:09 UTC (rev 1663)
+++ trunk/src/thumb.c   2009-04-26 09:01:35 UTC (rev 1664)
@@ -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)

Modified: trunk/src/thumb_standard.c
===================================================================
--- trunk/src/thumb_standard.c  2009-04-25 22:08:09 UTC (rev 1663)
+++ trunk/src/thumb_standard.c  2009-04-26 09:01:35 UTC (rev 1664)
@@ -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)


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Crystal Reports &#45; New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty&#45;free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Geeqie-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geeqie-svn

Reply via email to