From 55e596d08571462e3bdcde1e745948c5cbdc7f2a Mon Sep 17 00:00:00 2001 From: kabeer khan Date: Fri, 20 Feb 2015 14:33:04 +0100 Subject: [PATCH] elm_photocam: add API's to change photocam image orientation Summary: Added API's to rotate(90, 180, 270), flip(horizontal, vertical), transpose and transverse Photocam Image. Signed-off-by: kabeer khan Reviewers: seoz, stephenmhouston, raster, cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D1541 Signed-off-by: Cedric BAIL Conflicts: src/lib/elm_photocam.c Change-Id: I9f8e79cd3550b82e80c0b4c4de8447b38cd23f8e Origin: upstream --- src/bin/test_photocam.c | 76 +++++++++++++++++++++++++++++++++++++++++-- src/lib/elm_photocam.c | 64 +++++++++++++++++++++++++++++++++++- src/lib/elm_photocam.eo | 30 +++++++++++++++++ src/lib/elm_photocam.h | 1 - src/lib/elm_widget_photocam.h | 1 + 5 files changed, 167 insertions(+), 5 deletions(-) diff --git a/src/bin/test_photocam.c b/src/bin/test_photocam.c index b85adc3..1b5a027 100644 --- a/src/bin/test_photocam.c +++ b/src/bin/test_photocam.c @@ -3,6 +3,21 @@ #endif #include +static const struct { + Evas_Image_Orient orient; + const char *name; +} photocam_orient[] = { + { EVAS_IMAGE_ORIENT_NONE, "None" }, + { EVAS_IMAGE_ORIENT_90, "Rotate 90" }, + { EVAS_IMAGE_ORIENT_180, "Rotate 180" }, + { EVAS_IMAGE_ORIENT_270, "Rotate 270" }, + { EVAS_IMAGE_FLIP_HORIZONTAL, "Horizontal Flip" }, + { EVAS_IMAGE_FLIP_VERTICAL, "Vertical Flip" }, + { EVAS_IMAGE_FLIP_TRANSPOSE, "Transpose" }, + { EVAS_IMAGE_FLIP_TRANSVERSE, "Transverse" }, + { 0, NULL } +}; + static void my_ph_clicked(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { @@ -10,6 +25,17 @@ my_ph_clicked(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_ } static void +my_ph_ch(void *data, Evas_Object *obj, void *event_info EINA_UNUSED) +{ + Evas_Object *photocam = data; + Evas_Image_Orient orient = elm_radio_value_get(obj); + + elm_photocam_image_orient_set(photocam, orient); + fprintf(stderr, "Set %i and got %i\n", + orient, elm_photocam_image_orient_get(photocam)); +} + +static void my_ph_press(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { printf("press\n"); @@ -254,9 +280,9 @@ _photocam_move_resize_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void void test_photocam(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - Evas_Object *win, *ph, *tb2, *bt, *box; + Evas_Object *win, *ph, *tb2, *bt, *box, *rd, *rdg = NULL; + int i; Evas_Object *rect = NULL; - win = elm_win_util_standard_add("photocam", "PhotoCam"); elm_win_autodel_set(win, EINA_TRUE); @@ -387,6 +413,27 @@ test_photocam(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_ elm_box_pack_end(box, bt); evas_object_show(bt); + box = elm_box_add(tb2); + elm_box_horizontal_set(box, EINA_TRUE); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(box, 0.9, 0.9); + elm_table_pack(tb2, box, 1, 2, 1, 1); + evas_object_show(box); + + for (i = 0; photocam_orient[i].name; ++i) + { + rd = elm_radio_add(win); + evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_radio_state_value_set(rd, photocam_orient[i].orient); + elm_object_text_set(rd, photocam_orient[i].name); + elm_box_pack_end(box, rd); + evas_object_show(rd); + evas_object_smart_callback_add(rd, "changed", my_ph_ch, ph); + if (!rdg) + rdg = rd; + else + elm_radio_group_add(rd, rdg); + } evas_object_show(box); evas_object_show(tb2); @@ -397,10 +444,12 @@ test_photocam(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_ void test_photocam_remote(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) { - Evas_Object *win, *ph, *tb2, *bt, *box, *pb; + Evas_Object *win, *ph, *tb2, *bt, *box, *pb, *rd; + Evas_Object *rdg = NULL; Evas_Object *rect = NULL; // these were just testing - use the "select photo" browser to select one static const char *url = "http://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73751/world.topo.bathy.200407.3x21600x10800.jpg"; + int i; win = elm_win_util_standard_add("photocam", "PhotoCam"); elm_win_autodel_set(win, EINA_TRUE); @@ -535,6 +584,27 @@ test_photocam_remote(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void elm_box_pack_end(box, bt); evas_object_show(bt); + box = elm_box_add(tb2); + elm_box_horizontal_set(box, EINA_TRUE); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(box, 0.9, 0.9); + elm_table_pack(tb2, box, 1, 2, 1, 1); + evas_object_show(box); + + for (i = 0; photocam_orient[i].name; ++i) + { + rd = elm_radio_add(win); + evas_object_size_hint_weight_set(rd, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_radio_state_value_set(rd, photocam_orient[i].orient); + elm_object_text_set(rd, photocam_orient[i].name); + elm_box_pack_end(box, rd); + evas_object_show(rd); + evas_object_smart_callback_add(rd, "changed", my_ph_ch, ph); + if (!rdg) + rdg = rd; + else + elm_radio_group_add(rd, rdg); + } evas_object_show(box); evas_object_show(tb2); diff --git a/src/lib/elm_photocam.c b/src/lib/elm_photocam.c index 68af62c..d20a252 100644 --- a/src/lib/elm_photocam.c +++ b/src/lib/elm_photocam.c @@ -696,6 +696,7 @@ _grid_create(Evas_Object *obj) g->grid[tn].img = evas_object_image_add(evas_object_evas_get(obj)); evas_object_image_load_orientation_set(g->grid[tn].img, EINA_TRUE); + evas_object_image_orient_set(g->grid[tn].img, sd->orient); evas_object_image_scale_hint_set (g->grid[tn].img, EVAS_IMAGE_SCALE_HINT_DYNAMIC); evas_object_pass_events_set(g->grid[tn].img, EINA_TRUE); @@ -1334,6 +1335,67 @@ _g_layer_zoom_end_cb(void *data, return EVAS_EVENT_FLAG_NONE; } +static void +_orient_do(Evas_Object *obj, Elm_Photocam_Data *sd) +{ + evas_object_smart_member_del(sd->img); + elm_widget_sub_object_del(obj, sd->img); + evas_object_smart_member_add(sd->img, sd->pan_obj); + elm_widget_sub_object_add(obj, sd->img); + ecore_job_del(sd->calc_job); + sd->calc_job = ecore_job_add(_calc_job_cb, obj); +} + +EOLIAN static void +_elm_photocam_image_orient_set(Eo *obj, Elm_Photocam_Data *sd, Evas_Image_Orient orient) +{ + int iw, ih; + Eina_List *l; + Elm_Phocam_Grid *g, *g_orient = NULL; + + if (sd->orient == orient) return; + + sd->orient = orient; + g = _grid_create(obj); + if (g) + { + if (eina_list_count(sd->grids) > 1) + { + g_orient = eina_list_last(sd->grids)->data; + sd->grids = eina_list_remove(sd->grids, g_orient); + _grid_clear(obj, g_orient); + free(g_orient); + EINA_LIST_FOREACH(sd->grids, l, g_orient) + { + g_orient->dead = 1; + } + } + sd->grids = eina_list_prepend(sd->grids, g); + } + else + { + EINA_LIST_FREE(sd->grids, g) + { + _grid_clear(obj, g); + free(g); + } + } + + evas_object_image_orient_set(sd->img, orient); + evas_object_image_size_get(sd->img, &iw, &ih); + sd->size.imw = iw; + sd->size.imh = ih; + sd->size.w = iw / sd->zoom; + sd->size.h = ih / sd->zoom; + _orient_do(obj, sd); +} + +EOLIAN static Evas_Image_Orient +_elm_photocam_image_orient_get(Eo *obj EINA_UNUSED, Elm_Photocam_Data *sd) +{ + return sd->orient; +} + EOLIAN static void _elm_photocam_evas_object_smart_add(Eo *obj, Elm_Photocam_Data *priv) { @@ -1523,6 +1585,7 @@ _internal_file_set(Eo *obj, Elm_Photocam_Data *sd, const char *file, Eina_File * tz = sd->zoom; sd->zoom = 0.0; elm_photocam_zoom_set(obj, tz); + sd->orient = EVAS_IMAGE_ORIENT_NONE; if (ret) *ret = evas_object_image_load_error_get(sd->img); } @@ -1771,7 +1834,6 @@ EOLIAN static void _elm_photocam_zoom_mode_set(Eo *obj, Elm_Photocam_Data *sd, Elm_Photocam_Zoom_Mode mode) { double tz; - if (sd->mode == mode) return; sd->mode = mode; diff --git a/src/lib/elm_photocam.eo b/src/lib/elm_photocam.eo index 261e550..5482745 100644 --- a/src/lib/elm_photocam.eo +++ b/src/lib/elm_photocam.eo @@ -205,6 +205,36 @@ class Elm_Photocam (Elm_Widget, Elm_Interface_Scrollable, int h; /*@ A pointer to the height return */ } } + image_orient { + set { + /*@ + Set the photocam image orientation. + + This function allows to rotate or flip the photocam image. + + @see elm_photocam_image_orient_get() + @see @ref Evas_Image_Orient + + @since 1.14 + @ingroup Photocam */ + } + get { + /*@ + Get the photocam image orientation. + + @return The photocam image orientation @ref Evas_Image_Orient + + @see elm_photocam_image_orient_set() + @see @ref Evas_Image_Orient + + @since 1.14 + @ingroup Photocam */ + } + values { + Evas_Image_Orient orient; /*@ The photocam image orientation @ref Evas_Image_Orient + Default is #EVAS_IMAGE_ORIENT_NONE. */ + } + } } methods { image_region_show { diff --git a/src/lib/elm_photocam.h b/src/lib/elm_photocam.h index d6b7c98..ac7f8b0 100644 --- a/src/lib/elm_photocam.h +++ b/src/lib/elm_photocam.h @@ -80,7 +80,6 @@ struct _Elm_Photocam_Progress double total; }; - /** * Structre associated with smart callback 'download,error' * @since 1.8 diff --git a/src/lib/elm_widget_photocam.h b/src/lib/elm_widget_photocam.h index 7d05df1..afb3ce5 100644 --- a/src/lib/elm_widget_photocam.h +++ b/src/lib/elm_widget_photocam.h @@ -119,6 +119,7 @@ struct _Elm_Photocam_Data int preload_num; Eina_List *grids; + Evas_Image_Orient orient; /**< This stores the current orientation of Photocam. By default this is set to EVAS_IMAGE_ORIENT_NONE */ Eina_Bool main_load_pending : 1; Eina_Bool longpressed : 1; -- 2.7.4