From 97cefca2739715b57e50243810046e0ae3b68e6c Mon Sep 17 00:00:00 2001 From: kabeer khan Date: Fri, 20 Feb 2015 14:26:01 +0100 Subject: [PATCH] elm_image: changed orient_set code to use evas_object_image_orient_set API Summary: evas_image_orient_set is a newly added API to set orientation of evas image. Using this API to set orientation of image widget. Also removed Elm_Image_Orient enums and replaced it with Evas_Image_Orient enums. Signed-off-by: kabeer khan Reviewers: raster, seoz, cedric Differential Revision: https://phab.enlightenment.org/D1987 Signed-off-by: Cedric BAIL --- legacy/elementary/src/bin/test_image.c | 20 +- legacy/elementary/src/lib/elm_image.c | 307 +------------------ legacy/elementary/src/lib/elm_image_common.h | 35 +-- 3 files changed, 28 insertions(+), 334 deletions(-) diff --git a/legacy/elementary/src/bin/test_image.c b/legacy/elementary/src/bin/test_image.c index 9ab0ebc8df..77d7bb2387 100644 --- a/legacy/elementary/src/bin/test_image.c +++ b/legacy/elementary/src/bin/test_image.c @@ -4,17 +4,17 @@ #include static const struct { - Elm_Image_Orient orient; + Evas_Image_Orient orient; const char *name; } images_orient[] = { - { ELM_IMAGE_ORIENT_NONE, "None" }, - { ELM_IMAGE_ROTATE_90, "Rotate 90" }, - { ELM_IMAGE_ROTATE_180, "Rotate 180" }, - { ELM_IMAGE_ROTATE_270, "Rotate 270" }, - { ELM_IMAGE_FLIP_HORIZONTAL, "Horizontal Flip" }, - { ELM_IMAGE_FLIP_VERTICAL, "Vertical Flip" }, - { ELM_IMAGE_FLIP_TRANSPOSE, "Transpose" }, - { ELM_IMAGE_FLIP_TRANSVERSE, "Transverse" }, + { 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 } }; @@ -24,7 +24,7 @@ my_im_ch(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) Evas_Object *win = data; Evas_Object *im = evas_object_data_get(win, "im"); Evas_Object *rdg = evas_object_data_get(win, "rdg"); - Elm_Image_Orient v = elm_radio_value_get(rdg); + Evas_Image_Orient v = elm_radio_value_get(rdg); elm_image_orient_set(im, v); fprintf(stderr, "Set %i and got %i\n", diff --git a/legacy/elementary/src/lib/elm_image.c b/legacy/elementary/src/lib/elm_image.c index cddc2c45a0..503bc56df5 100644 --- a/legacy/elementary/src/lib/elm_image.c +++ b/legacy/elementary/src/lib/elm_image.c @@ -1031,319 +1031,16 @@ _elm_image_efl_image_load_size_get(Eo *obj EINA_UNUSED, Elm_Image_Data *sd, int if (h) *h = sd->load_size; } -static void -_elm_image_flip_horizontal(Elm_Image_Data *sd) -{ - unsigned int *p1, *p2, tmp; - unsigned int *data; - int x, y, iw, ih; - - evas_object_image_size_get(sd->img, &iw, &ih); - data = evas_object_image_data_get(sd->img, EINA_TRUE); - - for (y = 0; y < ih; y++) - { - p1 = data + (y * iw); - p2 = data + ((y + 1) * iw) - 1; - for (x = 0; x < (iw >> 1); x++) - { - tmp = *p1; - *p1 = *p2; - *p2 = tmp; - p1++; - p2--; - } - } - - evas_object_image_data_set(sd->img, data); -} - -static void -_elm_image_flip_vertical(Elm_Image_Data *sd) -{ - unsigned int *p1, *p2, tmp; - unsigned int *data; - int x, y, iw, ih; - - evas_object_image_size_get(sd->img, &iw, &ih); - data = evas_object_image_data_get(sd->img, EINA_TRUE); - - for (y = 0; y < (ih >> 1); y++) - { - p1 = data + (y * iw); - p2 = data + ((ih - 1 - y) * iw); - for (x = 0; x < iw; x++) - { - tmp = *p1; - *p1 = *p2; - *p2 = tmp; - p1++; - p2++; - } - } - - evas_object_image_data_set(sd->img, data); -} - -static void -_elm_image_smart_rotate_180(Elm_Image_Data *sd) -{ - unsigned int *p1, *p2, tmp; - unsigned int *data; - int x, hw, iw, ih; - - evas_object_image_size_get(sd->img, &iw, &ih); - data = evas_object_image_data_get(sd->img, 1); - - hw = iw * ih; - x = (hw / 2); - p1 = data; - p2 = data + hw - 1; - - for (; --x > 0; ) - { - tmp = *p1; - *p1 = *p2; - *p2 = tmp; - p1++; - p2--; - } - - evas_object_image_data_set(sd->img, data); -} - -#define GETDAT(neww, newh) \ - unsigned int *data, *data2; \ - int iw, ih, w, h; \ - evas_object_image_size_get(sd->img, &iw, &ih); \ - data = evas_object_image_data_get(sd->img, EINA_FALSE); \ - if (!data) return; \ - data2 = malloc(iw * ih * sizeof(int)); \ - if (!data2) { \ - evas_object_image_data_set(sd->img, data); \ - return; \ - } \ - memcpy(data2, data, iw * ih * sizeof(int)); \ - evas_object_image_data_set(sd->img, data); \ - w = neww; h = newh; \ - evas_object_image_size_set(sd->img, w, h); \ - data = evas_object_image_data_get(sd->img, EINA_TRUE); \ - if (!data) { \ - free(data2); \ - return; \ - } \ - -#define PUTDAT \ - evas_object_image_data_set(sd->img, data); \ - free(data2); - -#define TILE 32 - -static void -_elm_image_smart_rotate_90(Elm_Image_Data *sd) -{ - GETDAT(ih, iw); - int x, y, xx, yy, xx2, yy2; - unsigned int *src, *dst; - - for (y = 0; y < ih; y += TILE) - { - yy2 = y + TILE; - if (yy2 > ih) yy2 = ih; - for (x = 0; x < iw; x += TILE) - { - xx2 = x + TILE; - if (xx2 > iw) xx2 = iw; - for (yy = y; yy < yy2; yy++) - { - src = data2 + (yy * iw) + x; - dst = data + (x * w) + (w - yy - 1); - for (xx = x; xx < xx2; xx++) - { - *dst = *src; - src++; - dst += w; - } - } - } - } - PUTDAT; -} - -static void -_elm_image_smart_rotate_270(Elm_Image_Data *sd) -{ - GETDAT(ih, iw); - int x, y, xx, yy, xx2, yy2; - unsigned int *src, *dst; - - for (y = 0; y < ih; y += TILE) - { - yy2 = y + TILE; - if (yy2 > ih) yy2 = ih; - for (x = 0; x < iw; x += TILE) - { - xx2 = x + TILE; - if (xx2 > iw) xx2 = iw; - for (yy = y; yy < yy2; yy++) - { - src = data2 + (yy * iw) + x; - dst = data + ((h - x - 1) * w) + yy; - for (xx = x; xx < xx2; xx++) - { - *dst = *src; - src++; - dst -= w; - } - } - } - } - PUTDAT; -} - -static void -_elm_image_smart_flip_transverse(Elm_Image_Data *sd) -{ - GETDAT(ih, iw); - int x, y; - unsigned int *src, *dst; - - src = data2; - for (y = 0; y < ih; y++) - { - dst = data + y; - for (x = 0; x < iw; x++) - { - *dst = *src; - src++; - dst += w; - } - } - PUTDAT; -} - -static void -_elm_image_smart_flip_transpose(Elm_Image_Data *sd) -{ - GETDAT(ih, iw); - int x, y; - unsigned int *src, *dst; - - src = data2 + (iw * ih) - 1; - for (y = 0; y < ih; y++) - { - dst = data + y; - for (x = 0; x < iw; x++) - { - *dst = *src; - src--; - dst += w; - } - } - PUTDAT; -} - EOLIAN static void _elm_image_orient_set(Eo *obj, Elm_Image_Data *sd, Elm_Image_Orient orient) { - int iw, ih; if (sd->edje) return; if (sd->orient == orient) return; - evas_object_image_size_get(sd->img, &iw, &ih); - if ((sd->orient >= ELM_IMAGE_ORIENT_0) && - (sd->orient <= ELM_IMAGE_ROTATE_270) && - (orient >= ELM_IMAGE_ORIENT_0) && - (orient <= ELM_IMAGE_ROTATE_270)) - { - // we are rotating from one anglee to another, so figure out delta - // and apply that delta - Elm_Image_Orient rot_delta = (4 + orient - sd->orient) % 4; - switch (rot_delta) - { - case ELM_IMAGE_ORIENT_0: - // this should never hppen - break; - case ELM_IMAGE_ORIENT_90: - _elm_image_smart_rotate_90(sd); - sd->orient = orient; - break; - case ELM_IMAGE_ORIENT_180: - _elm_image_smart_rotate_180(sd); - sd->orient = orient; - break; - case ELM_IMAGE_ORIENT_270: - _elm_image_smart_rotate_270(sd); - sd->orient = orient; - break; - default: - // this should never hppen - break; - } - } - else if (((sd->orient == ELM_IMAGE_ORIENT_NONE) && - (orient == ELM_IMAGE_FLIP_HORIZONTAL)) || - ((sd->orient == ELM_IMAGE_FLIP_HORIZONTAL) && - (orient == ELM_IMAGE_ORIENT_NONE))) - { - // flip horizontally to get thew new orientation - _elm_image_flip_horizontal(sd); - sd->orient = orient; - } - else if (((sd->orient == ELM_IMAGE_ORIENT_NONE) && - (orient == ELM_IMAGE_FLIP_VERTICAL)) || - ((sd->orient == ELM_IMAGE_FLIP_VERTICAL) && - (orient == ELM_IMAGE_ORIENT_NONE))) - { - // flipvertically to get thew new orientation - _elm_image_flip_vertical(sd); - sd->orient = orient; - } - else - { - // generic solution - undo the previous orientation and then apply the - // new one after that - int i; - - for (i = 0; i < 2; i++) - { - switch (sd->orient) - { - case ELM_IMAGE_ORIENT_0: - break; - case ELM_IMAGE_ORIENT_90: - if (i == 0) _elm_image_smart_rotate_270(sd); - else _elm_image_smart_rotate_90(sd); - break; - case ELM_IMAGE_ORIENT_180: - _elm_image_smart_rotate_180(sd); - break; - case ELM_IMAGE_ORIENT_270: - if (i == 0) _elm_image_smart_rotate_90(sd); - else _elm_image_smart_rotate_270(sd); - break; - case ELM_IMAGE_FLIP_HORIZONTAL: - _elm_image_flip_horizontal(sd); - break; - case ELM_IMAGE_FLIP_VERTICAL: - _elm_image_flip_vertical(sd); - break; - case ELM_IMAGE_FLIP_TRANSPOSE: - _elm_image_smart_flip_transpose(sd); - break; - case ELM_IMAGE_FLIP_TRANSVERSE: - _elm_image_smart_flip_transverse(sd); - break; - default: - // this should never hppen - break; - } - sd->orient = orient; - } - } - + evas_object_image_orient_set(sd->img, orient); + sd->orient = orient; evas_object_image_size_get(sd->img, &iw, &ih); evas_object_image_data_update_add(sd->img, 0, 0, iw, ih); _elm_image_internal_sizing_eval(obj, sd); diff --git a/legacy/elementary/src/lib/elm_image_common.h b/legacy/elementary/src/lib/elm_image_common.h index a652f260c2..497a23184f 100644 --- a/legacy/elementary/src/lib/elm_image_common.h +++ b/legacy/elementary/src/lib/elm_image_common.h @@ -5,26 +5,23 @@ */ /** - * Possible orientation options for elm_image_orient_set(). - * - * @image html elm_image_orient_set.png - * @image latex elm_image_orient_set.eps width=\textwidth + * Using Evas_Image_Orient enums + * @since 1.14 */ -typedef enum -{ - ELM_IMAGE_ORIENT_NONE = 0, /**< no orientation change */ - ELM_IMAGE_ORIENT_0 = 0, /**< no orientation change */ - ELM_IMAGE_ROTATE_90 = 1, /**< rotate 90 degrees clockwise */ - ELM_IMAGE_ORIENT_90 = 1, /**< rotate 90 degrees clockwise @since 1.13 */ - ELM_IMAGE_ROTATE_180 = 2, /**< rotate 180 degrees clockwise */ - ELM_IMAGE_ORIENT_180 = 2, /**< rotate 180 degrees clockwise @since 1.13 */ - ELM_IMAGE_ROTATE_270 = 3, /**< rotate 90 degrees counter-clockwise (i.e. 270 degrees clockwise) */ - ELM_IMAGE_ORIENT_270 = 3, /**< rotate 90 degrees counter-clockwise (i.e. 270 degrees clockwise) @since 1.13 */ - ELM_IMAGE_FLIP_HORIZONTAL = 4, /**< flip image horizontally */ - ELM_IMAGE_FLIP_VERTICAL = 5, /**< flip image vertically */ - ELM_IMAGE_FLIP_TRANSPOSE = 6, /**< flip the image along the y = (width - x) line (bottom-left to top-right) */ - ELM_IMAGE_FLIP_TRANSVERSE = 7 /**< flip the image along the y = x line (top-left to bottom-right) */ -} Elm_Image_Orient; +typedef Evas_Image_Orient Elm_Image_Orient; + +#define ELM_IMAGE_ORIENT_NONE EVAS_IMAGE_ORIENT_NONE +#define ELM_IMAGE_ORIENT_0 EVAS_IMAGE_ORIENT_0 +#define ELM_IMAGE_ROTATE_90 EVAS_IMAGE_ORIENT_90 +#define ELM_IMAGE_ORIENT_90 EVAS_IMAGE_ORIENT_90 +#define ELM_IMAGE_ROTATE_180 EVAS_IMAGE_ORIENT_180 +#define ELM_IMAGE_ORIENT_180 EVAS_IMAGE_ORIENT_180 +#define ELM_IMAGE_ROTATE_270 EVAS_IMAGE_ORIENT_270 +#define ELM_IMAGE_ORIENT_270 EVAS_IMAGE_ORIENT_270 +#define ELM_IMAGE_FLIP_HORIZONTAL EVAS_IMAGE_FLIP_HORIZONTAL +#define ELM_IMAGE_FLIP_VERTICAL EVAS_IMAGE_FLIP_VERTICAL +#define ELM_IMAGE_FLIP_TRANSPOSE EVAS_IMAGE_FLIP_TRANSPOSE +#define ELM_IMAGE_FLIP_TRANSVERSE EVAS_IMAGE_FLIP_TRANSVERSE /** * Structure associated with smart callback 'download,progress'.