From ad73446df733245b7f451174c1e62c14a1b67bc3 Mon Sep 17 00:00:00 2001 From: Gustavo Sverzut Barbieri Date: Tue, 12 Oct 2010 18:16:42 +0000 Subject: [PATCH] support more exif orientation modes. Raster, this exposes some problems with map as well. At least flipping seems to not work properly sometimes. In my case I just use Shift+[ to flip horizontally and it does not work. SVN revision: 53312 --- data/themes/default/ephoto.edc | 58 ++++++++++++++ src/bin/ephoto.h | 14 ++-- src/bin/ephoto_flow_browser.c | 141 ++++++++++++++++++++++++++++----- src/bin/ephoto_slideshow.c | 47 +++++++++++ 4 files changed, 233 insertions(+), 27 deletions(-) diff --git a/data/themes/default/ephoto.edc b/data/themes/default/ephoto.edc index 8a032a8..20c360d 100644 --- a/data/themes/default/ephoto.edc +++ b/data/themes/default/ephoto.edc @@ -1066,6 +1066,40 @@ collections rotation.z: 270; } } + description { state: "flip_horiz" 0.0; + inherit: "default" 0.0; + map { + on: 1; + rotation.y: 180; + } + } + description { state: "flip_vert" 0.0; + inherit: "default" 0.0; + map { + on: 1; + rotation.x: 180; + } + } + description { state: "flip_horiz_90" 0.0; + inherit: "default" 0.0; + map { + on: 1; + rotation { + z: 90; + y: 180; + } + } + } + description { state: "flip_vert_90" 0.0; + inherit: "default" 0.0; + map { + on: 1; + rotation { + z: 90; + x: 180; + } + } + } } programs { program { @@ -1092,6 +1126,30 @@ collections action: STATE_SET "rotate_270" 0.0; target: "ephoto.swallow.flow"; } + program { + signal: "state,flip,horiz"; + source: "ephoto"; + action: STATE_SET "flip_horiz" 0.0; + target: "ephoto.swallow.flow"; + } + program { + signal: "state,flip,vert"; + source: "ephoto"; + action: STATE_SET "flip_vert" 0.0; + target: "ephoto.swallow.flow"; + } + program { + signal: "state,flip,horiz,90"; + source: "ephoto"; + action: STATE_SET "flip_horiz_90" 0.0; + target: "ephoto.swallow.flow"; + } + program { + signal: "state,flip,vert,90"; + source: "ephoto"; + action: STATE_SET "flip_vert_90" 0.0; + target: "ephoto.swallow.flow"; + } } part { name: "iconbar.bg"; diff --git a/src/bin/ephoto.h b/src/bin/ephoto.h index 92b50b8..ade0744 100644 --- a/src/bin/ephoto.h +++ b/src/bin/ephoto.h @@ -72,12 +72,16 @@ enum _Ephoto_State EPHOTO_STATE_SLIDESHOW }; -enum _Ephoto_Orient +enum _Ephoto_Orient /* matches with exif orientation tag */ { - EPHOTO_ORIENT_0, - EPHOTO_ORIENT_90, - EPHOTO_ORIENT_180, - EPHOTO_ORIENT_270 + EPHOTO_ORIENT_0 = 1, + EPHOTO_ORIENT_FLIP_HORIZ = 2, + EPHOTO_ORIENT_180 = 3, + EPHOTO_ORIENT_FLIP_VERT = 4, + EPHOTO_ORIENT_FLIP_VERT_90 = 5, + EPHOTO_ORIENT_90 = 6, + EPHOTO_ORIENT_FLIP_HORIZ_90 = 7, + EPHOTO_ORIENT_270 = 8 }; /* TODO: split into window & global config, allow multi window diff --git a/src/bin/ephoto_flow_browser.c b/src/bin/ephoto_flow_browser.c index eea98bf..52f2012 100644 --- a/src/bin/ephoto_flow_browser.c +++ b/src/bin/ephoto_flow_browser.c @@ -139,9 +139,22 @@ _orient_apply(Ephoto_Flow_Browser *fb) case EPHOTO_ORIENT_270: sig = "state,rotate,270"; break; + case EPHOTO_ORIENT_FLIP_HORIZ: + sig = "state,flip,horiz"; + break; + case EPHOTO_ORIENT_FLIP_VERT: + sig = "state,flip,vert"; + break; + case EPHOTO_ORIENT_FLIP_HORIZ_90: + sig = "state,flip,horiz,90"; + break; + case EPHOTO_ORIENT_FLIP_VERT_90: + sig = "state,flip,vert,90"; + break; default: return; } + DBG("orient: %d, signal '%s'", fb->orient, sig); edje_object_signal_emit(fb->edje, sig, "ephoto"); } @@ -162,6 +175,18 @@ _rotate_counterclock(Ephoto_Flow_Browser *fb) case EPHOTO_ORIENT_270: fb->orient = EPHOTO_ORIENT_180; break; + case EPHOTO_ORIENT_FLIP_HORIZ: + fb->orient = EPHOTO_ORIENT_FLIP_HORIZ_90; + break; + case EPHOTO_ORIENT_FLIP_VERT: + fb->orient = EPHOTO_ORIENT_FLIP_VERT_90; + break; + case EPHOTO_ORIENT_FLIP_HORIZ_90: + fb->orient = EPHOTO_ORIENT_FLIP_VERT; + break; + case EPHOTO_ORIENT_FLIP_VERT_90: + fb->orient = EPHOTO_ORIENT_FLIP_HORIZ; + break; } _orient_apply(fb); } @@ -183,6 +208,84 @@ _rotate_clock(Ephoto_Flow_Browser *fb) case EPHOTO_ORIENT_270: fb->orient = EPHOTO_ORIENT_0; break; + case EPHOTO_ORIENT_FLIP_HORIZ: + fb->orient = EPHOTO_ORIENT_FLIP_VERT_90; + break; + case EPHOTO_ORIENT_FLIP_VERT: + fb->orient = EPHOTO_ORIENT_FLIP_HORIZ_90; + break; + case EPHOTO_ORIENT_FLIP_HORIZ_90: + fb->orient = EPHOTO_ORIENT_FLIP_HORIZ; + break; + case EPHOTO_ORIENT_FLIP_VERT_90: + fb->orient = EPHOTO_ORIENT_FLIP_VERT; + break; + } + _orient_apply(fb); +} + +static void +_flip_horiz(Ephoto_Flow_Browser *fb) +{ + switch (fb->orient) + { + case EPHOTO_ORIENT_0: + fb->orient = EPHOTO_ORIENT_FLIP_HORIZ; + break; + case EPHOTO_ORIENT_90: + fb->orient = EPHOTO_ORIENT_FLIP_HORIZ_90; + break; + case EPHOTO_ORIENT_180: + fb->orient = EPHOTO_ORIENT_FLIP_VERT; + break; + case EPHOTO_ORIENT_270: + fb->orient = EPHOTO_ORIENT_FLIP_VERT_90; + break; + case EPHOTO_ORIENT_FLIP_HORIZ: + fb->orient = EPHOTO_ORIENT_0; + break; + case EPHOTO_ORIENT_FLIP_VERT: + fb->orient = EPHOTO_ORIENT_180; + break; + case EPHOTO_ORIENT_FLIP_HORIZ_90: + fb->orient = EPHOTO_ORIENT_90; + break; + case EPHOTO_ORIENT_FLIP_VERT_90: + fb->orient = EPHOTO_ORIENT_270; + break; + } + _orient_apply(fb); +} + +static void +_flip_vert(Ephoto_Flow_Browser *fb) +{ + switch (fb->orient) + { + case EPHOTO_ORIENT_0: + fb->orient = EPHOTO_ORIENT_FLIP_VERT; + break; + case EPHOTO_ORIENT_90: + fb->orient = EPHOTO_ORIENT_FLIP_VERT_90; + break; + case EPHOTO_ORIENT_180: + fb->orient = EPHOTO_ORIENT_FLIP_HORIZ; + break; + case EPHOTO_ORIENT_270: + fb->orient = EPHOTO_ORIENT_FLIP_HORIZ_90; + break; + case EPHOTO_ORIENT_FLIP_HORIZ: + fb->orient = EPHOTO_ORIENT_180; + break; + case EPHOTO_ORIENT_FLIP_VERT: + fb->orient = EPHOTO_ORIENT_0; + break; + case EPHOTO_ORIENT_FLIP_HORIZ_90: + fb->orient = EPHOTO_ORIENT_270; + break; + case EPHOTO_ORIENT_FLIP_VERT_90: + fb->orient = EPHOTO_ORIENT_90; + break; } _orient_apply(fb); } @@ -257,34 +360,21 @@ ephoto_file_orient_get(const char *path) ExifData *exif; ExifEntry *entry; ExifByteOrder bo; - int exif_orient; if (!_path_is_jpeg(path)) return orient; exif = exif_data_new_from_file(path); - EINA_SAFETY_ON_NULL_GOTO(exif, end); + if (!exif) goto end; bo = exif_data_get_byte_order(exif); entry = exif_data_get_entry(exif, EXIF_TAG_ORIENTATION); - EINA_SAFETY_ON_NULL_GOTO(entry, end_entry); + if (!entry) goto end_entry; - exif_orient = exif_get_short(entry->data, bo); - DBG("exif_orient=%d", exif_orient); - switch (exif_orient) + orient = exif_get_short(entry->data, bo); + DBG("orient=%d", orient); + if ((orient < 1) || (orient > 8)) { - case 1: - orient = EPHOTO_ORIENT_0; - break; - case 3: - orient = EPHOTO_ORIENT_180; - break; - case 6: - orient = EPHOTO_ORIENT_90; - break; - case 8: - orient = EPHOTO_ORIENT_270; - break; - default: - ERR("exif orient not supported: %d", exif_orient); + ERR("exif orient not supported: %d", orient); + orient = EPHOTO_ORIENT_0; } end_entry: @@ -437,6 +527,7 @@ _key_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event Ephoto_Flow_Browser *fb = data; Evas_Event_Key_Down *ev = event_info; Eina_Bool ctrl = evas_key_modifier_is_set(ev->modifiers, "Control"); + Eina_Bool shift = evas_key_modifier_is_set(ev->modifiers, "Shift"); const char *k = ev->keyname; if (ctrl) @@ -462,9 +553,15 @@ _key_down(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event else if (!strcmp(k, "End")) _last_entry(fb); else if (!strcmp(k, "bracketleft")) - _rotate_counterclock(fb); + { + if (!shift) _rotate_counterclock(fb); + else _flip_horiz(fb); + } else if (!strcmp(k, "bracketright")) - _rotate_clock(fb); + { + if (!shift) _rotate_clock(fb); + else _flip_vert(fb); + } else if (!strcmp(k, "F5")) { if (fb->entry) diff --git a/src/bin/ephoto_slideshow.c b/src/bin/ephoto_slideshow.c index b3efcf7..c321976 100644 --- a/src/bin/ephoto_slideshow.c +++ b/src/bin/ephoto_slideshow.c @@ -84,6 +84,47 @@ ephoto_slideshow_add(Ephoto *ephoto, Evas_Object *parent) return NULL; } +static void +_image_resized(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *image, void *event_info __UNUSED__) +{ + Evas_Map *map = evas_map_new(4); + Evas_Coord cx, cy, x, y, w, h; + int orient = (long)evas_object_data_get(image, "orient"); + + evas_object_geometry_get(image, &x, &y, &w, &h); + evas_map_util_points_populate_from_geometry(map, x, y, w, h, 0); + cx = x + w / 2; + cy = y + h / 2; + + switch (orient) + { + case EPHOTO_ORIENT_0: + break; + case EPHOTO_ORIENT_90: + evas_map_util_rotate(map, 90.0, cx, cy); + evas_object_map_enable_set(image, EINA_TRUE); + evas_object_map_set(image, map); + printf("rotated 90 around %d,%d (%dx%d)\n", cx, cy, w, h); + break; + case EPHOTO_ORIENT_180: + evas_map_util_rotate(map, 180.0, cx, cy); + evas_object_map_enable_set(image, EINA_TRUE); + evas_object_map_set(image, map); + printf("rotated 180 around %d,%d (%d,%d %dx%d)\n", cx, cy, x, y, w, h); + break; + case EPHOTO_ORIENT_270: + evas_map_util_rotate(map, 270.0, cx, cy); + evas_object_map_enable_set(image, EINA_TRUE); + evas_object_map_set(image, map); + printf("rotated 270 around %d,%d (%dx%d)\n", cx, cy, w, h); + break; + default: + ERR("unknown orient %d", orient); + } + + evas_map_free(map); +} + static Evas_Object * _slideshow_item_get(void *data, Evas_Object *obj) { @@ -94,6 +135,12 @@ _slideshow_item_get(void *data, Evas_Object *obj) elm_photo_file_set(image, entry->path); elm_photo_fill_inside_set(image, EINA_TRUE); elm_object_style_set(image, "shadow"); + + evas_object_data_set + (image, "orient", (void*)(long)ephoto_file_orient_get(entry->path)); + evas_object_event_callback_add + (image, EVAS_CALLBACK_RESIZE, _image_resized, NULL); + return image; }