[gegl] sampler.h: enlarge samplers' buffer tiles to 256x256. may need to be tweaked further



commit 9db8bfed10d5821d3bc617db1ae256c8735ace3a
Author: Nicolas Robidoux <nrobidoux git gnome org>
Date:   Tue Dec 18 22:37:58 2012 -0500

    sampler.h: enlarge samplers' buffer tiles to 256x256. may need to be tweaked further

 gegl/buffer/gegl-sampler-lohalo.c     |  166 ++++++++++++++++++---------------
 gegl/buffer/gegl-sampler.c            |   16 ++-
 gegl/buffer/gegl-sampler.h            |    2 +-
 operations/transform/transform-core.c |  139 ++++------------------------
 4 files changed, 122 insertions(+), 201 deletions(-)
---
diff --git a/gegl/buffer/gegl-sampler-lohalo.c b/gegl/buffer/gegl-sampler-lohalo.c
index f0dadc4..989bde3 100644
--- a/gegl/buffer/gegl-sampler-lohalo.c
+++ b/gegl/buffer/gegl-sampler-lohalo.c
@@ -411,7 +411,7 @@ gegl_sampler_lohalo_class_init (GeglSamplerLohaloClass *klass)
 /*
  * IMPORTANT: LOHALO_OFFSET_0 SHOULD BE AN INTEGER >= 2.
  */
-#define LOHALO_OFFSET_0 (14)
+#define LOHALO_OFFSET_0 (16)
 #define LOHALO_SIZE_0 ( 1 + 2 * LOHALO_OFFSET_0 )
 
 /*
@@ -424,7 +424,7 @@ gegl_sampler_lohalo_class_init (GeglSamplerLohaloClass *klass)
  * mipmap level's offset should almost never be smaller than half the
  * previous level's offset.
  */
-#define LOHALO_OFFSET_MIPMAP (14)
+#define LOHALO_OFFSET_MIPMAP (16)
 #define LOHALO_SIZE_MIPMAP ( 1 + 2 * LOHALO_OFFSET_MIPMAP )
 
 #define LOHALO_OFFSET_1 LOHALO_OFFSET_MIPMAP
@@ -2250,36 +2250,95 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
           const gfloat c_minor_y = minor_unit_y / minor_mag;
 
           /*
-           * Accumulator for the EWA weights:
+           * Remainder of the ellipse geometry computation:
            */
-          gdouble total_weight = (gdouble) 0.0;
           /*
-           * Storage for the EWA contribution:
+           * Major and minor axis direction vectors:
            */
-          gfloat ewa_newval[channels];
-          ewa_newval[0] = (gfloat) 0.0;
-          ewa_newval[1] = (gfloat) 0.0;
-          ewa_newval[2] = (gfloat) 0.0;
-          ewa_newval[3] = (gfloat) 0.0;
+          const gdouble major_x = major_mag * major_unit_x;
+          const gdouble major_y = major_mag * major_unit_y;
+          const gdouble minor_x = minor_mag * minor_unit_x;
+          const gdouble minor_y = minor_mag * minor_unit_y;
+
+          /*
+           * Ellipse coefficients:
+           */
+          const gdouble ellipse_a =
+            major_y * major_y + minor_y * minor_y;
+          const gdouble folded_ellipse_b =
+            major_x * major_y + minor_x * minor_y;
+          const gdouble ellipse_c =
+            major_x * major_x + minor_x * minor_x;
+          const gdouble ellipse_f = major_mag * minor_mag;
+
+          /*
+           * Bounding box of the ellipse:
+           */
+          const gdouble bounding_box_factor =
+            ellipse_f * ellipse_f /
+            ( ellipse_c * ellipse_a - folded_ellipse_b * folded_ellipse_b );
+          const gfloat bounding_box_half_width =
+            sqrtf( (gfloat) (ellipse_c * bounding_box_factor) );
+          const gfloat bounding_box_half_height =
+            sqrtf( (gfloat) (ellipse_a * bounding_box_factor) );
 
           /*
-           * Grab the pixel values located within the context_rect of
-           * "pure" LBB-Nohalo.  Farther ones will be accessed through
+           * Relative weight of the contribution of LBB-Nohalo:
+           */
+          const gfloat theta = (gfloat) ( (gdouble) 1. / ellipse_f );
+
+          /*
+           * Grab the pixel values located within the level 0
+           * context_rect.  Farther ones will be accessed through
            * higher mipmap levels.
            */
+          const gint out_left_0 =
+            LOHALO_MAX
+            (
+              (gint) ceil  ( (double) ( x_0 - bounding_box_half_width  ) )
+              ,
+              -LOHALO_OFFSET_0
+            );
+          const gint out_rite_0 =
+            LOHALO_MIN
+            (
+              (gint) floorf ( (double) ( x_0 + bounding_box_half_width  ) )
+              ,
+              LOHALO_OFFSET_0
+            );
+          const gint out_top_0 =
+            LOHALO_MAX
+            (
+              (gint) ceilf  ( (double) ( y_0 - bounding_box_half_height ) )
+              ,
+              -LOHALO_OFFSET_0
+            );
+          const gint out_bot_0 =
+            LOHALO_MIN
+            (
+              (gint) floorf ( (double) ( y_0 + bounding_box_half_height ) )
+              ,
+              LOHALO_OFFSET_0
+            );
+
+          /*
+           * Accumulator for the EWA weights:
+           */
+          gdouble total_weight = (gdouble) 0.0;
           /*
-           * TODO: Given that we now use a somewhat large level 0
-           * context_rect, it makes sense to restrict the EWA
-           * computation to the bounding box even at level 0. With
-           * small context_rect, this is a waste. But right now, when
-           * barely downsmapling, there are lots of multiplications by
-           * zero weights.
+           * Storage for the EWA contribution:
            */
+          gfloat ewa_newval[channels];
+          ewa_newval[0] = (gfloat) 0;
+          ewa_newval[1] = (gfloat) 0;
+          ewa_newval[2] = (gfloat) 0;
+          ewa_newval[3] = (gfloat) 0;
+
           {
-            gint i = -LOHALO_OFFSET_0;
+            gint i = out_top_0;
             do
               {
-                gint j = -LOHALO_OFFSET_0;
+                gint j = out_left_0;
                 do
                   {
                     ewa_update (j,
@@ -2295,8 +2354,8 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
                                 input_bptr,
                                 &total_weight,
                                 ewa_newval);
-                  } while ( ++j <= LOHALO_OFFSET_0 );
-              } while ( ++i <= LOHALO_OFFSET_0 );
+                  } while ( ++j <= out_rite_0 );
+              } while ( ++i <= out_bot_0 );
           }
 
           {
@@ -2307,7 +2366,7 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
              * determine the alignment of the level 1 mipmap level
              * w.r.t. the current level 0.
              *
-             * At level 0, we can access pixels which are
+             * At level 0, we can access pixels which are at most
              * LOHALO_OFFSET_0 away from the anchor pixel location in
              * box distance.
              */
@@ -2318,47 +2377,11 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
             const gint odd_ix_0 = ix_0 % 2;
             const gint odd_iy_0 = iy_0 % 2;
             /*
-             * Find the closest locations, on all four sides, of level
-             * 1 pixels which involve data not found in the level 0
+             * Find the closest locations, on all four sides, of level 1
+             * pixels which involve data not found in the level 0
              * LOHALO_SIZE_0xLOHALO_SIZE_0.
              */
             LOHALO_FIND_CLOSEST_LOCATIONS(0,1)
-
-            /*
-             * Remainder of the ellipse geometry computation:
-             */
-            /*
-             * Major and minor axis direction vectors:
-             */
-            const gdouble major_x = major_mag * major_unit_x;
-            const gdouble major_y = major_mag * major_unit_y;
-            const gdouble minor_x = minor_mag * minor_unit_x;
-            const gdouble minor_y = minor_mag * minor_unit_y;
-
-            /*
-             * Ellipse coefficients:
-             */
-            const gdouble ellipse_a =
-              major_y * major_y + minor_y * minor_y;
-            const gdouble folded_ellipse_b =
-              major_x * major_y + minor_x * minor_y;
-            const gdouble ellipse_c =
-              major_x * major_x + minor_x * minor_x;
-            const gdouble ellipse_f = major_mag * minor_mag;
-
-            /*
-             * Bounding box of the ellipse:
-             */
-            const gdouble bounding_box_factor =
-              ellipse_f * ellipse_f
-              /
-              (
-               ellipse_c * ellipse_a - folded_ellipse_b * folded_ellipse_b
-               );
-            const gfloat bounding_box_half_width =
-              sqrtf( (gfloat) (ellipse_c * bounding_box_factor) );
-            const gfloat bounding_box_half_height =
-              sqrtf( (gfloat) (ellipse_a * bounding_box_factor) );
             /*
              * Bounding box shrunk a smidgen given that a location
              * very close to the edge of the bounding box will get a
@@ -2369,11 +2392,6 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
             const gfloat fudged_bounding_box_half_height =
               bounding_box_half_height - LOHALO_FUDGEF;
 
-            /*
-             * Relative weight of the contribution of LBB-Nohalo:
-             */
-            const gfloat theta = (gfloat) ( (gdouble) 1. / ellipse_f );
-
             if (( x_0 - fudged_bounding_box_half_width  < closest_left_1 )
                 ||
                 ( x_0 + fudged_bounding_box_half_width  > closest_rite_1 )
@@ -2429,7 +2447,7 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
                  * The "in" indices are the closest relative mipmap 1
                  * indices of needed mipmap values:
                  */
-		LOHALO_FIND_CLOSEST_INDICES(0,1)
+                LOHALO_FIND_CLOSEST_INDICES(0,1)
                 /*
                  * The "out" indices are the farthest relative mipmap
                  * 1 indices we use at this level:
@@ -2440,7 +2458,7 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
                  * Update using mipmap level 1 values.
                  */
                 LOHALO_MIPMAP_EWA_UPDATE(1)
-		{
+                {
                   /*
                    * In order to know whether we use even higher
                    * mipmap level values, we need to check whether
@@ -2454,7 +2472,7 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
                    * access pixels which are LOHALO_OFFSET_MIPMAP away
                    * from the level 1 anchor pixel location in box
                    * distance.
-		   */
+                   */
                   /*
                    * Determine whether the anchor level_1 pixel
                    * locations are odd (VS even):
@@ -2488,7 +2506,7 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
                        * pixel values will get 0 coefficients--but we
                        * used a quick and dirty bounding box test
                        * which lets through false positives.)
-		       */
+                       */
 
                       /*
                        * Nearest mipmap anchor pixel location:
@@ -2514,12 +2532,12 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
                        * the center of a level 1 pixel is at a box
                        * distance of 1 from the center of the closest
                        * level 2 pixel.
-		       */
+                       */
                       const gfloat x_2 =
                         x_1 + (gfloat) ( 2 * ( ix_1 - 2 * ix_2 ) - 1 );
                       const gfloat y_2 =
                         y_1 + (gfloat) ( 2 * ( iy_1 - 2 * iy_2 ) - 1 );
-  
+
                       /*
                        * Key index ranges:
                        */
@@ -2527,7 +2545,7 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
                        * The "in" indices are the closest relative
                        * mipmap 2 indices of needed mipmap values:
                        */
-		      LOHALO_FIND_CLOSEST_INDICES(1,2)
+                      LOHALO_FIND_CLOSEST_INDICES(1,2)
                       /*
                        * The "out" indices are the farthest relative
                        * mipmap 1 indices we use at this level:
@@ -2572,7 +2590,7 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
                               x_2 + (gfloat) ( 2 * ( ix_2 - 2 * ix_3 ) - 1 );
                             const gfloat y_3 =
                               y_2 + (gfloat) ( 2 * ( iy_2 - 2 * iy_3 ) - 1 );
-			    LOHALO_FIND_CLOSEST_INDICES(2,3)
+                            LOHALO_FIND_CLOSEST_INDICES(2,3)
                             LOHALO_FIND_FARTHEST_INDICES(3)
                             LOHALO_MIPMAP_EWA_UPDATE(3)
                           }
diff --git a/gegl/buffer/gegl-sampler.c b/gegl/buffer/gegl-sampler.c
index 5f80788..f2bc629 100644
--- a/gegl/buffer/gegl-sampler.c
+++ b/gegl/buffer/gegl-sampler.c
@@ -267,10 +267,12 @@ gegl_sampler_get_ptr (GeglSampler *const sampler,
        */
       fetch_rectangle.x =
         x + sampler->context_rect[0].x -
-        (maximum_width_and_height - sampler->context_rect[0].width ) / (gint) 8;
+        (maximum_width_and_height - sampler->context_rect[0].width ) /
+        (gint) 8;
       fetch_rectangle.y =
         y + sampler->context_rect[0].y -
-        (maximum_width_and_height - sampler->context_rect[0].height) / (gint) 8;
+        (maximum_width_and_height - sampler->context_rect[0].height) /
+        (gint) 8;
 
       fetch_rectangle.width  = maximum_width_and_height;
       fetch_rectangle.height = maximum_width_and_height;
@@ -347,9 +349,11 @@ gegl_sampler_get_from_buffer (GeglSampler *const sampler,
       GeglRectangle fetch_rectangle;
 
       fetch_rectangle.x = x -
-	(maximum_width_and_height - sampler->context_rect[0].width ) / (gint) 8;
+        (maximum_width_and_height - sampler->context_rect[0].width ) /
+        (gint) 8;
       fetch_rectangle.y = y -
-	(maximum_width_and_height - sampler->context_rect[0].height) / (gint) 8;
+        (maximum_width_and_height - sampler->context_rect[0].height) /
+        (gint) 8;
 
       fetch_rectangle.width  = maximum_width_and_height;
       fetch_rectangle.height = maximum_width_and_height;
@@ -438,11 +442,11 @@ gegl_sampler_get_from_mipmap (GeglSampler *const sampler,
       fetch_rectangle.x =
         x + sampler->context_rect[level].x -
         (maximum_width_and_height - sampler->context_rect[level].width ) /
-	(gint) 8;
+        (gint) 8;
       fetch_rectangle.y =
         y + sampler->context_rect[level].y -
         (maximum_width_and_height - sampler->context_rect[level].height) /
-	(gint) 8;
+        (gint) 8;
 
       fetch_rectangle.width  = maximum_width_and_height;
       fetch_rectangle.height = maximum_width_and_height;
diff --git a/gegl/buffer/gegl-sampler.h b/gegl/buffer/gegl-sampler.h
index 7b01ef3..3d73ccd 100644
--- a/gegl/buffer/gegl-sampler.h
+++ b/gegl/buffer/gegl-sampler.h
@@ -41,7 +41,7 @@ G_BEGIN_DECLS
  * The way the samplers use mipmap levels, square buffers are
  * preferable to rectangular ones.
  */
-#define GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT 64
+#define GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT 256
 
 typedef struct _GeglSamplerClass GeglSamplerClass;
 
diff --git a/operations/transform/transform-core.c b/operations/transform/transform-core.c
index 9965ea0..1723726 100644
--- a/operations/transform/transform-core.c
+++ b/operations/transform/transform-core.c
@@ -797,20 +797,14 @@ transform_affine (GeglBuffer  *dest,
   const GeglRectangle *dest_extent;
   gint                 x,
                        y;
-  gfloat * restrict    dest_buf,
-                      *dest_ptr;
   GeglMatrix3          inverse;
   GeglMatrix2          inverse_jacobian;
-  gdouble              u_start,
-                       v_start,
-                       u_float,
-                       v_float,
-                       base_u,
+  gdouble              base_u,
                        base_v;
-  const Babl          *format = babl_format ("RaGaBaA float");
   gint                 dest_pixels,
                        flip_x = 0,
                        flip_y = 0;
+  const Babl          *format = babl_format ("RaGaBaA float");
 
   /*
    * XXX: fast paths as existing in files in the same dir as
@@ -966,24 +960,26 @@ transform_affine (GeglBuffer  *dest,
   while (gegl_buffer_iterator_next (i))
     {
       GeglRectangle *roi = &i->roi[0];
+      gfloat * restrict dest_buf = (gfloat *)i->data[0];
 
-      dest_buf = (gfloat *)i->data[0];
-
-      u_start = base_u +
-                inverse.coeff [0][0] * ( roi->x + flip_x * roi->width  ) +
-                inverse.coeff [0][1] * ( roi->y + flip_y * roi->height );
-      v_start = base_v +
-                inverse.coeff [1][0] * ( roi->x + flip_x * roi->width  ) +
-                inverse.coeff [1][1] * ( roi->y + flip_y * roi->height );
-
-      dest_ptr = dest_buf +
-                 (gint) 4 * flip_x * (roi->width  - (gint) 1) +
-                 (gint) 4 * flip_y * (roi->height - (gint) 1) * roi->width;
+      gfloat * restrict dest_ptr =
+        dest_buf +
+        (gint) 4 * ( flip_x * (roi->width  - (gint) 1) +
+                     flip_y * (roi->height - (gint) 1) * roi->width );
+
+      gdouble u_start =
+        base_u +
+        inverse.coeff [0][0] * ( roi->x + flip_x * roi->width  ) +
+        inverse.coeff [0][1] * ( roi->y + flip_y * roi->height );
+      gdouble v_start =
+        base_v +
+        inverse.coeff [1][0] * ( roi->x + flip_x * roi->width  ) +
+        inverse.coeff [1][1] * ( roi->y + flip_y * roi->height );
 
       for (y = roi->height; y--;)
         {
-          u_float = u_start;
-          v_float = v_start;
+          gdouble u_float = u_start;
+          gdouble v_float = v_start;
 
           for (x = roi->width; x--;)
             {
@@ -993,7 +989,6 @@ transform_affine (GeglBuffer  *dest,
                                 &inverse_jacobian,
                                 dest_ptr,
                                 GEGL_ABYSS_NONE);
-
               dest_ptr += (gint) 4 - (gint) 8 * flip_x;
 
               u_float += inverse_jacobian.coeff [0][0];
@@ -1008,102 +1003,6 @@ transform_affine (GeglBuffer  *dest,
     }
 }
 
-#if 0
-static void
-transform_generic (GeglBuffer  *dest,
-                   GeglBuffer  *src,
-                   GeglMatrix3 *matrix,
-                   GeglSampler *sampler,
-                   gint         level)
-{
-  GeglBufferIterator  *i;
-  const GeglRectangle *dest_extent;
-  gint                 x,
-                       y;
-  gfloat * restrict    dest_buf,
-                      *dest_ptr;
-  GeglMatrix3          inverse;
-  gdouble              u_start,
-                       v_start,
-                       w_start,
-                       u_float,
-                       v_float,
-                       w_float;
-  const Babl          *format = babl_format ("RaGaBaA float");
-  gint                 dest_pixels;
-
-  g_object_get (dest, "pixels", &dest_pixels, NULL);
-  dest_extent = gegl_buffer_get_extent (dest);
-
-  i = gegl_buffer_iterator_new (dest,
-                                dest_extent,
-                                level,
-                                format,
-                                GEGL_BUFFER_WRITE,
-                                GEGL_ABYSS_NONE);
-
-  while (gegl_buffer_iterator_next (i))
-    {
-      GeglRectangle *roi = &i->roi[0];
-
-      dest_buf = (gfloat *)i->data[0];
-
-      gegl_matrix3_copy_into (&inverse, matrix);
-      gegl_matrix3_invert (&inverse);
-
-      u_start = inverse.coeff [0][0] * (roi->x + (gdouble) 0.5) +
-                inverse.coeff [0][1] * (roi->y + (gdouble) 0.5) +
-                inverse.coeff [0][2];
-      v_start = inverse.coeff [1][0] * (roi->x + (gdouble) 0.5)  +
-                inverse.coeff [1][1] * (roi->y + (gdouble) 0.5)  +
-                inverse.coeff [1][2];
-      w_start = inverse.coeff [2][0] * (roi->x + (gdouble) 0.5)  +
-                inverse.coeff [2][1] * (roi->y + (gdouble) 0.5)  +
-                inverse.coeff [2][2];
-
-      for (dest_ptr = dest_buf, y = roi->height; y--;)
-        {
-          u_float = u_start;
-          v_float = v_start;
-          w_float = w_start;
-
-          for (x = roi->width; x--;)
-            {
-              GeglMatrix2 inverse_jacobian;
-              gdouble w_recip = 1.0 / w_float;
-              gdouble u = u_float * w_recip;
-              gdouble v = v_float * w_recip;
-
-              inverse_jacobian.coeff [0][0] =
-                (inverse.coeff [0][0] - inverse.coeff [2][0] * u) * w_recip;
-              inverse_jacobian.coeff [0][1] =
-                (inverse.coeff [0][1] - inverse.coeff [2][1] * u) * w_recip;
-              inverse_jacobian.coeff [1][0] =
-                (inverse.coeff [1][0] - inverse.coeff [2][0] * v) * w_recip;
-              inverse_jacobian.coeff [1][1] =
-                (inverse.coeff [1][1] - inverse.coeff [2][1] * v) * w_recip;
-
-              gegl_sampler_get (sampler,
-                                u,
-                                v,
-                                &inverse_jacobian,
-                                dest_ptr,
-                                GEGL_ABYSS_NONE);
-              dest_ptr+=4;
-
-              u_float += inverse.coeff [0][0];
-              v_float += inverse.coeff [1][0];
-              w_float += inverse.coeff [2][0];
-            }
-
-          u_start += inverse.coeff [0][1];
-          v_start += inverse.coeff [1][1];
-          w_start += inverse.coeff [2][1];
-        }
-    }
-}
-#endif
-
 static void
 transform_generic (GeglBuffer  *dest,
                    GeglBuffer  *src,



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