aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2014-11-17 14:31:11 +0100
committerGerd Hoffmann <kraxel@redhat.com>2014-11-17 14:31:11 +0100
commitb1ad6e37beddb396f7cbd1fd1dca48036d85c016 (patch)
tree320b18c93a3a6b348651cb608b2998a02c9c9c5d
parente5ce55c474f9af03862fcdef696f68d2addd39ae (diff)
downloadfbida-b1ad6e37beddb396f7cbd1fd1dca48036d85c016.tar.gz
shortcut jpeg_transform_inplace if there is nothing to do
-rw-r--r--jpegtools.c22
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) {