1 diff --git a/src/lib/Evas.h b/src/lib/Evas.h
2 index 18864ce..a56fd92 100644
5 @@ -478,6 +478,7 @@ extern "C" {
6 EAPI void evas_object_image_size_get (Evas_Object *obj, int *w, int *h);
7 EAPI int evas_object_image_stride_get (Evas_Object *obj);
8 EAPI int evas_object_image_load_error_get (Evas_Object *obj);
9 + EAPI void *evas_object_image_data_convert (Evas_Object *obj, Evas_Colorspace to_cspace);
10 EAPI void evas_object_image_data_set (Evas_Object *obj, void *data);
11 EAPI void *evas_object_image_data_get (Evas_Object *obj, Evas_Bool for_writing);
12 EAPI void evas_object_image_data_copy_set (Evas_Object *obj, void *data);
13 diff --git a/src/lib/canvas/evas_object_image.c b/src/lib/canvas/evas_object_image.c
14 index 6a8df55..92b0651 100644
15 --- a/src/lib/canvas/evas_object_image.c
16 +++ b/src/lib/canvas/evas_object_image.c
17 @@ -69,6 +69,8 @@ static int evas_object_image_is_opaque(Evas_Object *obj);
18 static int evas_object_image_was_opaque(Evas_Object *obj);
19 static int evas_object_image_is_inside(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
21 +static void *evas_object_image_data_convert_internal(Evas_Object_Image *o, void *data, Evas_Colorspace to_cspace);
23 static const Evas_Object_Func object_func =
25 /* methods (compulsory) */
26 @@ -708,6 +710,46 @@ evas_object_image_load_error_get(Evas_Object *obj)
30 + * Converts the raw image data of the given image object to the
31 + * specified colorspace.
33 + * Note that this function does not modify the raw image data.
34 + * If the requested colorspace is the same as the image colorspace
35 + * nothing is done and NULL is returned. You should use
36 + * evas_object_image_colorspace_get() to check the current image
39 + * See @ref evas_object_image_colorspace_get.
41 + * @param obj The given image object.
42 + * @param to_cspace The colorspace to which the image raw data will be converted.
43 + * @return data A newly allocated data in the format specified by to_cspace.
44 + * @ingroup Evas_Object_Image_Data
47 +evas_object_image_data_convert(Evas_Object *obj, Evas_Colorspace to_cspace)
49 + Evas_Object_Image *o;
52 + MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
55 + o = (Evas_Object_Image *)(obj->object_data);
56 + MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
59 + if (!o->engine_data) return NULL;
60 + if (!o->cur.cspace == to_cspace) return NULL;
62 + o->engine_data = obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
66 + return evas_object_image_data_convert_internal(o, data, to_cspace);
70 * Sets the raw image data of the given image object.
72 * Note that the raw data must be of the same size and colorspace
73 @@ -1126,11 +1168,22 @@ evas_object_image_save(Evas_Object *obj, const char *file, const char *key, cons
75 if (o->cur.has_alpha) im->flags |= RGBA_IMAGE_HAS_ALPHA;
77 - im->image->data = data;
78 - im->image->w = o->cur.image.w;
79 - im->image->h = o->cur.image.h;
80 - im->image->no_free = 1;
81 - ok = evas_common_save_image_to_file(im, file, key, quality, compress);
82 + if (o->cur.cspace == EVAS_COLORSPACE_ARGB8888)
83 + im->image->data = data;
85 + im->image->data = evas_object_image_data_convert_internal(o,
87 + EVAS_COLORSPACE_ARGB8888);
88 + if (im->image->data)
90 + im->image->w = o->cur.image.w;
91 + im->image->h = o->cur.image.h;
92 + im->image->no_free = 1;
93 + ok = evas_common_save_image_to_file(im, file, key, quality, compress);
95 + if (o->cur.cspace != EVAS_COLORSPACE_ARGB8888)
96 + free(im->image->data);
99 evas_cache_image_drop(im);
101 @@ -2376,3 +2429,36 @@ evas_object_image_is_inside(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
107 +evas_object_image_data_convert_internal(Evas_Object_Image *o, void *data, Evas_Colorspace to_cspace)
114 + switch (o->cur.cspace)
116 + case EVAS_COLORSPACE_ARGB8888:
117 + out = evas_common_convert_argb8888_to(data,
120 + o->cur.image.stride,
124 + case EVAS_COLORSPACE_RGB565_A5P:
125 + out = evas_common_convert_rgb565_a5p_to(data,
128 + o->cur.image.stride,
138 diff --git a/src/lib/engines/common/Makefile.am b/src/lib/engines/common/Makefile.am
139 index c15675b..3d5fd7c 100644
140 --- a/src/lib/engines/common/Makefile.am
141 +++ b/src/lib/engines/common/Makefile.am
142 @@ -21,6 +21,7 @@ evas_op_mul_main_.c \
145 evas_convert_color.c \
146 +evas_convert_colorspace.c \
147 evas_convert_gry_1.c \
148 evas_convert_gry_4.c \
149 evas_convert_gry_8.c \
150 diff --git a/src/lib/engines/common/evas_convert_colorspace.c b/src/lib/engines/common/evas_convert_colorspace.c
152 index 0000000..287bd2e
154 +++ b/src/lib/engines/common/evas_convert_colorspace.c
156 +#include "evas_common.h"
158 +#define CONVERT_RGB_565_TO_RGB_888(s) \
159 + (((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7)) | \
160 + ((((s) << 5) & 0xfc00) | (((s) >> 1) & 0x300)) | \
161 + ((((s) << 8) & 0xf80000) | (((s) << 3) & 0x70000)))
163 +#define CONVERT_A5P_TO_A8(s) \
164 + ((((s) << 3) & 0xf8) | (((s) >> 2) & 0x7))
166 +static inline void *
167 +evas_common_convert_argb8888_to_rgb565_a5p(void *data, int w, int h, int stride, Evas_Bool has_alpha)
171 +static inline void *
172 +evas_common_convert_rgb565_a5p_to_argb8888(void *data, int w, int h, int stride, Evas_Bool has_alpha)
179 + end = src + (stride * h);
180 + ret = malloc(w * h * sizeof(DATA32));
188 + for (; src < end; src++, alpha++, dst++)
189 + *dst = (CONVERT_A5P_TO_A8(*alpha) << 24) |
190 + CONVERT_RGB_565_TO_RGB_888(*src);
194 + for (; src < end; src++, dst++)
195 + *dst = CONVERT_RGB_565_TO_RGB_888(*src);
201 +evas_common_convert_argb8888_to(void *data, int w, int h, int stride, Evas_Bool has_alpha, Evas_Colorspace cspace)
205 + case EVAS_COLORSPACE_RGB565_A5P:
206 + return evas_common_convert_argb8888_to_rgb565_a5p(data, w, h, stride, has_alpha);
214 +evas_common_convert_rgb565_a5p_to(void *data, int w, int h, int stride, Evas_Bool has_alpha, Evas_Colorspace cspace)
218 + case EVAS_COLORSPACE_ARGB8888:
219 + return evas_common_convert_rgb565_a5p_to_argb8888(data, w, h, stride, has_alpha);
225 diff --git a/src/lib/include/evas_common.h b/src/lib/include/evas_common.h
226 index a61ed6d..4c724b1 100644
227 --- a/src/lib/include/evas_common.h
228 +++ b/src/lib/include/evas_common.h
229 @@ -998,6 +998,9 @@ EAPI void evas_common_convert_color_rgb_to_hsv (int r, int g
230 EAPI void evas_common_convert_color_hsv_to_rgb_int (int h, int s, int v, int *r, int *g, int *b);
231 EAPI void evas_common_convert_color_rgb_to_hsv_int (int r, int g, int b, int *h, int *s, int *v);
233 +EAPI void *evas_common_convert_argb8888_to (void *data, int w, int h, int stride, Evas_Bool has_alpha, Evas_Colorspace cspace);
234 +EAPI void *evas_common_convert_rgb565_a5p_to (void *data, int w, int h, int stride, Evas_Bool has_alpha, Evas_Colorspace cspace);
237 EAPI void evas_common_scale_init (void);