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

git pushed a commit to branch master
in repository efl.

View the commit online.

commit e3b47488280909f4b70ab2587e1d9ef818ba0137
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 12:42:31 2026 -0600

    evas: canvas images answer scale_method, can_upscale and can_downscale
    
    These members of the stable Efl.Gfx.Image were implemented only by
    Efl.Ui.Image, while the canvas image claimed the interface without
    answering a third of it. They are implemented here, where fill_auto
    already computes a fill rectangle: that computation now honours the
    scale method and clamps to the native size when scaling in a direction
    is refused, centring the result.
    
    Defaults are FILL with both directions allowed, which is exactly what
    fill_auto did before, so no rendering changes until someone asks for it.
    
    The new evas test uses an object deliberately wider and shorter than the
    image so fill, fit and none cannot accidentally agree, and checks that
    refusing to upscale clamps width while downscale still applies to
    height.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/evas/canvas/efl_canvas_image_internal.eo |   3 +
 src/lib/evas/canvas/evas_image_private.h         |   3 +
 src/lib/evas/canvas/evas_object_image.c          | 150 +++++++++++++++++++++--
 src/tests/evas/evas_test_image.c                 |  84 +++++++++++++
 4 files changed, 232 insertions(+), 8 deletions(-)

diff --git a/src/lib/evas/canvas/efl_canvas_image_internal.eo b/src/lib/evas/canvas/efl_canvas_image_internal.eo
index 3a96eb972c..f0f919e36e 100644
--- a/src/lib/evas/canvas/efl_canvas_image_internal.eo
+++ b/src/lib/evas/canvas/efl_canvas_image_internal.eo
@@ -13,6 +13,9 @@ abstract @beta Efl.Canvas.Image_Internal extends Efl.Canvas.Object implements Ef
       Efl.File_Save.save;
       Efl.Gfx.Image_Orientable.image_orientation { get; set; }
       Efl.Gfx.Image.smooth_scale { get; set; }
+      Efl.Gfx.Image.scale_method { get; set; }
+      Efl.Gfx.Image.can_upscale { get; set; }
+      Efl.Gfx.Image.can_downscale { get; set; }
       Efl.Gfx.Image.ratio { get; }
       Efl.Gfx.Image.content_region { get; }
       Efl.Gfx.Image.border_insets { get; set; }
diff --git a/src/lib/evas/canvas/evas_image_private.h b/src/lib/evas/canvas/evas_image_private.h
index e094478def..39929da25b 100644
--- a/src/lib/evas/canvas/evas_image_private.h
+++ b/src/lib/evas/canvas/evas_image_private.h
@@ -128,8 +128,11 @@ struct _Evas_Image_Data
    } file_size;
 
    unsigned char     preload;  //See above EVAS_IMAGE_PRELOAD***
+   unsigned char     scale_method; /* Efl_Gfx_Image_Scale_Method */
 
    Eina_Bool         changed : 1;
+   Eina_Bool         can_upscale : 1;
+   Eina_Bool         can_downscale : 1;
    Eina_Bool         dirty_pixels : 1;
    Eina_Bool         filled : 1;
    Eina_Bool         filled_set : 1;
diff --git a/src/lib/evas/canvas/evas_object_image.c b/src/lib/evas/canvas/evas_object_image.c
index cfe2adb44d..c05cbc5d72 100644
--- a/src/lib/evas/canvas/evas_object_image.c
+++ b/src/lib/evas/canvas/evas_object_image.c
@@ -226,6 +226,11 @@ _efl_canvas_image_internal_efl_object_constructor(Eo *eo_obj, Evas_Image_Data *o
    o->prev = eina_cow_alloc(evas_object_image_state_cow);
    o->proxy_src_clip = EINA_TRUE;
 
+   /* Defaults match the historic fill_auto: stretch, in both directions. */
+   o->scale_method = EFL_GFX_IMAGE_SCALE_METHOD_FILL;
+   o->can_upscale = EINA_TRUE;
+   o->can_downscale = EINA_TRUE;
+
    cspace = ENFN->image_colorspace_get(ENC, o->engine_data);
    if (cspace != o->cur->cspace)
      {
@@ -933,11 +938,145 @@ _efl_canvas_image_internal_efl_gfx_image_stretch_region_get(const Eo *eo_obj,
    *vertical = &it->iterator;
 }
 
+/* Where fill_auto lands the image inside the object: scale_method decides the
+ * rectangle, can_upscale and can_downscale clamp it to the native size when
+ * scaling in that direction is refused, and the result is centred.
+ */
+static void
+_evas_image_fill_auto_apply(Eo *eo_obj, Evas_Image_Data *o)
+{
+   int iw = 0, ih = 0, w, h, x, y;
+   Eina_Size2D sz;
+
+   sz = efl_gfx_entity_size_get(eo_obj);
+   if (sz.w < 1) sz.w = 1;
+   if (sz.h < 1) sz.h = 1;
+
+   iw = o->cur->image.w;
+   ih = o->cur->image.h;
+   if ((iw < 1) || (ih < 1))
+     {
+        _evas_image_fill_set(eo_obj, o, 0, 0, sz.w, sz.h);
+        return;
+     }
+
+   switch (o->scale_method)
+     {
+      case EFL_GFX_IMAGE_SCALE_METHOD_NONE:
+        w = iw;
+        h = ih;
+        break;
+
+      case EFL_GFX_IMAGE_SCALE_METHOD_FIT:
+        w = sz.w;
+        h = (int) (((double) ih * w) / (double) iw);
+        if (h > sz.h)
+          {
+             h = sz.h;
+             w = (int) (((double) iw * h) / (double) ih);
+          }
+        break;
+
+      case EFL_GFX_IMAGE_SCALE_METHOD_FIT_WIDTH:
+        w = sz.w;
+        h = (int) (((double) ih * w) / (double) iw);
+        break;
+
+      case EFL_GFX_IMAGE_SCALE_METHOD_FIT_HEIGHT:
+        h = sz.h;
+        w = (int) (((double) iw * h) / (double) ih);
+        break;
+
+      case EFL_GFX_IMAGE_SCALE_METHOD_EXPAND:
+        w = sz.w;
+        h = (int) (((double) ih * w) / (double) iw);
+        if (h < sz.h)
+          {
+             h = sz.h;
+             w = (int) (((double) iw * h) / (double) ih);
+          }
+        break;
+
+      case EFL_GFX_IMAGE_SCALE_METHOD_TILE:
+        /* repeat the image at its native size across the object */
+        _evas_image_fill_set(eo_obj, o, 0, 0, iw, ih);
+        return;
+
+      case EFL_GFX_IMAGE_SCALE_METHOD_FILL:
+      default:
+        w = sz.w;
+        h = sz.h;
+        break;
+     }
+
+   if ((!o->can_upscale) && (w > iw)) w = iw;
+   if ((!o->can_upscale) && (h > ih)) h = ih;
+   if ((!o->can_downscale) && (w < iw)) w = iw;
+   if ((!o->can_downscale) && (h < ih)) h = ih;
+
+   if (w < 1) w = 1;
+   if (h < 1) h = 1;
+
+   x = (sz.w - w) / 2;
+   y = (sz.h - h) / 2;
+
+   _evas_image_fill_set(eo_obj, o, x, y, w, h);
+}
+
+EOLIAN static void
+_efl_canvas_image_internal_efl_gfx_image_scale_method_set(Eo *eo_obj, Evas_Image_Data *o,
+                                                          Efl_Gfx_Image_Scale_Method scale_method)
+{
+   if (o->scale_method == scale_method) return;
+   o->scale_method = scale_method;
+   if (o->filled) _evas_image_fill_auto_apply(eo_obj, o);
+}
+
+EOLIAN static Efl_Gfx_Image_Scale_Method
+_efl_canvas_image_internal_efl_gfx_image_scale_method_get(const Eo *eo_obj EINA_UNUSED,
+                                                          Evas_Image_Data *o)
+{
+   return o->scale_method;
+}
+
+EOLIAN static void
+_efl_canvas_image_internal_efl_gfx_image_can_upscale_set(Eo *eo_obj, Evas_Image_Data *o,
+                                                         Eina_Bool upscale)
+{
+   upscale = !!upscale;
+   if (o->can_upscale == upscale) return;
+   o->can_upscale = upscale;
+   if (o->filled) _evas_image_fill_auto_apply(eo_obj, o);
+}
+
+EOLIAN static Eina_Bool
+_efl_canvas_image_internal_efl_gfx_image_can_upscale_get(const Eo *eo_obj EINA_UNUSED,
+                                                         Evas_Image_Data *o)
+{
+   return o->can_upscale;
+}
+
+EOLIAN static void
+_efl_canvas_image_internal_efl_gfx_image_can_downscale_set(Eo *eo_obj, Evas_Image_Data *o,
+                                                           Eina_Bool downscale)
+{
+   downscale = !!downscale;
+   if (o->can_downscale == downscale) return;
+   o->can_downscale = downscale;
+   if (o->filled) _evas_image_fill_auto_apply(eo_obj, o);
+}
+
+EOLIAN static Eina_Bool
+_efl_canvas_image_internal_efl_gfx_image_can_downscale_get(const Eo *eo_obj EINA_UNUSED,
+                                                           Evas_Image_Data *o)
+{
+   return o->can_downscale;
+}
+
 EOLIAN static void
 _efl_canvas_image_internal_efl_gfx_fill_fill_auto_set(Eo *eo_obj, Evas_Image_Data *o, Eina_Bool setting)
 {
    Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
-   Eina_Size2D sz;
    setting = !!setting;
    o->filled_set = 1;
    if (o->filled == setting) return;
@@ -949,8 +1088,7 @@ _efl_canvas_image_internal_efl_gfx_fill_fill_auto_set(Eo *eo_obj, Evas_Image_Dat
 
    if (!o->filled) return;
 
-   sz = efl_gfx_entity_size_get(eo_obj);
-   _evas_image_fill_set(eo_obj, o, 0, 0, sz.w, sz.h);
+   _evas_image_fill_auto_apply(eo_obj, o);
 }
 
 EOLIAN static Eina_Bool
@@ -3926,12 +4064,8 @@ static void
 evas_object_image_filled_resize_listener(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *einfo EINA_UNUSED)
 {
    Evas_Image_Data *o = efl_data_scope_get(obj, EFL_CANVAS_IMAGE_INTERNAL_CLASS);
-   Eina_Size2D sz;
 
-   sz = efl_gfx_entity_size_get(obj);
-   if (sz.w < 1) sz.w = 1;
-   if (sz.h < 1) sz.h = 1;
-   _evas_image_fill_set(obj, o, 0, 0, sz.w, sz.h);
+   _evas_image_fill_auto_apply(obj, o);
 }
 
 Eina_Bool
diff --git a/src/tests/evas/evas_test_image.c b/src/tests/evas/evas_test_image.c
index f1fc4307d2..b34ed7c03f 100644
--- a/src/tests/evas/evas_test_image.c
+++ b/src/tests/evas/evas_test_image.c
@@ -842,6 +842,89 @@ EFL_START_TEST(evas_object_image_defaults)
 }
 EFL_END_TEST
 
+EFL_START_TEST(evas_object_image_scale_method)
+{
+   Evas *e = _setup_evas();
+   const char *imgpath = TESTS_IMG_DIR "/Pic4.png";
+   Eina_Size2D img, sz;
+   Eina_Rect fill;
+   Eo *o;
+
+   o = efl_add(EFL_CANVAS_IMAGE_CLASS, e);
+   efl_file_simple_load(o, imgpath, NULL);
+   img = efl_gfx_view_size_get(o);
+   fail_if((img.w < 4) || (img.h < 4));
+
+   /* an object deliberately wider and shorter than the image, so fit and fill
+    * cannot accidentally agree */
+   sz = EINA_SIZE2D(img.w * 2, img.h / 2);
+   efl_gfx_entity_size_set(o, sz);
+   efl_gfx_fill_auto_set(o, EINA_TRUE);
+
+   // fill_auto has always stretched to the object, and still reports that
+   fail_if(efl_gfx_image_scale_method_get(o) != EFL_GFX_IMAGE_SCALE_METHOD_FILL);
+   fill = efl_gfx_fill_get(o);
+   fail_if((fill.w != sz.w) || (fill.h != sz.h));
+
+   // fit keeps the aspect ratio and stays inside the object
+   efl_gfx_image_scale_method_set(o, EFL_GFX_IMAGE_SCALE_METHOD_FIT);
+   fill = efl_gfx_fill_get(o);
+   fail_if((fill.w > sz.w) || (fill.h > sz.h));
+   fail_if(fill.h != sz.h); // the object is the limiting dimension here
+   fail_if(abs((fill.w * img.h) - (fill.h * img.w)) > img.w);
+
+   // none leaves the image at its own size, centred
+   efl_gfx_image_scale_method_set(o, EFL_GFX_IMAGE_SCALE_METHOD_NONE);
+   fill = efl_gfx_fill_get(o);
+   fail_if((fill.w != img.w) || (fill.h != img.h));
+   fail_if(fill.x != (sz.w - img.w) / 2);
+
+   // refusing to upscale clamps fill back to the native width
+   efl_gfx_image_scale_method_set(o, EFL_GFX_IMAGE_SCALE_METHOD_FILL);
+   efl_gfx_image_can_upscale_set(o, EINA_FALSE);
+   fail_if(efl_gfx_image_can_upscale_get(o));
+   fill = efl_gfx_fill_get(o);
+   fail_if(fill.w != img.w); // object is wider than the image, so no upscale
+   fail_if(fill.h != sz.h);  // object is shorter, so downscale still applies
+
+   // refusing to downscale clamps fill back to the native height
+   efl_gfx_image_can_upscale_set(o, EINA_TRUE);
+   efl_gfx_image_can_downscale_set(o, EINA_FALSE);
+   fail_if(efl_gfx_image_can_downscale_get(o));
+   fill = efl_gfx_fill_get(o);
+   fail_if(fill.w != sz.w);
+   fail_if(fill.h != img.h);
+   efl_gfx_image_can_downscale_set(o, EINA_TRUE);
+
+   // fit width follows the object width and lets the height overflow
+   efl_gfx_image_scale_method_set(o, EFL_GFX_IMAGE_SCALE_METHOD_FIT_WIDTH);
+   fill = efl_gfx_fill_get(o);
+   fail_if(fill.w != sz.w);
+   fail_if(fill.h != ((img.h * sz.w) / img.w));
+
+   // fit height follows the object height and leaves the width short
+   efl_gfx_image_scale_method_set(o, EFL_GFX_IMAGE_SCALE_METHOD_FIT_HEIGHT);
+   fill = efl_gfx_fill_get(o);
+   fail_if(fill.h != sz.h);
+   fail_if(fill.w != ((img.w * sz.h) / img.h));
+
+   // expand covers the object, here by following its width
+   efl_gfx_image_scale_method_set(o, EFL_GFX_IMAGE_SCALE_METHOD_EXPAND);
+   fill = efl_gfx_fill_get(o);
+   fail_if(fill.w != sz.w);
+   fail_if(fill.h < sz.h);
+
+   // tile repeats the image at its own size
+   efl_gfx_image_scale_method_set(o, EFL_GFX_IMAGE_SCALE_METHOD_TILE);
+   fill = efl_gfx_fill_get(o);
+   fail_if((fill.x != 0) || (fill.y != 0));
+   fail_if((fill.w != img.w) || (fill.h != img.h));
+
+   efl_del(o);
+   evas_free(e);
+}
+EFL_END_TEST
+
 // FIXME: belongs to another file
 EFL_START_TEST(evas_object_image_map_unmap)
 {
@@ -1330,6 +1413,7 @@ void evas_test_image_object(TCase *tc)
 #endif
    tcase_add_test(tc, evas_object_image_buggy);
    tcase_add_test(tc, evas_object_image_map_unmap);
+   tcase_add_test(tc, evas_object_image_scale_method);
    tcase_add_test(tc, evas_object_image_buffer_copy);
 #endif
    tcase_add_test(tc, evas_object_image_partially_load_orientation);

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

Reply via email to