On Di, 2014-10-28 at 23:58 +0100, Stéphane Aulery wrote:
> In automatic mode, does not change the picture if it is already well oriented,
> unless other options are used together, especially -c and -g.

How about attached patch instead?

cheers,
  Gerd

diff --git a/jpegtools.c b/jpegtools.c
index 188ab1d..7c5a288 100644
--- a/jpegtools.c
+++ b/jpegtools.c
@@ -202,6 +202,17 @@ static int get_orientation(ExifData *ed)
     return get_int(ed,ee);
 }
 
+static int get_file_orientation(const char *file)
+{
+    ExifData *ed;
+    int ret;
+
+    ed = exif_data_new_from_file(file);
+    ret = ed ? get_orientation(ed) : 1 /* top - left */;
+    exif_data_unref(ed);
+    return ret;
+}
+
 /* ---------------------------------------------------------------------- */
 
 struct th {
@@ -551,11 +562,20 @@ int jpeg_transform_inplace(char *file,
     FILE *out = NULL;
 
     /* are we allowed to write to the file? */
-    if (0 != access(file,W_OK)) {
+    if (0 != access(file, R_OK | W_OK)) {
 	fprintf(stderr,"access %s: %s\n",file,strerror(errno));
 	return -1;
     }
 
+    if (!(flags & JFLAG_UPDATE_COMMENT) &&
+        !(flags & JFLAG_UPDATE_THUMBNAIL)) {
+        /* no forced updates, maybe we can shortcut here? */
+        if (transform == JXFORM_NONE)
+            return 0;
+        if (transform == -1 && get_file_orientation(file) == 1)
+            return 0;
+    }
+
     /* open infile */
     in = fopen(file,"r");
     if (NULL == in) {

Reply via email to