In automatic mode, does not change the picture if it is already well oriented, unless other options are used together, especially -c and -g.
Signed-off-by: Stéphane Aulery <saul...@free.fr> --- exiftran.c | 25 +++++++++++++++++++------ jpegtools.c | 56 ++++++++++++++++++++++++++++++++++++++++---------------- jpegtools.h | 1 + 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/exiftran.c b/exiftran.c index 410d937..21f00b6 100644 --- a/exiftran.c +++ b/exiftran.c @@ -263,13 +263,26 @@ int main(int argc, char *argv[]) rc = 0; for (i = optind; i < argc; i++) { fprintf(stderr,"processing %s\n",argv[i]); - if (flags & JFLAG_UPDATE_THUMBNAIL) { - thumbnail = malloc(THUMB_MAX); - tsize = create_thumbnail(argv[i],thumbnail,THUMB_MAX); - } - if (0 != jpeg_transform_inplace(argv[i], transform, comment, + + if ( + (transform == -1) + && (get_file_automagic_orientation(argv[optind]) == JXFORM_NONE) + && !((flags & JFLAG_UPDATE_COMMENT) && NULL != comment) + && !(flags & JFLAG_UPDATE_THUMBNAIL)) { + // If the rotation is automatic but the image is well oriented, + // and should not change the comment, + // and not update exif thumbnail, + // then do nothing. + } + else { + if (flags & JFLAG_UPDATE_THUMBNAIL) { + thumbnail = malloc(THUMB_MAX); + tsize = create_thumbnail(argv[i],thumbnail,THUMB_MAX); + } + if (0 != jpeg_transform_inplace(argv[i], transform, comment, thumbnail, tsize, flags)) - rc = 1; + rc = 1; + } } return rc; } diff --git a/jpegtools.c b/jpegtools.c index 3e5f75c..c647761 100644 --- a/jpegtools.c +++ b/jpegtools.c @@ -192,14 +192,46 @@ static void update_dimension(ExifData *ed, JXFORM_CODE transform, } } -static int get_orientation(ExifData *ed) +static int get_automagic_orientation(ExifData *ed) { - ExifEntry *ee; + int orientation; - ee = exif_content_get_entry(ed->ifd[EXIF_IFD_0], 0x0112); - if (NULL == ee) - return 1; /* top - left */ - return get_int(ed,ee); + ExifEntry *ee; + ee = exif_content_get_entry(ed->ifd[EXIF_IFD_0], 0x0112); + + if (NULL == ee) + orientation = 1; /* top - left */ + else + orientation = get_int(ed, ee); + + if (orientation >= 1 && orientation <= 8) + orientation = transmagic[orientation]; + else + orientation = JXFORM_NONE; + +#if 0 + if (debug) + fprintf(stderr, "autotrans: %s\n", transname[orientation]); +#endif + + return orientation; +} + +int get_file_automagic_orientation(char *filename) +{ + int orientation; + + ExifData *ed; + ed = exif_data_new_from_file (filename); + + if (ed != NULL) + orientation = get_automagic_orientation(ed); + else + orientation = JXFORM_NONE; + + exif_data_unref (ed); + + return orientation; } /* ---------------------------------------------------------------------- */ @@ -340,17 +372,9 @@ static void do_exif(struct jpeg_decompress_struct *src, if (NULL == ed) return; - if (-1 == *transform) { /* automagic image transformation */ - int orientation = get_orientation(ed); - *transform = JXFORM_NONE; - if (orientation >= 1 && orientation <= 8) - *transform = transmagic[orientation]; -#if 0 - if (debug) - fprintf(stderr,"autotrans: %s\n",transname[*transform]); -#endif - } + if (-1 == *transform) + *transform = get_automagic_orientation(ed); /* update exif data */ if (flags & JFLAG_UPDATE_ORIENTATION) { diff --git a/jpegtools.h b/jpegtools.h index 964f3c3..ec4a473 100644 --- a/jpegtools.h +++ b/jpegtools.h @@ -12,6 +12,7 @@ #define JFLAG_FILE_KEEP_TIME 0x0200 /* functions */ +int get_file_automagic_orientation(char *filename); int jpeg_transform_fp(FILE *in, FILE *out, JXFORM_CODE transform, unsigned char *comment, -- 2.1.1 -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org