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

git pushed a commit to branch v-1.29
in repository efl.

View the commit online.

commit a4f2375706a675f2c8dcdc9d3cbe1f70194432c6
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 12:29:09 2026 -0600

    evas: fix the sample scaler's clamp to the mask
    
    The software sample scaler clamps the area it draws to the mask it is
    given. Moving the left or top edge of that area did not shrink the
    span, nor move the destination, source and scale table pointers that
    were computed from the unclamped origin. The masked pixels landed at
    the clip origin instead of over the mask, the mask rows were read past
    their end, and a clip that did not overlap the mask at all still drew
    part of it.
    
    The pointers now follow the clamped edges, the span shrinks with
    them, and nothing is drawn when the clip and the mask do not overlap.
    The right and bottom edges were already handled.
    
    A test drives the scaler directly, unscaled and scaled, with masks
    inside, across and outside of the clip, and checks every pixel.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/evas/common/evas_scale_sample.c      |  28 ++++-
 src/tests/evas/evas_test_scale_sample_mask.c | 167 +++++++++++++++++++++++++++
 src/tests/evas/meson.build                   |  13 +++
 3 files changed, 204 insertions(+), 4 deletions(-)

diff --git a/src/lib/evas/common/evas_scale_sample.c b/src/lib/evas/common/evas_scale_sample.c
index cd59ed20b0..4e11a4afab 100644
--- a/src/lib/evas/common/evas_scale_sample.c
+++ b/src/lib/evas/common/evas_scale_sample.c
@@ -146,17 +146,37 @@ _evas_common_scale_rgba_sample_scale_mask(int y,
                                           DATA32 *srcptr, int src_w)
 {
    DATA32 *buf;
-   int x;
+   int x, dx = 0, dy = 0;
 
-   /* clamp/map to mask geometry */
+   /* clamp/map to mask geometry: nothing is drawn outside of the mask.
+    * dptr, srcptr, row_ptr and lin_ptr all start at the unclamped clip origin,
+    * so moving the left or top edge moves them too and shrinks the span. */
    if (EINA_UNLIKELY(dst_clip_x < mask_x))
-     dst_clip_x = mask_x;
+     {
+        dx = mask_x - dst_clip_x;
+        dst_clip_x = mask_x;
+        dst_clip_w -= dx;
+     }
    if (EINA_UNLIKELY(dst_clip_y < mask_y))
-     dst_clip_y = mask_y;
+     {
+        dy = mask_y - dst_clip_y;
+        dst_clip_y = mask_y;
+        dst_clip_h -= dy;
+     }
    if (EINA_UNLIKELY(dst_clip_x + dst_clip_w > mask_x + (int)mask_ie->cache_entry.w))
      dst_clip_w = mask_x + mask_ie->cache_entry.w - dst_clip_x;
    if (EINA_UNLIKELY(dst_clip_y + dst_clip_h > mask_y + (int)mask_ie->cache_entry.h))
      dst_clip_h = mask_y + mask_ie->cache_entry.h - dst_clip_y;
+   if ((dst_clip_w <= 0) || (dst_clip_h <= y)) return;
+
+   dptr += (dy * dst_w) + dx;
+   if (srcptr)
+     srcptr += (dy * src_w) + dx;
+   else
+     {
+        row_ptr += dy;
+        lin_ptr += dx;
+     }
 
    /* a scanline buffer */
    buf = alloca(dst_clip_w * sizeof(DATA32));
diff --git a/src/tests/evas/evas_test_scale_sample_mask.c b/src/tests/evas/evas_test_scale_sample_mask.c
new file mode 100644
index 0000000000..8d3cd5fd8e
--- /dev/null
+++ b/src/tests/evas/evas_test_scale_sample_mask.c
@@ -0,0 +1,167 @@
+/* The software sample scaler clamps the area it draws to the mask it was
+ * given. Moving the left or top edge of that area has to move the source and
+ * destination pointers along with it and shrink the span by the same amount,
+ * or the masked pixels land at the unclamped origin and the mask rows are read
+ * past their end.
+ *
+ * This draws through evas_common_scale_rgba_in_to_out_clip_sample() with a
+ * mask that only partly covers the clip, unscaled and scaled, and checks every
+ * destination pixel against what the mask allows. It needs the internal
+ * draw context and image structures, so it is its own program. */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <Evas.h>
+
+#include "evas_common_private.h"
+
+#define DST_W 16
+#define DST_H 16
+
+typedef struct
+{
+   const char *name;
+   int src_w, src_h;          /* source image, drawn over the whole dst */
+   int clip_x, clip_y, clip_w, clip_h;
+   int mask_x, mask_y, mask_w, mask_h;
+} Test_Case;
+
+static const Test_Case cases[] = {
+   /* clip larger than the mask on every side */
+   { "unscaled, mask inside clip", DST_W, DST_H, 0, 0, 16, 16, 4, 4, 8, 8 },
+   /* clip starts before the mask but ends inside it: the span must shrink */
+   { "unscaled, clip over top-left", DST_W, DST_H, 0, 0, 10, 10, 4, 4, 8, 8 },
+   /* clip starts inside the mask and ends after it */
+   { "unscaled, clip over bottom-right", DST_W, DST_H, 6, 6, 10, 10, 4, 4, 8, 8 },
+   /* no overlap at all: nothing may be drawn */
+   { "unscaled, mask outside clip", DST_W, DST_H, 0, 0, 8, 8, 12, 12, 4, 4 },
+   { "scaled, mask inside clip", 8, 8, 0, 0, 16, 16, 4, 4, 8, 8 },
+   { "scaled, clip over top-left", 8, 8, 0, 0, 10, 10, 4, 4, 8, 8 },
+   { "scaled, clip over bottom-right", 8, 8, 6, 6, 10, 10, 4, 4, 8, 8 },
+   { "scaled, mask outside clip", 8, 8, 0, 0, 8, 8, 12, 12, 4, 4 },
+};
+
+static RGBA_Image *
+_image_new(int w, int h, Eina_Bool alpha8)
+{
+   RGBA_Image *im = calloc(1, sizeof(RGBA_Image));
+
+   im->cache_entry.w = w;
+   im->cache_entry.h = h;
+   im->cache_entry.flags.alpha = EINA_TRUE;
+   if (alpha8)
+     {
+        im->cache_entry.space = EVAS_COLORSPACE_GRY8;
+        /* exactly sized, so a read past the last row leaves the allocation */
+        im->image.data8 = malloc(w * h);
+     }
+   else
+     im->image.data = "" * h * sizeof(DATA32));
+   return im;
+}
+
+static void
+_image_free(RGBA_Image *im)
+{
+   free(im->image.data);
+   free(im);
+}
+
+/* opaque, and different for every source pixel, so a shifted source shows */
+static DATA32
+_src_pixel(int x, int y)
+{
+   return 0xff000000 | ((DATA32)(x + 1) << 16) | ((DATA32)(y + 1) << 8) | 0x80;
+}
+
+/* not symmetric in x and y, so a transposed or shifted mask shows */
+static DATA8
+_mask_value(int mx, int my)
+{
+   return (((mx / 2) + my) & 1) ? 255 : 0;
+}
+
+static int
+_run(const Test_Case *tc)
+{
+   RGBA_Image *src, *dst, *mask;
+   RGBA_Draw_Context *dc;
+   int x, y, errors = 0;
+
+   src = "" tc->src_h, EINA_FALSE);
+   dst = _image_new(DST_W, DST_H, EINA_FALSE);
+   mask = _image_new(tc->mask_w, tc->mask_h, EINA_TRUE);
+
+   for (y = 0; y < tc->src_h; y++)
+     for (x = 0; x < tc->src_w; x++)
+       src->image.data[y * tc->src_w + x] = _src_pixel(x, y);
+   for (y = 0; y < DST_H; y++)
+     for (x = 0; x < DST_W; x++)
+       dst->image.data[y * DST_W + x] = 0;
+   for (y = 0; y < tc->mask_h; y++)
+     for (x = 0; x < tc->mask_w; x++)
+       mask->image.data8[y * tc->mask_w + x] = _mask_value(x, y);
+
+   dc = evas_common_draw_context_new();
+   evas_common_draw_context_set_clip(dc, tc->clip_x, tc->clip_y,
+                                     tc->clip_w, tc->clip_h);
+   dc->clip.mask = mask;
+   dc->clip.mask_x = tc->mask_x;
+   dc->clip.mask_y = tc->mask_y;
+
+   evas_common_scale_rgba_in_to_out_clip_sample(src, dst, dc,
+                                                0, 0, tc->src_w, tc->src_h,
+                                                0, 0, DST_W, DST_H);
+
+   for (y = 0; y < DST_H; y++)
+     for (x = 0; x < DST_W; x++)
+       {
+          DATA32 expected = 0, got = dst->image.data[y * DST_W + x];
+          int mx = x - tc->mask_x, my = y - tc->mask_y;
+
+          if ((x >= tc->clip_x) && (x < tc->clip_x + tc->clip_w) &&
+              (y >= tc->clip_y) && (y < tc->clip_y + tc->clip_h) &&
+              (mx >= 0) && (mx < tc->mask_w) &&
+              (my >= 0) && (my < tc->mask_h) &&
+              _mask_value(mx, my))
+            expected = _src_pixel((x * tc->src_w) / DST_W,
+                                  (y * tc->src_h) / DST_H);
+
+          if (got != expected)
+            {
+               if (errors < 4)
+                 fprintf(stderr, "%s: pixel %d,%d is %08x, expected %08x\n",
+                         tc->name, x, y, got, expected);
+               errors++;
+            }
+       }
+
+   if (errors)
+     fprintf(stderr, "%s: %d wrong pixels\n", tc->name, errors);
+
+   dc->clip.mask = NULL;
+   evas_common_draw_context_free(dc);
+   _image_free(mask);
+   _image_free(dst);
+   _image_free(src);
+   return errors;
+}
+
+int
+main(void)
+{
+   unsigned int i;
+   int failed = 0;
+
+   evas_init();
+   for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
+     if (_run(&cases[i])) failed++;
+   evas_shutdown();
+
+   return failed ? 1 : 0;
+}
diff --git a/src/tests/evas/meson.build b/src/tests/evas/meson.build
index 4d7d13e8e6..46afabbe0c 100644
--- a/src/tests/evas/meson.build
+++ b/src/tests/evas/meson.build
@@ -66,6 +66,19 @@ test('evas-cpu-disable', evas_cpu_disable,
   timeout : master_timeout
 )
 
+# Drives the software sample scaler directly with a mask that only partly
+# covers the clip; needs the internal draw context, as above.
+evas_scale_sample_mask = executable('evas_scale_sample_mask',
+  ['evas_test_scale_sample_mask.c'],
+  dependencies: [evas_bin, evas, evas_ext_none_static_deps, eet], #internal headers, as above
+  c_args : ['-DEVAS_BUILD']
+)
+
+test('evas-scale-sample-mask', evas_scale_sample_mask,
+  env : test_env,
+  timeout : master_timeout
+)
+
 # Compares every C/NEON pair in the evas span and point op tables. It includes
 # the op translation units directly rather than linking them, because the copy
 # tables are static; that keeps the library itself untouched. Skips (exit 77)

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

Reply via email to