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 29c805e57085c228711d97a5a84e51777cc198ba
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 15:53:28 2026 -0600

    evas/filters: modulate a filtered image by its color
    
    The color of an image modulates its pixels, but a filtered image only
    took the clipper's color and the alpha of its own: a tinted image lost
    its tint with any filter, unlike a filtered Textblock.
    
    The result of the filter of an image, snapshots included, is now drawn
    with its color. state.color reads as white there, as its alpha already
    read as opaque, or a program blending with it would tint twice.
    
    A Text keeps choosing colors in its filter, its object color being the
    color of the text.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/evas/canvas/evas_filter_mixin.c  | 35 ++++++++++++++++++++++++++------
 src/tests/evas/evas_test_filter_values.c | 27 ++++++++++++++++++++----
 2 files changed, 52 insertions(+), 10 deletions(-)

diff --git a/src/lib/evas/canvas/evas_filter_mixin.c b/src/lib/evas/canvas/evas_filter_mixin.c
index 402382e759..4724939870 100644
--- a/src/lib/evas/canvas/evas_filter_mixin.c
+++ b/src/lib/evas/canvas/evas_filter_mixin.c
@@ -204,6 +204,14 @@ _evas_filter_source_hash_free_cb(void *data)
    free(pb);
 }
 
+/* The color of an image modulates its pixels, so also what a filter makes of
+ * them. That of a Text is the color of its text: its filter chooses colors. */
+static inline Eina_Bool
+_evas_filter_color_modulates(const Eo *eo_obj)
+{
+   return efl_isa(eo_obj, EFL_CANVAS_IMAGE_INTERNAL_CLASS);
+}
+
 static inline Eina_Bool
 _evas_filter_state_set_internal(Evas_Filter_Program *pgm, Evas_Filter_Data *pd)
 {
@@ -213,7 +221,10 @@ _evas_filter_state_set_internal(Evas_Filter_Program *pgm, Evas_Filter_Data *pd)
    /* The result of the filter is faded by the alpha of the object, so its
     * color is given without it: a program using it would apply it twice.
     * Colors are premultiplied. */
-   if (state.color.a && (state.color.a < 255))
+   /* Likewise for the color of an image, applied to the result as a whole */
+   if (_evas_filter_color_modulates(pd->data->obj->object))
+     state.color.r = state.color.g = state.color.b = state.color.a = 255;
+   else if (state.color.a && (state.color.a < 255))
      {
         state.color.r = MIN(255, state.color.r * 255 / state.color.a);
         state.color.g = MIN(255, state.color.g * 255 / state.color.a);
@@ -277,7 +288,8 @@ evas_filter_object_render(Eo *eo_obj, Evas_Object_Protected_Data *obj,
                            obj->cur->cache.clip.b,
                            obj->cur->cache.clip.a);
    /* The filter works on the object at full strength: its result is then
-    * clipped, and faded by the alpha of the object, as a whole and once. */
+    * clipped, and faded by the alpha of the object, as a whole and once. An
+    * image is also modulated by its color, as without a filter. */
    {
       const int alpha = obj->cur->color.a;
       int r = 255, g = 255, b = 255, a = 255;
@@ -289,10 +301,21 @@ evas_filter_object_render(Eo *eo_obj, Evas_Object_Protected_Data *obj,
            b = obj->cur->clipper->cur->cache.clip.b;
            a = obj->cur->clipper->cur->cache.clip.a;
         }
-      r = r * alpha / 255;
-      g = g * alpha / 255;
-      b = b * alpha / 255;
-      a = a * alpha / 255;
+      if (_evas_filter_color_modulates(eo_obj))
+        {
+           /* premultiplied, the clipper already in it */
+           r = obj->cur->cache.clip.r;
+           g = obj->cur->cache.clip.g;
+           b = obj->cur->cache.clip.b;
+           a = obj->cur->cache.clip.a;
+        }
+      else
+        {
+           r = r * alpha / 255;
+           g = g * alpha / 255;
+           b = b * alpha / 255;
+           a = a * alpha / 255;
+        }
 
       if ((r & g & b & a) != 255)
         ENFN->context_multiplier_set(engine, context, r, g, b, a);
diff --git a/src/tests/evas/evas_test_filter_values.c b/src/tests/evas/evas_test_filter_values.c
index 12591f2ca7..3c7ec5772d 100644
--- a/src/tests/evas/evas_test_filter_values.c
+++ b/src/tests/evas/evas_test_filter_values.c
@@ -928,7 +928,7 @@ typedef struct _Alpha_Case Alpha_Case;
 struct _Alpha_Case
 {
    const char *name;
-   Eina_Bool image;
+   int image;   /* 0 a Text, 1 a black image, 2 a white one, 3 scaled */
    int red, alpha, clip_alpha;
    const char *code;
    Probe darkest;
@@ -955,6 +955,21 @@ _alpha_check(const char *engine)
       { "translucent image", 1, 0, 64, 255, "blend { }", GREY(191) },
       { "clipped image", 1, 0, 255, 64, "blend { }", GREY(191) },
       { "translucent clipped image", 1, 0, 128, 128, "blend { }", GREY(191) },
+      /* the color of an image modulates it, filtered or not */
+      { "tinted image", 2, 128, 255, 255, "blend { }", { 0, 0, 128, 0, 0 } },
+      { "tinted image, no filter", 2, 128, 255, 255, NULL,
+        { 0, 0, 128, 0, 0 } },
+      { "tinted scaled image", 3, 128, 255, 255, "blend { }",
+        { 0, 0, 128, 0, 0 } },
+      { "tinted translucent image", 2, 64, 128, 255, "blend { }",
+        { 0, 0, 191, 127, 127 } },
+      { "tinted clipped image", 2, 128, 255, 128, "blend { }",
+        { 0, 0, 191, 127, 127 } },
+      { "tinted image blended in its color", 2, 128, 255, 255,
+        "blend { color = state.color }", { 0, 0, 128, 0, 0 } },
+      /* that of a Text is its text color, a filter picks its own */
+      { "text color left to the filter", 0, 255, 255, 255,
+        "blend { color = '#0f0' }", { 0, 0, 0, 255, 0 } },
    };
    int failed = 0;
 
@@ -994,12 +1009,16 @@ _alpha_check(const char *engine)
           }
         else
           {
+             const int w = (t->image == 3) ? W / 4 : W;
+             const int h = (t->image == 3) ? H / 4 : H;
+
              o = evas_object_image_filled_add(evas);
-             evas_object_image_size_set(o, W, H);
+             evas_object_image_size_set(o, w, h);
              pixels = evas_object_image_data_get(o, EINA_TRUE);
-             for (int k = 0; k < W * H; k++) pixels[k] = 0xff000000;
+             for (int k = 0; k < w * h; k++)
+               pixels[k] = (t->image == 1) ? 0xff000000 : 0xffffffff;
              evas_object_image_data_set(o, pixels);
-             evas_object_image_data_update_add(o, 0, 0, W, H);
+             evas_object_image_data_update_add(o, 0, 0, w, h);
              evas_object_resize(o, W, H);
           }
         evas_object_color_set(o, t->red, 0, 0, t->alpha);

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

Reply via email to