diff options
Diffstat (limited to 'jpegtools.c')
-rw-r--r-- | jpegtools.c | 22 |
1 files changed, 21 insertions, 1 deletions
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) { |