Krolyxon
Commit bfab4dc

Branches

Refs →

nsxivbfab4dc

Added EXIF auto-orientation

Author
Bert
Date
2011-09-06 11:09 +0200
Committer
Bert · 2011-09-08 15:57 +0200
Parent
b96c106
Commit
bfab4dc328f580cc21c31ee3e4f53e1b8ca7c4ab

+56 −1

2 files changed

  1. M image.c +47 −1
  2. M thumbs.c +9 −0
M image.c View
@@ -16,11 +16,12 @@
1616 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1717 */
1818
19+#include <string.h>
1920 #include <unistd.h>
21+#include <libexif/exif-data.h>
2022
2123 #ifdef GIF_SUPPORT
2224 #include <stdlib.h>
23−#include <string.h>
2425 #include <sys/types.h>
2526 #include <gif_lib.h>
2627 #endif
@@ -37,6 +38,49 @@ enum { MIN_GIF_DELAY = 50 };
3738 float zoom_min;
3839 float zoom_max;
3940
41+void exif_auto_orientate(const fileinfo_t *file) {
42+ ExifData *ed;
43+ ExifEntry *entry;
44+ int byte_order, orientation;
45+
46+ if (!(ed = exif_data_new_from_file(file->path)))
47+ return;
48+ entry = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_ORIENTATION);
49+ if (entry) {
50+ byte_order = exif_data_get_byte_order(ed);
51+ orientation = exif_get_short(entry->data, byte_order);
52+ }
53+ exif_data_unref(ed);
54+ if (!entry)
55+ return;
56+
57+ switch (orientation) {
58+ case 5:
59+ imlib_image_orientate(1);
60+ case 2:
61+ imlib_image_flip_vertical();
62+ break;
63+
64+ case 3:
65+ imlib_image_orientate(2);
66+ break;
67+
68+ case 7:
69+ imlib_image_orientate(1);
70+ case 4:
71+ imlib_image_flip_horizontal();
72+ break;
73+
74+ case 6:
75+ imlib_image_orientate(1);
76+ break;
77+
78+ case 8:
79+ imlib_image_orientate(270);
80+ break;
81+ }
82+}
83+
4084 void img_init(img_t *img, win_t *win) {
4185 zoom_min = zoom_levels[0] / 100.0;
4286 zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0;
@@ -241,6 +285,8 @@ int img_load(img_t *img, const fileinfo_t *file) {
241285 imlib_context_set_anti_alias(img->aa);
242286
243287 fmt = imlib_image_format();
288+ if (!strcmp(fmt, "jpeg"))
289+ exif_auto_orientate(file);
244290 #ifdef GIF_SUPPORT
245291 if (!strcmp(fmt, "gif"))
246292 img_load_gif(img, file);
M thumbs.c View
@@ -34,6 +34,8 @@
3434 #define st_atim st_atimespec
3535 #endif
3636
37+void exif_auto_orientate(const fileinfo_t*);
38+
3739 const int thumb_dim = THUMB_SIZE + 10;
3840 char *cache_dir = NULL;
3941
@@ -221,6 +223,7 @@ int tns_load(tns_t *tns, int n, const fileinfo_t *file,
221223 float z, zw, zh;
222224 thumb_t *t;
223225 Imlib_Image *im;
226+ const char *fmt;
224227
225228 if (!tns || !tns->thumbs || !file || !file->name || !file->path)
226229 return 0;
@@ -252,6 +255,12 @@ int tns_load(tns_t *tns, int n, const fileinfo_t *file,
252255 imlib_context_set_image(im);
253256 imlib_context_set_anti_alias(1);
254257
258+ if (!cache_hit) {
259+ fmt = imlib_image_format();
260+ if (!strcmp(fmt, "jpeg"))
261+ exif_auto_orientate(file);
262+ }
263+
255264 w = imlib_image_get_width();
256265 h = imlib_image_get_height();
257266 zw = (float) THUMB_SIZE / (float) w;