From b1ad6e37beddb396f7cbd1fd1dca48036d85c016 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Mon, 17 Nov 2014 14:31:11 +0100 Subject: shortcut jpeg_transform_inplace if there is nothing to do --- jpegtools.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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) { -- cgit