[gegl] sampler: increase elbow in bilinear, use mipmap 0, set max width and height through #define



commit 6a619071b5596aa3846cad4be30bcb9251a9d8e5
Author: Nicolas Robidoux <nrobidoux git gnome org>
Date:   Sat Dec 15 18:47:58 2012 -0500

    sampler: increase elbow in bilinear, use mipmap 0, set max width and height through #define

 gegl/buffer/gegl-sampler-cubic.c  |   27 ++++++++++++++-------------
 gegl/buffer/gegl-sampler-linear.c |   14 ++++++++++----
 gegl/buffer/gegl-sampler-lohalo.c |    2 +-
 gegl/buffer/gegl-sampler.c        |   20 ++++++++++++--------
 gegl/buffer/gegl-sampler.h        |   10 ++++++++++
 5 files changed, 47 insertions(+), 26 deletions(-)
---
diff --git a/gegl/buffer/gegl-sampler-cubic.c b/gegl/buffer/gegl-sampler-cubic.c
index e4eff69..8448adf 100644
--- a/gegl/buffer/gegl-sampler-cubic.c
+++ b/gegl/buffer/gegl-sampler-cubic.c
@@ -166,26 +166,27 @@ gegl_sampler_cubic_get (      GeglSampler     *self,
                               GeglAbyssPolicy  repeat_mode)
 {
   GeglSamplerCubic *cubic = (GeglSamplerCubic*)(self);
-  const gint        offsets[16]={-4-64*4, 4, 4, 4,
-                                (64-3)*4, 4, 4, 4,
-                                (64-3)*4, 4, 4, 4,
-                                (64-3)*4, 4, 4, 4};
+  const gint        offsets[16] =
+                      {-4-GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT   *4, 4, 4, 4,
+                         (GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT-3)*4, 4, 4, 4,
+                         (GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT-3)*4, 4, 4, 4,
+                         (GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT-3)*4, 4, 4, 4};
   gfloat           *sampler_bptr;
   gfloat            factor;
-
   gfloat            newval[4] = {0.0, 0.0, 0.0, 0.0};
-
   gint              i,j;
   gint              k=0;
 
   /*
-   * The "-1/2"s are there because we want the index of the pixel to
-   * the left and top of the location, and with GIMP's convention the
-   * top left of the top left pixel is located at
-   * (1/2,1/2). Basically, we are converting from a coordinate system
-   * in which the origin is at the top left pixel of the pixel with
-   * index (0,0), to a coordinate system in which the origin is at the
-   * center of the same pixel.
+   * The "-1/2"s are there because we want the index of the pixel
+   * center to the left and top of the location, and with GIMP's
+   * convention the top left of the top left pixel is located at
+   * (0,0), and its center is at (1/2,1/2), so that anything less than
+   * 1/2 needs to go negative. Another way to look at this is that we
+   * are converting from a coordinate system in which the origin is at
+   * the top left corner of the pixel with index (0,0), to a
+   * coordinate system in which the origin is at the center of the
+   * same pixel.
    */
   const double iabsolute_x = (double) absolute_x - 0.5;
   const double iabsolute_y = (double) absolute_y - 0.5;
diff --git a/gegl/buffer/gegl-sampler-linear.c b/gegl/buffer/gegl-sampler-linear.c
index d9eab2c..ddb7e8e 100644
--- a/gegl/buffer/gegl-sampler-linear.c
+++ b/gegl/buffer/gegl-sampler-linear.c
@@ -66,7 +66,8 @@ gegl_sampler_linear_class_init (GeglSamplerLinearClass *klass)
  * 0 if it is found that round off error never sends things "too far
  * away". Nicolas would be very surprised if more than 1 is necessary.
  */
-#define LINEAR_EXTRA_ELBOW_ROOM 1
+#define LINEAR_EXTRA_ELBOW_ROOM 2
+
 static void
 gegl_sampler_linear_init (GeglSamplerLinear *self)
 {
@@ -85,7 +86,7 @@ gegl_sampler_linear_get (      GeglSampler*    restrict  self,
                                void*           restrict  output,
                                GeglAbyssPolicy           repeat_mode)
 {
-  const gint pixels_per_buffer_row = 64;
+  const gint pixels_per_buffer_row = GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT;
   const gint channels = 4;
 
   /*
@@ -107,8 +108,13 @@ gegl_sampler_linear_get (      GeglSampler*    restrict  self,
    * Point the data tile pointer to the first channel of the top_left
    * pixel value:
    */
-  const gfloat* restrict in_bptr =
-    gegl_sampler_get_ptr (self, ix, iy, repeat_mode);
+  const gfloat* restrict in_bptr = gegl_sampler_get_from_mipmap (self,
+								 ix,
+								 iy,
+								 0,
+								 repeat_mode);
+  /* const gfloat* restrict in_bptr = */
+  /*   gegl_sampler_get_ptr (self, ix, iy, repeat_mode); */
 
   /*
    * x is the x-coordinate of the sampling point relative to the
diff --git a/gegl/buffer/gegl-sampler-lohalo.c b/gegl/buffer/gegl-sampler-lohalo.c
index 7470f65..f0dadc4 100644
--- a/gegl/buffer/gegl-sampler-lohalo.c
+++ b/gegl/buffer/gegl-sampler-lohalo.c
@@ -1442,7 +1442,7 @@ gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
    * corresponds to fetch_rectangle.width in gegl_sampler_get_ptr.
    */
   const gint channels  = 4;
-  const gint pixels_per_row = 64;
+  const gint pixels_per_row = GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT;
   const gint row_skip = channels * pixels_per_row;
 
   /*
diff --git a/gegl/buffer/gegl-sampler.c b/gegl/buffer/gegl-sampler.c
index 9b93ed1..5f80788 100644
--- a/gegl/buffer/gegl-sampler.c
+++ b/gegl/buffer/gegl-sampler.c
@@ -225,7 +225,8 @@ gegl_sampler_get_ptr (GeglSampler *const sampler,
    * can be be requested in the horizontal or vertical directions (64
    * in GEGL).
    */
-  const gint maximum_width_and_height = 64;
+  const gint maximum_width_and_height =
+    GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT;
   g_assert (sampler->context_rect[0].width  <= maximum_width_and_height);
   g_assert (sampler->context_rect[0].height <= maximum_width_and_height);
 
@@ -257,12 +258,13 @@ gegl_sampler_get_ptr (GeglSampler *const sampler,
        * position. Consequently, we move the top left corner of the
        * context_rect by about one fourth of the maximal distance we
        * can (one fourth of one half = one eight), leaving an elbow
-       * room of about seven eight of what it could be. Given that the
-       * maximum width and height of the fetch_rectangle is 64, so
-       * that half of it is 32, one fourth of the elbow room is at most
-       * 8.
+       * room of about seven eight of what it could be.
+       *
+       * If the maximum width and height of the fetch_rectangle is 64,
+       * so that half of it is 32, one fourth of the elbow room is at
+       * most 8. If the fetch_rectangle is larger than that, a smaller
+       * elbow room may be preferable.
        */
-
       fetch_rectangle.x =
         x + sampler->context_rect[0].x -
         (maximum_width_and_height - sampler->context_rect[0].width ) / (gint) 8;
@@ -321,7 +323,8 @@ gegl_sampler_get_from_buffer (GeglSampler *const sampler,
    * can be be requested in the horizontal or vertical directions (64
    * in GEGL).
    */
-  const gint maximum_width_and_height = 64;
+  const gint maximum_width_and_height =
+    GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT;
   g_assert (sampler->context_rect[0].width  <= maximum_width_and_height);
   g_assert (sampler->context_rect[0].height <= maximum_width_and_height);
 
@@ -402,7 +405,8 @@ gegl_sampler_get_from_mipmap (GeglSampler *const sampler,
    * can be be requested in the horizontal or vertical directions (64
    * in GEGL).
    */
-  const gint maximum_width_and_height = 64;
+  const gint maximum_width_and_height =
+    GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT;
   g_assert (sampler->context_rect[level].width  <= maximum_width_and_height);
   g_assert (sampler->context_rect[level].height <= maximum_width_and_height);
   g_assert (level >= 0 && level < GEGL_SAMPLER_MIPMAP_LEVELS);
diff --git a/gegl/buffer/gegl-sampler.h b/gegl/buffer/gegl-sampler.h
index 72563be..7b01ef3 100644
--- a/gegl/buffer/gegl-sampler.h
+++ b/gegl/buffer/gegl-sampler.h
@@ -31,7 +31,17 @@ G_BEGIN_DECLS
 #define GEGL_IS_SAMPLER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_SAMPLER))
 #define GEGL_IS_SAMPLER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GEGL_TYPE_SAMPLER))
 #define GEGL_SAMPLER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GEGL_TYPE_SAMPLER, GeglSamplerClass))
+
+/*
+ * This should be set to the largest number of mipmap levels (counted
+ * starting at 0 = no box filtering) actually used by any sampler.
+ */
 #define GEGL_SAMPLER_MIPMAP_LEVELS   4
+/*
+ * The way the samplers use mipmap levels, square buffers are
+ * preferable to rectangular ones.
+ */
+#define GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT 64
 
 typedef struct _GeglSamplerClass GeglSamplerClass;
 



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