1 #include "evas_common.h"
2 #include "evas_private.h"
3 #include "../engines/common/evas_convert_color.h"
4 #include "../engines/common/evas_convert_colorspace.h"
5 #include "../engines/common/evas_convert_yuv.h"
7 /* private magic number for image objects */
8 static const char o_type[] = "image";
10 /* private struct for rectangle object internal data */
11 typedef struct _Evas_Object_Image Evas_Object_Image;
13 struct _Evas_Object_Image
19 Evas_Coord_Rectangle fill;
33 unsigned char smooth_scale : 1;
34 unsigned char has_alpha :1;
35 unsigned char opaque :1;
36 unsigned char opaque_valid :1;
39 int pixels_checked_out;
41 Eina_List *pixel_updates;
44 unsigned char scale_down_by;
53 Evas_Object_Image_Pixels_Get_Cb get_pixels;
54 void *get_pixels_data;
57 Evas_Image_Scale_Hint scale_hint;
58 Evas_Image_Content_Hint content_hint;
62 unsigned char changed : 1;
63 unsigned char dirty_pixels : 1;
64 unsigned char filled : 1;
67 /* private methods for image objects */
68 static void evas_object_image_unload(Evas_Object *obj, Eina_Bool dirty);
69 static void evas_object_image_load(Evas_Object *obj);
70 static Evas_Coord evas_object_image_figure_x_fill(Evas_Object *obj, Evas_Coord start, Evas_Coord size, Evas_Coord *size_ret);
71 static Evas_Coord evas_object_image_figure_y_fill(Evas_Object *obj, Evas_Coord start, Evas_Coord size, Evas_Coord *size_ret);
73 static void evas_object_image_init(Evas_Object *obj);
74 static void *evas_object_image_new(void);
75 static void evas_object_image_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y);
76 static void evas_object_image_free(Evas_Object *obj);
77 static void evas_object_image_render_pre(Evas_Object *obj);
78 static void evas_object_image_render_post(Evas_Object *obj);
80 static unsigned int evas_object_image_id_get(Evas_Object *obj);
81 static unsigned int evas_object_image_visual_id_get(Evas_Object *obj);
82 static void *evas_object_image_engine_data_get(Evas_Object *obj);
84 static int evas_object_image_is_opaque(Evas_Object *obj);
85 static int evas_object_image_was_opaque(Evas_Object *obj);
86 static int evas_object_image_is_inside(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
87 static int evas_object_image_has_opaque_rect(Evas_Object *obj);
88 static int evas_object_image_get_opaque_rect(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h);
89 static int evas_object_image_can_map(Evas_Object *obj);
91 static void *evas_object_image_data_convert_internal(Evas_Object_Image *o, void *data, Evas_Colorspace to_cspace);
92 static void evas_object_image_filled_resize_listener(void *data, Evas *e, Evas_Object *obj, void *einfo);
94 static const Evas_Object_Func object_func =
96 /* methods (compulsory) */
97 evas_object_image_free,
98 evas_object_image_render,
99 evas_object_image_render_pre,
100 evas_object_image_render_post,
101 evas_object_image_id_get,
102 evas_object_image_visual_id_get,
103 evas_object_image_engine_data_get,
104 /* these are optional. NULL = nothing */
109 evas_object_image_is_opaque,
110 evas_object_image_was_opaque,
111 evas_object_image_is_inside,
115 evas_object_image_has_opaque_rect,
116 evas_object_image_get_opaque_rect,
117 evas_object_image_can_map
122 * @addtogroup Evas_Object_Image
126 EVAS_MEMPOOL(_mp_obj);
129 * Creates a new image object on the given evas.
131 * @param e The given evas.
132 * @return The created image object.
135 evas_object_image_add(Evas *e)
138 Evas_Object_Image *o;
140 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
143 obj = evas_object_new(e);
144 evas_object_image_init(obj);
145 evas_object_inject(obj, e);
146 o = (Evas_Object_Image *)(obj->object_data);
147 o->cur.cspace = obj->layer->evas->engine.func->image_colorspace_get(obj->layer->evas->engine.data.output,
153 * Creates a new image object that automatically scales on the given evas.
155 * This is a helper around evas_object_image_add() and
156 * evas_object_image_filled_set(), it will track object resizes and apply
157 * evas_object_image_fill_set() with the new geometry.
159 * @see evas_object_image_add()
160 * @see evas_object_image_filled_set()
161 * @see evas_object_image_fill_set()
164 evas_object_image_filled_add(Evas *e)
167 obj = evas_object_image_add(e);
168 evas_object_image_filled_set(obj, 1);
173 * Sets the filename and key of the given image object.
175 * If the file supports multiple data stored in it as eet, you can
176 * specify the key to be used as the index of the image in this file.
178 * @param obj The given image object.
179 * @param file The image filename.
180 * @param key The image key in file, or NULL.
183 evas_object_image_file_set(Evas_Object *obj, const char *file, const char *key)
185 Evas_Object_Image *o;
186 Evas_Image_Load_Opts lo;
188 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
191 o = (Evas_Object_Image *)(obj->object_data);
192 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
195 if ((o->cur.file) && (file) && (!strcmp(o->cur.file, file)))
197 if ((!o->cur.key) && (!key))
199 if ((o->cur.key) && (key) && (!strcmp(o->cur.key, key)))
203 * WTF? why cancel a null image preload? this is just silly (tm)
205 obj->layer->evas->engine.func->image_data_preload_cancel(obj->layer->evas->engine.data.output,
210 if (o->cur.file) eina_stringshare_del(o->cur.file);
211 if (o->cur.key) eina_stringshare_del(o->cur.key);
212 if (file) o->cur.file = eina_stringshare_add(file);
213 else o->cur.file = NULL;
214 if (key) o->cur.key = eina_stringshare_add(key);
215 else o->cur.key = NULL;
220 obj->layer->evas->engine.func->image_data_preload_cancel(obj->layer->evas->engine.data.output,
223 obj->layer->evas->engine.func->image_free(obj->layer->evas->engine.data.output,
226 o->load_error = EVAS_LOAD_ERROR_NONE;
227 lo.scale_down_by = o->load_opts.scale_down_by;
228 lo.dpi = o->load_opts.dpi;
229 lo.w = o->load_opts.w;
230 lo.h = o->load_opts.h;
231 lo.region.x = o->load_opts.region.x;
232 lo.region.y = o->load_opts.region.y;
233 lo.region.w = o->load_opts.region.w;
234 lo.region.h = o->load_opts.region.h;
235 o->engine_data = obj->layer->evas->engine.func->image_load(obj->layer->evas->engine.data.output,
245 obj->layer->evas->engine.func->image_size_get(obj->layer->evas->engine.data.output,
246 o->engine_data, &w, &h);
247 if (obj->layer->evas->engine.func->image_stride_get)
248 obj->layer->evas->engine.func->image_stride_get(obj->layer->evas->engine.data.output,
249 o->engine_data, &stride);
252 o->cur.has_alpha = obj->layer->evas->engine.func->image_alpha_get(obj->layer->evas->engine.data.output,
254 o->cur.cspace = obj->layer->evas->engine.func->image_colorspace_get(obj->layer->evas->engine.data.output,
258 o->cur.image.stride = stride;
262 if (o->load_error == EVAS_LOAD_ERROR_NONE)
263 o->load_error = EVAS_LOAD_ERROR_GENERIC;
264 o->cur.has_alpha = 1;
265 o->cur.cspace = EVAS_COLORSPACE_ARGB8888;
268 o->cur.image.stride = 0;
271 evas_object_change(obj);
275 * Retrieves the filename and key of the given image object.
277 * @param obj The given image object.
278 * @param file Location to store the image filename, or NULL.
279 * @param key Location to store the image key, or NULL.
282 evas_object_image_file_get(const Evas_Object *obj, const char **file, const char **key)
284 Evas_Object_Image *o;
286 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
287 if (file) *file = NULL;
288 if (key) *key = NULL;
291 o = (Evas_Object_Image *)(obj->object_data);
292 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
293 if (file) *file = NULL;
294 if (key) *key = NULL;
297 if (file) *file = o->cur.file;
298 if (key) *key = o->cur.key;
302 * Sets how much of each border of the given image object is not
305 * When rendering, the image may be scaled to fit the size of the
306 * image object. This function sets what area around the border of the
307 * image is not to be scaled. This sort of function is useful for
308 * widget theming, where, for example, buttons may be of varying
309 * sizes, but the border size must remain constant.
311 * The units used for @p l, @p r, @p t and @p b are output units.
313 * @param obj The given image object.
314 * @param l Distance of the left border that is not to be stretched.
315 * @param r Distance of the right border that is not to be stretched.
316 * @param t Distance of the top border that is not to be stretched.
317 * @param b Distance of the bottom border that is not to be stretched.
320 evas_object_image_border_set(Evas_Object *obj, int l, int r, int t, int b)
322 Evas_Object_Image *o;
324 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
327 o = (Evas_Object_Image *)(obj->object_data);
328 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
335 if ((o->cur.border.l == l) &&
336 (o->cur.border.r == r) &&
337 (o->cur.border.t == t) &&
338 (o->cur.border.b == b)) return;
343 o->cur.opaque_valid = 0;
345 evas_object_change(obj);
349 * Retrieves how much of each border of the given image object is not
352 * See @ref evas_object_image_border_set for more details.
354 * @param obj The given image object.
355 * @param l Location to store the left border width in, or NULL.
356 * @param r Location to store the right border width in, or NULL.
357 * @param t Location to store the top border width in, or NULL.
358 * @param b Location to store the bottom border width in, or NULL.
361 evas_object_image_border_get(const Evas_Object *obj, int *l, int *r, int *t, int *b)
363 Evas_Object_Image *o;
365 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
372 o = (Evas_Object_Image *)(obj->object_data);
373 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
380 if (l) *l = o->cur.border.l;
381 if (r) *r = o->cur.border.r;
382 if (t) *t = o->cur.border.t;
383 if (b) *b = o->cur.border.b;
387 * Sets if the center part of the given image object (not the border)
390 * When rendering, the image may be scaled to fit the size of the
391 * image object. This function sets if the center part of the scaled
392 * image is to be drawn or left completely blank, or forced to be
393 * solid. Very useful for frames and decorations.
395 * @param obj The given image object.
396 * @param fill Fill mode of the middle.
399 evas_object_image_border_center_fill_set(Evas_Object *obj, Evas_Border_Fill_Mode fill)
401 Evas_Object_Image *o;
403 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
406 o = (Evas_Object_Image *)(obj->object_data);
407 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
410 if (fill == o->cur.border.fill) return;
411 o->cur.border.fill = fill;
413 evas_object_change(obj);
417 * Retrieves if the center of the given image object is to be drawn or
420 * See @ref evas_object_image_fill_set for more details.
422 * @param obj The given image object.
423 * @return Fill mode of the center.
425 EAPI Evas_Border_Fill_Mode
426 evas_object_image_border_center_fill_get(const Evas_Object *obj)
428 Evas_Object_Image *o;
430 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
433 o = (Evas_Object_Image *)(obj->object_data);
434 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
437 return o->cur.border.fill;
441 * Sets if image fill property should track object size.
443 * If set to true, then every evas_object_resize() will automatically
444 * trigger call to evas_object_image_fill_set() with the new size so
445 * image will fill the whole object area.
447 * @param obj The given image object.
448 * @param setting whether to follow object size.
450 * @see evas_object_image_filled_add()
451 * @see evas_object_image_fill_set()
454 evas_object_image_filled_set(Evas_Object *obj, Eina_Bool setting)
456 Evas_Object_Image *o;
458 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
461 o = (Evas_Object_Image *)(obj->object_data);
462 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
467 if (o->filled == setting) return;
471 evas_object_event_callback_del(obj, EVAS_CALLBACK_RESIZE, evas_object_image_filled_resize_listener);
476 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
477 evas_object_image_fill_set(obj, 0, 0, w, h);
479 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, evas_object_image_filled_resize_listener, NULL);
484 * Retrieves if image fill property is tracking object size.
486 * @param obj The given image object.
487 * @return 1 if it is tracking, 0 if not and evas_object_fill_set()
488 * must be called manually.
491 evas_object_image_filled_get(const Evas_Object *obj)
493 Evas_Object_Image *o;
495 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
498 o = (Evas_Object_Image *)(obj->object_data);
499 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
507 * Sets a scale factor (multiplier) for the borders of an image
509 * @param obj The given image object.
510 * @param scale The scale factor (default is 1.0 - i.e. no scale)
513 evas_object_image_border_scale_set(Evas_Object *obj, double scale)
515 Evas_Object_Image *o;
517 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
520 o = (Evas_Object_Image *)(obj->object_data);
521 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
524 if (scale == o->cur.border.scale) return;
525 o->cur.border.scale = scale;
527 evas_object_change(obj);
531 * Retrieves the border scale factor
533 * See evas_object_image_border_scale_set()
535 * @param obj The given image object.
536 * @return The scale factor
539 evas_object_image_border_scale_get(const Evas_Object *obj)
541 Evas_Object_Image *o;
543 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
546 o = (Evas_Object_Image *)(obj->object_data);
547 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
550 return o->cur.border.scale;
554 * Sets the rectangle of the given image object that the image will be
557 * Note that the image will be tiled around this one rectangle. To
558 * have only one copy of the image drawn, @p x and @p y must be 0 and
559 * @p w and @p h need to be the width and height of the image object
562 * The default values for the fill parameters is @p x = 0, @p y = 0,
563 * @p w = 32 and @p h = 32.
565 * @param obj The given image object.
566 * @param x The X coordinate for the top left corner of the image.
567 * @param y The Y coordinate for the top left corner of the image.
568 * @param w The width of the image.
569 * @param h The height of the image.
572 evas_object_image_fill_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
574 Evas_Object_Image *o;
580 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
583 o = (Evas_Object_Image *)(obj->object_data);
584 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
587 if ((o->cur.fill.x == x) &&
588 (o->cur.fill.y == y) &&
589 (o->cur.fill.w == w) &&
590 (o->cur.fill.h == h)) return;
595 o->cur.opaque_valid = 0;
597 evas_object_change(obj);
601 * Retrieves the dimensions of the rectangle of the given image object
602 * that the image will be drawn to.
604 * See @ref evas_object_image_fill_set for more details.
606 * @param obj The given image object.
607 * @param x Location to store the X coordinate for the top left corner of the image in, or NULL.
608 * @param y Location to store the Y coordinate for the top left corner of the image in, or NULL.
609 * @param w Location to store the width of the image in, or NULL.
610 * @param h Location to store the height of the image in, or NULL.
613 evas_object_image_fill_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
615 Evas_Object_Image *o;
617 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
624 o = (Evas_Object_Image *)(obj->object_data);
625 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
632 if (x) *x = o->cur.fill.x;
633 if (y) *y = o->cur.fill.y;
634 if (w) *w = o->cur.fill.w;
635 if (h) *h = o->cur.fill.h;
640 * Sets the tiling mode for the given evas image object's fill.
641 * @param obj The given evas image object.
642 * @param spread One of EVAS_TEXTURE_REFLECT, EVAS_TEXTURE_REPEAT,
643 * EVAS_TEXTURE_RESTRICT, or EVAS_TEXTURE_PAD.
646 evas_object_image_fill_spread_set(Evas_Object *obj, Evas_Fill_Spread spread)
648 Evas_Object_Image *o;
650 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
653 o = (Evas_Object_Image *)(obj->object_data);
654 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
657 if (spread == (Evas_Fill_Spread)o->cur.spread) return;
658 o->cur.spread = spread;
660 evas_object_change(obj);
664 * Retrieves the spread (tiling mode) for the given image object's
667 * @param obj The given evas image object.
668 * @return The current spread mode of the image object.
670 EAPI Evas_Fill_Spread
671 evas_object_image_fill_spread_get(const Evas_Object *obj)
673 Evas_Object_Image *o;
675 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
676 return EVAS_TEXTURE_REPEAT;
678 o = (Evas_Object_Image *)(obj->object_data);
679 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
680 return EVAS_TEXTURE_REPEAT;
682 return (Evas_Fill_Spread)o->cur.spread;
686 * Sets the size of the given image object.
688 * This function will scale down or crop the image so that it is
689 * treated as if it were at the given size. If the size given is
690 * smaller than the image, it will be cropped. If the size given is
691 * larger, then the image will be treated as if it were in the upper
692 * left hand corner of a larger image that is otherwise transparent.
694 * @param obj The given image object.
695 * @param w The new width of the image.
696 * @param h The new height of the image.
699 evas_object_image_size_set(Evas_Object *obj, int w, int h)
701 Evas_Object_Image *o;
704 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
707 o = (Evas_Object_Image *)(obj->object_data);
708 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
713 if (w > 32768) return;
714 if (h > 32768) return;
715 if ((w == o->cur.image.w) &&
716 (h == o->cur.image.h)) return;
720 o->engine_data = obj->layer->evas->engine.func->image_size_set(obj->layer->evas->engine.data.output,
724 o->engine_data = obj->layer->evas->engine.func->image_new_from_copied_data
725 (obj->layer->evas->engine.data.output, w, h, NULL, o->cur.has_alpha,
730 if (obj->layer->evas->engine.func->image_scale_hint_set)
731 obj->layer->evas->engine.func->image_scale_hint_set
732 (obj->layer->evas->engine.data.output,
733 o->engine_data, o->scale_hint);
734 if (obj->layer->evas->engine.func->image_content_hint_set)
735 obj->layer->evas->engine.func->image_content_hint_set
736 (obj->layer->evas->engine.data.output,
737 o->engine_data, o->content_hint);
738 if (obj->layer->evas->engine.func->image_stride_get)
739 obj->layer->evas->engine.func->image_stride_get
740 (obj->layer->evas->engine.data.output,
741 o->engine_data, &stride);
747 o->cur.image.stride = stride;
749 /* FIXME - in engine call above
751 o->engine_data = obj->layer->evas->engine.func->image_alpha_set(obj->layer->evas->engine.data.output,
755 EVAS_OBJECT_IMAGE_FREE_FILE_AND_KEY(o);
757 evas_object_change(obj);
761 * Retrieves the size of the given image object.
763 * See @ref evas_object_image_size_set for more details.
765 * @param obj The given image object.
766 * @param w Location to store the width of the image in, or NULL.
767 * @param h Location to store the height of the image in, or NULL.
770 evas_object_image_size_get(const Evas_Object *obj, int *w, int *h)
772 Evas_Object_Image *o;
774 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
779 o = (Evas_Object_Image *)(obj->object_data);
780 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
785 if (w) *w = o->cur.image.w;
786 if (h) *h = o->cur.image.h;
790 * Retrieves the row stride of the given image object,
792 * The row stride is the number of units between the start of a
793 * row and the start of the next row.
795 * @param obj The given image object.
796 * @return The stride of the image.
799 evas_object_image_stride_get(const Evas_Object *obj)
801 Evas_Object_Image *o;
803 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
806 o = (Evas_Object_Image *)(obj->object_data);
807 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
810 return o->cur.image.stride;
814 * Retrieves a number representing any error that occurred during the last
815 * load of the given image object.
817 * @param obj The given image object.
818 * @return A value giving the last error that occurred. It should be one of
819 * the @c EVAS_LOAD_ERROR_* values. @c EVAS_LOAD_ERROR_NONE is
820 * returned if there was no error.
823 evas_object_image_load_error_get(const Evas_Object *obj)
825 Evas_Object_Image *o;
827 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
830 o = (Evas_Object_Image *)(obj->object_data);
831 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
834 return o->load_error;
838 * Converts the raw image data of the given image object to the
839 * specified colorspace.
841 * Note that this function does not modify the raw image data. If the
842 * requested colorspace is the same as the image colorspace nothing is
843 * done and NULL is returned. You should use
844 * evas_object_image_colorspace_get() to check the current image
847 * See @ref evas_object_image_colorspace_get.
849 * @param obj The given image object.
850 * @param to_cspace The colorspace to which the image raw data will be converted.
851 * @return data A newly allocated data in the format specified by to_cspace.
854 evas_object_image_data_convert(Evas_Object *obj, Evas_Colorspace to_cspace)
856 Evas_Object_Image *o;
859 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
862 o = (Evas_Object_Image *)(obj->object_data);
863 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
866 if (!o->engine_data) return NULL;
867 if (!o->cur.cspace == to_cspace) return NULL;
869 o->engine_data = obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
873 return evas_object_image_data_convert_internal(o, data, to_cspace);
877 * Sets the raw image data of the given image object.
879 * Note that the raw data must be of the same size and colorspace of
880 * the image. If data is NULL the current image data will be freed.
882 * @param obj The given image object.
883 * @param data The raw data, or NULL.
886 evas_object_image_data_set(Evas_Object *obj, void *data)
888 Evas_Object_Image *o;
891 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
894 o = (Evas_Object_Image *)(obj->object_data);
895 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
898 #ifdef EVAS_FRAME_QUEUING
900 evas_common_pipe_op_image_flush(o->engine_data);
902 p_data = o->engine_data;
906 o->engine_data = obj->layer->evas->engine.func->image_data_put(obj->layer->evas->engine.data.output,
910 o->engine_data = obj->layer->evas->engine.func->image_new_from_data(obj->layer->evas->engine.data.output,
920 if (obj->layer->evas->engine.func->image_scale_hint_set)
921 obj->layer->evas->engine.func->image_scale_hint_set
922 (obj->layer->evas->engine.data.output,
923 o->engine_data, o->scale_hint);
924 if (obj->layer->evas->engine.func->image_content_hint_set)
925 obj->layer->evas->engine.func->image_content_hint_set
926 (obj->layer->evas->engine.data.output,
927 o->engine_data, o->content_hint);
928 if (obj->layer->evas->engine.func->image_stride_get)
929 obj->layer->evas->engine.func->image_stride_get
930 (obj->layer->evas->engine.data.output,
931 o->engine_data, &stride);
933 stride = o->cur.image.w * 4;
934 o->cur.image.stride = stride;
940 obj->layer->evas->engine.func->image_free(obj->layer->evas->engine.data.output,
942 o->load_error = EVAS_LOAD_ERROR_NONE;
945 o->cur.image.stride = 0;
946 o->engine_data = NULL;
948 /* FIXME - in engine call above
950 o->engine_data = obj->layer->evas->engine.func->image_alpha_set(obj->layer->evas->engine.data.output,
954 if (o->pixels_checked_out > 0) o->pixels_checked_out--;
955 if (p_data != o->engine_data)
957 EVAS_OBJECT_IMAGE_FREE_FILE_AND_KEY(o);
958 o->pixels_checked_out = 0;
961 evas_object_change(obj);
965 * Get a pointer to the raw image data of the given image object.
967 * This function returns a pointer to an image object's internal pixel
968 * buffer, for reading only or read/write. If you request it for
969 * writing, the image will be marked dirty so that it gets redrawn at
972 * This is best suited when you want to modify an existing image,
973 * without changing its dimensions.
975 * @param obj The given image object.
976 * @param for_writing Whether the data being retrieved will be modified.
977 * @return The raw image data.
980 evas_object_image_data_get(const Evas_Object *obj, Eina_Bool for_writing)
982 Evas_Object_Image *o;
985 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
988 o = (Evas_Object_Image *)(obj->object_data);
989 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
992 if (!o->engine_data) return NULL;
993 #ifdef EVAS_FRAME_QUEUING
994 evas_common_pipe_op_image_flush(o->engine_data);
998 if (obj->layer->evas->engine.func->image_scale_hint_set)
999 obj->layer->evas->engine.func->image_scale_hint_set
1000 (obj->layer->evas->engine.data.output,
1001 o->engine_data, o->scale_hint);
1002 if (obj->layer->evas->engine.func->image_content_hint_set)
1003 obj->layer->evas->engine.func->image_content_hint_set
1004 (obj->layer->evas->engine.data.output,
1005 o->engine_data, o->content_hint);
1006 o->engine_data = obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
1014 if (obj->layer->evas->engine.func->image_stride_get)
1015 obj->layer->evas->engine.func->image_stride_get
1016 (obj->layer->evas->engine.data.output,
1017 o->engine_data, &stride);
1019 stride = o->cur.image.w * 4;
1020 o->cur.image.stride = stride;
1022 o->pixels_checked_out++;
1025 EVAS_OBJECT_IMAGE_FREE_FILE_AND_KEY(o);
1032 * Preload image in the background
1034 * This function request the preload of the data image in the
1035 * background. The worked is queued before being processed.
1037 * If image data is already loaded, it will callback
1038 * EVAS_CALLBACK_IMAGE_PRELOADED immediatelly and do nothing else.
1040 * If cancel is set, it will remove the image from the workqueue.
1042 * @param obj The given image object.
1043 * @param cancel 0 means add to the workqueue, 1 remove it.
1046 evas_object_image_preload(Evas_Object *obj, Eina_Bool cancel)
1048 Evas_Object_Image *o;
1050 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1053 o = (Evas_Object_Image *)(obj->object_data);
1054 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1057 if (!o->engine_data)
1059 evas_object_inform_call_image_preloaded(obj);
1063 obj->layer->evas->engine.func->image_data_preload_cancel(obj->layer->evas->engine.data.output,
1067 obj->layer->evas->engine.func->image_data_preload_request(obj->layer->evas->engine.data.output,
1073 * Replaces the raw image data of the given image object.
1075 * This function lets the application replace an image object's
1076 * internal pixel buffer with a user-allocated one. For best results,
1077 * you should generally first call evas_object_image_size_set() with
1078 * the width and height for the new buffer.
1080 * This call is best suited for when you will be using image data with
1081 * different dimensions than the existing image data, if any. If you
1082 * only need to modify the existing image in some fashion, then using
1083 * evas_object_image_data_get() is probably what you are after.
1085 * Note that the caller is responsible for freeing the buffer when
1086 * finished with it, as user-set image data will not be automatically
1087 * freed when the image object is deleted.
1089 * See @ref evas_object_image_data_get for more details.
1091 * @param obj The given image object.
1092 * @param data The raw data.
1095 evas_object_image_data_copy_set(Evas_Object *obj, void *data)
1097 Evas_Object_Image *o;
1100 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1103 o = (Evas_Object_Image *)(obj->object_data);
1104 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1107 if ((o->cur.image.w <= 0) ||
1108 (o->cur.image.h <= 0)) return;
1110 obj->layer->evas->engine.func->image_free(obj->layer->evas->engine.data.output,
1112 o->engine_data = obj->layer->evas->engine.func->image_new_from_copied_data(obj->layer->evas->engine.data.output,
1122 o->engine_data = obj->layer->evas->engine.func->image_alpha_set(obj->layer->evas->engine.data.output,
1125 if (obj->layer->evas->engine.func->image_scale_hint_set)
1126 obj->layer->evas->engine.func->image_scale_hint_set
1127 (obj->layer->evas->engine.data.output,
1128 o->engine_data, o->scale_hint);
1129 if (obj->layer->evas->engine.func->image_content_hint_set)
1130 obj->layer->evas->engine.func->image_content_hint_set
1131 (obj->layer->evas->engine.data.output,
1132 o->engine_data, o->content_hint);
1133 if (obj->layer->evas->engine.func->image_stride_get)
1134 obj->layer->evas->engine.func->image_stride_get
1135 (obj->layer->evas->engine.data.output,
1136 o->engine_data, &stride);
1138 stride = o->cur.image.w * 4;
1139 o->cur.image.stride = stride;
1141 o->pixels_checked_out = 0;
1142 EVAS_OBJECT_IMAGE_FREE_FILE_AND_KEY(o);
1146 * Mark a sub-region of the given image object to be redrawn.
1148 * This function schedules a particular rectangular region of an image
1149 * object to be updated (redrawn) at the next render.
1151 * @param obj The given image object.
1152 * @param x X-offset of the region to be updated.
1153 * @param y Y-offset of the region to be updated.
1154 * @param w Width of the region to be updated.
1155 * @param h Height of the region to be updated.
1158 evas_object_image_data_update_add(Evas_Object *obj, int x, int y, int w, int h)
1160 Evas_Object_Image *o;
1163 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1166 o = (Evas_Object_Image *)(obj->object_data);
1167 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1170 RECTS_CLIP_TO_RECT(x, y, w, h, 0, 0, o->cur.image.w, o->cur.image.h);
1171 if ((w <= 0) || (h <= 0)) return;
1172 NEW_RECT(r, x, y, w, h);
1173 if (r) o->pixel_updates = eina_list_append(o->pixel_updates, r);
1175 evas_object_change(obj);
1179 * Enable or disable alpha channel of the given image object.
1181 * This function sets a flag on an image object indicating whether or
1182 * not to use alpha channel data. A value of 1 indicates to use alpha
1183 * channel data, and 0 indicates to ignore any alpha channel
1184 * data. Note that this has nothing to do with an object's color as
1185 * manipulated by evas_object_color_set().
1187 * @param obj The given image object.
1188 * @param has_alpha Whether to use alpha channel data or not.
1191 evas_object_image_alpha_set(Evas_Object *obj, Eina_Bool has_alpha)
1193 Evas_Object_Image *o;
1195 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1198 o = (Evas_Object_Image *)(obj->object_data);
1199 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1202 if (((has_alpha) && (o->cur.has_alpha)) ||
1203 ((!has_alpha) && (!o->cur.has_alpha)))
1205 o->cur.has_alpha = has_alpha;
1210 #ifdef EVAS_FRAME_QUEUING
1211 evas_common_pipe_op_image_flush(o->engine_data);
1213 o->engine_data = obj->layer->evas->engine.func->image_alpha_set(obj->layer->evas->engine.data.output,
1216 if (obj->layer->evas->engine.func->image_scale_hint_set)
1217 obj->layer->evas->engine.func->image_scale_hint_set
1218 (obj->layer->evas->engine.data.output,
1219 o->engine_data, o->scale_hint);
1220 if (obj->layer->evas->engine.func->image_content_hint_set)
1221 obj->layer->evas->engine.func->image_content_hint_set
1222 (obj->layer->evas->engine.data.output,
1223 o->engine_data, o->content_hint);
1224 if (obj->layer->evas->engine.func->image_stride_get)
1225 obj->layer->evas->engine.func->image_stride_get
1226 (obj->layer->evas->engine.data.output,
1227 o->engine_data, &stride);
1229 stride = o->cur.image.w * 4;
1230 o->cur.image.stride = stride;
1232 evas_object_image_data_update_add(obj, 0, 0, o->cur.image.w, o->cur.image.h);
1233 EVAS_OBJECT_IMAGE_FREE_FILE_AND_KEY(o);
1238 * @brief Retrieves the alpha channel setting of the given image object.
1240 * @param obj The given image object.
1241 * @return Whether the alpha channel data is being used.
1243 * This function returns 1 if the image object's alpha channel is
1244 * being used, or 0 otherwise.
1246 * See @ref evas_object_image_alpha_set for more details.
1249 evas_object_image_alpha_get(const Evas_Object *obj)
1251 Evas_Object_Image *o;
1253 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1256 o = (Evas_Object_Image *)(obj->object_data);
1257 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1260 return o->cur.has_alpha;
1264 * Sets whether to use of high-quality image scaling algorithm
1265 * of the given image object.
1267 * When enabled, a higher quality image scaling algorithm is used when
1268 * scaling images to sizes other than the source image. This gives
1269 * better results but is more computationally expensive.
1271 * @param obj The given image object.
1272 * @param smooth_scale Whether to use smooth scale or not.
1275 evas_object_image_smooth_scale_set(Evas_Object *obj, Eina_Bool smooth_scale)
1277 Evas_Object_Image *o;
1279 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1282 o = (Evas_Object_Image *)(obj->object_data);
1283 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1286 if (((smooth_scale) && (o->cur.smooth_scale)) ||
1287 ((!smooth_scale) && (!o->cur.smooth_scale)))
1289 o->cur.smooth_scale = smooth_scale;
1291 evas_object_change(obj);
1295 * Retrieves whether the given image object is using use a
1296 * high-quality image scaling algorithm.
1298 * See @ref evas_object_image_smooth_scale_set for more details.
1300 * @param obj The given image object.
1301 * @return Whether smooth scale is being used.
1304 evas_object_image_smooth_scale_get(const Evas_Object *obj)
1306 Evas_Object_Image *o;
1308 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1311 o = (Evas_Object_Image *)(obj->object_data);
1312 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1315 return o->cur.smooth_scale;
1319 * Reload a image of the canvas.
1321 * @param obj The given image object pointer.
1323 * This function reloads a image of the given canvas.
1327 evas_object_image_reload(Evas_Object *obj)
1329 Evas_Object_Image *o;
1331 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1334 o = (Evas_Object_Image *)(obj->object_data);
1335 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1338 if ((!o->cur.file) ||
1339 (o->pixels_checked_out > 0)) return;
1341 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);
1342 evas_object_image_unload(obj, 1);
1343 evas_object_image_load(obj);
1344 o->prev.file = NULL;
1347 evas_object_change(obj);
1351 * Save the given image object to a file.
1353 * Note that you should pass the filename extension when saving. If
1354 * the file supports multiple data stored in it as eet, you can
1355 * specify the key to be used as the index of the image in this file.
1357 * You can specify some flags when saving the image. Currently
1358 * acceptable flags are quality and compress. Eg.: "quality=100
1361 * @param obj The given image object.
1362 * @param file The filename to be used to save the image.
1363 * @param key The image key in file, or NULL.
1364 * @param flags String containing the flags to be used.
1367 evas_object_image_save(const Evas_Object *obj, const char *file, const char *key, const char *flags)
1369 Evas_Object_Image *o;
1370 DATA32 *data = NULL;
1371 int quality = 80, compress = 9, ok = 0;
1374 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1377 o = (Evas_Object_Image *)(obj->object_data);
1378 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1382 if (!o->engine_data) return 0;
1383 o->engine_data = obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
1392 tflags = alloca(strlen(flags) + 1);
1393 strcpy(tflags, flags);
1397 pp = strchr(p, ' ');
1399 sscanf(p, "quality=%i", &quality);
1400 sscanf(p, "compress=%i", &compress);
1405 im = (RGBA_Image*) evas_cache_image_data(evas_common_image_cache_get(),
1410 EVAS_COLORSPACE_ARGB8888);
1413 if (o->cur.cspace == EVAS_COLORSPACE_ARGB8888)
1414 im->image.data = data;
1416 im->image.data = evas_object_image_data_convert_internal(o,
1418 EVAS_COLORSPACE_ARGB8888);
1421 ok = evas_common_save_image_to_file(im, file, key, quality, compress);
1423 if (o->cur.cspace != EVAS_COLORSPACE_ARGB8888)
1424 free(im->image.data);
1427 evas_cache_image_drop(&im->cache_entry);
1433 * Import pixels from given source to a given canvas image object.
1435 * @param obj The given canvas object.
1436 * @param pixels The pixel's source to be imported.
1438 * This function imports pixels from a given source to a given canvas image.
1442 evas_object_image_pixels_import(Evas_Object *obj, Evas_Pixel_Import_Source *pixels)
1444 Evas_Object_Image *o;
1446 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1449 o = (Evas_Object_Image *)(obj->object_data);
1450 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1454 if ((pixels->w != o->cur.image.w) || (pixels->h != o->cur.image.h)) return 0;
1455 switch (pixels->format)
1458 case EVAS_PIXEL_FORMAT_ARGB32:
1462 DATA32 *image_pixels = NULL;
1465 obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
1469 /* FIXME: need to actualyl support this */
1470 /* memcpy(image_pixels, pixels->rows, o->cur.image.w * o->cur.image.h * 4);*/
1473 obj->layer->evas->engine.func->image_data_put(obj->layer->evas->engine.data.output,
1478 obj->layer->evas->engine.func->image_alpha_set(obj->layer->evas->engine.data.output,
1482 evas_object_change(obj);
1487 #ifdef BUILD_CONVERT_YUV
1488 case EVAS_PIXEL_FORMAT_YUV420P_601:
1492 DATA32 *image_pixels = NULL;
1495 obj->layer->evas->engine.func->image_data_get(obj->layer->evas->engine.data.output,
1500 evas_common_convert_yuv_420p_601_rgba((DATA8 **) pixels->rows,
1501 (DATA8 *) image_pixels,
1506 obj->layer->evas->engine.func->image_data_put(obj->layer->evas->engine.data.output,
1511 obj->layer->evas->engine.func->image_alpha_set(obj->layer->evas->engine.data.output,
1515 evas_object_change(obj);
1528 * Set the callback function to get pixels from a canva's image.
1530 * @param obj The given canvas pointer.
1531 * @param func The callback function.
1532 * @param data The data pointer to be passed to @a func.
1534 * This functions sets a function to be the callback function that get
1535 * pixes from a image of the canvas.
1539 evas_object_image_pixels_get_callback_set(Evas_Object *obj, Evas_Object_Image_Pixels_Get_Cb func, void *data)
1541 Evas_Object_Image *o;
1543 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1546 o = (Evas_Object_Image *)(obj->object_data);
1547 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1550 o->func.get_pixels = func;
1551 o->func.get_pixels_data = data;
1555 * Mark whether the given image object is dirty (needs to be redrawn).
1557 * @param obj The given image object.
1558 * @param dirty Whether the image is dirty.
1561 evas_object_image_pixels_dirty_set(Evas_Object *obj, Eina_Bool dirty)
1563 Evas_Object_Image *o;
1565 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1568 o = (Evas_Object_Image *)(obj->object_data);
1569 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1572 if (dirty) o->dirty_pixels = 1;
1573 else o->dirty_pixels = 0;
1575 evas_object_change(obj);
1579 * Retrieves whether the given image object is dirty (needs to be redrawn).
1581 * @param obj The given image object.
1582 * @return Whether the image is dirty.
1585 evas_object_image_pixels_dirty_get(const Evas_Object *obj)
1587 Evas_Object_Image *o;
1589 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1592 o = (Evas_Object_Image *)(obj->object_data);
1593 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1596 if (o->dirty_pixels) return 1;
1601 * Set the dpi resolution of a loaded image of the canvas.
1603 * @param obj The given canvas pointer.
1604 * @param dpi The new dpi resolution.
1606 * This function set the dpi resolution of a given loaded canvas image.
1610 evas_object_image_load_dpi_set(Evas_Object *obj, double dpi)
1612 Evas_Object_Image *o;
1614 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1617 o = (Evas_Object_Image *)(obj->object_data);
1618 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1621 if (dpi == o->load_opts.dpi) return;
1622 o->load_opts.dpi = dpi;
1625 evas_object_image_unload(obj, 0);
1626 evas_object_image_load(obj);
1628 evas_object_change(obj);
1633 * Get the dpi resolution of a loaded image of the canvas.
1635 * @param obj The given canvas pointer.
1636 * @return The dpi resolution of the given canvas image.
1638 * This function returns the dpi resolution of given canvas image.
1642 evas_object_image_load_dpi_get(const Evas_Object *obj)
1644 Evas_Object_Image *o;
1646 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1649 o = (Evas_Object_Image *)(obj->object_data);
1650 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1653 return o->load_opts.dpi;
1657 * Set the size of a loaded image of the canvas.
1659 * @param obj The given canvas object.
1660 * @param w The new width of the canvas image given.
1661 * @param h Th new height of the canvas image given.
1663 * This function sets a new size for the given canvas image.
1667 evas_object_image_load_size_set(Evas_Object *obj, int w, int h)
1669 Evas_Object_Image *o;
1671 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1674 o = (Evas_Object_Image *)(obj->object_data);
1675 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1678 if ((o->load_opts.w == w) && (o->load_opts.h == h)) return;
1683 evas_object_image_unload(obj, 0);
1684 evas_object_image_load(obj);
1686 evas_object_change(obj);
1691 * Get the size of a loaded image of the canvas.
1693 * @param obj The given canvas object.
1694 * @param w The width of the canvas image given.
1695 * @param h The height of the canvas image given.
1697 * This function get the size of the given canvas image.
1701 evas_object_image_load_size_get(const Evas_Object *obj, int *w, int *h)
1703 Evas_Object_Image *o;
1705 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1708 o = (Evas_Object_Image *)(obj->object_data);
1709 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1712 if (w) *w = o->load_opts.w;
1713 if (h) *h = o->load_opts.h;
1717 * Set the scale down of a loaded image of the canvas.
1719 * @param obj The given canvas pointer.
1720 * @param scale_down The scale to down value.
1722 * This function sets the scale down of a given canvas image.
1726 evas_object_image_load_scale_down_set(Evas_Object *obj, int scale_down)
1728 Evas_Object_Image *o;
1730 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1733 o = (Evas_Object_Image *)(obj->object_data);
1734 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1737 if (o->load_opts.scale_down_by == scale_down) return;
1738 o->load_opts.scale_down_by = scale_down;
1741 evas_object_image_unload(obj, 0);
1742 evas_object_image_load(obj);
1744 evas_object_change(obj);
1749 * Get the scale down value of given image of the canvas.
1751 * @param obj The given image object pointer.
1753 * This function returns the scale down value of a given canvas image.
1757 evas_object_image_load_scale_down_get(const Evas_Object *obj)
1759 Evas_Object_Image *o;
1761 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1764 o = (Evas_Object_Image *)(obj->object_data);
1765 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1768 return o->load_opts.scale_down_by;
1772 evas_object_image_load_region_set(Evas_Object *obj, int x, int y, int w, int h)
1774 Evas_Object_Image *o;
1776 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1779 o = (Evas_Object_Image *)(obj->object_data);
1780 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1783 if ((o->load_opts.region.x == x) && (o->load_opts.region.y == y) &&
1784 (o->load_opts.region.w == w) && (o->load_opts.region.h == h)) return;
1785 o->load_opts.region.x = x;
1786 o->load_opts.region.y = y;
1787 o->load_opts.region.w = w;
1788 o->load_opts.region.h = h;
1791 evas_object_image_unload(obj, 0);
1792 evas_object_image_load(obj);
1794 evas_object_change(obj);
1799 evas_object_image_load_region_get(const Evas_Object *obj, int *x, int *y, int *w, int *h)
1801 Evas_Object_Image *o;
1803 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1806 o = (Evas_Object_Image *)(obj->object_data);
1807 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1810 if (x) *x = o->load_opts.region.x;
1811 if (y) *y = o->load_opts.region.y;
1812 if (w) *w = o->load_opts.region.w;
1813 if (h) *h = o->load_opts.region.h;
1817 * Set the colorspace of a given image of the canvas.
1819 * @param obj The given image object pointer.
1820 * @param cspace The new color space.
1822 * This function sets the colorspace of given canvas image.
1826 evas_object_image_colorspace_set(Evas_Object *obj, Evas_Colorspace cspace)
1828 Evas_Object_Image *o;
1830 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1833 o = (Evas_Object_Image *)(obj->object_data);
1834 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1838 #ifdef EVAS_FRAME_QUEUING
1839 if ((Evas_Colorspace)o->cur.cspace != cspace)
1842 evas_common_pipe_op_image_flush(o->engine_data);
1846 o->cur.cspace = cspace;
1848 obj->layer->evas->engine.func->image_colorspace_set(obj->layer->evas->engine.data.output,
1854 * Get the colorspace of a given image of the canvas.
1856 * @param obj The given image object pointer.
1857 * @return The colorspace of the image.
1859 * This function returns the colorspace of given canvas image.
1862 EAPI Evas_Colorspace
1863 evas_object_image_colorspace_get(const Evas_Object *obj)
1865 Evas_Object_Image *o;
1867 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1868 return EVAS_COLORSPACE_ARGB8888;
1870 o = (Evas_Object_Image *)(obj->object_data);
1871 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1872 return EVAS_COLORSPACE_ARGB8888;
1874 return o->cur.cspace;
1878 * Set the native surface of a given image of the canvas
1880 * @param obj The given canvas pointer.
1881 * @param surf The new native surface.
1883 * This function sets a native surface of a given canvas image.
1887 evas_object_image_native_surface_set(Evas_Object *obj, Evas_Native_Surface *surf)
1889 Evas_Object_Image *o;
1891 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1894 o = (Evas_Object_Image *)(obj->object_data);
1895 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1898 if (!obj->layer->evas->engine.func->image_native_set) return;
1900 obj->layer->evas->engine.func->image_native_set(obj->layer->evas->engine.data.output,
1906 * Get the native surface of a given image of the canvas
1908 * @param obj The given canvas pointer.
1909 * @return The native surface of the given canvas image.
1911 * This function returns the native surface of a given canvas image.
1914 EAPI Evas_Native_Surface *
1915 evas_object_image_native_surface_get(const Evas_Object *obj)
1917 Evas_Object_Image *o;
1919 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1922 o = (Evas_Object_Image *)(obj->object_data);
1923 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1926 if (!obj->layer->evas->engine.func->image_native_get) return NULL;
1927 return obj->layer->evas->engine.func->image_native_get(obj->layer->evas->engine.data.output,
1932 * Set the scale hint of a given image of the canvas.
1934 * @param obj The given canvas pointer.
1935 * @param hint The scale hint value.
1937 * This function sets the scale hint value of the given image of the canvas.
1941 evas_object_image_scale_hint_set(Evas_Object *obj, Evas_Image_Scale_Hint hint)
1943 Evas_Object_Image *o;
1945 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1948 o = (Evas_Object_Image *)(obj->object_data);
1949 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1952 if (o->scale_hint == hint) return;
1953 #ifdef EVAS_FRAME_QUEUING
1955 evas_common_pipe_op_image_flush(o->engine_data);
1957 o->scale_hint = hint;
1962 if (obj->layer->evas->engine.func->image_scale_hint_set)
1963 obj->layer->evas->engine.func->image_scale_hint_set
1964 (obj->layer->evas->engine.data.output,
1965 o->engine_data, o->scale_hint);
1966 if (obj->layer->evas->engine.func->image_stride_get)
1967 obj->layer->evas->engine.func->image_stride_get
1968 (obj->layer->evas->engine.data.output,
1969 o->engine_data, &stride);
1971 stride = o->cur.image.w * 4;
1972 o->cur.image.stride = stride;
1977 * Get the scale hint of a given image of the canvas.
1979 * @param obj The given canvas pointer.
1981 * This function returns the scale hint value of the given image of the canvas.
1984 EAPI Evas_Image_Scale_Hint
1985 evas_object_image_scale_hint_get(const Evas_Object *obj)
1987 Evas_Object_Image *o;
1989 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
1990 return EVAS_IMAGE_SCALE_HINT_NONE;
1992 o = (Evas_Object_Image *)(obj->object_data);
1993 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
1994 return EVAS_IMAGE_SCALE_HINT_NONE;
1996 return o->scale_hint;
2000 * Set the content hint of a given image of the canvas.
2002 * @param obj The given canvas pointer.
2003 * @param hint The content hint value.
2005 * This function sets the content hint value of the given image of the canvas.
2009 evas_object_image_content_hint_set(Evas_Object *obj, Evas_Image_Content_Hint hint)
2011 Evas_Object_Image *o;
2013 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
2016 o = (Evas_Object_Image *)(obj->object_data);
2017 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
2020 if (o->content_hint == hint) return;
2021 #ifdef EVAS_FRAME_QUEUING
2023 evas_common_pipe_op_image_flush(o->engine_data);
2025 o->content_hint = hint;
2030 if (obj->layer->evas->engine.func->image_content_hint_set)
2031 obj->layer->evas->engine.func->image_content_hint_set
2032 (obj->layer->evas->engine.data.output,
2033 o->engine_data, o->content_hint);
2034 if (obj->layer->evas->engine.func->image_stride_get)
2035 obj->layer->evas->engine.func->image_stride_get
2036 (obj->layer->evas->engine.data.output,
2037 o->engine_data, &stride);
2039 stride = o->cur.image.w * 4;
2040 o->cur.image.stride = stride;
2045 * Get the content hint of a given image of the canvas.
2047 * @param obj The given canvas pointer.
2049 * This function returns the content hint value of the given image of the canvas.
2052 EAPI Evas_Image_Content_Hint
2053 evas_object_image_content_hint_get(const Evas_Object *obj)
2055 Evas_Object_Image *o;
2057 MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
2058 return EVAS_IMAGE_CONTENT_HINT_NONE;
2060 o = (Evas_Object_Image *)(obj->object_data);
2061 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
2062 return EVAS_IMAGE_CONTENT_HINT_NONE;
2064 return o->content_hint;
2072 * @addtogroup Evas_Image_Group
2077 * Flush the image cache of the canvas.
2079 * @param e The given evas pointer.
2081 * This function flushes image cache of canvas.
2085 evas_image_cache_flush(Evas *e)
2087 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
2091 e->engine.func->image_cache_flush(e->engine.data.output);
2095 * Reload the image cache
2097 * @param e The given evas pointer.
2099 * This function reloads the image cache of canvas.
2103 evas_image_cache_reload(Evas *e)
2107 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
2111 evas_image_cache_flush(e);
2112 EINA_INLIST_FOREACH(e->layers, layer)
2116 EINA_INLIST_FOREACH(layer->objects, obj)
2118 Evas_Object_Image *o;
2120 o = (Evas_Object_Image *)(obj->object_data);
2121 if (o->magic == MAGIC_OBJ_IMAGE)
2123 evas_object_image_unload(obj, 1);
2127 evas_image_cache_flush(e);
2128 EINA_INLIST_FOREACH(e->layers, layer)
2132 EINA_INLIST_FOREACH(layer->objects, obj)
2134 Evas_Object_Image *o;
2136 o = (Evas_Object_Image *)(obj->object_data);
2137 if (o->magic == MAGIC_OBJ_IMAGE)
2139 evas_object_image_load(obj);
2141 evas_object_change(obj);
2145 evas_image_cache_flush(e);
2149 * Set the image cache.
2151 * @param e The given evas pointer.
2152 * @param size The cache size.
2154 * This function sets the image cache of canvas.
2158 evas_image_cache_set(Evas *e, int size)
2160 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
2164 if (size < 0) size = 0;
2165 e->engine.func->image_cache_set(e->engine.data.output, size);
2169 * Set the image cache
2171 * @param e The given evas pointer.
2173 * This function returns the image cache of canvas.
2177 evas_image_cache_get(const Evas *e)
2179 MAGIC_CHECK(e, Evas, MAGIC_EVAS);
2183 return e->engine.func->image_cache_get(e->engine.data.output);
2190 /* all nice and private */
2193 evas_object_image_unload(Evas_Object *obj, Eina_Bool dirty)
2195 Evas_Object_Image *o;
2197 o = (Evas_Object_Image *)(obj->object_data);
2199 if ((!o->cur.file) ||
2200 (o->pixels_checked_out > 0)) return;
2204 o->engine_data = obj->layer->evas->engine.func->image_dirty_region
2205 (obj->layer->evas->engine.data.output,
2208 o->cur.image.w, o->cur.image.h);
2211 obj->layer->evas->engine.func->image_free(obj->layer->evas->engine.data.output,
2213 o->engine_data = NULL;
2214 o->load_error = EVAS_LOAD_ERROR_NONE;
2215 o->cur.has_alpha = 1;
2216 o->cur.cspace = EVAS_COLORSPACE_ARGB8888;
2219 o->cur.image.stride = 0;
2223 evas_object_image_load(Evas_Object *obj)
2225 Evas_Object_Image *o;
2226 Evas_Image_Load_Opts lo;
2228 o = (Evas_Object_Image *)(obj->object_data);
2229 if (o->engine_data) return;
2231 lo.scale_down_by = o->load_opts.scale_down_by;
2232 lo.dpi = o->load_opts.dpi;
2233 lo.w = o->load_opts.w;
2234 lo.h = o->load_opts.h;
2235 lo.region.x = o->load_opts.region.x;
2236 lo.region.y = o->load_opts.region.y;
2237 lo.region.w = o->load_opts.region.w;
2238 lo.region.h = o->load_opts.region.h;
2239 o->engine_data = obj->layer->evas->engine.func->image_load
2240 (obj->layer->evas->engine.data.output,
2250 obj->layer->evas->engine.func->image_size_get
2251 (obj->layer->evas->engine.data.output,
2252 o->engine_data, &w, &h);
2253 if (obj->layer->evas->engine.func->image_stride_get)
2254 obj->layer->evas->engine.func->image_stride_get
2255 (obj->layer->evas->engine.data.output,
2256 o->engine_data, &stride);
2259 o->cur.has_alpha = obj->layer->evas->engine.func->image_alpha_get
2260 (obj->layer->evas->engine.data.output,
2262 o->cur.cspace = obj->layer->evas->engine.func->image_colorspace_get
2263 (obj->layer->evas->engine.data.output,
2267 o->cur.image.stride = stride;
2271 o->load_error = EVAS_LOAD_ERROR_GENERIC;
2276 evas_object_image_figure_x_fill(Evas_Object *obj, Evas_Coord start, Evas_Coord size, Evas_Coord *size_ret)
2280 w = ((size * obj->layer->evas->output.w) /
2281 (Evas_Coord)obj->layer->evas->viewport.w);
2282 if (size <= 0) size = 1;
2285 while (start - size > 0) start -= size;
2289 while (start < 0) start += size;
2291 start = ((start * obj->layer->evas->output.w) /
2292 (Evas_Coord)obj->layer->evas->viewport.w);
2298 evas_object_image_figure_y_fill(Evas_Object *obj, Evas_Coord start, Evas_Coord size, Evas_Coord *size_ret)
2302 h = ((size * obj->layer->evas->output.h) /
2303 (Evas_Coord)obj->layer->evas->viewport.h);
2304 if (size <= 0) size = 1;
2307 while (start - size > 0) start -= size;
2311 while (start < 0) start += size;
2313 start = ((start * obj->layer->evas->output.h) /
2314 (Evas_Coord)obj->layer->evas->viewport.h);
2320 evas_object_image_init(Evas_Object *obj)
2322 /* alloc image ob, setup methods and default values */
2323 obj->object_data = evas_object_image_new();
2324 /* set up default settings for this kind of object */
2325 obj->cur.color.r = 255;
2326 obj->cur.color.g = 255;
2327 obj->cur.color.b = 255;
2328 obj->cur.color.a = 255;
2329 obj->cur.geometry.x = 0;
2330 obj->cur.geometry.y = 0;
2331 obj->cur.geometry.w = 0;
2332 obj->cur.geometry.h = 0;
2334 obj->cur.anti_alias = 0;
2335 obj->cur.render_op = EVAS_RENDER_BLEND;
2336 /* set up object-specific settings */
2337 obj->prev = obj->cur;
2338 /* set up methods (compulsory) */
2339 obj->func = &object_func;
2344 evas_object_image_new(void)
2346 Evas_Object_Image *o;
2348 /* alloc obj private data */
2349 EVAS_MEMPOOL_INIT(_mp_obj, "evas_object_image", Evas_Object_Image, 256, NULL);
2350 o = EVAS_MEMPOOL_ALLOC(_mp_obj, Evas_Object_Image);
2351 if (!o) return NULL;
2352 EVAS_MEMPOOL_PREP(_mp_obj, o, Evas_Object_Image);
2353 o->magic = MAGIC_OBJ_IMAGE;
2356 o->cur.smooth_scale = 1;
2357 o->cur.border.fill = 1;
2358 o->cur.border.scale = 1.0;
2359 o->cur.cspace = EVAS_COLORSPACE_ARGB8888;
2360 o->cur.spread = EVAS_TEXTURE_REPEAT;
2361 o->cur.opaque_valid = 0;
2367 evas_object_image_free(Evas_Object *obj)
2369 Evas_Object_Image *o;
2372 /* frees private object data. very simple here */
2373 o = (Evas_Object_Image *)(obj->object_data);
2374 MAGIC_CHECK(o, Evas_Object_Image, MAGIC_OBJ_IMAGE);
2378 if (o->cur.file) eina_stringshare_del(o->cur.file);
2379 if (o->cur.key) eina_stringshare_del(o->cur.key);
2382 obj->layer->evas->engine.func->image_data_preload_cancel(obj->layer->evas->engine.data.output,
2385 obj->layer->evas->engine.func->image_free(obj->layer->evas->engine.data.output,
2388 o->engine_data = NULL;
2390 EINA_LIST_FREE(o->pixel_updates, r)
2391 eina_rectangle_free(r);
2392 EVAS_MEMPOOL_FREE(_mp_obj, o);
2396 evas_object_image_render(Evas_Object *obj, void *output, void *context, void *surface, int x, int y)
2398 Evas_Object_Image *o;
2400 /* render object to surface with context, and offset by x,y */
2401 o = (Evas_Object_Image *)(obj->object_data);
2403 if ((o->cur.fill.w < 1) || (o->cur.fill.h < 1))
2404 return; /* no error message, already printed in pre_render */
2406 obj->layer->evas->engine.func->context_color_set(output,
2408 255, 255, 255, 255);
2410 if ((obj->cur.cache.clip.r == 255) &&
2411 (obj->cur.cache.clip.g == 255) &&
2412 (obj->cur.cache.clip.b == 255) &&
2413 (obj->cur.cache.clip.a == 255))
2415 obj->layer->evas->engine.func->context_multiplier_unset(output,
2419 obj->layer->evas->engine.func->context_multiplier_set(output,
2421 obj->cur.cache.clip.r,
2422 obj->cur.cache.clip.g,
2423 obj->cur.cache.clip.b,
2424 obj->cur.cache.clip.a);
2426 obj->layer->evas->engine.func->context_render_op_set(output, context,
2427 obj->cur.render_op);
2430 Evas_Coord idw, idh, idx, idy;
2433 if (o->dirty_pixels)
2435 if (o->func.get_pixels)
2437 o->func.get_pixels(o->func.get_pixels_data, obj);
2438 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);
2440 o->dirty_pixels = 0;
2442 if ((obj->cur.map) && (obj->cur.map->count == 4) && (obj->cur.usemap))
2444 const Evas_Map_Point *p, *p_end;
2445 RGBA_Map_Point pts[4], *pt;
2447 p = obj->cur.map->points;
2451 pts[0].px = obj->cur.map->persp.px << FP;
2452 pts[0].py = obj->cur.map->persp.py << FP;
2453 pts[0].foc = obj->cur.map->persp.foc << FP;
2454 pts[0].z0 = obj->cur.map->persp.z0 << FP;
2456 for (; p < p_end; p++, pt++)
2458 pt->x = (p->x + x) << FP;
2459 pt->y = (p->y + y) << FP;
2460 pt->z = (p->z) << FP;
2461 pt->x3 = p->px << FP;
2462 pt->y3 = p->py << FP;
2465 pt->col = ARGB_JOIN(p->a, p->r, p->g, p->b);
2467 obj->layer->evas->engine.func->image_map4_draw
2468 (output, context, surface, o->engine_data, pts,
2469 o->cur.smooth_scale | obj->cur.map->smooth, 0);
2473 obj->layer->evas->engine.func->image_scale_hint_set(output,
2476 o->engine_data = obj->layer->evas->engine.func->image_border_set(output, o->engine_data,
2477 o->cur.border.l, o->cur.border.r,
2478 o->cur.border.t, o->cur.border.b);
2479 idx = evas_object_image_figure_x_fill(obj, o->cur.fill.x, o->cur.fill.w, &idw);
2480 idy = evas_object_image_figure_y_fill(obj, o->cur.fill.y, o->cur.fill.h, &idh);
2481 if (idw < 1) idw = 1;
2482 if (idh < 1) idh = 1;
2483 if (idx > 0) idx -= idw;
2484 if (idy > 0) idy -= idh;
2485 while ((int)idx < obj->cur.geometry.w)
2492 if ((o->cur.fill.w == obj->cur.geometry.w) &&
2493 (o->cur.fill.x == 0))
2496 iw = obj->cur.geometry.w;
2499 iw = ((int)(idx + idw)) - ix;
2500 while ((int)idy < obj->cur.geometry.h)
2505 if ((o->cur.fill.h == obj->cur.geometry.h) &&
2506 (o->cur.fill.y == 0))
2508 ih = obj->cur.geometry.h;
2512 ih = ((int)(idy + idh)) - iy;
2513 if ((o->cur.border.l == 0) &&
2514 (o->cur.border.r == 0) &&
2515 (o->cur.border.t == 0) &&
2516 (o->cur.border.b == 0) &&
2517 (o->cur.border.fill != 0))
2518 obj->layer->evas->engine.func->image_draw(output,
2525 obj->cur.geometry.x + ix + x,
2526 obj->cur.geometry.y + iy + y,
2528 o->cur.smooth_scale);
2531 int inx, iny, inw, inh, outx, outy, outw, outh;
2532 int bl, br, bt, bb, bsl, bsr, bst, bsb;
2533 int imw, imh, ox, oy;
2535 ox = obj->cur.geometry.x + ix + x;
2536 oy = obj->cur.geometry.y + iy + y;
2537 imw = o->cur.image.w;
2538 imh = o->cur.image.h;
2539 bl = o->cur.border.l;
2540 br = o->cur.border.r;
2541 bt = o->cur.border.t;
2542 bb = o->cur.border.b;
2548 if ((bl + br) > imw)
2558 if ((bt + bb) > imh)
2563 if (o->cur.border.scale != 1.0)
2565 bsl = ((double)bl * o->cur.border.scale);
2566 bsr = ((double)br * o->cur.border.scale);
2567 bst = ((double)bt * o->cur.border.scale);
2568 bsb = ((double)bb * o->cur.border.scale);
2572 bsl = bl; bsr = br; bst = bt; bsb = bb;
2578 outx = ox; outy = oy;
2579 outw = bsl; outh = bst;
2580 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);
2584 inw = imw - bl - br; inh = bt;
2585 outx = ox + bsl; outy = oy;
2586 outw = iw - bsl - bsr; outh = bst;
2587 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);
2590 inx = imw - br; iny = 0;
2592 outx = ox + iw - bsr; outy = oy;
2593 outw = bsr; outh = bst;
2594 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);
2598 inw = bl; inh = imh - bt - bb;
2599 outx = ox; outy = oy + bst;
2600 outw = bsl; outh = ih - bst - bsb;
2601 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);
2604 if (o->cur.border.fill > EVAS_BORDER_FILL_NONE)
2607 inw = imw - bl - br; inh = imh - bt - bb;
2608 outx = ox + bsl; outy = oy + bst;
2609 outw = iw - bsl - bsr; outh = ih - bst - bsb;
2610 if ((o->cur.border.fill == EVAS_BORDER_FILL_SOLID) &&
2611 (obj->cur.cache.clip.a == 255) &&
2612 (obj->cur.render_op == EVAS_RENDER_BLEND))
2614 obj->layer->evas->engine.func->context_render_op_set(output, context,
2616 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);
2617 obj->layer->evas->engine.func->context_render_op_set(output, context,
2618 obj->cur.render_op);
2621 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);
2625 inx = imw - br; iny = bt;
2626 inw = br; inh = imh - bt - bb;
2627 outx = ox + iw - bsr; outy = oy + bst;
2628 outw = bsr; outh = ih - bst - bsb;
2629 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);
2632 inx = 0; iny = imh - bb;
2634 outx = ox; outy = oy + ih - bsb;
2635 outw = bsl; outh = bsb;
2636 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);
2639 inx = bl; iny = imh - bb;
2640 inw = imw - bl - br; inh = bb;
2641 outx = ox + bsl; outy = oy + ih - bsb;
2642 outw = iw - bsl - bsr; outh = bsb;
2643 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);
2646 inx = imw - br; iny = imh - bb;
2648 outx = ox + iw - bsr; outy = oy + ih - bsb;
2649 outw = bsr; outh = bsb;
2650 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);
2653 if (dobreak_h) break;
2657 if (dobreak_w) break;
2664 evas_object_image_render_pre(Evas_Object *obj)
2666 Evas_Object_Image *o;
2669 /* dont pre-render the obj twice! */
2670 if (obj->pre_render_done) return;
2671 obj->pre_render_done = 1;
2672 /* pre-render phase. this does anything an object needs to do just before */
2673 /* rendering. this could mean loading the image data, retrieving it from */
2674 /* elsewhere, decoding video etc. */
2675 /* then when this is done the object needs to figure if it changed and */
2676 /* if so what and where and add the appropriate redraw rectangles */
2677 o = (Evas_Object_Image *)(obj->object_data);
2679 if ((o->cur.fill.w < 1) || (o->cur.fill.h < 1))
2681 ERR("%p has invalid fill size: %dx%d. Ignored",
2682 obj, o->cur.fill.w, o->cur.fill.h);
2686 /* if someone is clipping this obj - go calculate the clipper */
2687 if (obj->cur.clipper)
2689 if (obj->cur.cache.clip.dirty)
2690 evas_object_clip_recalc(obj->cur.clipper);
2691 obj->cur.clipper->func->render_pre(obj->cur.clipper);
2693 /* now figure what changed and add draw rects */
2694 /* if it just became visible or invisible */
2695 is_v = evas_object_is_visible(obj);
2696 was_v = evas_object_was_visible(obj);
2699 evas_object_render_pre_visible_change(&obj->layer->evas->clip_changes, obj, is_v, was_v);
2700 if (!o->pixel_updates) goto done;
2702 if ((obj->cur.map != obj->prev.map) ||
2703 (obj->cur.usemap != obj->prev.usemap))
2705 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
2708 /* it's not visible - we accounted for it appearing or not so just abort */
2709 if (!is_v) goto done;
2710 /* clipper changed this is in addition to anything else for obj */
2711 evas_object_render_pre_clipper_change(&obj->layer->evas->clip_changes, obj);
2712 /* if we restacked (layer or just within a layer) and don't clip anyone */
2715 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
2716 if (!o->pixel_updates) goto done;
2718 /* if it changed color */
2719 if ((obj->cur.color.r != obj->prev.color.r) ||
2720 (obj->cur.color.g != obj->prev.color.g) ||
2721 (obj->cur.color.b != obj->prev.color.b) ||
2722 (obj->cur.color.a != obj->prev.color.a))
2724 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
2725 if (!o->pixel_updates) goto done;
2727 /* if it changed render op */
2728 if (obj->cur.render_op != obj->prev.render_op)
2730 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
2731 if (!o->pixel_updates) goto done;
2733 /* if it changed anti_alias */
2734 if (obj->cur.anti_alias != obj->prev.anti_alias)
2736 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
2737 if (!o->pixel_updates) goto done;
2741 if (((o->cur.file) && (!o->prev.file)) ||
2742 ((!o->cur.file) && (o->prev.file)) ||
2743 ((o->cur.key) && (!o->prev.key)) ||
2744 ((!o->cur.key) && (o->prev.key))
2747 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
2748 if (!o->pixel_updates) goto done;
2750 if ((o->cur.image.w != o->prev.image.w) ||
2751 (o->cur.image.h != o->prev.image.h) ||
2752 (o->cur.has_alpha != o->prev.has_alpha) ||
2753 (o->cur.cspace != o->prev.cspace) ||
2754 (o->cur.smooth_scale != o->prev.smooth_scale))
2756 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
2757 if (!o->pixel_updates) goto done;
2759 if ((o->cur.border.l != o->prev.border.l) ||
2760 (o->cur.border.r != o->prev.border.r) ||
2761 (o->cur.border.t != o->prev.border.t) ||
2762 (o->cur.border.b != o->prev.border.b) ||
2763 (o->cur.border.fill != o->prev.border.fill) ||
2764 (o->cur.border.scale != o->prev.border.scale))
2766 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
2767 if (!o->pixel_updates) goto done;
2769 if (o->dirty_pixels)
2771 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
2772 if (!o->pixel_updates) goto done;
2775 /* if it changed geometry - and obviously not visibility or color */
2776 /* calculate differences since we have a constant color fill */
2777 /* we really only need to update the differences */
2778 #if 0 // XXX: maybe buggy?
2779 if (((obj->cur.geometry.x != obj->prev.geometry.x) ||
2780 (obj->cur.geometry.y != obj->prev.geometry.y) ||
2781 (obj->cur.geometry.w != obj->prev.geometry.w) ||
2782 (obj->cur.geometry.h != obj->prev.geometry.h)) &&
2783 (o->cur.fill.w == o->prev.fill.w) &&
2784 (o->cur.fill.h == o->prev.fill.h) &&
2785 ((o->cur.fill.x + obj->cur.geometry.x) == (o->prev.fill.x + obj->prev.geometry.x)) &&
2786 ((o->cur.fill.y + obj->cur.geometry.y) == (o->prev.fill.y + obj->prev.geometry.y)) &&
2790 evas_rects_return_difference_rects(&obj->layer->evas->clip_changes,
2791 obj->cur.geometry.x,
2792 obj->cur.geometry.y,
2793 obj->cur.geometry.w,
2794 obj->cur.geometry.h,
2795 obj->prev.geometry.x,
2796 obj->prev.geometry.y,
2797 obj->prev.geometry.w,
2798 obj->prev.geometry.h);
2799 if (!o->pixel_updates) goto done;
2802 if (((obj->cur.geometry.x != obj->prev.geometry.x) ||
2803 (obj->cur.geometry.y != obj->prev.geometry.y) ||
2804 (obj->cur.geometry.w != obj->prev.geometry.w) ||
2805 (obj->cur.geometry.h != obj->prev.geometry.h))
2808 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
2809 if (!o->pixel_updates) goto done;
2813 if ((o->cur.fill.x != o->prev.fill.x) ||
2814 (o->cur.fill.y != o->prev.fill.y) ||
2815 (o->cur.fill.w != o->prev.fill.w) ||
2816 (o->cur.fill.h != o->prev.fill.h))
2818 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
2819 if (!o->pixel_updates) goto done;
2821 if ((o->cur.border.l == 0) &&
2822 (o->cur.border.r == 0) &&
2823 (o->cur.border.t == 0) &&
2824 (o->cur.border.b == 0) &&
2825 (o->cur.image.w > 0) &&
2826 (o->cur.image.h > 0))
2830 EINA_LIST_FREE(o->pixel_updates, rr)
2832 Evas_Coord idw, idh, idx, idy;
2835 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);
2837 idx = evas_object_image_figure_x_fill(obj, o->cur.fill.x, o->cur.fill.w, &idw);
2838 idy = evas_object_image_figure_y_fill(obj, o->cur.fill.y, o->cur.fill.h, &idh);
2840 if (idw < 1) idw = 1;
2841 if (idh < 1) idh = 1;
2842 if (idx > 0) idx -= idw;
2843 if (idy > 0) idy -= idh;
2844 while (idx < obj->cur.geometry.w)
2850 w = ((int)(idx + idw)) - x;
2851 while (idy < obj->cur.geometry.h)
2856 h = ((int)(idy + idh)) - y;
2858 r.x = ((rr->x - 1) * w) / o->cur.image.w;
2859 r.y = ((rr->y - 1) * h) / o->cur.image.h;
2860 r.w = ((rr->w + 2) * w) / o->cur.image.w;
2861 r.h = ((rr->h + 2) * h) / o->cur.image.h;
2862 r.x += obj->cur.geometry.x + x;
2863 r.y += obj->cur.geometry.y + y;
2864 evas_add_rect(&obj->layer->evas->clip_changes, r.x, r.y, r.w, r.h);
2870 eina_rectangle_free(rr);
2876 if (o->pixel_updates)
2880 EINA_LIST_FREE(o->pixel_updates, r)
2881 eina_rectangle_free(r);
2882 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);
2883 evas_object_render_pre_prev_cur_add(&obj->layer->evas->clip_changes, obj);
2888 /* it obviously didn't change - add a NO obscure - this "unupdates" this */
2889 /* area so if there were updates for it they get wiped. don't do it if we */
2890 /* aren't fully opaque and we are visible */
2891 if (evas_object_is_visible(obj) &&
2892 evas_object_is_opaque(obj))
2894 obj->layer->evas->engine.func->output_redraws_rect_del(obj->layer->evas->engine.data.output,
2895 obj->cur.cache.clip.x,
2896 obj->cur.cache.clip.y,
2897 obj->cur.cache.clip.w,
2898 obj->cur.cache.clip.h);
2901 evas_object_render_pre_effect_updates(&obj->layer->evas->clip_changes, obj, is_v, was_v);
2905 evas_object_image_render_post(Evas_Object *obj)
2907 Evas_Object_Image *o;
2910 /* this moves the current data to the previous state parts of the object */
2911 /* in whatever way is safest for the object. also if we don't need object */
2912 /* data anymore we can free it if the object deems this is a good idea */
2913 o = (Evas_Object_Image *)(obj->object_data);
2914 /* remove those pesky changes */
2915 evas_object_clip_changes_clean(obj);
2916 EINA_LIST_FREE(o->pixel_updates, r)
2917 eina_rectangle_free(r);
2918 /* move cur to prev safely for object data */
2919 obj->prev = obj->cur;
2922 /* FIXME: copy strings across */
2925 static unsigned int evas_object_image_id_get(Evas_Object *obj)
2927 Evas_Object_Image *o;
2929 o = (Evas_Object_Image *)(obj->object_data);
2931 return MAGIC_OBJ_IMAGE;
2934 static unsigned int evas_object_image_visual_id_get(Evas_Object *obj)
2936 Evas_Object_Image *o;
2938 o = (Evas_Object_Image *)(obj->object_data);
2940 return MAGIC_OBJ_IMAGE;
2943 static void *evas_object_image_engine_data_get(Evas_Object *obj)
2945 Evas_Object_Image *o;
2947 o = (Evas_Object_Image *)(obj->object_data);
2948 if (!o) return NULL;
2949 return o->engine_data;
2953 evas_object_image_is_opaque(Evas_Object *obj)
2955 Evas_Object_Image *o;
2957 /* this returns 1 if the internal object data implies that the object is */
2958 /* currently fully opaque over the entire rectangle it occupies */
2959 o = (Evas_Object_Image *)(obj->object_data);
2960 if (o->cur.opaque_valid)
2962 if (!o->cur.opaque) return 0;
2967 o->cur.opaque_valid = 1;
2968 if ((o->cur.fill.w < 1) || (o->cur.fill.h < 1))
2970 if (((o->cur.border.l != 0) ||
2971 (o->cur.border.r != 0) ||
2972 (o->cur.border.t != 0) ||
2973 (o->cur.border.b != 0)) &&
2974 (!o->cur.border.fill)) return 0;
2975 if (!o->engine_data) return 0;
2978 if ((obj->cur.map) && (obj->cur.usemap)) return 0;
2979 if (obj->cur.render_op == EVAS_RENDER_COPY) return 1;
2980 if (o->cur.has_alpha) return 0;
2985 evas_object_image_was_opaque(Evas_Object *obj)
2987 Evas_Object_Image *o;
2989 /* this returns 1 if the internal object data implies that the object was */
2990 /* previously fully opaque over the entire rectangle it occupies */
2991 o = (Evas_Object_Image *)(obj->object_data);
2992 if (o->prev.opaque_valid)
2994 if (!o->prev.opaque) return 0;
2999 o->prev.opaque_valid = 1;
3000 if ((o->prev.fill.w < 1) || (o->prev.fill.h < 1))
3002 if (((o->prev.border.l != 0) ||
3003 (o->prev.border.r != 0) ||
3004 (o->prev.border.t != 0) ||
3005 (o->prev.border.b != 0)) &&
3006 (!o->prev.border.fill)) return 0;
3007 if (!o->engine_data) return 0;
3010 if (obj->prev.usemap) return 0;
3011 if (obj->prev.render_op == EVAS_RENDER_COPY) return 1;
3012 if (o->prev.has_alpha) return 0;
3013 if (obj->prev.render_op != EVAS_RENDER_BLEND) return 0;
3018 evas_object_image_is_inside(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
3020 Evas_Object_Image *o;
3022 int w, h, stride, iw, ih;
3025 o = (Evas_Object_Image *)(obj->object_data);
3027 x -= obj->cur.cache.clip.x;
3028 y -= obj->cur.cache.clip.y;
3029 w = obj->cur.cache.clip.w;
3030 h = obj->cur.cache.clip.h;
3031 iw = o->cur.image.w;
3032 ih = o->cur.image.h;
3034 if ((x < 0) || (y < 0) || (x >= w) || (y >= h)) return 0;
3035 if (!o->cur.has_alpha) return 1;
3039 x = obj->cur.map->mx;
3040 y = obj->cur.map->my;
3044 int bl, br, bt, bb, bsl, bsr, bst, bsb;
3046 bl = o->cur.border.l;
3047 br = o->cur.border.r;
3048 bt = o->cur.border.t;
3049 bb = o->cur.border.b;
3070 if (o->cur.border.scale != 1.0)
3072 bsl = ((double)bl * o->cur.border.scale);
3073 bsr = ((double)br * o->cur.border.scale);
3074 bst = ((double)bt * o->cur.border.scale);
3075 bsb = ((double)bb * o->cur.border.scale);
3079 bsl = bl; bsr = br; bst = bt; bsb = bb;
3092 if (o->cur.border.fill != EVAS_BORDER_FILL_DEFAULT)
3094 if ((x > bsl) && (x < (w - bsr)) &&
3095 (y > bst) && (y < (h - bsb)))
3097 if (o->cur.border.fill == EVAS_BORDER_FILL_SOLID) return 1;
3102 if (x < bsl) x = (x * bl) / bsl;
3103 else if (x > (w - bsr)) x = iw - (((w - x) * br) / bsr);
3104 else if ((bsl + bsr) < w) x = bl + (((x - bsl) * (iw - bl - br)) / (w - bsl - bsr));
3107 if (y < bst) y = (y * bt) / bst;
3108 else if (y > (h - bsb)) y = ih - (((h - y) * bb) / bsb);
3109 else if ((bst + bsb) < h) y = bt + (((y - bst) * (ih - bt - bb)) / (h - bst - bsb));
3115 if (x >= iw) x = iw - 1;
3116 if (y >= ih) y = ih - 1;
3118 stride = o->cur.image.stride;
3120 o->engine_data = obj->layer->evas->engine.func->image_data_get
3121 (obj->layer->evas->engine.data.output,
3128 switch (o->cur.cspace)
3130 case EVAS_COLORSPACE_ARGB8888:
3131 data = ((DATA32*)(data) + ((y * (stride >> 2)) + x));
3132 a = (*((DATA32*)(data)) >> 24) & 0xff;
3134 case EVAS_COLORSPACE_RGB565_A5P:
3135 data = (void*) ((DATA16*)(data) + (h * (stride >> 1)));
3136 data = (void*) ((DATA8*)(data) + ((y * (stride >> 1)) + x));
3137 a = (*((DATA8*)(data))) & 0x1f;
3148 evas_object_image_has_opaque_rect(Evas_Object *obj)
3150 Evas_Object_Image *o;
3152 o = (Evas_Object_Image *)(obj->object_data);
3153 if ((obj->cur.map) && (obj->cur.usemap)) return 0;
3154 if (((o->cur.border.l | o->cur.border.r | o->cur.border.t | o->cur.border.b) != 0) &&
3155 (o->cur.border.fill == EVAS_BORDER_FILL_SOLID) &&
3156 (obj->cur.render_op == EVAS_RENDER_BLEND) &&
3157 (obj->cur.cache.clip.a == 255) &&
3158 (o->cur.fill.x == 0) &&
3159 (o->cur.fill.y == 0) &&
3160 (o->cur.fill.w == obj->cur.geometry.w) &&
3161 (o->cur.fill.h == obj->cur.geometry.h)
3167 evas_object_image_get_opaque_rect(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
3169 Evas_Object_Image *o;
3171 o = (Evas_Object_Image *)(obj->object_data);
3172 if (o->cur.border.scale == 1.0)
3174 *x = obj->cur.geometry.x + o->cur.border.l;
3175 *y = obj->cur.geometry.y + o->cur.border.t;
3176 *w = obj->cur.geometry.w - (o->cur.border.l + o->cur.border.r);
3178 *h = obj->cur.geometry.h - (o->cur.border.t + o->cur.border.b);
3183 *x = obj->cur.geometry.x + (o->cur.border.l * o->cur.border.scale);
3184 *y = obj->cur.geometry.y + (o->cur.border.t * o->cur.border.scale);
3185 *w = obj->cur.geometry.w - ((o->cur.border.l * o->cur.border.scale) + (o->cur.border.r * o->cur.border.scale));
3187 *h = obj->cur.geometry.h - ((o->cur.border.t * o->cur.border.scale) + (o->cur.border.b * o->cur.border.scale));
3194 evas_object_image_can_map(Evas_Object *obj __UNUSED__)
3200 evas_object_image_data_convert_internal(Evas_Object_Image *o, void *data, Evas_Colorspace to_cspace)
3207 switch (o->cur.cspace)
3209 case EVAS_COLORSPACE_ARGB8888:
3210 out = evas_common_convert_argb8888_to(data,
3213 o->cur.image.stride >> 2,
3217 case EVAS_COLORSPACE_RGB565_A5P:
3218 out = evas_common_convert_rgb565_a5p_to(data,
3221 o->cur.image.stride >> 1,
3233 evas_object_image_filled_resize_listener(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *einfo __UNUSED__)
3237 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
3238 evas_object_image_fill_set(obj, 0, 0, w, h);