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

git pushed a commit to branch master
in repository legacy-imlib2.

View the commit online.

commit b24db48dbc94b226d1f309fed83065f423b2e934
Author: Kim Woelders <[email protected]>
AuthorDate: Fri Jan 27 16:44:36 2023 +0100

    test: Add test_rgba
---
 test/Makefile.am   |   9 ++
 test/test_rgba.cpp | 255 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 264 insertions(+)

diff --git a/test/Makefile.am b/test/Makefile.am
index 876ed66..3c344d4 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -17,6 +17,7 @@ CLEANFILES = file.c img_save-*.*
  GTESTS += test_save
  GTESTS += test_scale
  GTESTS += test_rotate
+ GTESTS += test_rgba
 if BUILD_X11
  GTESTS += test_grab
 endif
@@ -38,6 +39,8 @@ endif
 
 %.c: $(top_srcdir)/src/lib/%.c
 	ln -s $< $@
+%.S: $(top_srcdir)/src/lib/%.S
+	ln -s $< $@
 
  TEST_COMMON = test.cpp test.h
 
@@ -73,6 +76,12 @@ test_scale_LDADD = $(LIBS)
 test_rotate_SOURCES = $(TEST_COMMON) test_rotate.cpp
 test_rotate_LDADD = $(LIBS)
 
+test_rgba_SOURCES = $(TEST_COMMON) test_rgba.cpp x11_rgba.c
+if BUILD_MMX
+test_rgba_SOURCES += asm_c.c asm_rgba.S
+endif
+test_rgba_LDADD = $(LIBS)
+
  TESTS_RUN = $(addprefix run-, $(GTESTS))
 
  TEST_ENV = IMLIB2_LOADER_PATH=$(top_builddir)/src/modules/loaders/.libs
diff --git a/test/test_rgba.cpp b/test/test_rgba.cpp
new file mode 100644
index 0000000..a6789da
--- /dev/null
+++ b/test/test_rgba.cpp
@@ -0,0 +1,255 @@
+#include <gtest/gtest.h>
+
+#include "config.h"
+#include <Imlib2.h>
+
+#include "test.h"
+/**INDENT-OFF**/
+extern "C" {
+#include "x11_rgba.h"
+}
+/**INDENT-ON**/
+
+typedef struct {
+   char                bypp;
+   short               depth;
+   char                hiq;
+   char                pal;
+   unsigned char       rmb, rms, gmb, gms, bmb, bms;
+} td_t;
+
+#define TD(byp, d, h, t, rmb_, rms_, gmb_, gms_, bmb_, bms_) \
+   { .bypp = byp, .depth = d, \
+     .hiq = h, .pal = t, \
+     .rmb = rmb_, .rms = rms_, .gmb = gmb_, .gms = gms_, .bmb = bmb_, .bms = bms_, \
+   }
+
+/**INDENT-OFF**/
+static const td_t   td[] = {
+   TD(4, 32, 0, 0, 8, 16,  8,  8, 8,  0),
+   TD(3, 24, 0, 0, 8, 16,  8,  8, 8,  0),
+   TD(2, 16, 0, 0, 5, 11,  6,  5, 5,  0),	// RGB 565
+   TD(2, 16, 0, 0, 5, 10,  5,  5, 5,  0),	// RGB 555
+   TD(2, 16, 0, 0, 5,  0,  6,  5, 5, 11),	// BGR 565
+   TD(2, 16, 0, 0, 5,  0,  5,  5, 5, 10),	// BGR 565
+};
+/**INDENT-ON**/
+#define N_TD (sizeof(td) / sizeof(td[0]))
+
+static void
+fill(void *ptr_, int w, int h, uint32_t pix)
+{
+   uint32_t           *ptr = (uint32_t *) ptr_;
+   int                 i, j;
+
+   for (i = 0; i < h; i++)
+     {
+        for (j = 0; j < w; j++)
+          {
+             ptr[i * w + j] = pix;
+          }
+     }
+}
+
+static int
+check_2(const void *ptr_, int w, int h, uint32_t pix)
+{
+   const uint8_t      *ptr = (const uint8_t *)ptr_;
+   int                 i, j;
+   uint32_t            pixi;
+
+   for (i = 0; i < h; i++)
+     {
+        for (j = 0; j < w; j++)
+          {
+             pixi = (ptr[1] << 8) | ptr[0];
+             if (pixi != pix)
+                return 1;
+             ptr += 2;
+          }
+     }
+
+   return 0;
+}
+
+static int
+check_3(const void *ptr_, int w, int h, uint32_t pix)
+{
+   const uint8_t      *ptr = (const uint8_t *)ptr_;
+   int                 i, j;
+   uint32_t            pixi;
+
+   for (i = 0; i < h; i++)
+     {
+        for (j = 0; j < w; j++)
+          {
+             pixi = (ptr[2] << 16) | (ptr[1] << 8) | ptr[0];
+             if (pixi != pix)
+                return 1;
+             ptr += 3;
+          }
+     }
+
+   return 0;
+}
+
+static int
+check_4(const void *ptr_, int w, int h, uint32_t pix)
+{
+   const uint32_t     *ptr = (const uint32_t *)ptr_;
+   int                 i, j;
+
+   for (i = 0; i < h; i++)
+     {
+        for (j = 0; j < w; j++)
+          {
+             if (ptr[i * w + j] != pix)
+                return 1;
+          }
+     }
+
+   return 0;
+}
+
+static void
+print_2(const void *ptr_, int w, int h)
+{
+   const uint8_t      *ptr = (const uint8_t *)ptr_;
+   int                 i, j;
+   uint32_t            pixi;
+
+   for (i = 0; i < h; i++)
+     {
+        D("%2d ", i);
+        for (j = 0; j < w; j++)
+          {
+             pixi = (ptr[1] << 8) | ptr[0];
+             D(" %04x", pixi);
+             ptr += 2;
+          }
+        D("\n");
+     }
+}
+
+static void
+print_3(const void *ptr_, int w, int h)
+{
+   const uint8_t      *ptr = (const uint8_t *)ptr_;
+   int                 i, j;
+   uint32_t            pixi;
+
+   for (i = 0; i < h; i++)
+     {
+        D("%2d ", i);
+        for (j = 0; j < w; j++)
+          {
+             pixi = (ptr[2] << 16) | (ptr[1] << 8) | ptr[0];
+             D(" %06x", pixi);
+             ptr += 3;
+          }
+        D("\n");
+     }
+}
+
+static void
+print_4(const void *ptr_, int w, int h)
+{
+   const uint32_t     *ptr = (const uint32_t *)ptr_;
+   int                 i, j;
+
+   for (i = 0; i < h; i++)
+     {
+        D("%2d ", i);
+        for (j = 0; j < w; j++)
+          {
+             D(" %08x", ptr[i * w + j]);
+          }
+        D("\n");
+     }
+}
+
+TEST(ARGB, argb_1)
+{
+   ImlibRGBAFunction   rgbaer;
+   int                 depth, hiq, pal_type;
+   unsigned int        rm, gm, bm;
+   int                 w, h, jump_src, jump_dst;
+   unsigned int        i;
+   uint32_t           *src, pixi;
+   uint8_t            *dst;
+   unsigned int        pixo, r8, g8, b8;
+   int                 rs, gs, bs;
+
+   w = 8;
+   h = 8;
+   src = "" *) malloc(sizeof(uint32_t) * w * h);
+   dst = (uint8_t *) malloc(sizeof(uint32_t) * w * h);
+   jump_src = 0;
+   jump_dst = 0;
+
+   pixi = 0x12345678;
+
+   fill(src, w, h, pixi);
+
+   for (i = 0; i < N_TD; i++)
+     {
+        fill(dst, w, h, 0);
+
+        depth = td[i].depth;
+        hiq = td[i].hiq;
+        pal_type = td[i].pal;
+        rm = ((1 << td[i].rmb) - 1) << td[i].rms;
+        gm = ((1 << td[i].gmb) - 1) << td[i].gms;
+        bm = ((1 << td[i].bmb) - 1) << td[i].bms;
+
+        rgbaer = __imlib_GetRGBAFunction(depth, rm, gm, bm, hiq, pal_type);
+        ASSERT_TRUE(rgbaer);
+
+        jump_dst = td[i].bypp * w;
+
+        rgbaer(src, jump_src, dst, jump_dst, w, h, 0, 0);
+
+        D("pixi = %08x(%02x,%02x,%02x)\n", pixi, r8, g8, b8);
+
+        r8 = (pixi >> 16) & 0xff;
+        g8 = (pixi >> 8) & 0xff;
+        b8 = (pixi >> 0) & 0xff;
+
+        rs = td[i].rmb + td[i].rms - 8;
+        gs = td[i].gmb + td[i].gms - 8;
+        bs = td[i].bmb + td[i].bms - 8; // Always non-positive
+
+        pixo = 0;
+        pixo |= (rs >= 0) ? (r8 << rs) & rm : (r8 >> -rs) & rm;
+        pixo |= (gs >= 0) ? (g8 << gs) & gm : (g8 >> -gs) & gm;
+        pixo |= (bs >= 0) ? (b8 << bs) & bm : (b8 >> -bs) & bm;
+
+        D("pixo = %06x  r,g,b m/s = %02x/%d %02x/%d %02x/%d\n",
+          pixo, rm, rs, gm, gs, bm, bs);
+
+        switch (td[i].bypp)
+          {
+          default:
+             ASSERT_TRUE(false);
+             break;
+          case 2:
+             print_2(dst, w, h);
+
+             EXPECT_FALSE(check_2(dst, w, h, pixo));
+             break;
+          case 3:
+             print_3(dst, w, h);
+
+             EXPECT_FALSE(check_3(dst, w, h, pixo));
+             break;
+          case 4:
+             print_4(dst, w, h);
+             pixo |= pixi & 0xff000000;
+             EXPECT_FALSE(check_4(dst, w, h, pixo));
+             break;
+          }
+     }
+
+   free(src);
+   free(dst);
+}

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

Reply via email to