[gegl] gegl/buffer: remove mipmap code from nohalo



commit 0b0ecbb67198d6318ed163522e5233ecbc18ff25
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed Oct 11 03:48:44 2017 +0200

    gegl/buffer: remove mipmap code from nohalo
    
    This does the same modification that preceding commits did to lohalo, for
    sigificant downsampling this might result in sharper/aliased results, and maybe
    the user would be better of having chosen linear or cubic resamplers which use
    a box-filter for scaling down. A similar box-filter might at a later stage be
    integrated as a replacement for the mipmap using code that were in nohalo and
    lohalo.
    
    This should fix bug #763557

 gegl/buffer/gegl-sampler-nohalo.c |  415 +------------------------------------
 1 files changed, 1 insertions(+), 414 deletions(-)
---
diff --git a/gegl/buffer/gegl-sampler-nohalo.c b/gegl/buffer/gegl-sampler-nohalo.c
index 68cb552..09aa747 100644
--- a/gegl/buffer/gegl-sampler-nohalo.c
+++ b/gegl/buffer/gegl-sampler-nohalo.c
@@ -231,143 +231,6 @@
  */
 #define NOHALO_FLOORED_DIVISION_BY_2(_a_) ( (_a_)>>1 )
 
-/*
- * Convenience macros. _level_ and _previous_level_ must be a plain
- * integers (like "1", "2" etc) because it is literally replaced (note
- * the "##_level").
- */
-
-#define NOHALO_FIND_CLOSEST_LOCATIONS(_previous_level_,_level_) \
-  const gfloat closest_left_##_level_ =                         \
-    odd_ix_##_previous_level_                                   \
-    ?                                                           \
-    (gfloat) ( -( NOHALO_OFFSET_##_previous_level_ + 1.5 ) )    \
-    :                                                           \
-    (gfloat) ( -( NOHALO_OFFSET_##_previous_level_ + 0.5 ) );   \
-  const gfloat closest_rite_##_level_ =                         \
-    odd_ix_##_previous_level_                                   \
-    ?                                                           \
-    (gfloat) (  ( NOHALO_OFFSET_##_previous_level_ + 0.5 ) )    \
-    :                                                           \
-    (gfloat) (  ( NOHALO_OFFSET_##_previous_level_ + 1.5 ) );   \
-  const gfloat closest_top_##_level_  =                         \
-    odd_iy_##_previous_level_                                   \
-    ?                                                           \
-    (gfloat) ( -( NOHALO_OFFSET_##_previous_level_ + 1.5 ) )    \
-    :                                                           \
-    (gfloat) ( -( NOHALO_OFFSET_##_previous_level_ + 0.5 ) );   \
-  const gfloat closest_bot_##_level_  =                         \
-    odd_iy_##_previous_level_                                   \
-    ?                                                           \
-    (gfloat) (  ( NOHALO_OFFSET_##_previous_level_ + 0.5 ) )    \
-    :                                                           \
-    (gfloat) (  ( NOHALO_OFFSET_##_previous_level_ + 1.5 ) );
-
-#define NOHALO_FIND_CLOSEST_INDICES(_previous_level_,_level_)             \
-  const gint in_left_##_level_ =                                          \
-    -NOHALO_OFFSET_##_previous_level_        + odd_ix_##_previous_level_; \
-  const gint in_rite_##_level_ =                                          \
-    ( NOHALO_OFFSET_##_previous_level_ - 1 ) + odd_ix_##_previous_level_; \
-  const gint in_top_##_level_  =                                          \
-    -NOHALO_OFFSET_##_previous_level_        + odd_iy_##_previous_level_; \
-  const gint in_bot_##_level_  =                                          \
-    ( NOHALO_OFFSET_##_previous_level_ - 1 ) + odd_iy_##_previous_level_;
-
-#define NOHALO_FIND_FARTHEST_INDICES(_level_)                            \
-  const gint out_left_##_level_ =                                        \
-    NOHALO_MAX                                                           \
-    (                                                                    \
-      (gint) ceilf  (                                                    \
-        (float)                                                          \
-          ( ( x_##_level_ - bounding_box_half_width  ) * (gfloat) 0.5 )) \
-      ,                                                                  \
-      -NOHALO_OFFSET_MIPMAP                                              \
-    );                                                                   \
-  const gint out_rite_##_level_ =                                        \
-    NOHALO_MIN                                                           \
-    (                                                                    \
-      (gint) floorf (                                                    \
-        (float)                                                          \
-          ( ( x_##_level_ + bounding_box_half_width  ) * (gfloat) 0.5 )) \
-      ,                                                                  \
-      NOHALO_OFFSET_MIPMAP                                               \
-    );                                                                   \
-  const gint out_top_##_level_ =                                         \
-    NOHALO_MAX                                                           \
-    (                                                                    \
-      (gint) ceilf  (                                                    \
-        (float)                                                          \
-          ( ( y_##_level_ - bounding_box_half_height ) * (gfloat) 0.5 )) \
-      ,                                                                  \
-      -NOHALO_OFFSET_MIPMAP                                              \
-    );                                                                   \
-  const gint out_bot_##_level_ =                                         \
-    NOHALO_MIN                                                           \
-    (                                                                    \
-      (gint) floorf (                                                    \
-        (float)                                                          \
-          ( ( y_##_level_ + bounding_box_half_height ) * (gfloat) 0.5 )) \
-      ,                                                                  \
-      NOHALO_OFFSET_MIPMAP                                               \
-    );
-
-#define NOHALO_MIPMAP_EWA_UPDATE(_level_)                           \
-  {                                                                 \
-    gint i;                                                         \
-    for ( i = out_top_##_level_; i <= in_top_##_level_; i++ )       \
-      {                                                             \
-        gint j = out_left_##_level_;                                \
-        do {                                                        \
-          NOHALO_MIPMAP_PIXEL_UPDATE(_level_);                      \
-        } while ( ++j <= out_rite_##_level_ );                      \
-      }                                                             \
-  }                                                                 \
-  {                                                                 \
-    gint i = in_top_##_level_ + (gint) 1;                           \
-    do {                                                            \
-      {                                                             \
-        gint j;                                                     \
-        for ( j = out_left_##_level_; j <= in_left_##_level_; j++ ) \
-          {                                                         \
-            NOHALO_MIPMAP_PIXEL_UPDATE(_level_);                    \
-          }                                                         \
-      }                                                             \
-      {                                                             \
-        gint j;                                                     \
-        for ( j = in_rite_##_level_; j <= out_rite_##_level_; j++ ) \
-          {                                                         \
-            NOHALO_MIPMAP_PIXEL_UPDATE(_level_);                    \
-          }                                                         \
-      }                                                             \
-    } while ( ++i < in_bot_##_level_ );                             \
-  }                                                                 \
-  {                                                                 \
-    gint i;                                                         \
-    for ( i = in_bot_##_level_; i <= out_bot_##_level_; i++ )       \
-      {                                                             \
-        gint j = out_left_##_level_;                                \
-        do {                                                        \
-          NOHALO_MIPMAP_PIXEL_UPDATE(_level_);                      \
-        } while ( ++j <= out_rite_##_level_ );                      \
-      }                                                             \
-  }
-
-#define NOHALO_MIPMAP_PIXEL_UPDATE(_level_) \
-  mipmap_ewa_update (_level_,               \
-                     j,                     \
-                     i,                     \
-                     c_major_x,             \
-                     c_major_y,             \
-                     c_minor_x,             \
-                     c_minor_y,             \
-                     x_##_level_,           \
-                     y_##_level_,           \
-                     channels,              \
-                     row_skip,              \
-                     input_ptr_##_level_,   \
-                     &total_weight,         \
-                     ewa_newval)
-
 enum
 {
   PROP_0,
@@ -2324,8 +2187,7 @@ gegl_sampler_nohalo_get (      GeglSampler*    restrict  self,
 
           /*
            * Grab the pixel values located within the level 0
-           * context_rect.  Farther ones will be accessed through
-           * higher mipmap levels.
+           * context_rect.
            */
           const gint out_left_0 =
             NOHALO_MAX
@@ -2392,281 +2254,6 @@ gegl_sampler_nohalo_get (      GeglSampler*    restrict  self,
           }
 
           {
-            /*
-             * In order to know whether we use higher mipmap level
-             * values, we need to check whether there is a level 1
-             * mipmap location within the ellipse. So, we need to
-             * 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 most
-             * NOHALO_OFFSET_0 away from the anchor pixel location in
-             * box distance.
-             */
-            /*
-             * Determine whether the anchor level_0 pixel locations
-             * are odd (VS even):
-             */
-            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
-             * NOHALO_SIZE_0xNOHALO_SIZE_0.
-             */
-            NOHALO_FIND_CLOSEST_LOCATIONS(0,1)
-
-            if (( x_0 - bounding_box_half_width  < closest_left_1 ) ||
-                ( x_0 + bounding_box_half_width  > closest_rite_1 ) ||
-                ( y_0 - bounding_box_half_height < closest_top_1  ) ||
-                ( y_0 + bounding_box_half_height > closest_bot_1  ))
-              {
-                /*
-                 * We most likely need higher mipmap level(s) because
-                 * the bounding box of the ellipse covers mipmap pixel
-                 * locations which involve data not "covered" by the
-                 * level 0 context_rect. (The ellipse may still fail
-                 * to involve mipmap level 1 values--in which case all
-                 * mipmap 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:
-                 */
-                const gint ix_1 = NOHALO_FLOORED_DIVISION_BY_2(ix_0);
-                const gint iy_1 = NOHALO_FLOORED_DIVISION_BY_2(iy_0);
-                /*
-                 * Get pointer to mipmap level 1 data:
-                 */
-                const gfloat* restrict input_ptr_1 =
-                  (gfloat*) gegl_sampler_get_from_mipmap (self,
-                                                          ix_1,
-                                                          iy_1,
-                                                          (gint) 1,
-                                                          repeat_mode);
-                /*
-                 * Position of the sampling location in the coordinate
-                 * system defined by the mipmap "pixel locations"
-                 * relative to the level 1 anchor pixel location. The
-                 * "-1/2"s are because the center of a level 0 pixel
-                 * is at a box distance of 1/2 from the center of the
-                 * closest level 1 pixel.
-                 */
-                const gfloat x_1 =
-                  x_0 + (gfloat) ( ix_0 - 2 * ix_1 ) - (gfloat) 0.5;
-                const gfloat y_1 =
-                  y_0 + (gfloat) ( iy_0 - 2 * iy_1 ) - (gfloat) 0.5;
-                /*
-                 * Key index ranges:
-                 */
-                /*
-                 * The "in" indices are the closest relative mipmap 1
-                 * indices of needed mipmap values:
-                 */
-                NOHALO_FIND_CLOSEST_INDICES(0,1)
-                /*
-                 * The "out" indices are the farthest relative mipmap 1
-                 * indices we use at this level:
-                 */
-                NOHALO_FIND_FARTHEST_INDICES(1)
-                /*
-                 * Update using mipmap level 1 values.
-                 */
-                NOHALO_MIPMAP_EWA_UPDATE(1)
-
-                {
-                /*
-                 * Second mipmap level.
-                 */
-                const gint odd_ix_1 = ix_1 % 2;
-                const gint odd_iy_1 = iy_1 % 2;
-                NOHALO_FIND_CLOSEST_LOCATIONS(1,2)
-                if (( x_1 - bounding_box_half_width  < closest_left_2 ) ||
-                    ( x_1 + bounding_box_half_width  > closest_rite_2 ) ||
-                    ( y_1 - bounding_box_half_height < closest_top_2  ) ||
-                    ( y_1 + bounding_box_half_height > closest_bot_2  ))
-                  {
-                  const gint ix_2 = NOHALO_FLOORED_DIVISION_BY_2(ix_1);
-                  const gint iy_2 = NOHALO_FLOORED_DIVISION_BY_2(iy_1);
-                  const gfloat* restrict input_ptr_2 =
-                    (gfloat*) gegl_sampler_get_from_mipmap (self,
-                                                            ix_2,
-                                                            iy_2,
-                                                            (gint) 2,
-                                                            repeat_mode);
-                  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 );
-                  NOHALO_FIND_CLOSEST_INDICES(1,2)
-                  NOHALO_FIND_FARTHEST_INDICES(2)
-                  NOHALO_MIPMAP_EWA_UPDATE(2)
-
-                  {
-                  /*
-                   * Third mipmap level.
-                   */
-                  const gint odd_ix_2 = ix_2 % 2;
-                  const gint odd_iy_2 = iy_2 % 2;
-                  NOHALO_FIND_CLOSEST_LOCATIONS(2,3)
-                  if (( x_2 - bounding_box_half_width  < closest_left_3 ) ||
-                      ( x_2 + bounding_box_half_width  > closest_rite_3 ) ||
-                      ( y_2 - bounding_box_half_height < closest_top_3  ) ||
-                      ( y_2 + bounding_box_half_height > closest_bot_3  ))
-                    {
-                    const gint ix_3 = NOHALO_FLOORED_DIVISION_BY_2(ix_2);
-                    const gint iy_3 = NOHALO_FLOORED_DIVISION_BY_2(iy_2);
-                    const gfloat* restrict input_ptr_3 =
-                      (gfloat*) gegl_sampler_get_from_mipmap (self,
-                                                              ix_3,
-                                                              iy_3,
-                                                              (gint) 3,
-                                                              repeat_mode);
-                    const gfloat x_3 =
-                      x_2 + (gfloat) ( 2 * ( ix_2 - 2 * ix_3 ) - 1 );
-                    const gfloat y_3 =
-                      y_2 + (gfloat) ( 2 * ( iy_2 - 2 * iy_3 ) - 1 );
-                    NOHALO_FIND_CLOSEST_INDICES(2,3)
-                    NOHALO_FIND_FARTHEST_INDICES(3)
-                    NOHALO_MIPMAP_EWA_UPDATE(3)
-
-                    {
-                    /*
-                     * Fourth mipmap level.
-                     */
-                    const gint odd_ix_3 = ix_3 % 2;
-                    const gint odd_iy_3 = iy_3 % 2;
-                    NOHALO_FIND_CLOSEST_LOCATIONS(3,4)
-                    if (( x_3 - bounding_box_half_width  < closest_left_4 ) ||
-                        ( x_3 + bounding_box_half_width  > closest_rite_4 ) ||
-                        ( y_3 - bounding_box_half_height < closest_top_4  ) ||
-                        ( y_3 + bounding_box_half_height > closest_bot_4  ))
-                      {
-                      const gint ix_4 = NOHALO_FLOORED_DIVISION_BY_2(ix_3);
-                      const gint iy_4 = NOHALO_FLOORED_DIVISION_BY_2(iy_3);
-                      const gfloat* restrict input_ptr_4 =
-                        (gfloat*) gegl_sampler_get_from_mipmap (self,
-                                                                ix_4,
-                                                                iy_4,
-                                                                (gint) 4,
-                                                                repeat_mode);
-                      const gfloat x_4 =
-                        x_3 + (gfloat) ( 2 * ( ix_3 - 2 * ix_4 ) - 1 );
-                      const gfloat y_4 =
-                        y_3 + (gfloat) ( 2 * ( iy_3 - 2 * iy_4 ) - 1 );
-                      NOHALO_FIND_CLOSEST_INDICES(3,4)
-                      NOHALO_FIND_FARTHEST_INDICES(4)
-                      NOHALO_MIPMAP_EWA_UPDATE(4)
-
-                      {
-                      /*
-                       * Fifth mipmap level.
-                       */
-                      const gint odd_ix_4 = ix_4 % 2;
-                      const gint odd_iy_4 = iy_4 % 2;
-                      NOHALO_FIND_CLOSEST_LOCATIONS(4,5)
-                      if (( x_4 - bounding_box_half_width  < closest_left_5 ) ||
-                          ( x_4 + bounding_box_half_width  > closest_rite_5 ) ||
-                          ( y_4 - bounding_box_half_height < closest_top_5  ) ||
-                          ( y_4 + bounding_box_half_height > closest_bot_5  ))
-                        {
-                        const gint ix_5 = NOHALO_FLOORED_DIVISION_BY_2(ix_4);
-                        const gint iy_5 = NOHALO_FLOORED_DIVISION_BY_2(iy_4);
-                        const gfloat* restrict input_ptr_5 =
-                          (gfloat*) gegl_sampler_get_from_mipmap (self,
-                                                                  ix_5,
-                                                                  iy_5,
-                                                                  (gint) 5,
-                                                                  repeat_mode);
-                        const gfloat x_5 =
-                          x_4 + (gfloat) ( 2 * ( ix_4 - 2 * ix_5 ) - 1 );
-                        const gfloat y_5 =
-                          y_4 + (gfloat) ( 2 * ( iy_4 - 2 * iy_5 ) - 1 );
-                        NOHALO_FIND_CLOSEST_INDICES(4,5)
-                        NOHALO_FIND_FARTHEST_INDICES(5)
-                        NOHALO_MIPMAP_EWA_UPDATE(5)
-
-                        {
-                        /*
-                         * Sixth mipmap level.
-                         */
-                        const gint odd_ix_5 = ix_5 % 2;
-                        const gint odd_iy_5 = iy_5 % 2;
-                        NOHALO_FIND_CLOSEST_LOCATIONS(5,6)
-                        if (( x_5 - bounding_box_half_width
-                              < closest_left_6 ) ||
-                            ( x_5 + bounding_box_half_width
-                              > closest_rite_6 ) ||
-                            ( y_5 - bounding_box_half_height
-                              < closest_top_6  ) ||
-                            ( y_5 + bounding_box_half_height
-                              > closest_bot_6  ))
-                          {
-                          const gint ix_6 = NOHALO_FLOORED_DIVISION_BY_2(ix_5);
-                          const gint iy_6 = NOHALO_FLOORED_DIVISION_BY_2(iy_5);
-                          const gfloat* restrict input_ptr_6 = (gfloat*)
-                            gegl_sampler_get_from_mipmap (self,
-                                                          ix_6,
-                                                          iy_6,
-                                                          (gint) 6,
-                                                          repeat_mode);
-                          const gfloat x_6 =
-                            x_5 + (gfloat) ( 2 * ( ix_5 - 2 * ix_6 ) - 1 );
-                          const gfloat y_6 =
-                            y_5 + (gfloat) ( 2 * ( iy_5 - 2 * iy_6 ) - 1 );
-                          NOHALO_FIND_CLOSEST_INDICES(5,6)
-                          NOHALO_FIND_FARTHEST_INDICES(6)
-                          NOHALO_MIPMAP_EWA_UPDATE(6)
-
-                          {
-                          /*
-                           * Seventh mipmap level (eight if counted
-                           * from zero = "straight up").
-                           */
-                          const gint odd_ix_6 = ix_6 % 2;
-                          const gint odd_iy_6 = iy_6 % 2;
-                          NOHALO_FIND_CLOSEST_LOCATIONS(6,7)
-                          if (( x_6 - bounding_box_half_width
-                                < closest_left_7 ) ||
-                              ( x_6 + bounding_box_half_width
-                                > closest_rite_7 ) ||
-                              ( y_6 - bounding_box_half_height
-                                < closest_top_7  ) ||
-                              ( y_6 + bounding_box_half_height
-                                > closest_bot_7  ))
-                            {
-                            const gint ix_7 =
-                              NOHALO_FLOORED_DIVISION_BY_2(ix_6);
-                            const gint iy_7 =
-                              NOHALO_FLOORED_DIVISION_BY_2(iy_6);
-                            const gfloat* restrict input_ptr_7 = (gfloat*)
-                              gegl_sampler_get_from_mipmap (self,
-                                                            ix_7,
-                                                            iy_7,
-                                                            (gint) 7,
-                                                            repeat_mode);
-                            const gfloat x_7 =
-                              x_6 + (gfloat) ( 2 * ( ix_6 - 2 * ix_7 ) - 1 );
-                            const gfloat y_7 =
-                              y_6 + (gfloat) ( 2 * ( iy_6 - 2 * iy_7 ) - 1 );
-                            NOHALO_FIND_CLOSEST_INDICES(6,7)
-                            NOHALO_FIND_FARTHEST_INDICES(7)
-                            NOHALO_MIPMAP_EWA_UPDATE(7)
-                            }
-                          }
-                          }
-                        }
-                        }
-                      }
-                      }
-                    }
-                    }
-                  }
-                  }
-                }
-              }
-
             {
               /*
                * Blend the LBB-Nohalo and EWA results:


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