summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkabeer khan <kabeer.khan@samsung.com>2015-02-11 17:30:49 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-02-11 17:30:54 +0100
commit46b9b23144ba6a95d619b1aa21ec326ea92303b6 (patch)
tree1fb951df8d0f01d8477352f42438c003326be1fe /src
parent566eefd7d0e4ac70dca3f12b6ce99ae12bec7102 (diff)
evas: add image orient set/get API in software backend for now.
Summary: Added API's to rotate(0, 90, 180, 270), flip(horizontal, vertical, transpose, transverse) evas image object. Also added example to demonstrate this. Signed-off-by: kabeer khan <kabeer.khan@samsung.com> Reviewers: raster, stephenmhouston, cedric Subscribers: stephenmhouston, cedric Differential Revision: https://phab.enlightenment.org/D1950 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/examples/evas/.gitignore1
-rw-r--r--src/examples/evas/Makefile.am6
-rw-r--r--src/examples/evas/Makefile.examples1
-rw-r--r--src/examples/evas/evas-images4.c180
-rw-r--r--src/lib/evas/Evas_Common.h18
-rw-r--r--src/lib/evas/canvas/evas_image.eo28
-rw-r--r--src/lib/evas/canvas/evas_object_image.c64
-rw-r--r--src/lib/evas/include/evas_common_private.h1
-rw-r--r--src/lib/evas/include/evas_private.h2
-rw-r--r--src/modules/evas/engines/software_generic/evas_engine.c341
10 files changed, 641 insertions, 1 deletions
diff --git a/src/examples/evas/.gitignore b/src/examples/evas/.gitignore
index 7c29ff584b..579d96b971 100644
--- a/src/examples/evas/.gitignore
+++ b/src/examples/evas/.gitignore
@@ -5,6 +5,7 @@
5/evas_images 5/evas_images
6/evas_images2 6/evas_images2
7/evas_images3 7/evas_images3
8/evas_images4
8/evas_init_shutdown 9/evas_init_shutdown
9/evas_object_manipulation 10/evas_object_manipulation
10/evas_object_manipulation-eo 11/evas_object_manipulation-eo
diff --git a/src/examples/evas/Makefile.am b/src/examples/evas/Makefile.am
index fd8e552e00..b5846f3e24 100644
--- a/src/examples/evas/Makefile.am
+++ b/src/examples/evas/Makefile.am
@@ -139,6 +139,11 @@ evas_images3_SOURCES = evas-images3.c
139evas_images3_LDADD = $(ECORE_EVAS_COMMON_LDADD) 139evas_images3_LDADD = $(ECORE_EVAS_COMMON_LDADD)
140evas_images3_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS) 140evas_images3_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
141 141
142EXTRA_PROGRAMS += evas_images4
143evas_images4_SOURCES = evas-images4.c
144evas_images4_LDADD = $(ECORE_EVAS_COMMON_LDADD)
145evas_images4_CPPFLAGS = $(ECORE_EVAS_COMMON_CPPFLAGS)
146
142EXTRA_PROGRAMS += evas_text 147EXTRA_PROGRAMS += evas_text
143evas_text_SOURCES = evas-text.c 148evas_text_SOURCES = evas-text.c
144evas_text_LDADD = $(ECORE_EVAS_COMMON_LDADD) 149evas_text_LDADD = $(ECORE_EVAS_COMMON_LDADD)
@@ -300,6 +305,7 @@ evas-hints.c \
300evas-images.c \ 305evas-images.c \
301evas-images2.c \ 306evas-images2.c \
302evas-images3.c \ 307evas-images3.c \
308evas-images4.c \
303evas-init-shutdown.c \ 309evas-init-shutdown.c \
304evas-map-utils.c \ 310evas-map-utils.c \
305evas-map-aa.c \ 311evas-map-aa.c \
diff --git a/src/examples/evas/Makefile.examples b/src/examples/evas/Makefile.examples
index be10cd57cd..313be1b3b0 100644
--- a/src/examples/evas/Makefile.examples
+++ b/src/examples/evas/Makefile.examples
@@ -14,6 +14,7 @@ EXAMPLES= evas-aspect-hints \
14 evas-images \ 14 evas-images \
15 evas-images2 \ 15 evas-images2 \
16 evas-images3 \ 16 evas-images3 \
17 evas-images4 \
17 evas-init-shutdown \ 18 evas-init-shutdown \
18 evas-map-utils \ 19 evas-map-utils \
19 evas-object-manipulation \ 20 evas-object-manipulation \
diff --git a/src/examples/evas/evas-images4.c b/src/examples/evas/evas-images4.c
new file mode 100644
index 0000000000..391664ef94
--- /dev/null
+++ b/src/examples/evas/evas-images4.c
@@ -0,0 +1,180 @@
1/**
2 * Simple Evas example illustrating some image objects functions
3 *
4 * You'll need at least one engine built for it (excluding the buffer
5 * one) and the png image loader/saver also built. See stdout/stderr
6 * for output.
7 *
8 * @verbatim
9 * gcc -o evas-images4 evas-images4.c `pkg-config --libs --cflags evas ecore ecore-evas`
10 * @endverbatim
11 */
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#else
16#define PACKAGE_EXAMPLES_DIR "."
17#endif
18
19#include <Ecore.h>
20#include <Ecore_Evas.h>
21#include <stdio.h>
22#include <errno.h>
23
24#define WIDTH (320)
25#define HEIGHT (240)
26
27static const char *img_path = PACKAGE_EXAMPLES_DIR "/im1.png";
28static const char *commands = \
29 "commands are:\n"
30 "\tp - print image fill property\n"
31 "\t0 - rotate by 0\n"
32 "\t1 - rotate by 90\n"
33 "\t2 - rotate by 180\n"
34 "\t3 - rotate by 270\n"
35 "\t4 - flip horizontal\n"
36 "\t5 - flip vertical\n"
37 "\t6 - flip transpose\n"
38 "\t7 - flip transverse\n"
39 "\ts - save noise image to disk (/tmp dir)\n"
40 "\th - print help\n";
41
42const char *file_path = "/tmp/evas-images4-example.png";
43const char *quality_str = "quality=100";
44
45struct test_data
46{
47 Ecore_Evas *ee;
48 Evas *evas;
49 Evas_Object *bg, *img;
50};
51
52static struct test_data d = {0};
53
54static void
55_on_destroy(Ecore_Evas *ee EINA_UNUSED)
56{
57 ecore_main_loop_quit();
58}
59
60/* here just to keep our example's window size and background image's
61 * size in synchrony */
62static void
63_canvas_resize_cb(Ecore_Evas *ee)
64{
65 int w, h;
66
67 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
68 evas_object_resize(d.bg, w, h);
69}
70
71static void
72_on_keydown(void *data EINA_UNUSED,
73 Evas *evas EINA_UNUSED,
74 Evas_Object *o EINA_UNUSED,
75 void *einfo)
76{
77 Evas_Event_Key_Down *ev = einfo;
78
79 if (strcmp(ev->key, "h") == 0) /* print help */
80 {
81 fprintf(stdout, commands);
82 return;
83 }
84
85 if (strcmp(ev->key, "s") == 0) /* save noise image to disk */
86 {
87 if (!evas_object_image_save(d.img, file_path, NULL, quality_str))
88 fprintf(stderr, "Cannot save image to '%s' (flags '%s')\n",
89 file_path, quality_str);
90 else
91 fprintf(stdout, "Image saved to '%s' (flags '%s'), check it out with "
92 "an image viewer\n", file_path, quality_str);
93
94 return;
95 }
96
97 if (strcmp(ev->key, "p") == 0) /* print image size*/
98 {
99 Evas_Coord w, h;
100
101 evas_object_image_size_get(d.img, &w, &h);
102 fprintf(stdout, "Image has size set to: w=%d, h=%d\n", w, h);
103 return;
104 }
105
106 int key_val = ev->key[0] - '0';
107 if (key_val >= 0 && key_val <= 7)
108 {
109 evas_object_image_orient_set(d.img, key_val);
110 fprintf(stdout, "Set %i and got %i\n", key_val,
111 evas_object_image_orient_get(d.img));
112
113 return;
114 }
115}
116
117int
118main(void)
119{
120 int err;
121
122 if (!ecore_evas_init())
123 return EXIT_FAILURE;
124
125 /* this will give you a window with an Evas canvas under the first
126 * engine available */
127 d.ee = ecore_evas_new(NULL, 10, 10, WIDTH, HEIGHT, NULL);
128 if (!d.ee)
129 goto error;
130
131 ecore_evas_callback_destroy_set(d.ee, _on_destroy);
132 ecore_evas_callback_resize_set(d.ee, _canvas_resize_cb);
133 ecore_evas_show(d.ee);
134
135 /* the canvas pointer, de facto */
136 d.evas = ecore_evas_get(d.ee);
137
138 d.bg = evas_object_rectangle_add(d.evas);
139 evas_object_color_set(d.bg, 255, 255, 255, 255); /* white bg */
140 evas_object_move(d.bg, 0, 0); /* at canvas' origin */
141 evas_object_resize(d.bg, WIDTH, HEIGHT); /* covers full canvas */
142 evas_object_show(d.bg);
143
144 d.img = evas_object_image_add(d.evas);
145 evas_object_image_file_set(d.img, img_path, NULL);
146 err = evas_object_image_load_error_get(d.img);
147 if (err != EVAS_LOAD_ERROR_NONE)
148 {
149 fprintf(stderr, "could not load image '%s'. error string is \"%s\"\n",
150 img_path, evas_load_error_str(err));
151 }
152 else
153 {
154 fprintf(stdout,
155 "loaded image '%s' with succes! error string is \"%s\"\n",
156 img_path, evas_load_error_str(err));
157
158 evas_object_move(d.img, WIDTH / 2, HEIGHT / 2);
159 evas_object_image_fill_set(d.img, 0, 0, WIDTH / 2, HEIGHT / 2);
160 evas_object_resize(d.img, WIDTH / 2, HEIGHT / 2);
161 evas_object_show(d.img);
162
163 evas_object_focus_set(d.bg, EINA_TRUE);
164 evas_object_event_callback_add(
165 d.bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
166 }
167
168 fprintf(stdout, commands);
169 ecore_main_loop_begin();
170
171 ecore_evas_free(d.ee);
172 ecore_evas_shutdown();
173 return 0;
174
175error:
176 fprintf(stderr, "you got to have at least one evas engine built and linked"
177 " up to ecore-evas for this example to run properly.\n");
178 ecore_evas_shutdown();
179 return -1;
180}
diff --git a/src/lib/evas/Evas_Common.h b/src/lib/evas/Evas_Common.h
index e1ab7d6c42..27d8dfa199 100644
--- a/src/lib/evas/Evas_Common.h
+++ b/src/lib/evas/Evas_Common.h
@@ -631,6 +631,24 @@ typedef enum _Evas_Image_Content_Hint
631 EVAS_IMAGE_CONTENT_HINT_STATIC = 2 /**< The contents won't change over time */ 631 EVAS_IMAGE_CONTENT_HINT_STATIC = 2 /**< The contents won't change over time */
632} Evas_Image_Content_Hint; /**< How an image's data is to be treated by Evas, for optimization */ 632} Evas_Image_Content_Hint; /**< How an image's data is to be treated by Evas, for optimization */
633 633
634/**
635 * Possible orientation options for evas_object_image_orient_set().
636 * @brief Types of orientation available
637 * @since 1.14
638 */
639typedef enum _Evas_Image_Orient
640{
641 EVAS_IMAGE_ORIENT_NONE = 0, /**< no orientation change */
642 EVAS_IMAGE_ORIENT_0 = 0, /**< no orientation change */
643 EVAS_IMAGE_ORIENT_90 = 1, /**< orient 90 degrees clockwise*/
644 EVAS_IMAGE_ORIENT_180 = 2, /**< orient 180 degrees clockwise */
645 EVAS_IMAGE_ORIENT_270 = 3, /**< rotate 90 degrees counter-clockwise (i.e. 270 degrees clockwise)*/
646 EVAS_IMAGE_FLIP_HORIZONTAL = 4, /**< flip image horizontally */
647 EVAS_IMAGE_FLIP_VERTICAL = 5, /**< flip image vertically */
648 EVAS_IMAGE_FLIP_TRANSPOSE = 6, /**< flip image along the y = (width - x) line (bottom-left to top-right) */
649 EVAS_IMAGE_FLIP_TRANSVERSE = 7 /**< flip image along the y = x line (top-left to bottom-right) */
650} Evas_Image_Orient;
651
634typedef enum _Evas_Device_Class 652typedef enum _Evas_Device_Class
635{ 653{
636 EVAS_DEVICE_CLASS_NONE, /**< Not a device @since 1.8 */ 654 EVAS_DEVICE_CLASS_NONE, /**< Not a device @since 1.8 */
diff --git a/src/lib/evas/canvas/evas_image.eo b/src/lib/evas/canvas/evas_image.eo
index 23e563de6c..df97e32525 100644
--- a/src/lib/evas/canvas/evas_image.eo
+++ b/src/lib/evas/canvas/evas_image.eo
@@ -925,6 +925,34 @@ class Evas.Image (Evas.Object, Efl.File, Efl.Image)
925 int b; /*@ Bottom padding in pixels */ 925 int b; /*@ Bottom padding in pixels */
926 } 926 }
927 } 927 }
928 orient {
929 set {
930 /*@
931 Set the image orientation.
932
933 This function allows to rotate or flip the image.
934
935 @see evas_object_image_orient_get()
936 @see @ref Evas_Image_Orient
937
938 @since 1.14*/
939 }
940 get {
941 /*@
942 Get the image orientation.
943
944 @return The image orientation @ref Evas_Image_Orient
945
946 @see evas_object_image_orient_set()
947 @see @ref Evas_Image_Orient
948
949 @since 1.14*/
950 }
951 values {
952 Evas_Image_Orient orient; /*@ The image orientation @ref Evas_Image_Orient
953 Default is #EVAS_IMAGE_ORIENT_NONE. */
954 }
955 }
928 } 956 }
929 methods { 957 methods {
930 preload_begin { 958 preload_begin {
diff --git a/src/lib/evas/canvas/evas_object_image.c b/src/lib/evas/canvas/evas_object_image.c
index 9ec344a15d..cf4309778c 100644
--- a/src/lib/evas/canvas/evas_object_image.c
+++ b/src/lib/evas/canvas/evas_object_image.c
@@ -92,7 +92,8 @@ struct _Evas_Object_Image_State
92 int frame; 92 int frame;
93 int spread; 93 int spread;
94 94
95 Evas_Colorspace cspace; 95 Evas_Colorspace cspace;
96 Evas_Image_Orient orient;
96 97
97 Eina_Bool smooth_scale : 1; 98 Eina_Bool smooth_scale : 1;
98 Eina_Bool has_alpha :1; 99 Eina_Bool has_alpha :1;
@@ -237,6 +238,7 @@ static const Evas_Object_Image_State default_state = {
237 0, //frame 238 0, //frame
238 EVAS_TEXTURE_REPEAT, 239 EVAS_TEXTURE_REPEAT,
239 EVAS_COLORSPACE_ARGB8888, 240 EVAS_COLORSPACE_ARGB8888,
241 EVAS_IMAGE_ORIENT_NONE,
240 242
241 // flags 243 // flags
242 EINA_TRUE, EINA_FALSE, EINA_FALSE, EINA_FALSE, EINA_FALSE 244 EINA_TRUE, EINA_FALSE, EINA_FALSE, EINA_FALSE, EINA_FALSE
@@ -661,6 +663,61 @@ _evas_image_source_get(Eo *eo_obj EINA_UNUSED, Evas_Image_Data *o)
661 return o->cur->source; 663 return o->cur->source;
662} 664}
663 665
666EOLIAN static void
667_evas_image_orient_set(Eo *eo_obj, Evas_Image_Data *o, Evas_Image_Orient orient)
668{
669 Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS);
670 int iw, ih;
671
672 if (o->cur->orient == orient) return;
673
674 if ((o->preloading) && (o->engine_data))
675 {
676 o->preloading = EINA_FALSE;
677 ENFN->image_data_preload_cancel(ENDT, o->engine_data, eo_obj);
678 }
679
680 if(o->engine_data)
681 {
682 int stride = 0;
683
684 o->engine_data = ENFN->image_orient_set(ENDT, o->engine_data, orient);
685 if(o->engine_data)
686 {
687 EINA_COW_IMAGE_STATE_WRITE_BEGIN(o, state_write)
688 state_write->orient = orient;
689 EINA_COW_IMAGE_STATE_WRITE_END(o, state_write);
690
691 if (ENFN->image_stride_get)
692 ENFN->image_stride_get(ENDT, o->engine_data, &stride);
693 else
694 stride = o->cur->image.w * 4;
695 if (o->cur->image.stride != stride)
696 {
697 EINA_COW_IMAGE_STATE_WRITE_BEGIN(o, state_write)
698 state_write->image.stride = stride;
699 EINA_COW_IMAGE_STATE_WRITE_END(o, state_write);
700 }
701 o->written = EINA_TRUE;
702 }
703 ENFN->image_size_get(ENDT, o->engine_data, &iw, &ih);
704 EINA_COW_IMAGE_STATE_WRITE_BEGIN(o, state_write)
705 {
706 state_write->image.w = iw;
707 state_write->image.h = ih;
708 }
709 EINA_COW_IMAGE_STATE_WRITE_END(o, state_write);
710 }
711 o->changed = EINA_TRUE;
712 evas_object_change(eo_obj, obj);
713}
714
715EOLIAN static Evas_Image_Orient
716_evas_image_orient_get(Eo *eo_obj EINA_UNUSED, Evas_Image_Data *o)
717{
718 return o->cur->orient;
719}
720
664EAPI Eina_Bool 721EAPI Eina_Bool
665evas_object_image_source_unset(Evas_Object *eo_obj) 722evas_object_image_source_unset(Evas_Object *eo_obj)
666{ 723{
@@ -3588,6 +3645,11 @@ evas_object_image_render_pre(Evas_Object *eo_obj,
3588 evas_object_render_pre_prev_cur_add(&e->clip_changes, eo_obj, obj); 3645 evas_object_render_pre_prev_cur_add(&e->clip_changes, eo_obj, obj);
3589 if (!o->pixels->pixel_updates) goto done; 3646 if (!o->pixels->pixel_updates) goto done;
3590 } 3647 }
3648 if (o->cur->orient != o->prev->orient)
3649 {
3650 evas_object_render_pre_prev_cur_add(&e->clip_changes, eo_obj, obj);
3651 if (!o->pixels->pixel_updates) goto done;
3652 }
3591 3653
3592 } 3654 }
3593 if (((obj->cur->geometry.x != obj->prev->geometry.x) || 3655 if (((obj->cur->geometry.x != obj->prev->geometry.x) ||
diff --git a/src/lib/evas/include/evas_common_private.h b/src/lib/evas/include/evas_common_private.h
index 56dc039c53..0160af565b 100644
--- a/src/lib/evas/include/evas_common_private.h
+++ b/src/lib/evas/include/evas_common_private.h
@@ -596,6 +596,7 @@ struct _Image_Entry
596 Evas_Image_Load_Opts load_opts; 596 Evas_Image_Load_Opts load_opts;
597 Evas_Colorspace space; 597 Evas_Colorspace space;
598 const Evas_Colorspace *cspaces; // owned by the loader, live as long as the loader 598 const Evas_Colorspace *cspaces; // owned by the loader, live as long as the loader
599 Evas_Image_Orient orient;
599 600
600 unsigned int w; 601 unsigned int w;
601 unsigned int h; 602 unsigned int h;
diff --git a/src/lib/evas/include/evas_private.h b/src/lib/evas/include/evas_private.h
index 3cd94aa6f8..c07cfa31df 100644
--- a/src/lib/evas/include/evas_private.h
+++ b/src/lib/evas/include/evas_private.h
@@ -1217,6 +1217,8 @@ struct _Evas_Func
1217 void (*image_data_preload_cancel) (void *data, void *image, const Eo *target); 1217 void (*image_data_preload_cancel) (void *data, void *image, const Eo *target);
1218 void *(*image_alpha_set) (void *data, void *image, int has_alpha); 1218 void *(*image_alpha_set) (void *data, void *image, int has_alpha);
1219 int (*image_alpha_get) (void *data, void *image); 1219 int (*image_alpha_get) (void *data, void *image);
1220 void *(*image_orient_set) (void *data, void *image, Evas_Image_Orient orient);
1221 Evas_Image_Orient (*image_orient_get) (void *data, void *image);
1220 void *(*image_border_set) (void *data, void *image, int l, int r, int t, int b); 1222 void *(*image_border_set) (void *data, void *image, int l, int r, int t, int b);
1221 void (*image_border_get) (void *data, void *image, int *l, int *r, int *t, int *b); 1223 void (*image_border_get) (void *data, void *image, int *l, int *r, int *t, int *b);
1222 Eina_Bool (*image_draw) (void *data, void *context, void *surface, void *image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, int smooth, Eina_Bool do_async); 1224 Eina_Bool (*image_draw) (void *data, void *context, void *surface, void *image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h, int smooth, Eina_Bool do_async);
diff --git a/src/modules/evas/engines/software_generic/evas_engine.c b/src/modules/evas/engines/software_generic/evas_engine.c
index a3b15b4dcc..58cbb23a60 100644
--- a/src/modules/evas/engines/software_generic/evas_engine.c
+++ b/src/modules/evas/engines/software_generic/evas_engine.c
@@ -57,6 +57,9 @@
57#define OSMESA_MAX_WIDTH 0x24 /* new in 4.0 */ 57#define OSMESA_MAX_WIDTH 0x24 /* new in 4.0 */
58#define OSMESA_MAX_HEIGHT 0x25 /* new in 4.0 */ 58#define OSMESA_MAX_HEIGHT 0x25 /* new in 4.0 */
59 59
60/* Required for orient */
61#define TILE 32
62
60 63
61typedef void (*OSMESAproc)(); 64typedef void (*OSMESAproc)();
62typedef struct osmesa_context *OSMesaContext; 65typedef struct osmesa_context *OSMesaContext;
@@ -1291,6 +1294,342 @@ eng_image_data_put(void *data, void *image, DATA32 *image_data)
1291 return im; 1294 return im;
1292} 1295}
1293 1296
1297static void *
1298_image_flip_horizontal(void *data, Image_Entry *im)
1299{
1300 unsigned int *p1, *p2, tmp;
1301 DATA32 *image_data;
1302 int x, y, iw, ih;
1303 Image_Entry *im2;
1304
1305 iw = im->w;
1306 ih = im->h;
1307 image_data = evas_cache_image_pixels(im);
1308 for (y = 0; y < ih; y++)
1309 {
1310 p1 = image_data + (y * iw);
1311 p2 = image_data + ((y + 1) * iw) - 1;
1312 for (x = 0; x < (iw >> 1); x++)
1313 {
1314 tmp = *p1;
1315 *p1 = *p2;
1316 *p2 = tmp;
1317 p1++;
1318 p2--;
1319 }
1320 }
1321 im2 = eng_image_new_from_data(data, iw, ih, image_data,
1322 eng_image_alpha_get(data, im),
1323 eng_image_colorspace_get(data, im));
1324 return im2;
1325}
1326
1327static void *
1328_image_flip_vertical(void *data, Image_Entry *im)
1329{
1330 unsigned int *p1, *p2, tmp;
1331 DATA32 *image_data;
1332 int x, y, iw, ih;
1333 Image_Entry *im2;
1334
1335 iw = im->w;
1336 ih = im->h;
1337 image_data = evas_cache_image_pixels(im);
1338 for (y = 0; y < (ih >> 1); y++)
1339 {
1340 p1 = image_data + (y * iw);
1341 p2 = image_data + ((ih - 1 - y) * iw);
1342 for (x = 0; x < iw; x++)
1343 {
1344 tmp = *p1;
1345 *p1 = *p2;
1346 *p2 = tmp;
1347 p1++;
1348 p2++;
1349 }
1350 }
1351 im2 = eng_image_new_from_data(data, iw, ih, image_data,
1352 eng_image_alpha_get(data, im),
1353 eng_image_colorspace_get(data, im));
1354 return im2;
1355}
1356
1357static void *
1358_image_rotate_180(void *data, Image_Entry *im)
1359{
1360 unsigned int *p1, *p2, tmp;
1361 DATA32 *image_data;
1362 int x, hw, iw, ih;
1363 Image_Entry *im2;
1364
1365 iw = im->w;
1366 ih = im->h;
1367 image_data = evas_cache_image_pixels(im);
1368 if(!image_data) return im;
1369 hw = iw * ih;
1370 x = (hw / 2);
1371 p1 = image_data;
1372 p2 = image_data + hw - 1;
1373 for (; --x > 0; )
1374 {
1375 tmp = *p1;
1376 *p1 = *p2;
1377 *p2 = tmp;
1378 p1++;
1379 p2--;
1380 }
1381 im2 = eng_image_new_from_data(data, iw, ih, image_data,
1382 eng_image_alpha_get(data, im),
1383 eng_image_colorspace_get(data, im));
1384 return im2;
1385}
1386
1387# define GETDAT(neww, newh) \
1388 DATA32 *image_data, *image_data2; \
1389 int iw, ih, w, h; \
1390 Image_Entry *im2; \
1391 iw = im->w; \
1392 ih = im->h; \
1393 image_data = evas_cache_image_pixels(im); \
1394 if (!image_data) return im; \
1395 image_data2 = malloc(iw * ih * sizeof(int)); \
1396 if (!image_data2) { \
1397 return im; \
1398 } \
1399 memcpy(image_data2, image_data, iw * ih * sizeof(int)); \
1400 im = eng_image_new_from_data(data, iw, ih, image_data, \
1401 eng_image_alpha_get(data, im), \
1402 eng_image_colorspace_get(data, im)); \
1403 w = neww; h = newh; \
1404 image_data = evas_cache_image_pixels(im); \
1405
1406# define PUTDAT \
1407 im2 = eng_image_new_from_data(data, w, h, image_data, \
1408 eng_image_alpha_get(data, im), \
1409 eng_image_colorspace_get(data, im)); \
1410 im2 = eng_image_size_set(data, im2, w, h); \
1411 free(image_data2); \
1412 return im2; \
1413
1414static void *
1415_image_rotate_90(void *data, Image_Entry *im)
1416{
1417 GETDAT(ih, iw);
1418 int x, y, xx, yy, xx2, yy2;
1419 unsigned int *src, *dst;
1420
1421 for (y = 0; y < ih; y += TILE)
1422 {
1423 yy2 = y + TILE;
1424 if (yy2 > ih) yy2 = ih;
1425 for (x = 0; x < iw; x += TILE)
1426 {
1427 xx2 = x + TILE;
1428 if (xx2 > iw) xx2 = iw;
1429 for (yy = y; yy < yy2; yy++)
1430 {
1431 src = image_data2 + (yy * iw) + x;
1432 dst = image_data + (x * w) + (w - yy - 1);
1433 for (xx = x; xx < xx2; xx++)
1434 {
1435 *dst = *src;
1436 src++;
1437 dst += w;
1438 }
1439 }
1440 }
1441 }
1442 PUTDAT;
1443}
1444
1445static void *
1446_image_rotate_270(void *data, Image_Entry *im)
1447{
1448 GETDAT(ih, iw);
1449 int x, y, xx, yy, xx2, yy2;
1450 unsigned int *src, *dst;
1451
1452 for (y = 0; y < ih; y += TILE)
1453 {
1454 yy2 = y + TILE;
1455 if (yy2 > ih) yy2 = ih;
1456 for (x = 0; x < iw; x += TILE)
1457 {
1458 xx2 = x + TILE;
1459 if (xx2 > iw) xx2 = iw;
1460 for (yy = y; yy < yy2; yy++)
1461 {
1462 src = image_data2 + (yy * iw) + x;
1463 dst = image_data + ((h - x - 1) * w) + yy;
1464 for (xx = x; xx < xx2; xx++)
1465 {
1466 *dst = *src;
1467 src++;
1468 dst -= w;
1469 }
1470 }
1471 }
1472 }
1473 PUTDAT;
1474}
1475
1476static void *
1477_image_flip_transverse(void *data, Image_Entry *im)
1478{
1479 GETDAT(ih, iw);
1480 int x, y;
1481 unsigned int *src, *dst;
1482
1483 src = image_data2;
1484 for (y = 0; y < ih; y++)
1485 {
1486 dst = image_data + y;
1487 for (x = 0; x < iw; x++)
1488 {
1489 *dst = *src;
1490 src++;
1491 dst += w;
1492 }
1493 }
1494 PUTDAT;
1495}
1496
1497static void *
1498_image_flip_transpose(void *data, Image_Entry *im)
1499{
1500 GETDAT(ih, iw);
1501 int x, y;
1502 unsigned int *src, *dst;
1503
1504 src = image_data2 + (iw * ih) - 1;
1505 for (y = 0; y < ih; y++)
1506 {
1507 dst = image_data + y;
1508 for (x = 0; x < iw; x++)
1509 {
1510 *dst = *src;
1511 src--;
1512 dst += w;
1513 }
1514 }
1515 PUTDAT;
1516}
1517
1518#undef GETDAT
1519#undef PUTDAT
1520
1521static void *
1522eng_image_orient_set(void *data, void *image, Evas_Image_Orient orient)
1523{
1524 Image_Entry *im;
1525
1526 if (!image) return NULL;
1527 im = image;
1528 if (im->orient == orient) return im;
1529
1530 if ((im->orient >= EVAS_IMAGE_ORIENT_0) &&
1531 (im->orient <= EVAS_IMAGE_ORIENT_270) &&
1532 (orient >= EVAS_IMAGE_ORIENT_0) &&
1533 (orient <= EVAS_IMAGE_ORIENT_270))
1534 {
1535 // we are rotating from one anglee to another, so figure out delta
1536 // and apply that delta
1537 Evas_Image_Orient rot_delta = (4 + orient - im->orient) % 4;
1538 switch (rot_delta)
1539 {
1540 case EVAS_IMAGE_ORIENT_0:
1541 ERR("You shouldn't get this message, wrong orient value");
1542 break;
1543 case EVAS_IMAGE_ORIENT_90:
1544 im = _image_rotate_90(data, im);
1545 im->orient = orient;
1546 break;
1547 case EVAS_IMAGE_ORIENT_180:
1548 im = _image_rotate_180(data, im);
1549 im->orient = orient;
1550 break;
1551 case EVAS_IMAGE_ORIENT_270:
1552 im = _image_rotate_270(data, im);
1553 im->orient = orient;
1554 break;
1555 default:
1556 ERR("Wrong orient value");
1557 break;
1558 }
1559 }
1560 else if (((im->orient == EVAS_IMAGE_ORIENT_NONE) &&
1561 (orient == EVAS_IMAGE_FLIP_HORIZONTAL)) ||
1562 ((im->orient == EVAS_IMAGE_FLIP_HORIZONTAL) &&
1563 (orient == EVAS_IMAGE_ORIENT_NONE)))
1564 {
1565 // flip horizontally to get the new orientation
1566 im = _image_flip_horizontal(data, im);
1567 im->orient = orient;
1568 }
1569 else if (((im->orient == EVAS_IMAGE_ORIENT_NONE) &&
1570 (orient == EVAS_IMAGE_FLIP_VERTICAL)) ||
1571 ((im->orient == EVAS_IMAGE_FLIP_VERTICAL) &&
1572 (orient == EVAS_IMAGE_ORIENT_NONE)))
1573 {
1574 // flip vertically to get the new orientation
1575 im = _image_flip_vertical(data, im);
1576 im->orient = orient;
1577 }
1578 else
1579 {
1580 // generic solution - undo the previous orientation and then apply the
1581 // new one after that
1582 int i;
1583
1584 for (i = 0; i < 2; i++)
1585 {
1586 switch (im->orient)
1587 {
1588 case EVAS_IMAGE_ORIENT_0:
1589 break;
1590 case EVAS_IMAGE_ORIENT_90:
1591 if(i == 1) im = _image_rotate_90(data, im);
1592 else im = _image_rotate_270(data, im);
1593 break;
1594 case EVAS_IMAGE_ORIENT_180:
1595 im = _image_rotate_180(data, im);
1596 break;
1597 case EVAS_IMAGE_ORIENT_270:
1598 if(i == 1) im = _image_rotate_270(data, im);
1599 else im = _image_rotate_90(data, im);
1600 break;
1601 case EVAS_IMAGE_FLIP_HORIZONTAL:
1602 im = _image_flip_horizontal(data, im);
1603 break;
1604 case EVAS_IMAGE_FLIP_VERTICAL:
1605 im = _image_flip_vertical(data, im);
1606 break;
1607 case EVAS_IMAGE_FLIP_TRANSPOSE:
1608 im = _image_flip_transpose(data, im);
1609 break;
1610 case EVAS_IMAGE_FLIP_TRANSVERSE:
1611 im = _image_flip_transverse(data, im);
1612 break;
1613 default:
1614 ERR("Wrong orient value");
1615 break;
1616 }
1617 im->orient = orient;
1618 }
1619 }
1620 return im;
1621}
1622
1623static Evas_Image_Orient
1624eng_image_orient_get(void *data EINA_UNUSED, void *image)
1625{
1626 Image_Entry *im;
1627
1628 if (!image) return EVAS_IMAGE_ORIENT_NONE;
1629 im = image;
1630 return im->orient;
1631}
1632
1294static void 1633static void
1295eng_image_data_preload_request(void *data EINA_UNUSED, void *image, const Eo *target) 1634eng_image_data_preload_request(void *data EINA_UNUSED, void *image, const Eo *target)
1296{ 1635{
@@ -3158,6 +3497,8 @@ static Evas_Func func =
3158 eng_image_data_preload_cancel, 3497 eng_image_data_preload_cancel,
3159 eng_image_alpha_set, 3498 eng_image_alpha_set,
3160 eng_image_alpha_get, 3499 eng_image_alpha_get,
3500 eng_image_orient_set,
3501 eng_image_orient_get,
3161 eng_image_border_set, 3502 eng_image_border_set,
3162 eng_image_border_get, 3503 eng_image_border_get,
3163 eng_image_draw, 3504 eng_image_draw,