2 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
5 #include "evas_common.h"
6 #include "evas_private.h"
7 #include "../engines/common/evas_convert_color.h"
8 #include "../engines/common/evas_convert_colorspace.h"
9 #include "../engines/common/evas_convert_yuv.h"
11 /* private magic number for image objects */
12 static const char o_type[] = "image";
14 /* private struct for rectangle object internal data */
15 typedef struct _Evas_Object_Image Evas_Object_Image;
17 struct _Evas_Object_Image
22 Evas_Coord_Rectangle fill;
35 unsigned char smooth_scale : 1;
36 unsigned char has_alpha :1;
39 int pixels_checked_out;
41 Evas_List *pixel_updates;
44 unsigned char scale_down_by;
50 void (*get_pixels) (void *data, Evas_Object *o);
51 void *get_pixels_data;
56 unsigned char changed : 1;
57 unsigned char dirty_pixels : 1;
60 /* private methods for image objects */
61 static void evas_object_image_unload(Evas_Object *obj);
62 static void evas_object_image_load(Evas_Object *obj);
63 static Evas_Coord evas_object_image_figure_x_fill(Evas_Object *obj, Evas_Coord start, Evas_Coord size, Evas_Coord *size_ret);
64 static Evas_Coord evas_object_image_figure_y_fill(Evas_Object *obj, Evas_Coord start, Evas_Coord size, Evas_Coord *size_ret);
66 static void evas_object_image_init(Evas_Object *obj);
67 static void *evas_object_image_new(void);
68 static void evas_object_image_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y);
69 static void evas_object_image_free(Evas_Object *obj);
70 static void evas_object_image_render_pre(Evas_Object *obj);
71 static void evas_object_image_render_post(Evas_Object *obj);
73 static int evas_object_image_is_opaque(Evas_Object *obj);
74 static int evas_object_image_was_opaque(Evas_Object *obj);
75 static int evas_object_image_is_inside(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
77 static void *evas_object_image_data_convert_internal(Evas_Object_Image *o, void *data, Evas_Colorspace to_cspace);
79 static const Evas_Object_Func object_func =
81 /* methods (compulsory) */
82 evas_object_image_free,
83 evas_object_image_render,
84 evas_object_image_render_pre,
85 evas_object_image_render_post,
86 /* these are optional. NULL = nothing */
91 evas_object_image_is_opaque,
92 evas_object_image_was_opaque,
93 evas_object_image_is_inside,
99 * @defgroup Evas_Object_Image Image Object Functions
101 * Functions used to create and manipulate image objects.
103 * Note - Image objects may return or accept "image data" in multiple formats.
104 * This is based on the colorspace of an object. Here is a rundown on formats:
106 * EVAS_COLORSPACE_ARGB8888:
108 * This pixel format is a linear block of pixels, starting at the top-left row
109 * by row until the bottom right of the image or pixel region. All pixels are
110 * 32-bit unsigned int's with the high-byte being alpha and the low byte being
111 * blue in the format ARGB. Alpha may or may not be used by evas depending on
112 * the alpha flag of the image, but if not used, should be set to 0xff anyway.
114 * This colorspace uses premultiplied alpha. That means that R, G and B cannot
115 * exceed A in value. The conversion from non-premultiplied colorspace is:
117 * R = (r * a) / 255; G = (g * a) / 255; B = (b * a) / 255;
119 * So 50% transparent blue will be: 0x80000080. This will not be "dark" - just
120 * 50% transparent. Values are 0 == black, 255 == solid or full red, green or
123 * EVAS_COLORSPACE_YCBCR422P601_PL:
125 * This is a pointer-list indirected set of YUV (YCbCr) pixel data. This means
126 * that the data returned or set is not actual pixel data, but pointers TO
127 * lines of pixel data. The list of pointers will first be N rows of pointers
128 * to the Y plane - pointing to the first pixel at the start of each row in
129 * the Y plane. N is the height of the image data in pixels. Each pixel in the
130 * Y, U and V planes is 1 byte exactly, packed. The next N / 2 pointers will
131 * point to rows in the U plane, and the next N / 2 pointers will point to
132 * the V plane rows. U and V planes are half the horizontal and vertical
133 * resolution of the U plane.
135 * Row order is top to bottom and row pixels are stored left to right.
137 * There is a limitation that these images MUST be a multiple of 2 pixels in
138 * size horizontally or vertically. This is due to the U and V planes being
139 * half resolution. Also note that this assumes the itu601 YUV colorspace
140 * specification. This is defined for standard television and mpeg streams.
141 * HDTV may use the itu709 specification.
143 * Values are 0 to 255, indicating full or no signal in that plane
146 * EVAS_COLORSPACE_YCBCR422P709_PL:
148 * Not implemented yet.
150 * EVAS_COLORSPACE_RGB565_A5P:
152 * In the process of being implemented in 1 engine only. This may change.
154 * This is a pointer to image data for 16-bit half-word pixel data in 16bpp
155 * RGB 565 format (5 bits red, 6 bits green, 5 bits blue), with the high-byte
156 * containing red and the low byte containing blue, per pixel. This data is
157 * packed row by row from the top-left to the bottom right.
159 * If the image has an alpha channel enabled there will be an extra alpha plane
160 * after the color pixel plane. If not, then this data will not exist and
161 * should not be accessed in any way. This plane is a set of pixels with 1
162 * byte per pixel defining the alpha values of all pixels in the image from
163 * the top-left to the bottom right of the image, row by row. Even though
164 * the values of the alpha pixels can be 0 to 255, only values 0 through to 32
165 * are used, 32 being solid and 0 being transparent.
167 * RGB values can be 0 to 31 for red and blue and 0 to 63 for green, with 0
168 * being black and 31 or 63 being full red, green or blue respectively. This
169 * colorspace is also pre-multiplied like EVAS_COLORSPACE_ARGB8888 so:
171 * R = (r * a) / 32; G = (g * a) / 32; B = (b * a) / 32;
175 * Creates a new image object on the given evas.
177 * @param e The given evas.
178 * @return The created image object.
179 * @ingroup Evas_Object_Image
182 evas_object_image_add(Evas *e)
185 Evas_Object_Image *o;
187 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
190 obj = evas_object_new();
191 evas_object_image_init(obj);
192 evas_object_inject(obj, e);
193 o = (Evas_Object_Image *)(obj->object_data);
194 o->cur.cspace = obj->layer->evas->engine.func->image_colorspace_get(obj->layer->evas->engine.data.output,
200 * @defgroup Evas_Object_Image_File_Group Image Object File Functions
202 * Functions that write to or retrieve images from files.
206 * Sets the filename and key of the given image object.
208 * If the file supports multiple data stored in it as eet,
209 * you can specify the key to be used as the index of the
210 * image in this file.
212 * @param obj The given image object.
213 * @param file The image filename.
214 * @param key The image key in file, or NULL.
215 * @ingroup Evas_Object_Image_File_Group
218 evas_object_image_file_set(Evas_Object *obj, const char *file, const char *key)
220 Evas_Object_Image *o;
221 Evas_Image_Load_Opts lo;
223 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
226 o = (Evas_Object_Image *)(obj->object_data);
227 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
230 if ((o->cur.file) && (file) && (!strcmp(o->cur.file, file)))
232 if ((!o->cur.key) && (!key))
234 if ((o->cur.key) && (key) && (!strcmp(o->cur.key, key)))
237 if (o->cur.file) evas_stringshare_del(o->cur.file);
238 if (o->cur.key) evas_stringshare_del(o->cur.key);
239 if (file) o->cur.file = evas_stringshare_add(file);
240 else o->cur.file = NULL;
241 if (key) o->cur.key = evas_stringshare_add(key);
242 else o->cur.key = NULL;
246 obj->layer->evas->engine.func->image_free(obj->layer->evas->engine.data.output,
248 o->load_error = EVAS_LOAD_ERROR_NONE;
249 lo.scale_down_by = o->load_opts.scale_down_by;
250 lo.dpi = o->load_opts.dpi;
251 lo.w = o->load_opts.w;
252 lo.h = o->load_opts.h;
253 o->engine_data = obj->layer->evas->engine.func->image_load(obj->layer->evas->engine.data.output,
263 obj->layer->evas->engine.func->image_size_get(obj->layer->evas->engine.data.output,
264 o->engine_data, &w, &h);
265 if (obj->layer->evas->engine.func->image_stride_get)
266 obj->layer->evas->engine.func->image_stride_get(obj->layer->evas->engine.data.output,
267 o->engine_data, &stride);
270 o->cur.has_alpha = obj->layer->evas->engine.func->image_alpha_get(obj->layer->evas->engine.data.output,
272 o->cur.cspace = obj->layer->evas->engine.func->image_colorspace_get(obj->layer->evas->engine.data.output,
276 o->cur.image.stride = stride;
280 o->load_error = EVAS_LOAD_ERROR_GENERIC;
281 o->cur.has_alpha = 1;
282 o->cur.cspace = EVAS_COLORSPACE_ARGB8888;
285 o->cur.image.stride = 0;
288 evas_object_change(obj);
292 * Retrieves the filename and key of the given image object.
294 * @param obj The given image object.
295 * @param file Location to store the image filename, or NULL.
296 * @param key Location to store the image key, or NULL.
297 * @ingroup Evas_Object_Image_File_Group
300 evas_object_image_file_get(const Evas_Object *obj, const char **file, const char **key)
302 Evas_Object_Image *o;
304 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
305 if (file) *file = NULL;
306 if (key) *key = NULL;
309 o = (Evas_Object_Image *)(obj->object_data);
310 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
311 if (file) *file = NULL;
312 if (key) *key = NULL;
315 if (file) *file = o->cur.file;
316 if (key) *key = o->cur.key;
320 * @defgroup Evas_Object_Image_Border_Group Image Object Border Functions
322 * Functions that adjust the unscaled image border of image objects.
326 * Sets how much of each border of the given image object is not
329 * When rendering, the image may be scaled to fit the size of the
330 * image object. This function sets what area around the border of
331 * the image is not to be scaled. This sort of function is useful for
332 * widget theming, where, for example, buttons may be of varying
333 * sizes, but the border size must remain constant.
335 * The units used for @p l, @p r, @p t and @p b are output units.
337 * @param obj The given image object.
338 * @param l Distance of the left border that is not to be stretched.
339 * @param r Distance of the right border that is not to be stretched.
340 * @param t Distance of the top border that is not to be stretched.
341 * @param b Distance of the bottom border that is not to be stretched.
342 * @ingroup Evas_Object_Image_Border_Group
345 evas_object_image_border_set(Evas_Object *obj, int l, int r, int t, int b)
347 Evas_Object_Image *o;
349 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
352 o = (Evas_Object_Image *)(obj->object_data);
353 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
360 if ((o->cur.border.l == l) &&
361 (o->cur.border.r == r) &&
362 (o->cur.border.t == t) &&
363 (o->cur.border.b == b)) return;
369 evas_object_change(obj);
373 * Retrieves how much of each border of the given image object is not to
376 * See @ref evas_object_image_border_set for more details.
378 * @param obj The given image object.
379 * @param l Location to store the left border width in, or NULL.
380 * @param r Location to store the right border width in, or NULL.
381 * @param t Location to store the top border width in, or NULL.
382 * @param b Location to store the bottom border width in, or NULL.
383 * @ingroup Evas_Object_Image_Border_Group
386 evas_object_image_border_get(const Evas_Object *obj, int *l, int *r, int *t, int *b)
388 Evas_Object_Image *o;
390 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
397 o = (Evas_Object_Image *)(obj->object_data);
398 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
405 if (l) *l = o->cur.border.l;
406 if (r) *r = o->cur.border.r;
407 if (t) *t = o->cur.border.t;
408 if (b) *b = o->cur.border.b;
412 * @defgroup Evas_Object_Image_Fill_Group Image Object Fill Rectangle Functions
414 * Functions that deal with what areas of the image object are to be
415 * tiled with the given image.
419 * Sets if the center part of the given image object (not the border)
422 * When rendering, the image may be scaled to fit the size of the
423 * image object. This function sets if the center part of the scaled image
424 * is to be drawn or left completely blank. Very useful for frames and
427 * @param obj The given image object.
428 * @param fill Whether the center should be drawn.
429 * @ingroup Evas_Object_Image_Fill_Group
432 evas_object_image_border_center_fill_set(Evas_Object *obj, Evas_Bool fill)
434 Evas_Object_Image *o;
436 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
439 o = (Evas_Object_Image *)(obj->object_data);
440 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
443 if (((o->cur.border.fill) && (fill)) ||
444 ((!o->cur.border.fill) && (!fill)))
446 o->cur.border.fill = fill;
448 evas_object_change(obj);
452 * Retrieves if the center of the given image object is to be drawn
455 * See @ref evas_object_image_fill_set for more details.
457 * @param obj The given image object.
458 * @return If the center is to be drawn or not.
459 * @ingroup Evas_Object_Image_Fill_Group
462 evas_object_image_border_center_fill_get(const Evas_Object *obj)
464 Evas_Object_Image *o;
466 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
469 o = (Evas_Object_Image *)(obj->object_data);
470 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
473 return o->cur.border.fill;
477 * Sets the rectangle of the given image object that the image will
480 * Note that the image will be tiled around this one rectangle. To have
481 * only one copy of the image drawn, @p x and @p y must be 0 and @p w
482 * and @p h need to be the width and height of the image object
485 * The default values for the fill parameters is @p x = 0, @p y = 0,
486 * @p w = 32 and @p h = 32.
488 * @param obj The given image object.
489 * @param x The X coordinate for the top left corner of the image.
490 * @param y The Y coordinate for the top left corner of the image.
491 * @param w The width of the image.
492 * @param h The height of the image.
493 * @ingroup Evas_Object_Image_Fill_Group
496 evas_object_image_fill_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
498 Evas_Object_Image *o;
502 if (w == 0.0) return;
503 if (h == 0.0) return;
504 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
507 o = (Evas_Object_Image *)(obj->object_data);
508 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
511 if ((o->cur.fill.x == x) &&
512 (o->cur.fill.y == y) &&
513 (o->cur.fill.w == w) &&
514 (o->cur.fill.h == h)) return;
520 evas_object_change(obj);
524 * Retrieves the dimensions of the rectangle of the given image object
525 * that the image will be drawn to.
527 * See @ref evas_object_image_fill_set for more details.
529 * @param obj The given image object.
530 * @param x Location to store the X coordinate for the top left corner of the image in, or NULL.
531 * @param y Location to store the Y coordinate for the top left corner of the image in, or NULL.
532 * @param w Location to store the width of the image in, or NULL.
533 * @param h Location to store the height of the image in, or NULL.
534 * @ingroup Evas_Object_Image_Fill_Group
537 evas_object_image_fill_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
539 Evas_Object_Image *o;
541 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
548 o = (Evas_Object_Image *)(obj->object_data);
549 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
556 if (x) *x = o->cur.fill.x;
557 if (y) *y = o->cur.fill.y;
558 if (w) *w = o->cur.fill.w;
559 if (h) *h = o->cur.fill.h;
563 * @defgroup Evas_Object_Image_Size Image Object Image Size Functions
565 * Functions that change the size of the image used by an image object.
569 * Sets the size of the given image object.
571 * This function will scale down or crop the image so that it is
572 * treated as if it were at the given size. If the size given is
573 * smaller than the image, it will be cropped. If the size given is
574 * larger, then the image will be treated as if it were in the upper
575 * left hand corner of a larger image that is otherwise transparent.
577 * @param obj The given image object.
578 * @param w The new width of the image.
579 * @param h The new height of the image.
580 * @ingroup Evas_Object_Image_Size
583 evas_object_image_size_set(Evas_Object *obj, int w, int h)
585 Evas_Object_Image *o;
588 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
591 o = (Evas_Object_Image *)(obj->object_data);
592 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
597 if (w > 32768) return;
598 if (h > 32768) return;
599 if ((w == o->cur.image.w) &&
600 (h == o->cur.image.h)) return;
604 o->engine_data = obj->layer->evas->engine.func->image_size_set(obj->layer->evas->engine.data.output,
608 o->engine_data = obj->layer->evas->engine.func->image_new_from_copied_data
609 (obj->layer->evas->engine.data.output, w, h, NULL, o->cur.has_alpha,
612 if (obj->layer->evas->engine.func->image_stride_get)
613 obj->layer->evas->engine.func->image_stride_get(obj->layer->evas->engine.data.output,
614 o->engine_data, &stride);
617 o->cur.image.stride = stride;
619 /* FIXME - in engine call above
621 o->engine_data = obj->layer->evas->engine.func->image_alpha_set(obj->layer->evas->engine.data.output,
625 EVAS_OBJECT_IMAGE_FREE_FILE_AND_KEY(o);
627 evas_object_change(obj);
631 * Retrieves the size of the given image object.
633 * See @ref evas_object_image_size_set for more details.
635 * @param obj The given image object.
636 * @param w Location to store the width of the image in, or NULL.
637 * @param h Location to store the height of the image in, or NULL.
638 * @ingroup Evas_Object_Image_Size
641 evas_object_image_size_get(const Evas_Object *obj, int *w, int *h)
643 Evas_Object_Image *o;
645 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
650 o = (Evas_Object_Image *)(obj->object_data);
651 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
656 if (w) *w = o->cur.image.w;
657 if (h) *h = o->cur.image.h;
661 * Retrieves the row stride of the given image object,
663 * The row stride is the number of units between the start of a
664 * row and the start of the next row.
666 * @param obj The given image object.
667 * @return The stride of the image.
668 * @ingroup Evas_Object_Image_Size
671 evas_object_image_stride_get(const Evas_Object *obj)
673 Evas_Object_Image *o;
675 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
678 o = (Evas_Object_Image *)(obj->object_data);
679 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
682 return o->cur.image.stride;
686 * Retrieves a number representing any error that occurred during the last
687 * load of the given image object.
689 * @param obj The given image object.
690 * @return A value giving the last error that occurred. It should be one of
691 * the @c EVAS_LOAD_ERROR_* values. @c EVAS_LOAD_ERROR_NONE is
692 * returned if there was no error.
693 * @ingroup Evas_Object_Image
696 evas_object_image_load_error_get(const Evas_Object *obj)
698 Evas_Object_Image *o;
700 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
703 o = (Evas_Object_Image *)(obj->object_data);
704 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
707 return o->load_error;
711 * @defgroup Evas_Object_Image_Data Image Object Image Data Functions
713 * Functions that allow you to access or modify the image pixel data of an
718 * Converts the raw image data of the given image object to the
719 * specified colorspace.
721 * Note that this function does not modify the raw image data.
722 * If the requested colorspace is the same as the image colorspace
723 * nothing is done and NULL is returned. You should use
724 * evas_object_image_colorspace_get() to check the current image
727 * See @ref evas_object_image_colorspace_get.
729 * @param obj The given image object.
730 * @param to_cspace The colorspace to which the image raw data will be converted.
731 * @return data A newly allocated data in the format specified by to_cspace.
732 * @ingroup Evas_Object_Image_Data
735 evas_object_image_data_convert(Evas_Object *obj, Evas_Colorspace to_cspace)
737 Evas_Object_Image *o;
740 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
743 o = (Evas_Object_Image *)(obj->object_data);
744 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
747 if (!o->engine_data) return NULL;
748 if (!o->cur.cspace == to_cspace) return NULL;
750 o->engine_data = obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
754 return evas_object_image_data_convert_internal(o, data, to_cspace);
758 * Sets the raw image data of the given image object.
760 * Note that the raw data must be of the same size and colorspace
761 * of the image. If data is NULL the current image data will be freed.
763 * @param obj The given image object.
764 * @param data The raw data, or NULL.
765 * @ingroup Evas_Object_Image_Data
768 evas_object_image_data_set(Evas_Object *obj, void *data)
770 Evas_Object_Image *o;
773 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
776 o = (Evas_Object_Image *)(obj->object_data);
777 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
780 p_data = o->engine_data;
784 o->engine_data = obj->layer->evas->engine.func->image_data_put(obj->layer->evas->engine.data.output,
788 o->engine_data = obj->layer->evas->engine.func->image_new_from_data(obj->layer->evas->engine.data.output,
798 obj->layer->evas->engine.func->image_free(obj->layer->evas->engine.data.output,
800 o->load_error = EVAS_LOAD_ERROR_NONE;
803 o->cur.image.stride = 0;
804 o->engine_data = NULL;
806 /* FIXME - in engine call above
808 o->engine_data = obj->layer->evas->engine.func->image_alpha_set(obj->layer->evas->engine.data.output,
812 if (o->pixels_checked_out > 0) o->pixels_checked_out--;
813 if (p_data != o->engine_data)
815 EVAS_OBJECT_IMAGE_FREE_FILE_AND_KEY(o);
816 o->pixels_checked_out = 0;
819 evas_object_change(obj);
823 * Get a pointer to the raw image data of the given image object.
825 * This function returns a pointer to an image object's internal pixel buffer,
826 * for reading only or read/write. If you request it for writing, the image
827 * will be marked dirty so that it gets redrawn at the next update.
829 * This is best suited when you want to modify an existing image,
830 * without changing its dimensions.
832 * @param obj The given image object.
833 * @param for_writing Whether the data being retrieved will be modified.
834 * @return The raw image data.
835 * @ingroup Evas_Object_Image_Data
838 evas_object_image_data_get(const Evas_Object *obj, Evas_Bool for_writing)
840 Evas_Object_Image *o;
843 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
846 o = (Evas_Object_Image *)(obj->object_data);
847 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
850 if (!o->engine_data) return NULL;
852 o->engine_data = obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
856 o->pixels_checked_out++;
859 EVAS_OBJECT_IMAGE_FREE_FILE_AND_KEY(o);
866 * Replaces the raw image data of the given image object.
868 * This function lets the application replace an image object's internal pixel
869 * buffer with a user-allocated one. For best results, you should generally
870 * first call evas_object_image_size_set() with the width and height for the
873 * This call is best suited for when you will be using image data with
874 * different dimensions than the existing image data, if any. If you only need
875 * to modify the existing image in some fashion, then using
876 * evas_object_image_data_get() is probably what you are after.
878 * Note that the caller is responsible for freeing the buffer when finished
879 * with it, as user-set image data will not be automatically freed when the
880 * image object is deleted.
882 * See @ref evas_object_image_data_get for more details.
884 * @param obj The given image object.
885 * @param data The raw data.
886 * @ingroup Evas_Object_Image_Data
889 evas_object_image_data_copy_set(Evas_Object *obj, void *data)
891 Evas_Object_Image *o;
894 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
897 o = (Evas_Object_Image *)(obj->object_data);
898 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
901 if ((o->cur.image.w <= 0) ||
902 (o->cur.image.h <= 0)) return;
904 obj->layer->evas->engine.func->image_free(obj->layer->evas->engine.data.output,
906 o->engine_data = obj->layer->evas->engine.func->image_new_from_copied_data(obj->layer->evas->engine.data.output,
913 o->engine_data = obj->layer->evas->engine.func->image_alpha_set(obj->layer->evas->engine.data.output,
916 o->pixels_checked_out = 0;
917 EVAS_OBJECT_IMAGE_FREE_FILE_AND_KEY(o);
921 * Mark a sub-region of the given image object to be redrawn.
923 * This function schedules a particular rectangular region of an image
924 * object to be updated (redrawn) at the next render.
926 * @param obj The given image object.
927 * @param x X-offset of the region to be updated.
928 * @param y Y-offset of the region to be updated.
929 * @param w Width of the region to be updated.
930 * @param h Height of the region to be updated.
931 * @ingroup Evas_Object_Image_Data
934 evas_object_image_data_update_add(Evas_Object *obj, int x, int y, int w, int h)
936 Evas_Object_Image *o;
939 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
942 o = (Evas_Object_Image *)(obj->object_data);
943 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
946 RECTS_CLIP_TO_RECT(x, y, w, h, 0, 0, o->cur.image.w, o->cur.image.h);
947 if ((w <= 0) || (h <= 0)) return;
948 NEW_RECT(r, x, y, w, h);
949 if (r) o->pixel_updates = evas_list_append(o->pixel_updates, r);
951 evas_object_change(obj);
955 * @defgroup Evas_Object_Image_Alpha Image Object Image Alpha Functions
957 * Functions that change the alpha of an image object.
961 * Enable or disable alpha channel of the given image object.
963 * This function sets a flag on an image object indicating whether or not to
964 * use alpha channel data. A value of 1 indicates to use alpha channel data,
965 * and 0 indicates to ignore any alpha channel data. Note that this has
966 * nothing to do with an object's color as manipulated by
967 * evas_object_color_set().
969 * @param obj The given image object.
970 * @param has_alpha Whether to use alpha channel data or not.
971 * @ingroup Evas_Object_Image_Alpha
974 evas_object_image_alpha_set(Evas_Object *obj, Evas_Bool has_alpha)
976 Evas_Object_Image *o;
978 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
981 o = (Evas_Object_Image *)(obj->object_data);
982 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
985 if (((has_alpha) && (o->cur.has_alpha)) ||
986 ((!has_alpha) && (!o->cur.has_alpha)))
988 o->cur.has_alpha = has_alpha;
990 o->engine_data = obj->layer->evas->engine.func->image_alpha_set(obj->layer->evas->engine.data.output,
993 evas_object_image_data_update_add(obj, 0, 0, o->cur.image.w, o->cur.image.h);
994 EVAS_OBJECT_IMAGE_FREE_FILE_AND_KEY(o);
999 * Retrieves the alpha channel setting of the given image object.
1001 * This function returns 1 if the image object's alpha channel is being used,
1004 * See @ref evas_object_image_alpha_set for more details.
1006 * @param obj The given image object.
1007 * @return Whether the alpha channel data is being used.
1008 * @ingroup Evas_Object_Image_Alpha
1011 evas_object_image_alpha_get(const Evas_Object *obj)
1013 Evas_Object_Image *o;
1015 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1018 o = (Evas_Object_Image *)(obj->object_data);
1019 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1022 return o->cur.has_alpha;
1026 * @defgroup Evas_Object_Image_Scale Image Object Image Scaling Functions
1028 * Functions that change the scaling quality of an image object.
1032 * Sets whether to use of high-quality image scaling algorithm
1033 * of the given image object.
1035 * When enabled, a higher quality image scaling algorithm is used when scaling
1036 * images to sizes other than the source image. This gives better results but
1037 * is more computationally expensive.
1039 * @param obj The given image object.
1040 * @param smooth_scale Whether to use smooth scale or not.
1041 * @ingroup Evas_Object_Image_Scale
1044 evas_object_image_smooth_scale_set(Evas_Object *obj, Evas_Bool smooth_scale)
1046 Evas_Object_Image *o;
1048 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1051 o = (Evas_Object_Image *)(obj->object_data);
1052 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1055 if (((smooth_scale) && (o->cur.smooth_scale)) ||
1056 ((!smooth_scale) && (!o->cur.smooth_scale)))
1058 o->cur.smooth_scale = smooth_scale;
1062 * Retrieves whether the given image object is using use a high-quality
1063 * image scaling algorithm.
1065 * See @ref evas_object_image_smooth_scale_set for more details.
1067 * @param obj The given image object.
1068 * @return Whether smooth scale is being used.
1069 * @ingroup Evas_Object_Image_Scale
1072 evas_object_image_smooth_scale_get(const Evas_Object *obj)
1074 Evas_Object_Image *o;
1076 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1079 o = (Evas_Object_Image *)(obj->object_data);
1080 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1083 return o->cur.smooth_scale;
1089 * FIXME: To be fixed.
1093 evas_object_image_reload(Evas_Object *obj)
1095 Evas_Object_Image *o;
1097 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1100 o = (Evas_Object_Image *)(obj->object_data);
1101 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1104 if ((!o->cur.file) ||
1105 (o->pixels_checked_out > 0)) return;
1107 o->engine_data = obj->layer->evas->engine.func->image_dirty_region(obj->layer->evas->engine.data.output, o->engine_data, 0, 0, o->cur.image.w, o->cur.image.h);
1108 evas_object_image_unload(obj);
1109 evas_object_image_load(obj);
1111 evas_object_change(obj);
1115 * Save the given image object to a file.
1117 * Note that you should pass the filename extension when saving.
1118 * If the file supports multiple data stored in it as eet,
1119 * you can specify the key to be used as the index of the
1120 * image in this file.
1122 * You can specify some flags when saving the image.
1123 * Currently acceptable flags are quality and compress.
1124 * Eg.: "quality=100 compress=9"
1126 * @param obj The given image object.
1127 * @param file The filename to be used to save the image.
1128 * @param key The image key in file, or NULL.
1129 * @param flags String containing the flags to be used.
1130 * @ingroup Evas_Object_Image
1133 evas_object_image_save(const Evas_Object *obj, const char *file, const char *key, const char *flags)
1135 Evas_Object_Image *o;
1136 DATA32 *data = NULL;
1137 int quality = 80, compress = 9, ok = 0;
1140 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1143 o = (Evas_Object_Image *)(obj->object_data);
1144 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1148 if (!o->engine_data) return 0;
1149 o->engine_data = obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
1158 tflags = alloca(strlen(flags) + 1);
1159 strcpy(tflags, flags);
1163 pp = strchr(p, ' ');
1165 sscanf(p, "quality=%i", &quality);
1166 sscanf(p, "compress=%i", &compress);
1171 im = (RGBA_Image*) evas_cache_image_data(evas_common_image_cache_get(),
1176 EVAS_COLORSPACE_ARGB8888);
1179 if (o->cur.cspace == EVAS_COLORSPACE_ARGB8888)
1180 im->image.data = data;
1182 im->image.data = evas_object_image_data_convert_internal(o,
1184 EVAS_COLORSPACE_ARGB8888);
1187 ok = evas_common_save_image_to_file(im, file, key, quality, compress);
1189 if (o->cur.cspace != EVAS_COLORSPACE_ARGB8888)
1190 free(im->image.data);
1193 evas_cache_image_drop(&im->cache_entry);
1201 * FIXME: To be fixed.
1205 evas_object_image_pixels_import(Evas_Object *obj, Evas_Pixel_Import_Source *pixels)
1207 Evas_Object_Image *o;
1209 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1212 o = (Evas_Object_Image *)(obj->object_data);
1213 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1217 if ((pixels->w != o->cur.image.w) || (pixels->h != o->cur.image.h)) return 0;
1218 switch (pixels->format)
1221 case EVAS_PIXEL_FORMAT_ARGB32:
1225 DATA32 *image_pixels = NULL;
1228 obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
1232 /* FIXME: need to actualyl support this */
1233 /* memcpy(image_pixels, pixels->rows, o->cur.image.w * o->cur.image.h * 4);*/
1236 obj->layer->evas->engine.func->image_data_put(obj->layer->evas->engine.data.output,
1241 obj->layer->evas->engine.func->image_alpha_set(obj->layer->evas->engine.data.output,
1245 evas_object_change(obj);
1250 #ifdef BUILD_CONVERT_YUV
1251 case EVAS_PIXEL_FORMAT_YUV420P_601:
1255 DATA32 *image_pixels = NULL;
1258 obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
1263 evas_common_convert_yuv_420p_601_rgba((DATA8 **) pixels->rows,
1264 (DATA8 *) image_pixels,
1269 obj->layer->evas->engine.func->image_data_put(obj->layer->evas->engine.data.output,
1274 obj->layer->evas->engine.func->image_alpha_set(obj->layer->evas->engine.data.output,
1278 evas_object_change(obj);
1293 * FIXME: To be fixed.
1297 evas_object_image_pixels_get_callback_set(Evas_Object *obj, void (*func) (void *data, Evas_Object *o), void *data)
1299 Evas_Object_Image *o;
1301 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1304 o = (Evas_Object_Image *)(obj->object_data);
1305 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1308 o->func.get_pixels = func;
1309 o->func.get_pixels_data = data;
1313 * Mark whether the given image object is dirty (needs to be redrawn).
1315 * @param obj The given image object.
1316 * @param dirty Whether the image is dirty.
1317 * @ingroup Evas_Object_Image
1320 evas_object_image_pixels_dirty_set(Evas_Object *obj, Evas_Bool dirty)
1322 Evas_Object_Image *o;
1324 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1327 o = (Evas_Object_Image *)(obj->object_data);
1328 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1331 if (dirty) o->dirty_pixels = 1;
1332 else o->dirty_pixels = 0;
1334 evas_object_change(obj);
1338 * Retrieves whether the given image object is dirty (needs to be redrawn).
1340 * @param obj The given image object.
1341 * @return Whether the image is dirty.
1342 * @ingroup Evas_Object_Image
1345 evas_object_image_pixels_dirty_get(const Evas_Object *obj)
1347 Evas_Object_Image *o;
1349 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1352 o = (Evas_Object_Image *)(obj->object_data);
1353 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1356 if (o->dirty_pixels) return 1;
1363 * FIXME: To be fixed.
1367 evas_object_image_load_dpi_set(Evas_Object *obj, double dpi)
1369 Evas_Object_Image *o;
1371 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1374 o = (Evas_Object_Image *)(obj->object_data);
1375 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1378 o->load_opts.dpi = dpi;
1381 evas_object_image_unload(obj);
1382 evas_object_image_load(obj);
1384 evas_object_change(obj);
1391 * FIXME: To be fixed.
1395 evas_object_image_load_dpi_get(const Evas_Object *obj)
1397 Evas_Object_Image *o;
1399 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1402 o = (Evas_Object_Image *)(obj->object_data);
1403 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1406 return o->load_opts.dpi;
1412 * FIXME: To be fixed.
1416 evas_object_image_load_size_set(Evas_Object *obj, int w, int h)
1418 Evas_Object_Image *o;
1420 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1423 o = (Evas_Object_Image *)(obj->object_data);
1424 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1431 evas_object_image_unload(obj);
1432 evas_object_image_load(obj);
1434 evas_object_change(obj);
1439 evas_object_image_load_size_get(const Evas_Object *obj, int *w, int *h)
1441 Evas_Object_Image *o;
1443 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1446 o = (Evas_Object_Image *)(obj->object_data);
1447 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1450 if (w) *w = o->load_opts.w;
1451 if (h) *h = o->load_opts.h;
1457 * FIXME: To be fixed.
1461 evas_object_image_load_scale_down_set(Evas_Object *obj, int scale_down)
1463 Evas_Object_Image *o;
1465 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1468 o = (Evas_Object_Image *)(obj->object_data);
1469 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1472 o->load_opts.scale_down_by = scale_down;
1475 evas_object_image_unload(obj);
1476 evas_object_image_load(obj);
1478 evas_object_change(obj);
1485 * FIXME: To be fixed.
1489 evas_object_image_load_scale_down_get(const Evas_Object *obj)
1491 Evas_Object_Image *o;
1493 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1496 o = (Evas_Object_Image *)(obj->object_data);
1497 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1500 return o->load_opts.scale_down_by;
1506 * FIXME: To be fixed.
1510 evas_object_image_colorspace_set(Evas_Object *obj, Evas_Colorspace cspace)
1512 Evas_Object_Image *o;
1514 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1517 o = (Evas_Object_Image *)(obj->object_data);
1518 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1521 o->cur.cspace = cspace;
1523 obj->layer->evas->engine.func->image_colorspace_set(obj->layer->evas->engine.data.output,
1531 * FIXME: To be fixed.
1534 EAPI Evas_Colorspace
1535 evas_object_image_colorspace_get(const Evas_Object *obj)
1537 Evas_Object_Image *o;
1539 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1540 return EVAS_COLORSPACE_ARGB8888;
1542 o = (Evas_Object_Image *)(obj->object_data);
1543 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1544 return EVAS_COLORSPACE_ARGB8888;
1546 return o->cur.cspace;
1552 * FIXME: To be fixed.
1556 evas_object_image_native_surface_set(Evas_Object *obj, Evas_Native_Surface *surf)
1558 Evas_Object_Image *o;
1560 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1563 o = (Evas_Object_Image *)(obj->object_data);
1564 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1567 obj->layer->evas->engine.func->image_native_set(obj->layer->evas->engine.data.output,
1575 * FIXME: To be fixed.
1578 EAPI Evas_Native_Surface *
1579 evas_object_image_native_surface_get(const Evas_Object *obj)
1581 Evas_Object_Image *o;
1583 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1586 o = (Evas_Object_Image *)(obj->object_data);
1587 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1590 return obj->layer->evas->engine.func->image_native_get(obj->layer->evas->engine.data.output,
1597 * FIXME: To be fixed.
1601 evas_image_cache_flush(Evas *e)
1603 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
1607 e->engine.func->image_cache_flush(e->engine.data.output);
1613 * FIXME: To be fixed.
1617 evas_image_cache_reload(Evas *e)
1619 Evas_Object_List *l;
1621 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
1625 evas_image_cache_flush(e);
1626 for (l = (Evas_Object_List *)e->layers; l; l = l->next)
1629 Evas_Object_List *l2;
1631 layer = (Evas_Layer *)l;
1632 for (l2 = (Evas_Object_List *)layer->objects; l2; l2 = l2->next)
1635 Evas_Object_Image *o;
1637 obj = (Evas_Object *)l2;
1638 o = (Evas_Object_Image *)(obj->object_data);
1639 if (o->magic == MAGIC_OBJ_IMAGE)
1641 evas_object_image_unload(obj);
1645 evas_image_cache_flush(e);
1646 for (l = (Evas_Object_List *)e->layers; l; l = l->next)
1649 Evas_Object_List *l2;
1651 layer = (Evas_Layer *)l;
1652 for (l2 = (Evas_Object_List *)layer->objects; l2; l2 = l2->next)
1655 Evas_Object_Image *o;
1657 obj = (Evas_Object *)l2;
1658 o = (Evas_Object_Image *)(obj->object_data);
1659 if (o->magic == MAGIC_OBJ_IMAGE)
1661 evas_object_image_load(obj);
1663 evas_object_change(obj);
1667 evas_image_cache_flush(e);
1673 * FIXME: To be fixed.
1677 evas_image_cache_set(Evas *e, int size)
1679 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
1683 if (size < 0) size = 0;
1684 e->engine.func->image_cache_set(e->engine.data.output, size);
1690 * FIXME: To be fixed.
1694 evas_image_cache_get(const Evas *e)
1696 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
1700 return e->engine.func->image_cache_get(e->engine.data.output);
1703 /* all nice and private */
1706 evas_object_image_unload(Evas_Object *obj)
1708 Evas_Object_Image *o;
1710 o = (Evas_Object_Image *)(obj->object_data);
1712 if ((!o->cur.file) ||
1713 (o->pixels_checked_out > 0)) return;
1715 o->engine_data = obj->layer->evas->engine.func->image_dirty_region(obj->layer->evas->engine.data.output,
1718 o->cur.image.w, o->cur.image.h);
1720 obj->layer->evas->engine.func->image_free(obj->layer->evas->engine.data.output,
1722 o->engine_data = NULL;
1723 o->load_error = EVAS_LOAD_ERROR_NONE;
1724 o->cur.has_alpha = 1;
1725 o->cur.cspace = EVAS_COLORSPACE_ARGB8888;
1728 o->cur.image.stride = 0;
1732 evas_object_image_load(Evas_Object *obj)
1734 Evas_Object_Image *o;
1735 Evas_Image_Load_Opts lo;
1737 o = (Evas_Object_Image *)(obj->object_data);
1738 if (o->engine_data) return;
1740 lo.scale_down_by = o->load_opts.scale_down_by;
1741 lo.dpi = o->load_opts.dpi;
1742 lo.w = o->load_opts.w;
1743 lo.h = o->load_opts.h;
1744 o->engine_data = obj->layer->evas->engine.func->image_load(obj->layer->evas->engine.data.output,
1754 obj->layer->evas->engine.func->image_size_get(obj->layer->evas->engine.data.output,
1755 o->engine_data, &w, &h);
1756 if (obj->layer->evas->engine.func->image_stride_get)
1757 obj->layer->evas->engine.func->image_stride_get(obj->layer->evas->engine.data.output,
1758 o->engine_data, &stride);
1761 o->cur.has_alpha = obj->layer->evas->engine.func->image_alpha_get(obj->layer->evas->engine.data.output,
1763 o->cur.cspace = obj->layer->evas->engine.func->image_colorspace_get(obj->layer->evas->engine.data.output,
1767 o->cur.image.stride = stride;
1771 o->load_error = EVAS_LOAD_ERROR_GENERIC;
1776 evas_object_image_figure_x_fill(Evas_Object *obj, Evas_Coord start, Evas_Coord size, Evas_Coord *size_ret)
1780 w = ((size * obj->layer->evas->output.w) /
1781 (Evas_Coord)obj->layer->evas->viewport.w);
1782 if (size <= 0) size = 1;
1785 while (start - size > 0) start -= size;
1789 while (start < 0) start += size;
1791 start = ((start * obj->layer->evas->output.w) /
1792 (Evas_Coord)obj->layer->evas->viewport.w);
1798 evas_object_image_figure_y_fill(Evas_Object *obj, Evas_Coord start, Evas_Coord size, Evas_Coord *size_ret)
1802 h = ((size * obj->layer->evas->output.h) /
1803 (Evas_Coord)obj->layer->evas->viewport.h);
1804 if (size <= 0) size = 1;
1807 while (start - size > 0) start -= size;
1811 while (start < 0) start += size;
1813 start = ((start * obj->layer->evas->output.h) /
1814 (Evas_Coord)obj->layer->evas->viewport.h);
1820 evas_object_image_init(Evas_Object *obj)
1822 /* alloc image ob, setup methods and default values */
1823 obj->object_data = evas_object_image_new();
1824 /* set up default settings for this kind of object */
1825 obj->cur.color.r = 255;
1826 obj->cur.color.g = 255;
1827 obj->cur.color.b = 255;
1828 obj->cur.color.a = 255;
1829 obj->cur.geometry.x = 0;
1830 obj->cur.geometry.y = 0;
1831 obj->cur.geometry.w = 0;
1832 obj->cur.geometry.h = 0;
1834 obj->cur.anti_alias = 0;
1835 obj->cur.render_op = EVAS_RENDER_BLEND;
1836 /* set up object-specific settings */
1837 obj->prev = obj->cur;
1838 /* set up methods (compulsory) */
1839 obj->func = &object_func;
1844 evas_object_image_new(void)
1846 Evas_Object_Image *o;
1848 /* alloc obj private data */
1849 o = calloc(1, sizeof(Evas_Object_Image));
1850 o->magic = MAGIC_OBJ_IMAGE;
1853 o->cur.smooth_scale = 1;
1854 o->cur.border.fill = 1;
1855 o->cur.cspace = EVAS_COLORSPACE_ARGB8888;
1861 evas_object_image_free(Evas_Object *obj)
1863 Evas_Object_Image *o;
1865 /* frees private object data. very simple here */
1866 o = (Evas_Object_Image *)(obj->object_data);
1867 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1871 if (o->cur.file) evas_stringshare_del(o->cur.file);
1872 if (o->cur.key) evas_stringshare_del(o->cur.key);
1874 obj->layer->evas->engine.func->image_free(obj->layer->evas->engine.data.output,
1876 o->engine_data = NULL;
1878 while (o->pixel_updates)
1882 r = (Evas_Rectangle *)o->pixel_updates->data;
1883 o->pixel_updates = evas_list_remove(o->pixel_updates, r);
1890 evas_object_image_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y)
1892 Evas_Object_Image *o;
1894 /* render object to surface with context, and offset by x,y */
1895 o = (Evas_Object_Image *)(obj->object_data);
1896 obj->layer->evas->engine.func->context_color_set(output,
1898 255, 255, 255, 255);
1900 if ((obj->cur.cache.clip.r == 255) &&
1901 (obj->cur.cache.clip.g == 255) &&
1902 (obj->cur.cache.clip.b == 255) &&
1903 (obj->cur.cache.clip.a == 255))
1905 obj->layer->evas->engine.func->context_multiplier_unset(output,
1909 obj->layer->evas->engine.func->context_multiplier_set(output,
1911 obj->cur.cache.clip.r,
1912 obj->cur.cache.clip.g,
1913 obj->cur.cache.clip.b,
1914 obj->cur.cache.clip.a);
1916 obj->layer->evas->engine.func->context_render_op_set(output, context,
1917 obj->cur.render_op);
1920 Evas_Coord idw, idh, idx, idy;
1923 if (o->dirty_pixels)
1925 if (o->func.get_pixels)
1927 o->func.get_pixels(o->func.get_pixels_data, obj);
1928 o->engine_data = obj->layer->evas->engine.func->image_dirty_region(obj->layer->evas->engine.data.output, o->engine_data, 0, 0, o->cur.image.w, o->cur.image.h);
1930 o->dirty_pixels = 0;
1932 o->engine_data = obj->layer->evas->engine.func->image_border_set(output, o->engine_data,
1933 o->cur.border.l, o->cur.border.r,
1934 o->cur.border.t, o->cur.border.b);
1935 idx = evas_object_image_figure_x_fill(obj, o->cur.fill.x, o->cur.fill.w, &idw);
1936 idy = evas_object_image_figure_y_fill(obj, o->cur.fill.y, o->cur.fill.h, &idh);
1937 if (idw < 1.0) idw = 1.0;
1938 if (idh < 1.0) idh = 1.0;
1939 if (idx > 0.0) idx -= idw;
1940 if (idy > 0.0) idy -= idh;
1941 while ((int)idx < obj->cur.geometry.w)
1948 if ((o->cur.fill.w == obj->cur.geometry.w) &&
1949 (o->cur.fill.x == 0.0))
1952 iw = obj->cur.geometry.w;
1955 iw = ((int)(idx + idw)) - ix;
1956 while ((int)idy < obj->cur.geometry.h)
1961 if ((o->cur.fill.h == obj->cur.geometry.h) &&
1962 (o->cur.fill.y == 0.0))
1964 ih = obj->cur.geometry.h;
1968 ih = ((int)(idy + idh)) - iy;
1969 if ((o->cur.border.l == 0) &&
1970 (o->cur.border.r == 0) &&
1971 (o->cur.border.t == 0) &&
1972 (o->cur.border.b == 0) &&
1973 (o->cur.border.fill != 0))
1974 obj->layer->evas->engine.func->image_draw(output,
1981 obj->cur.geometry.x + ix + x,
1982 obj->cur.geometry.y + iy + y,
1984 o->cur.smooth_scale);
1987 int inx, iny, inw, inh, outx, outy, outw, outh;
1989 int imw, imh, ox, oy;
1991 ox = obj->cur.geometry.x + ix + x;
1992 oy = obj->cur.geometry.y + iy + y;
1993 imw = o->cur.image.w;
1994 imh = o->cur.image.h;
1995 bl = o->cur.border.l;
1996 br = o->cur.border.r;
1997 bt = o->cur.border.t;
1998 bb = o->cur.border.b;
2004 if ((bl + br) > imw)
2014 if ((bt + bb) > imh)
2022 outx = ox; outy = oy;
2023 outw = bl; outh = bt;
2024 obj->layer->evas->engine.func->image_draw(output, context, surface, o->engine_data, inx, iny, inw, inh, outx, outy, outw, outh, o->cur.smooth_scale);
2026 inw = imw - bl - br; inh = bt;
2027 outx = ox + bl; outy = oy;
2028 outw = iw - bl - br; outh = bt;
2029 obj->layer->evas->engine.func->image_draw(output, context, surface, o->engine_data, inx, iny, inw, inh, outx, outy, outw, outh, o->cur.smooth_scale);
2030 inx = imw - br; iny = 0;
2032 outx = ox + iw - br; outy = oy;
2033 outw = br; outh = bt;
2034 obj->layer->evas->engine.func->image_draw(output, context, surface, o->engine_data, inx, iny, inw, inh, outx, outy, outw, outh, o->cur.smooth_scale);
2037 inw = bl; inh = imh - bt - bb;
2038 outx = ox; outy = oy + bt;
2039 outw = bl; outh = ih - bt - bb;
2040 obj->layer->evas->engine.func->image_draw(output, context, surface, o->engine_data, inx, iny, inw, inh, outx, outy, outw, outh, o->cur.smooth_scale);
2041 if (o->cur.border.fill)
2044 inw = imw - bl - br; inh = imh - bt - bb;
2045 outx = ox + bl; outy = oy + bt;
2046 outw = iw - bl - br; outh = ih - bt - bb;
2047 obj->layer->evas->engine.func->image_draw(output, context, surface, o->engine_data, inx, iny, inw, inh, outx, outy, outw, outh, o->cur.smooth_scale);
2049 inx = imw - br; iny = bt;
2050 inw = br; inh = imh - bt - bb;
2051 outx = ox + iw - br; outy = oy + bt;
2052 outw = br; outh = ih - bt - bb;
2053 obj->layer->evas->engine.func->image_draw(output, context, surface, o->engine_data, inx, iny, inw, inh, outx, outy, outw, outh, o->cur.smooth_scale);
2055 inx = 0; iny = imh - bb;
2057 outx = ox; outy = oy + ih - bb;
2058 outw = bl; outh = bb;
2059 obj->layer->evas->engine.func->image_draw(output, context, surface, o->engine_data, inx, iny, inw, inh, outx, outy, outw, outh, o->cur.smooth_scale);
2060 inx = bl; iny = imh - bb;
2061 inw = imw - bl - br; inh = bb;
2062 outx = ox + bl; outy = oy + ih - bb;
2063 outw = iw - bl - br; outh = bb;
2064 obj->layer->evas->engine.func->image_draw(output, context, surface, o->engine_data, inx, iny, inw, inh, outx, outy, outw, outh, o->cur.smooth_scale);
2065 inx = imw - br; iny = imh - bb;
2067 outx = ox + iw - br; outy = oy + ih - bb;
2068 outw = br; outh = bb;
2069 obj->layer->evas->engine.func->image_draw(output, context, surface, o->engine_data, inx, iny, inw, inh, outx, outy, outw, outh, o->cur.smooth_scale);
2072 if (dobreak_h) break;
2076 if (dobreak_w) break;
2082 evas_object_image_render_pre(Evas_Object *obj)
2084 Evas_Rectangles rects = { 0, 0, NULL };
2085 Evas_Object_Image *o;
2088 /* dont pre-render the obj twice! */
2089 if (obj->pre_render_done) return;
2090 obj->pre_render_done = 1;
2091 /* pre-render phase. this does anything an object needs to do just before */
2092 /* rendering. this could mean loading the image data, retrieving it from */
2093 /* elsewhere, decoding video etc. */
2094 /* then when this is done the object needs to figure if it changed and */
2095 /* if so what and where and add the appropriate redraw rectangles */
2096 o = (Evas_Object_Image *)(obj->object_data);
2097 /* if someone is clipping this obj - go calculate the clipper */
2098 if (obj->cur.clipper)
2100 if (obj->cur.cache.clip.dirty)
2101 evas_object_clip_recalc(obj->cur.clipper);
2102 obj->cur.clipper->func->render_pre(obj->cur.clipper);
2104 /* now figure what changed and add draw rects */
2105 /* if it just became visible or invisible */
2106 is_v = evas_object_is_visible(obj);
2107 was_v = evas_object_was_visible(obj);
2110 evas_object_render_pre_visible_change(&rects, obj, is_v, was_v);
2111 if (!o->pixel_updates) goto done;
2113 /* it's not visible - we accounted for it appearing or not so just abort */
2114 if (!is_v) goto done;
2115 /* clipper changed this is in addition to anything else for obj */
2116 evas_object_render_pre_clipper_change(&rects, obj);
2117 /* if we restacked (layer or just within a layer) and don't clip anyone */
2120 evas_object_render_pre_prev_cur_add(&rects, obj);
2121 if (!o->pixel_updates) goto done;
2123 /* if it changed color */
2124 if ((obj->cur.color.r != obj->prev.color.r) ||
2125 (obj->cur.color.g != obj->prev.color.g) ||
2126 (obj->cur.color.b != obj->prev.color.b) ||
2127 (obj->cur.color.a != obj->prev.color.a))
2129 evas_object_render_pre_prev_cur_add(&rects, obj);
2130 if (!o->pixel_updates) goto done;
2132 /* if it changed render op */
2133 if (obj->cur.render_op != obj->prev.render_op)
2135 evas_object_render_pre_prev_cur_add(&rects, obj);
2136 if (!o->pixel_updates) goto done;
2138 /* if it changed anti_alias */
2139 if (obj->cur.anti_alias != obj->prev.anti_alias)
2141 evas_object_render_pre_prev_cur_add(&rects, obj);
2142 if (!o->pixel_updates) goto done;
2146 if (((o->cur.file) && (!o->prev.file)) ||
2147 ((!o->cur.file) && (o->prev.file)) ||
2148 ((o->cur.key) && (!o->prev.key)) ||
2149 ((!o->cur.key) && (o->prev.key))
2152 evas_object_render_pre_prev_cur_add(&rects, obj);
2153 if (!o->pixel_updates) goto done;
2155 if ((o->cur.image.w != o->prev.image.w) ||
2156 (o->cur.image.h != o->prev.image.h) ||
2157 (o->cur.has_alpha != o->prev.has_alpha) ||
2158 (o->cur.cspace != o->prev.cspace) ||
2159 (o->cur.smooth_scale != o->prev.smooth_scale))
2161 evas_object_render_pre_prev_cur_add(&rects, obj);
2162 if (!o->pixel_updates) goto done;
2164 if ((o->cur.border.l != o->prev.border.l) ||
2165 (o->cur.border.r != o->prev.border.r) ||
2166 (o->cur.border.t != o->prev.border.t) ||
2167 (o->cur.border.b != o->prev.border.b))
2169 evas_object_render_pre_prev_cur_add(&rects, obj);
2170 if (!o->pixel_updates) goto done;
2172 if (o->dirty_pixels)
2174 evas_object_render_pre_prev_cur_add(&rects, obj);
2175 if (!o->pixel_updates) goto done;
2178 /* if it changed geometry - and obviously not visibility or color */
2179 /* caluclate differences since we have a constant color fill */
2180 /* we really only need to update the differences */
2181 if (((obj->cur.geometry.x != obj->prev.geometry.x) ||
2182 (obj->cur.geometry.y != obj->prev.geometry.y) ||
2183 (obj->cur.geometry.w != obj->prev.geometry.w) ||
2184 (obj->cur.geometry.h != obj->prev.geometry.h)) &&
2185 (o->cur.fill.w == o->prev.fill.w) &&
2186 (o->cur.fill.h == o->prev.fill.h) &&
2187 ((o->cur.fill.x + obj->cur.geometry.x) == (o->prev.fill.x + obj->prev.geometry.x)) &&
2188 ((o->cur.fill.y + obj->cur.geometry.y) == (o->prev.fill.y + obj->prev.geometry.y)) &&
2192 evas_rects_return_difference_rects(&rects,
2193 obj->cur.geometry.x,
2194 obj->cur.geometry.y,
2195 obj->cur.geometry.w,
2196 obj->cur.geometry.h,
2197 obj->prev.geometry.x,
2198 obj->prev.geometry.y,
2199 obj->prev.geometry.w,
2200 obj->prev.geometry.h);
2201 if (!o->pixel_updates) goto done;
2203 if (((obj->cur.geometry.x != obj->prev.geometry.x) ||
2204 (obj->cur.geometry.y != obj->prev.geometry.y) ||
2205 (obj->cur.geometry.w != obj->prev.geometry.w) ||
2206 (obj->cur.geometry.h != obj->prev.geometry.h))
2209 evas_object_render_pre_prev_cur_add(&rects, obj);
2210 if (!o->pixel_updates) goto done;
2214 if ((o->cur.fill.x != o->prev.fill.x) ||
2215 (o->cur.fill.y != o->prev.fill.y) ||
2216 (o->cur.fill.w != o->prev.fill.w) ||
2217 (o->cur.fill.h != o->prev.fill.h))
2219 evas_object_render_pre_prev_cur_add(&rects, obj);
2220 if (!o->pixel_updates) goto done;
2222 if ((o->cur.border.l == 0) &&
2223 (o->cur.border.r == 0) &&
2224 (o->cur.border.t == 0) &&
2225 (o->cur.border.b == 0))
2227 while (o->pixel_updates)
2230 Evas_Coord idw, idh, idx, idy;
2233 rr = o->pixel_updates->data;
2234 o->pixel_updates = evas_list_remove(o->pixel_updates, rr);
2235 obj->layer->evas->engine.func->image_dirty_region(obj->layer->evas->engine.data.output, o->engine_data, rr->x, rr->y, rr->w, rr->h);
2237 idx = evas_object_image_figure_x_fill(obj, o->cur.fill.x, o->cur.fill.w, &idw);
2238 idy = evas_object_image_figure_y_fill(obj, o->cur.fill.y, o->cur.fill.h, &idh);
2240 if (idw < 1) idw = 1;
2241 if (idh < 1) idh = 1;
2242 if (idx > 0) idx -= idw;
2243 if (idy > 0) idy -= idh;
2244 while (idx < obj->cur.geometry.w)
2250 w = ((int)(idx + idw)) - x;
2251 while (idy < obj->cur.geometry.h)
2256 h = ((int)(idy + idh)) - y;
2258 r.x = ((rr->x - 1) * w) / o->cur.image.w;
2259 r.y = ((rr->y - 1) * h) / o->cur.image.h;
2260 r.w = ((rr->w + 2) * w) / o->cur.image.w;
2261 r.h = ((rr->h + 2) * h) / o->cur.image.h;
2262 r.x += obj->cur.geometry.x + x;
2263 r.y += obj->cur.geometry.y + y;
2264 evas_add_rect(&rects, r.x, r.y, r.w, r.h);
2276 if (o->pixel_updates)
2278 while (o->pixel_updates)
2282 r = (Evas_Rectangle *)o->pixel_updates->data;
2283 o->pixel_updates = evas_list_remove(o->pixel_updates, r);
2286 obj->layer->evas->engine.func->image_dirty_region(obj->layer->evas->engine.data.output, o->engine_data, 0, 0, o->cur.image.w, o->cur.image.h);
2287 evas_object_render_pre_prev_cur_add(&rects, obj);
2292 /* it obviously didn't change - add a NO obscure - this "unupdates" this */
2293 /* area so if there were updates for it they get wiped. don't do it if we */
2294 /* aren't fully opaque and we are visible */
2295 if (evas_object_is_visible(obj) &&
2296 evas_object_is_opaque(obj))
2297 obj->layer->evas->engine.func->output_redraws_rect_del(obj->layer->evas->engine.data.output,
2298 obj->cur.cache.clip.x,
2299 obj->cur.cache.clip.y,
2300 obj->cur.cache.clip.w,
2301 obj->cur.cache.clip.h);
2303 evas_object_render_pre_effect_updates(&rects, obj, is_v, was_v);
2307 evas_object_image_render_post(Evas_Object *obj)
2309 Evas_Object_Image *o;
2311 /* this moves the current data to the previous state parts of the object */
2312 /* in whatever way is safest for the object. also if we don't need object */
2313 /* data anymore we can free it if the object deems this is a good idea */
2314 o = (Evas_Object_Image *)(obj->object_data);
2315 /* remove those pesky changes */
2316 while (obj->clip.changes)
2320 r = (Evas_Rectangle *)obj->clip.changes->data;
2321 obj->clip.changes = evas_list_remove(obj->clip.changes, r);
2324 while (o->pixel_updates)
2328 r = (Evas_Rectangle *)o->pixel_updates->data;
2329 o->pixel_updates = evas_list_remove(o->pixel_updates, r);
2332 /* move cur to prev safely for object data */
2333 obj->prev = obj->cur;
2336 /* FIXME: copy strings across */
2340 evas_object_image_is_opaque(Evas_Object *obj)
2342 Evas_Object_Image *o;
2344 /* this returns 1 if the internal object data implies that the object is */
2345 /* currently fully opaque over the entire rectangle it occupies */
2346 o = (Evas_Object_Image *)(obj->object_data);
2347 if (((o->cur.border.l != 0) ||
2348 (o->cur.border.r != 0) ||
2349 (o->cur.border.t != 0) ||
2350 (o->cur.border.b != 0)) &&
2351 (!o->cur.border.fill)) return 0;
2352 if (!o->engine_data) return 0;
2353 if (obj->cur.render_op == EVAS_RENDER_COPY)
2355 if (o->cur.has_alpha) return 0;
2356 if (obj->cur.render_op != EVAS_RENDER_BLEND)
2362 evas_object_image_was_opaque(Evas_Object *obj)
2364 Evas_Object_Image *o;
2366 /* this returns 1 if the internal object data implies that the object was */
2367 /* previously fully opaque over the entire rectangle it occupies */
2368 o = (Evas_Object_Image *)(obj->object_data);
2369 if (((o->prev.border.l != 0) ||
2370 (o->prev.border.r != 0) ||
2371 (o->prev.border.t != 0) ||
2372 (o->prev.border.b != 0)) &&
2373 (!o->prev.border.fill)) return 0;
2374 if (!o->engine_data) return 0;
2375 if (obj->prev.render_op == EVAS_RENDER_COPY)
2377 if (o->prev.has_alpha) return 0;
2378 if (obj->prev.render_op != EVAS_RENDER_BLEND)
2384 evas_object_image_is_inside(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
2386 Evas_Object_Image *o;
2391 o = (Evas_Object_Image *)(obj->object_data);
2393 x -= obj->cur.cache.clip.x;
2394 y -= obj->cur.cache.clip.y;
2398 if ((x > w) || (y > h))
2401 if (!o->cur.has_alpha)
2404 stride = o->cur.image.stride;
2406 o->engine_data = obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
2413 switch (o->cur.cspace)
2415 case EVAS_COLORSPACE_ARGB8888:
2416 data = ((DATA32*)(data) + ((y * stride) + x));
2417 a = (*((DATA32*)(data)) >> 24) & 0xff;
2419 case EVAS_COLORSPACE_RGB565_A5P:
2420 data = (void*) ((DATA16*)(data) + (h * stride));
2421 data = (void*) ((DATA8*)(data) + ((y * stride) + x));
2422 a = (*((DATA8*)(data))) & 0x1f;
2433 evas_object_image_data_convert_internal(Evas_Object_Image *o, void *data, Evas_Colorspace to_cspace)
2440 switch (o->cur.cspace)
2442 case EVAS_COLORSPACE_ARGB8888:
2443 out = evas_common_convert_argb8888_to(data,
2446 o->cur.image.stride,
2450 case EVAS_COLORSPACE_RGB565_A5P:
2451 out = evas_common_convert_rgb565_a5p_to(data,
2454 o->cur.image.stride,