[gegl] gegl-buffer: make more code mipmap level aware



commit 82b95d60aa616914fdd20b84abb4afff00f3e50e
Author: Øyvind Kolås <pippin gimp org>
Date:   Sun Feb 5 19:38:46 2017 +0100

    gegl-buffer: make more code mipmap level aware
    
    Adds a level argument to gegl_tile_indice, this makes more tests pass.

 gegl/buffer/gegl-buffer-access.c            |   41 ++++++++++++++-------------
 gegl/buffer/gegl-buffer-iterator.c          |   23 ++++-----------
 gegl/buffer/gegl-buffer-private.h           |    7 ++--
 gegl/buffer/gegl-buffer-save.c              |    4 +-
 gegl/buffer/gegl-sampler-nearest.c          |    4 +-
 tests/Makefile.am                           |    5 +--
 tests/buffer/reference/mipmap_iterator.buf  |   12 ++++----
 tests/buffer/reference/mipmap_iterator2.buf |   32 ++++++++++----------
 tests/buffer/reference/mipmap_sampler.buf   |   40 +++++++++++++-------------
 tests/mipmap/unsharp-reference.png          |  Bin 87354 -> 87326 bytes
 tests/mipmap/unsharp.sh                     |    2 +-
 11 files changed, 78 insertions(+), 92 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index 94f129f..86e55c9 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -123,8 +123,8 @@ gegl_buffer_get_pixel (GeglBuffer     *buffer,
     gint tile_height = buffer->tile_height;
     gint tiledy      = y + buffer->shift_y;
     gint tiledx      = x + buffer->shift_x;
-    gint indice_x    = gegl_tile_indice (tiledx, tile_width);
-    gint indice_y    = gegl_tile_indice (tiledy, tile_height);
+    gint indice_x    = gegl_tile_indice (tiledx, tile_width, 0);
+    gint indice_y    = gegl_tile_indice (tiledy, tile_height, 0);
 
     GeglTile *tile = buffer->tile_storage->hot_tile;
     const Babl *fish = NULL;
@@ -190,8 +190,8 @@ __gegl_buffer_set_pixel (GeglBuffer     *buffer,
     gint tile_height = buffer->tile_height;
     gint tiledy      = y + buffer->shift_y;
     gint tiledx      = x + buffer->shift_x;
-    gint indice_x    = gegl_tile_indice (tiledx, tile_width);
-    gint indice_y    = gegl_tile_indice (tiledy, tile_height);
+    gint indice_x    = gegl_tile_indice (tiledx, tile_width, 0);
+    gint indice_y    = gegl_tile_indice (tiledy, tile_height, 0);
 
     GeglTile *tile = buffer->tile_storage->hot_tile;
     const Babl *fish = NULL;
@@ -386,8 +386,8 @@ gegl_buffer_iterate_write (GeglBuffer          *buffer,
           gint      tiledx  = buffer_x + bufx;
           gint      offsetx = gegl_tile_offset (tiledx, tile_width);
           gint      y       = bufy;
-          gint index_x;
-          gint index_y;
+          gint      index_x;
+          gint      index_y;
           gint      lskip, rskip, pixels, row;
           guchar   *bp, *tile_base, *tp;
           GeglTile *tile;
@@ -399,8 +399,8 @@ gegl_buffer_iterate_write (GeglBuffer          *buffer,
           else
             pixels = tile_width - offsetx;
 
-          index_x = gegl_tile_indice (tiledx, tile_width);
-          index_y = gegl_tile_indice (tiledy, tile_height);
+          index_x = gegl_tile_indice (tiledx, tile_width, level);
+          index_y = gegl_tile_indice (tiledy, tile_height, level);
 
           tile = gegl_buffer_get_tile (buffer, index_x, index_y, level);
 
@@ -598,8 +598,8 @@ gegl_buffer_iterate_read_simple (GeglBuffer          *buffer,
             pixels = tile_width - offsetx;
 
           tile = gegl_tile_source_get_tile ((GeglTileSource *) (buffer),
-                                            gegl_tile_indice (tiledx, tile_width),
-                                            gegl_tile_indice (tiledy, tile_height),
+                                            gegl_tile_indice (tiledx, tile_width, 0),
+                                            gegl_tile_indice (tiledy, tile_height, 0),
                                             level);
 
           if (!tile)
@@ -828,7 +828,7 @@ gegl_buffer_iterate_read_abyss_clamp (GeglBuffer          *buffer,
   read_input_rect.y = read_output_rect.y - y_read_offset;
   read_input_rect.width = read_output_rect.width;
   read_input_rect.height = read_output_rect.height;
-
+#if 1
   if (level)
     gegl_buffer_iterate_read_fringed (buffer,
                                       &read_input_rect,
@@ -839,6 +839,7 @@ gegl_buffer_iterate_read_abyss_clamp (GeglBuffer          *buffer,
                                       level,
                                       GEGL_ABYSS_CLAMP);
   else
+#endif
     gegl_buffer_iterate_read_simple (buffer,
                                      &read_input_rect,
                                      read_buf,
@@ -967,10 +968,10 @@ gegl_buffer_iterate_read_abyss_loop (GeglBuffer          *buffer,
   gint          origin_x;
 
   /* Loop abyss works like iterating over a grid of tiles the size of the abyss */
-  gint loop_chunk_ix = gegl_tile_indice (roi->x - abyss->x, abyss->width);
-  gint loop_chunk_iy = gegl_tile_indice (roi->y - abyss->y, abyss->height);
+  gint loop_chunk_ix = gegl_tile_indice (roi->x - abyss->x, abyss->width, level);
+  gint loop_chunk_iy = gegl_tile_indice (roi->y - abyss->y, abyss->height, level);
 
-  current_roi.x = loop_chunk_ix * abyss->width + abyss->x;
+  current_roi.x = loop_chunk_ix * abyss->width  + abyss->x;
   current_roi.y = loop_chunk_iy * abyss->height + abyss->y;
 
   current_roi.width  = abyss->width;
@@ -1685,10 +1686,10 @@ gegl_buffer_copy (GeglBuffer          *src,
                 src_x = dst_x - (dst_rect->x - src_rect->x) + src->shift_x;
                 src_y = dst_y - (dst_rect->y - src_rect->y) + src->shift_y;
 
-                stx = gegl_tile_indice (src_x, tile_width);
-                sty = gegl_tile_indice (src_y, tile_height);
-                dtx = gegl_tile_indice (dst_x, tile_width);
-                dty = gegl_tile_indice (dst_y, tile_height);
+                stx = gegl_tile_indice (src_x, tile_width, 0);
+                sty = gegl_tile_indice (src_y, tile_height, 0);
+                dtx = gegl_tile_indice (dst_x, tile_width, 0);
+                dty = gegl_tile_indice (dst_y, tile_height, 0);
 
                 src_tile = gegl_buffer_get_tile (src, stx, sty, 0);
 
@@ -1856,8 +1857,8 @@ gegl_buffer_clear (GeglBuffer          *dst,
               {
                 gint dtx, dty;
 
-                dtx = gegl_tile_indice (dst_x, tile_width);
-                dty = gegl_tile_indice (dst_y, tile_height);
+                dtx = gegl_tile_indice (dst_x, tile_width, 0);
+                dty = gegl_tile_indice (dst_y, tile_height, 0);
 
                 gegl_tile_source_void ((GeglTileSource*)dst, dtx, dty, 0);
               }
diff --git a/gegl/buffer/gegl-buffer-iterator.c b/gegl/buffer/gegl-buffer-iterator.c
index 4a99892..6d40f47 100644
--- a/gegl/buffer/gegl-buffer-iterator.c
+++ b/gegl/buffer/gegl-buffer-iterator.c
@@ -125,10 +125,10 @@ gegl_buffer_iterator_add (GeglBufferIterator  *iter,
   GeglBufferIteratorPriv *priv = iter->priv;
   int                     index;
   SubIterState           *sub;
+  level = 0;
 
   g_return_val_if_fail (priv->num_buffers < GEGL_BUFFER_MAX_ITERATORS, 0);
 
-
   index = priv->num_buffers++;
   sub = &priv->sub_iter[index];
 
@@ -141,14 +141,6 @@ gegl_buffer_iterator_add (GeglBufferIterator  *iter,
   sub->buffer       = buf;
   sub->full_rect    = *roi;
 
-  if (level)
-  {
-    sub->full_rect.x >>= level;
-    sub->full_rect.y >>= level;
-    sub->full_rect.width >>= level;
-    sub->full_rect.height >>= level;
-  }
-
   sub->access_mode  = access_mode;
   sub->abyss_policy = abyss_policy;
   sub->current_tile = NULL;
@@ -164,9 +156,6 @@ gegl_buffer_iterator_add (GeglBufferIterator  *iter,
       priv->sub_iter[index].full_rect.height = priv->sub_iter[0].full_rect.height;
     }
 
-  //if (level != 0)
-  //  g_warning ("iterator level != 0");
-
   return index;
 }
 
@@ -235,8 +224,8 @@ retile_subs (GeglBufferIterator *iter,
   int shift_x = priv->origin_tile.x;
   int shift_y = priv->origin_tile.y;
 
-  int tile_x = gegl_tile_indice (x + shift_x, priv->origin_tile.width);
-  int tile_y = gegl_tile_indice (y + shift_y, priv->origin_tile.height);
+  int tile_x = gegl_tile_indice (x + shift_x, priv->origin_tile.width, 0);
+  int tile_y = gegl_tile_indice (y + shift_y, priv->origin_tile.height, 0);
 
   /* Reset tile size */
   real_roi.x = (tile_x * priv->origin_tile.width)  - shift_x;
@@ -322,14 +311,14 @@ get_tile (GeglBufferIterator *iter,
     }
   else
     {
-      int shift_x = buf->shift_x; // XXX: affect by level?
+      int shift_x = buf->shift_x;
       int shift_y = buf->shift_y;
 
       int tile_width  = buf->tile_width;
       int tile_height = buf->tile_height;
 
-      int tile_x = gegl_tile_indice (iter->roi[index].x + shift_x, tile_width);
-      int tile_y = gegl_tile_indice (iter->roi[index].y + shift_y, tile_height);
+      int tile_x = gegl_tile_indice (iter->roi[index].x + shift_x, tile_width, sub->level);
+      int tile_y = gegl_tile_indice (iter->roi[index].y + shift_y, tile_height, sub->level);
 
       sub->current_tile = gegl_buffer_get_tile (buf, tile_x, tile_y, sub->level);
 
diff --git a/gegl/buffer/gegl-buffer-private.h b/gegl/buffer/gegl-buffer-private.h
index 9d9100e..3cb4264 100644
--- a/gegl/buffer/gegl-buffer-private.h
+++ b/gegl/buffer/gegl-buffer-private.h
@@ -213,10 +213,9 @@ gboolean gegl_buffer_scan_compatible (GeglBuffer *bufferA,
 /* helper function to compute tile indices and offsets for coordinates
  * based on a tile stride (tile_width or tile_height)
  */
-#define gegl_tile_indice(coordinate,stride) \
+#define gegl_tile_indice(coordinate,stride,level) \
   (((coordinate) >= 0)?\
-      (coordinate) / (stride):\
-      ((((coordinate) + 1) /(stride)) - 1))
-
+      ((coordinate)>>level) / (stride):\
+      (((((coordinate)>>level) + 1) /(stride)) - 1))
 
 #endif
diff --git a/gegl/buffer/gegl-buffer-save.c b/gegl/buffer/gegl-buffer-save.c
index ce0cbdd..16020e0 100644
--- a/gegl/buffer/gegl-buffer-save.c
+++ b/gegl/buffer/gegl-buffer-save.c
@@ -263,8 +263,8 @@ gegl_buffer_save (GeglBuffer          *buffer,
                 gint tiledx  = roi->x + bufx;
                 gint offsetx = gegl_tile_offset (tiledx, tile_width);
 
-                gint tx = gegl_tile_indice (tiledx / factor, tile_width);
-                gint ty = gegl_tile_indice (tiledy / factor, tile_height);
+                gint tx = gegl_tile_indice (tiledx / factor, tile_width, z);
+                gint ty = gegl_tile_indice (tiledy / factor, tile_height, z);
 
                 if (gegl_tile_source_exist (GEGL_TILE_SOURCE (buffer), tx, ty, z))
                   {
diff --git a/gegl/buffer/gegl-sampler-nearest.c b/gegl/buffer/gegl-sampler-nearest.c
index f610951..f17c031 100644
--- a/gegl/buffer/gegl-sampler-nearest.c
+++ b/gegl/buffer/gegl-sampler-nearest.c
@@ -139,8 +139,8 @@ gegl_sampler_get_pixel (GeglSampler    *sampler,
     gint tile_height = buffer->tile_height;
     gint tiledy      = y + buffer->shift_y;
     gint tiledx      = x + buffer->shift_x;
-    gint indice_x    = gegl_tile_indice (tiledx, tile_width);
-    gint indice_y    = gegl_tile_indice (tiledy, tile_height);
+    gint indice_x    = gegl_tile_indice (tiledx, tile_width, 0);
+    gint indice_y    = gegl_tile_indice (tiledy, tile_height, 0);
 
     GeglTile *tile = buffer->tile_storage->hot_tile;
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 865f359..55b3aeb 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,12 +4,9 @@ SUBDIRS = \
        buffer \
        compositions \
        simple \
+        mipmap \
        xml \
        ff-load-save \
        python 
 
-if ENABLE_WORKSHOP  # we do not want these tests to run by default, as long as they fail
-SUBDIRS += mipmap 
-endif
-
 #opencl
diff --git a/tests/buffer/reference/mipmap_iterator.buf b/tests/buffer/reference/mipmap_iterator.buf
index 8b1b573..01377cf 100644
--- a/tests/buffer/reference/mipmap_iterator.buf
+++ b/tests/buffer/reference/mipmap_iterator.buf
@@ -48,12 +48,12 @@ Test: mipmap_iterator
 ▌                    ▐
 ▌                    ▐
 ▌░░░░░░░░░░░░░░░░░░░░▐
-▌░░░░░░░░░░░░░░░░░░░░▐
-▌░░░░░░░░░░░░░░░░░░░░▐
-▌░░░░░░░░░░░░░░░░░░░░▐
-▌░░░░░░░░░░░░░░░░░░░░▐
-▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
-▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
+▌░░░░    ░░░░░░░░░░░░▐
+▌░░░░    ░░░░░░░░░░░░▐
+▌░░░░    ░░░░░░░░░░░░▐
+▌░░░░    ░░░░░░░░░░░░▐
+▌▒▒▒▒    ▒▒▒▒▒▒▒▒▒▒▒▒▐
+▌▒▒▒▒    ▒▒▒▒▒▒▒▒▒▒▒▒▐
 ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
 ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
 ▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
diff --git a/tests/buffer/reference/mipmap_iterator2.buf b/tests/buffer/reference/mipmap_iterator2.buf
index c3168e0..8f65cad 100644
--- a/tests/buffer/reference/mipmap_iterator2.buf
+++ b/tests/buffer/reference/mipmap_iterator2.buf
@@ -4,17 +4,17 @@ Test: mipmap_iterator2
 ▌                    ▐
 ▌                    ▐
 ▌░░░░░░░░░░░░░░░░░░░░▐
-▌░░░░░░░░░░░░░░░░░░░░▐
-▌░░░░░░░░░░░░░░░░░░░░▐
-▌░░░░░░░░░░░░░░░░░░░░▐
-▌░░░░░░░░░░░░░░░░░░░░▐
-▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
-▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
-▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
-▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
-▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▐
-▌▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▐
-▌▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▐
+▌░░░░▓▓▓▓▓▓▓▓▓░░░░░░░▐
+▌░░░░▓▓▓▓▓▓▓▓▓░░░░░░░▐
+▌░░░░▓▓▓▓▓▓▓▓▓░░░░░░░▐
+▌░░░░▓▓▓▓▓▓▓▓▓░░░░░░░▐
+▌▒▒▒▒█████████▒▒▒▒▒▒▒▐
+▌▒▒▒▒█████████▒▒▒▒▒▒▒▐
+▌▒▒▒▒█████████▒▒▒▒▒▒▒▐
+▌▒▒▒▒█████████▒▒▒▒▒▒▒▐
+▌▒▒▒▒█████████▒▒▒▒▒▒▒▐
+▌▓▓▓▓█████████▓▓▓▓▓▓▓▐
+▌▓▓▓▓█████████▓▓▓▓▓▓▓▐
 ▌▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▐
 ▌▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▐
 ▌▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▐
@@ -24,13 +24,13 @@ Test: mipmap_iterator2
 ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜
 ▌                    ▐
 ▌░░░░░░░░░░          ▐
-▌░░▓▓▓▓░░░░          ▐
-▌░░▓▓▓▓░░░░          ▐
-▌▒▒████▒▒▒▒          ▐
-▌▒▒████▒▒▒▒          ▐
+▌░░▓▓▓▓▒░░░          ▐
+▌░░▓▓▓▓▒░░░          ▐
+▌▒▒████▓▒▒▒          ▐
+▌▒▒████▓▒▒▒          ▐
+▌▓▓█████▓▓▓          ▐
 ▌▓▓████▓▓▓▓          ▐
 ▌▓▓▓▓▓▓▓▓▓▓          ▐
-▌▓▓▓▓▓▓▓▓▓▓          ▐
 ▌██████████          ▐
 ▌                    ▐
 ▌                    ▐
diff --git a/tests/buffer/reference/mipmap_sampler.buf b/tests/buffer/reference/mipmap_sampler.buf
index d57724d..e74f47a 100644
--- a/tests/buffer/reference/mipmap_sampler.buf
+++ b/tests/buffer/reference/mipmap_sampler.buf
@@ -1,31 +1,31 @@
 Test: mipmap_sampler
 ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
-▌                    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
+▌  ░░░░▒▒▒▒▓▓▓▓██    ▐
 ▌                    ▐
 ▌                    ▐
 ▌                    ▐
 ▌                    ▐
 ▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟
-4.000000,5.000000 : 0.250000
-6.000000,4.000000 : 0.375000
-8.000000,10.000000 : 0.500000
+4.000000,5.000000 : 0.281250
+6.000000,4.000000 : 0.406250
+8.000000,10.000000 : 0.531250
 ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜
-▌                    ▐
+▌ ░░▒▒▓▓█            ▐
 ▌ ░░▒▒▓▓█            ▐
 ▌ ░░▒▒▓▓█            ▐
 ▌ ░░▒▒▓▓█            ▐
diff --git a/tests/mipmap/unsharp-reference.png b/tests/mipmap/unsharp-reference.png
index d3435d5..2db523a 100644
Binary files a/tests/mipmap/unsharp-reference.png and b/tests/mipmap/unsharp-reference.png differ
diff --git a/tests/mipmap/unsharp.sh b/tests/mipmap/unsharp.sh
index 50154e5..366b331 100755
--- a/tests/mipmap/unsharp.sh
+++ b/tests/mipmap/unsharp.sh
@@ -14,7 +14,7 @@ else
           -- unsharp-mask scale=10.0  \
   && $abs_top_builddir/tools/gegl-imgcmp                           \
           $abs_top_srcdir/tests/mipmap/unsharp-reference.png \
-          $abs_top_builddir/tests/mipmap/unsharp-output.png 10.0
+          $abs_top_builddir/tests/mipmap/unsharp-output.png 20.0
   failure=$?
   #if [ $failure -eq 0 ]; then
    # rm -f $abs_top_builddir/tests/mipmap/unsharp-output.png


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