[gegl] algorithms: re-arrange pointer arithmetic and loops in downscale_2x2 functions



commit 37af1f48abd685cde9259ecf4a771f1424076646
Author: Øyvind Kolås <pippin gimp org>
Date:   Mon Apr 2 23:40:01 2018 +0200

    algorithms: re-arrange pointer arithmetic and loops in downscale_2x2 functions

 gegl/gegl-algorithms.c         |   28 ++++++++++++----------------
 perf/test-gegl-buffer-access.c |   19 +++++++++++++++++--
 2 files changed, 29 insertions(+), 18 deletions(-)
---
diff --git a/gegl/gegl-algorithms.c b/gegl/gegl-algorithms.c
index 874afff..d5304a3 100644
--- a/gegl/gegl-algorithms.c
+++ b/gegl/gegl-algorithms.c
@@ -469,6 +469,10 @@ gegl_bilinear_u8_nl (guchar              *dest_buf,
                      const gint           components,
                      const gint           d_rowstride)
 {
+  /* performance optimizations notes:
+   *   replacing the floating point fractions with fixed point arithmetic
+   *   slows things down.
+   */
   const gint ver  = s_rowstride;
   const gint diag = ver + components;
   const gint dst_y = dst_rect->y;
@@ -844,16 +848,15 @@ gegl_downscale_2x2_u8_rgba (const Babl *format,
   for (y = 0; y < src_height / 2; y++)
     {
       gint    x;
-      guchar *src = src_data + src_rowstride * y * 2;
+      guchar *aa = src_data + src_rowstride * y * 2;
       guchar *dst = dst_data + dst_rowstride * y;
 
-      uint8_t * aa = ((uint8_t *)(src));
-      uint8_t * ab = ((uint8_t *)(src + bpp));
-      uint8_t * ba = ((uint8_t *)(src + src_rowstride));
-      uint8_t * bb = ((uint8_t *)(src + diag));
 
       for (x = 0; x < src_width / 2; x++)
         {
+          uint8_t * ab = ((uint8_t *)(aa + bpp));
+          uint8_t * ba = ((uint8_t *)(aa + src_rowstride));
+          uint8_t * bb = ((uint8_t *)(aa + diag));
 
           ((uint8_t *)dst)[0] = lut_u16_to_u8[ (lut_u8_to_u14[aa[0]] +
                                                 lut_u8_to_u14[ab[0]] +
@@ -871,9 +874,6 @@ gegl_downscale_2x2_u8_rgba (const Babl *format,
 
           dst += bpp;
           aa += bpp * 2;
-          ab += bpp * 2;
-          ba += bpp * 2;
-          bb += bpp * 2;
         }
   }
 }
@@ -897,16 +897,15 @@ gegl_downscale_2x2_u8_rgb (const Babl *format,
   for (y = 0; y < src_height / 2; y++)
     {
       gint    x;
-      guchar *src = src_data + src_rowstride * y * 2;
+      guchar *aa = src_data + src_rowstride * y * 2;
       guchar *dst = dst_data + dst_rowstride * y;
 
-      uint8_t * aa = ((uint8_t *)(src));
-      uint8_t * ab = ((uint8_t *)(src + bpp));
-      uint8_t * ba = ((uint8_t *)(src + src_rowstride));
-      uint8_t * bb = ((uint8_t *)(src + diag));
 
       for (x = 0; x < src_width / 2; x++)
         {
+          uint8_t * ab = ((uint8_t *)(aa + bpp));
+          uint8_t * ba = ((uint8_t *)(aa + src_rowstride));
+          uint8_t * bb = ((uint8_t *)(aa + diag));
 
           ((uint8_t *)dst)[0] = lut_u16_to_u8[ (lut_u8_to_u14[aa[0]] +
                                                 lut_u8_to_u14[ab[0]] +
@@ -922,9 +921,6 @@ gegl_downscale_2x2_u8_rgb (const Babl *format,
                                                 lut_u8_to_u14[bb[2]]) ];
           dst += bpp;
           aa += bpp * 2;
-          ab += bpp * 2;
-          ba += bpp * 2;
-          bb += bpp * 2;
         }
   }
 }
diff --git a/perf/test-gegl-buffer-access.c b/perf/test-gegl-buffer-access.c
index b523f6d..11c5d2d 100644
--- a/perf/test-gegl-buffer-access.c
+++ b/perf/test-gegl-buffer-access.c
@@ -8,7 +8,7 @@ main (gint    argc,
 {
   GeglBuffer    *buffer;
   GeglRectangle  bound = {0, 0, 1024, 1024};
-  GeglRectangle  bound2 = {0, 0, 300, 300};
+  GeglRectangle  bound2 = {0, 0, 341, 341};
   const Babl *format;
   guchar *sbuf;
   guchar *buf;
@@ -101,7 +101,6 @@ main (gint    argc,
   test_end ("nearest 0.333", 1.0 * bound2.width * bound2.height * ITERATIONS * 4);
 
 
-
   {
       const Babl *format = babl_format ("R'G'B'A u8");
       GeglBuffer *buffer = gegl_buffer_new (&bound, format);
@@ -118,6 +117,22 @@ main (gint    argc,
   }
   test_end ("bilinear 0.333", 1.0 * bound2.width * bound2.height * ITERATIONS * 4);
 
+  {
+      const Babl *format = babl_format ("R'G'B'A u8");
+      GeglBuffer *buffer = gegl_buffer_new (&bound, format);
+  test_start ();
+  for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
+    {
+  /* pre-initialize */
+      gegl_buffer_set (buffer, &bound, 0, NULL, sbuf, GEGL_AUTO_ROWSTRIDE);
+      test_start_iter ();
+      gegl_buffer_get (buffer, &bound2, 0.333, NULL, buf, GEGL_AUTO_ROWSTRIDE, 
GEGL_ABYSS_NONE|GEGL_BUFFER_FILTER_BILINEAR);
+      test_end_iter ();
+     }
+      g_object_unref (buffer);
+  }
+  test_end ("mip+bilin 0.333", 1.0 * bound2.width * bound2.height * ITERATIONS * 4);
+
   test_start ();
   for (i=0;i<ITERATIONS && converged < BAIL_COUNT;i++)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]