[gimp/gimp-2-10] app: more optimizations to gimp_gegl_mask_bounds()



commit 563036eab671fcd0f8b2ff5a8a91afefe880212f
Author: Ell <ell_se yahoo com>
Date:   Tue Jan 1 06:51:45 2019 -0500

    app: more optimizations to gimp_gegl_mask_bounds()
    
    Another inner-loop logic improvement.
    
    (cherry picked from commit 3351174ebeab7446835ab68572d4d952a1cc810a)

 app/gegl/gimp-gegl-mask.c | 93 +++++++++++++++++++++++++----------------------
 1 file changed, 49 insertions(+), 44 deletions(-)
---
diff --git a/app/gegl/gimp-gegl-mask.c b/app/gegl/gimp-gegl-mask.c
index 19cf9b9b43..8c896b8eb5 100644
--- a/app/gegl/gimp-gegl-mask.c
+++ b/app/gegl/gimp-gegl-mask.c
@@ -87,47 +87,48 @@ gimp_gegl_mask_bounds (GeglBuffer *buffer,
             }
           else
             {
-              #define FIND_BOUNDS(bpp, type)                             \
-                G_STMT_START                                             \
-                  {                                                      \
-                    const type *data;                                    \
-                    gint        y;                                       \
-                                                                         \
-                    if ((guintptr) data_u8 % bpp)                        \
-                      goto generic;                                      \
-                                                                         \
-                    data = (const type *) data_u8;                       \
-                                                                         \
-                    for (y = roi->y; y < ey; y++)                        \
-                      {                                                  \
-                        gint x1;                                         \
-                                                                         \
-                        for (x1 = 0; x1 < roi->width; x1++)              \
-                          {                                              \
-                            if (data[x1])                                \
-                              {                                          \
-                                gint x2;                                 \
-                                                                         \
-                                for (x2 = roi->width - 1; x2 > x1; x2--) \
-                                  {                                      \
-                                    if (data[x2])                        \
-                                      break;                             \
-                                  }                                      \
-                                                                         \
-                                x1 += roi->x;                            \
-                                x2 += roi->x;                            \
-                                                                         \
-                                if (x1 < tx1) tx1 = x1;                  \
-                                if (x2 > tx2) tx2 = x2;                  \
-                                                                         \
-                                if (y < ty1) ty1 = y;                    \
-                                if (y > ty2) ty2 = y;                    \
-                              }                                          \
-                          }                                              \
-                                                                         \
-                        data += roi->width;                              \
-                      }                                                  \
-                  }                                                      \
+              #define FIND_BOUNDS(bpp, type)                                 \
+                G_STMT_START                                                 \
+                  {                                                          \
+                    const type *data;                                        \
+                    gint        y;                                           \
+                                                                             \
+                    if ((guintptr) data_u8 % bpp)                            \
+                      goto generic;                                          \
+                                                                             \
+                    data = (const type *) data_u8;                           \
+                                                                             \
+                    for (y = roi->y; y < ey; y++)                            \
+                      {                                                      \
+                        gint x1;                                             \
+                                                                             \
+                        for (x1 = 0; x1 < roi->width; x1++)                  \
+                          {                                                  \
+                            if (data[x1])                                    \
+                              {                                              \
+                                gint x2;                                     \
+                                gint x2_end = MAX (x1, tx2 - roi->x);        \
+                                                                             \
+                                for (x2 = roi->width - 1; x2 > x2_end; x2--) \
+                                  {                                          \
+                                    if (data[x2])                            \
+                                      break;                                 \
+                                  }                                          \
+                                                                             \
+                                x1 += roi->x;                                \
+                                x2 += roi->x;                                \
+                                                                             \
+                                if (x1 < tx1) tx1 = x1;                      \
+                                if (x2 > tx2) tx2 = x2;                      \
+                                                                             \
+                                if (y < ty1) ty1 = y;                        \
+                                if (y > ty2) ty2 = y;                        \
+                              }                                              \
+                          }                                                  \
+                                                                             \
+                        data += roi->width;                                  \
+                      }                                                      \
+                  }                                                          \
                 G_STMT_END
 
               switch (bpp)
@@ -163,11 +164,15 @@ gimp_gegl_mask_bounds (GeglBuffer *buffer,
                             if (! gegl_memeq_zero (data + x1 * bpp, bpp))
                               {
                                 gint x2;
+                                gint x2_end = MAX (x1, tx2 - roi->x);
 
-                                for (x2 = roi->width - 1; x2 > x1; x2--)
+                                for (x2 = roi->width - 1; x2 > x2_end; x2--)
                                   {
-                                    if (! gegl_memeq_zero (data + x2 * bpp, bpp))
-                                      break;
+                                    if (! gegl_memeq_zero (data + x2 * bpp,
+                                                           bpp))
+                                      {
+                                        break;
+                                      }
                                   }
 
                                 x1 += roi->x;


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