diff options
author | Bert <ber.t@gmx.com> | 2011-09-06 11:09:57 +0200 |
---|---|---|
committer | Bert <ber.t@gmx.com> | 2011-09-08 15:57:44 +0200 |
commit | bfab4dc328f580cc21c31ee3e4f53e1b8ca7c4ab (patch) | |
tree | 12c7c9a2538551f98b1712903c7408ecb2d7fd3b /image.c | |
parent | b96c10633782d697a4f5573099b0762630b45347 (diff) | |
download | nsxiv-bfab4dc328f580cc21c31ee3e4f53e1b8ca7c4ab.tar.zst |
Added EXIF auto-orientation
Diffstat (limited to 'image.c')
-rw-r--r-- | image.c | 48 |
1 files changed, 47 insertions, 1 deletions
@@ -16,11 +16,12 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include <string.h> #include <unistd.h> +#include <libexif/exif-data.h> #ifdef GIF_SUPPORT #include <stdlib.h> -#include <string.h> #include <sys/types.h> #include <gif_lib.h> #endif @@ -37,6 +38,49 @@ enum { MIN_GIF_DELAY = 50 }; float zoom_min; float zoom_max; +void exif_auto_orientate(const fileinfo_t *file) { + ExifData *ed; + ExifEntry *entry; + int byte_order, orientation; + + if (!(ed = exif_data_new_from_file(file->path))) + return; + entry = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_ORIENTATION); + if (entry) { + byte_order = exif_data_get_byte_order(ed); + orientation = exif_get_short(entry->data, byte_order); + } + exif_data_unref(ed); + if (!entry) + return; + + switch (orientation) { + case 5: + imlib_image_orientate(1); + case 2: + imlib_image_flip_vertical(); + break; + + case 3: + imlib_image_orientate(2); + break; + + case 7: + imlib_image_orientate(1); + case 4: + imlib_image_flip_horizontal(); + break; + + case 6: + imlib_image_orientate(1); + break; + + case 8: + imlib_image_orientate(270); + break; + } +} + void img_init(img_t *img, win_t *win) { zoom_min = zoom_levels[0] / 100.0; zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0; @@ -241,6 +285,8 @@ int img_load(img_t *img, const fileinfo_t *file) { imlib_context_set_anti_alias(img->aa); fmt = imlib_image_format(); + if (!strcmp(fmt, "jpeg")) + exif_auto_orientate(file); #ifdef GIF_SUPPORT if (!strcmp(fmt, "gif")) img_load_gif(img, file); |