This is an automated email from the git hooks/post-receive script.

git pushed a commit to reference refs/pull/142/head
in repository efl.

View the commit online.

commit 88ad7704302e47fd41b470c35f6cc6bdca828e4b
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 18:37:53 2026 -0600

    evas:tests: cover the image buffer crop property
    
    The buffer is four solid quadrants, so a crop pinned to one of them
    paints the object in exactly one color and every check is an exact
    pixel comparison, whatever the scaler does.
    
    They cover the getter and setter, each quadrant, clamping (an oversized
    crop, a negative origin, and a crop outside the buffer, which must leave
    the background visible), damage inside and outside the crop, the
    nine-patch path, and hit testing with precise_is_inside.
    
    Co-Authored-By: Claude Opus 5 <[email protected]>
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/tests/evas/evas_test_image.c | 299 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 299 insertions(+)

diff --git a/src/tests/evas/evas_test_image.c b/src/tests/evas/evas_test_image.c
index b77587bd29..186e242134 100644
--- a/src/tests/evas/evas_test_image.c
+++ b/src/tests/evas/evas_test_image.c
@@ -1613,6 +1613,297 @@ EFL_START_TEST(evas_object_image_load_head_skip)
 }
 EFL_END_TEST
 
+#ifdef BUILD_ENGINE_BUFFER
+/* The crop tests draw a 4x4 buffer of four solid 2x2 quadrants over a 20x20
+ * object. A crop pinned to one quadrant must paint the object in exactly one
+ * color, whatever the scaler does, so every check is an exact comparison. */
+#define CROP_IMG_W 4
+#define CROP_IMG_H 4
+#define CROP_OBJ_W 20
+#define CROP_OBJ_H 20
+
+#define CROP_TL 0xffff0000
+#define CROP_TR 0xff00ff00
+#define CROP_BL 0xff0000ff
+#define CROP_BR 0xffffff00
+#define CROP_BG 0xff123456
+
+typedef struct _Crop_Canvas Crop_Canvas;
+struct _Crop_Canvas
+{
+   Ecore_Evas *ee;
+   Evas *e;
+   Evas_Object *bg;
+   Evas_Object *img;
+};
+
+static void
+_crop_quadrant_fill(Evas_Object *img, int qx, int qy, unsigned int color)
+{
+   unsigned int *data;
+   int x, y;
+
+   data = "" EINA_TRUE);
+   fail_if(!data);
+   for (y = qy * (CROP_IMG_H / 2); y < (qy + 1) * (CROP_IMG_H / 2); y++)
+     {
+        for (x = qx * (CROP_IMG_W / 2); x < (qx + 1) * (CROP_IMG_W / 2); x++)
+          data[(y * CROP_IMG_W) + x] = color;
+     }
+   evas_object_image_data_set(img, data);
+   evas_object_image_data_update_add(img, qx * (CROP_IMG_W / 2),
+                                     qy * (CROP_IMG_H / 2),
+                                     CROP_IMG_W / 2, CROP_IMG_H / 2);
+}
+
+static void
+_crop_canvas_init(Crop_Canvas *cc)
+{
+   cc->ee = ecore_evas_buffer_new(CROP_OBJ_W, CROP_OBJ_H);
+   fail_if(!cc->ee);
+   ecore_evas_show(cc->ee);
+   ecore_evas_manual_render_set(cc->ee, EINA_TRUE);
+   cc->e = ecore_evas_get(cc->ee);
+
+   cc->bg = evas_object_rectangle_add(cc->e);
+   evas_object_color_set(cc->bg, 0x12, 0x34, 0x56, 0xff);
+   evas_object_resize(cc->bg, CROP_OBJ_W, CROP_OBJ_H);
+   evas_object_show(cc->bg);
+
+   cc->img = evas_object_image_add(cc->e);
+   evas_object_image_colorspace_set(cc->img, EVAS_COLORSPACE_ARGB8888);
+   evas_object_image_alpha_set(cc->img, EINA_FALSE);
+   evas_object_image_size_set(cc->img, CROP_IMG_W, CROP_IMG_H);
+   evas_object_image_smooth_scale_set(cc->img, EINA_FALSE);
+   _crop_quadrant_fill(cc->img, 0, 0, CROP_TL);
+   _crop_quadrant_fill(cc->img, 1, 0, CROP_TR);
+   _crop_quadrant_fill(cc->img, 0, 1, CROP_BL);
+   _crop_quadrant_fill(cc->img, 1, 1, CROP_BR);
+   evas_object_image_filled_set(cc->img, EINA_TRUE);
+   evas_object_resize(cc->img, CROP_OBJ_W, CROP_OBJ_H);
+   evas_object_show(cc->img);
+}
+
+static void
+_crop_canvas_shutdown(Crop_Canvas *cc)
+{
+   evas_object_del(cc->img);
+   evas_object_del(cc->bg);
+   ecore_evas_free(cc->ee);
+}
+
+static const unsigned int *
+_crop_canvas_render(Crop_Canvas *cc)
+{
+   const unsigned int *pix;
+
+   ecore_evas_manual_render(cc->ee);
+   pix = ecore_evas_buffer_pixels_get(cc->ee);
+   fail_if(!pix);
+   return pix;
+}
+
+static int
+_crop_pixels_not(const unsigned int *pix, unsigned int expected)
+{
+   int i, count = 0;
+
+   for (i = 0; i < (CROP_OBJ_W * CROP_OBJ_H); i++)
+     {
+        if (pix[i] != expected)
+          count++;
+     }
+   return count;
+}
+
+static Eina_Bool
+_crop_pixels_have(const unsigned int *pix, unsigned int color)
+{
+   return _crop_pixels_not(pix, color) < (CROP_OBJ_W * CROP_OBJ_H);
+}
+
+EFL_START_TEST(evas_object_image_buffer_crop_property)
+{
+   Evas *e = _setup_evas();
+   Evas_Object *o = evas_object_image_add(e);
+   int x, y, w, h;
+
+   evas_object_image_buffer_crop_get(o, &x, &y, &w, &h);
+   fail_if((x != 0) || (y != 0) || (w != 0) || (h != 0));
+
+   evas_object_image_buffer_crop_set(o, 3, 5, 7, 11);
+   evas_object_image_buffer_crop_get(o, &x, &y, &w, &h);
+   fail_if((x != 3) || (y != 5) || (w != 7) || (h != 11));
+
+   w = -1;
+   evas_object_image_buffer_crop_get(o, NULL, NULL, &w, NULL);
+   fail_if(w != 7);
+
+   /* Any empty extent unsets the crop, and unset has a single value. */
+   evas_object_image_buffer_crop_set(o, 3, 5, 0, 11);
+   evas_object_image_buffer_crop_get(o, &x, &y, &w, &h);
+   fail_if((x != 0) || (y != 0) || (w != 0) || (h != 0));
+
+   evas_object_image_buffer_crop_set(o, 3, 5, 7, -1);
+   evas_object_image_buffer_crop_get(o, &x, &y, &w, &h);
+   fail_if((x != 0) || (y != 0) || (w != 0) || (h != 0));
+
+   evas_object_del(o);
+   evas_free(e);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_object_image_buffer_crop_render)
+{
+   static const struct {
+      int x, y;
+      unsigned int color;
+   } quad[] = {
+      { 0, 0, CROP_TL },
+      { 2, 0, CROP_TR },
+      { 0, 2, CROP_BL },
+      { 2, 2, CROP_BR },
+   };
+   Crop_Canvas cc;
+   const unsigned int *pix;
+   unsigned int i;
+
+   _crop_canvas_init(&cc);
+
+   for (i = 0; i < EINA_C_ARRAY_LENGTH(quad); i++)
+     {
+        evas_object_image_buffer_crop_set(cc.img, quad[i].x, quad[i].y, 2, 2);
+        pix = _crop_canvas_render(&cc);
+        ck_assert_msg(_crop_pixels_not(pix, quad[i].color) == 0,
+                      "crop at %d,%d did not fill the object with %#x",
+                      quad[i].x, quad[i].y, quad[i].color);
+     }
+
+   evas_object_image_buffer_crop_set(cc.img, 0, 0, 0, 0);
+   pix = _crop_canvas_render(&cc);
+   ck_assert_msg(_crop_pixels_have(pix, CROP_TL) &&
+                 _crop_pixels_have(pix, CROP_TR) &&
+                 _crop_pixels_have(pix, CROP_BL) &&
+                 _crop_pixels_have(pix, CROP_BR),
+                 "unsetting the crop did not restore the whole buffer");
+
+   _crop_canvas_shutdown(&cc);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_object_image_buffer_crop_clamp)
+{
+   Crop_Canvas cc;
+   const unsigned int *pix;
+
+   _crop_canvas_init(&cc);
+
+   evas_object_image_buffer_crop_set(cc.img, 2, 2, 100, 100);
+   pix = _crop_canvas_render(&cc);
+   ck_assert_msg(_crop_pixels_not(pix, CROP_BR) == 0,
+                 "an oversized crop did not clamp to the buffer");
+
+   evas_object_image_buffer_crop_set(cc.img, -2, -2, 4, 4);
+   pix = _crop_canvas_render(&cc);
+   ck_assert_msg(_crop_pixels_not(pix, CROP_TL) == 0,
+                 "a negative crop origin was not clamped to the buffer");
+
+   /* If the object still claimed to be opaque, the background under it
+    * would not be drawn. */
+   evas_object_image_buffer_crop_set(cc.img, CROP_IMG_W + 4, 0, 2, 2);
+   pix = _crop_canvas_render(&cc);
+   ck_assert_msg(_crop_pixels_not(pix, CROP_BG) == 0,
+                 "a crop outside the buffer still drew something");
+
+   _crop_canvas_shutdown(&cc);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_object_image_buffer_crop_damage)
+{
+   Crop_Canvas cc;
+   const unsigned int *pix;
+
+   _crop_canvas_init(&cc);
+   evas_object_image_buffer_crop_set(cc.img, 0, 0, 2, 2);
+   _crop_canvas_render(&cc);
+
+   _crop_quadrant_fill(cc.img, 0, 0, CROP_BR);
+   pix = _crop_canvas_render(&cc);
+   ck_assert_msg(_crop_pixels_not(pix, CROP_BR) == 0,
+                 "damage inside the crop was not painted");
+
+   _crop_quadrant_fill(cc.img, 1, 1, CROP_TR);
+   pix = _crop_canvas_render(&cc);
+   ck_assert_msg(_crop_pixels_not(pix, CROP_BR) == 0,
+                 "damage outside the crop leaked onto the canvas");
+
+   _crop_canvas_shutdown(&cc);
+}
+EFL_END_TEST
+
+static void
+_crop_mouse_move_cb(void *data, Evas *e EINA_UNUSED,
+                    Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+   Eina_Bool *hit = data;
+
+   *hit = EINA_TRUE;
+}
+
+EFL_START_TEST(evas_object_image_buffer_crop_hittest)
+{
+   Crop_Canvas cc;
+   Eina_Bool hit;
+
+   _crop_canvas_init(&cc);
+
+   /* evas_object_top_at_xy_get() never asks precise_is_inside, only event
+    * delivery does, so feed real pointer events. */
+   evas_object_image_alpha_set(cc.img, EINA_TRUE);
+   _crop_quadrant_fill(cc.img, 0, 0, 0x00000000);
+   evas_object_precise_is_inside_set(cc.img, EINA_TRUE);
+   evas_object_event_callback_add(cc.img, EVAS_CALLBACK_MOUSE_MOVE,
+                                  _crop_mouse_move_cb, &hit);
+   evas_event_feed_mouse_in(cc.e, 0, NULL);
+
+   evas_object_image_buffer_crop_set(cc.img, 2, 2, 2, 2);
+   _crop_canvas_render(&cc);
+   hit = EINA_FALSE;
+   evas_event_feed_mouse_move(cc.e, (CROP_OBJ_W / 2) + 1, (CROP_OBJ_H / 2) + 1,
+                              0, NULL);
+   ck_assert_msg(hit, "hit testing missed an opaque cropped region");
+
+   evas_object_image_buffer_crop_set(cc.img, 0, 0, 2, 2);
+   _crop_canvas_render(&cc);
+   hit = EINA_FALSE;
+   evas_event_feed_mouse_move(cc.e, CROP_OBJ_W / 2, CROP_OBJ_H / 2, 0, NULL);
+   ck_assert_msg(!hit,
+                 "hit testing did not follow the crop into a transparent region");
+
+   _crop_canvas_shutdown(&cc);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_object_image_buffer_crop_border)
+{
+   Crop_Canvas cc;
+   const unsigned int *pix;
+
+   _crop_canvas_init(&cc);
+
+   /* Every cell of the nine-patch must come from inside the crop. */
+   evas_object_image_border_set(cc.img, 1, 1, 1, 1);
+   evas_object_image_buffer_crop_set(cc.img, 2, 2, 2, 2);
+   pix = _crop_canvas_render(&cc);
+   ck_assert_msg(_crop_pixels_not(pix, CROP_BR) == 0,
+                 "the bordered draw path read outside the crop");
+
+   _crop_canvas_shutdown(&cc);
+}
+EFL_END_TEST
+#endif
+
 void evas_test_image_object(TCase *tc)
 {
    tcase_add_test(tc, evas_object_image_api);
@@ -1649,6 +1940,14 @@ void evas_test_image_object(TCase *tc)
    tcase_add_test(tc, evas_object_image_9patch);
    tcase_add_test(tc, evas_object_image_save_from_proxy);
    tcase_add_test(tc, evas_object_image_load_head_skip);
+#ifdef BUILD_ENGINE_BUFFER
+   tcase_add_test(tc, evas_object_image_buffer_crop_property);
+   tcase_add_test(tc, evas_object_image_buffer_crop_render);
+   tcase_add_test(tc, evas_object_image_buffer_crop_clamp);
+   tcase_add_test(tc, evas_object_image_buffer_crop_damage);
+   tcase_add_test(tc, evas_object_image_buffer_crop_hittest);
+   tcase_add_test(tc, evas_object_image_buffer_crop_border);
+#endif
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to