[gegl] Moved GeglLookup to its own files.



commit 6287ded1dafbdf8632ad064968261a7bef20590d
Author: �yvind Kolås <pippin gimp org>
Date:   Thu Dec 3 13:09:42 2009 +0000

    Moved GeglLookup to its own files.
    
    Also turned off caching of negative values.
    Note: changes to these values are a change in the ABI and ops using
    GeglLookup will have to be recompiled.

 examples/float-lookup.c |    2 +-
 gegl/Makefile.am        |    3 +
 gegl/gegl-lookup.c      |   39 +++++
 gegl/gegl-lookup.h      |  115 +++++++++++++
 gegl/gegl-plugin.h      |    2 +
 gegl/gegl-types.h       |    1 -
 gegl/gegl-utils.c       |  427 ++++++++++++++++++++++++-----------------------
 gegl/gegl-utils.h       |   80 ---------
 8 files changed, 374 insertions(+), 295 deletions(-)
---
diff --git a/examples/float-lookup.c b/examples/float-lookup.c
index e554ee3..9a4a8bc 100644
--- a/examples/float-lookup.c
+++ b/examples/float-lookup.c
@@ -1,5 +1,5 @@
 #include <gegl.h>
-#include <gegl/gegl-utils.h>
+#include <gegl-plugin.h>
 #include <math.h>
 
 static gfloat wrapped_sqrt (gfloat   in,
diff --git a/gegl/Makefile.am b/gegl/Makefile.am
index 72d9d55..155758f 100644
--- a/gegl/Makefile.am
+++ b/gegl/Makefile.am
@@ -31,6 +31,7 @@ GEGL_public_HEADERS =	\
     gegl-utils.h			\
     gegl-matrix.h			\
     gegl-chant.h			\
+    gegl-lookup.h			\
     gegl-simd.h				\
     gegl-plugin.h			\
     gegl-version.h			\
@@ -49,10 +50,12 @@ GEGL_sources = \
 	gegl-init.c			\
 	gegl-instrument.c		\
 	gegl-utils.c			\
+	gegl-lookup.c			\
 	gegl-matrix.c			\
 	gegl-xml.c			\
 	\
 	gegl-chant.h			\
+	gegl-lookup.h			\
 	gegl-config.h			\
 	gegl-cpuaccel.h			\
 	gegl-debug.h			\
diff --git a/gegl/gegl-lookup.c b/gegl/gegl-lookup.c
new file mode 100644
index 0000000..4ed9110
--- /dev/null
+++ b/gegl/gegl-lookup.c
@@ -0,0 +1,39 @@
+/* This file is part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2009 �yvind Kolås.
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+
+#include "gegl.h"
+#include "gegl-lookup.h"
+
+GeglLookup *gegl_lookup_new  (GeglLookupFunction *function,
+                              gpointer            data)
+{
+  GeglLookup *lookup = g_slice_new (GeglLookup);
+  lookup->function = function;
+  lookup->data = data;
+  return lookup;
+}
+
+void
+gegl_lookup_free (GeglLookup *lookup)
+{
+  g_slice_free (GeglLookup, lookup);
+}
diff --git a/gegl/gegl-lookup.h b/gegl/gegl-lookup.h
new file mode 100644
index 0000000..96fbf3c
--- /dev/null
+++ b/gegl/gegl-lookup.h
@@ -0,0 +1,115 @@
+/* This file is part of GEGL
+ *
+ * GEGL is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * GEGL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright 2009 �yvind Kolås
+ */
+
+#ifndef __GEGL_LOOKUP_H__
+#define __GEGL_LOOKUP_H__
+
+G_BEGIN_DECLS
+
+/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ * NOTE! tweaking these values will change ABI for operations using GeglLookup
+ */
+#define GEGL_LOOKUP_NEGATIVE     0 /* set to 1 to also cache range -1.0..-0.0 */
+#define GEGL_LOOKUP_SHIFT_RIGHT  14 /* Number of bits to shift integer right
+                                       before computing lookup bits
+
+      value  tablesize  average error 
+        16   2554       0.001298
+        15   5108       0.000649
+        14   10216      0.000324
+ */
+
+#if GEGL_LOOKUP_SHIFT_RIGHT == 16
+
+#define GEGL_LOOKUP_START_POSITIVE   13702
+#define GEGL_LOOKUP_END_POSITIVE     16256
+#define GEGL_LOOKUP_START_NEGATIVE   46470
+#define GEGL_LOOKUP_END_NEGATIVE     49024
+
+#elif GEGL_LOOKUP_SHIFT_RIGHT == 15
+
+#define GEGL_LOOKUP_START_POSITIVE   27404
+#define GEGL_LOOKUP_END_POSITIVE     32512
+#define GEGL_LOOKUP_START_NEGATIVE   92940
+#define GEGL_LOOKUP_END_NEGATIVE     98048
+
+#elif GEGL_LOOKUP_SHIFT_RIGHT == 14
+
+#define GEGL_LOOKUP_START_POSITIVE   54808
+#define GEGL_LOOKUP_END_POSITIVE     65024
+#define GEGL_LOOKUP_START_NEGATIVE   185880
+#define GEGL_LOOKUP_END_NEGATIVE     196096
+
+#endif
+
+#define GEGL_LOOKUP_SUM_POSITIVE    (GEGL_LOOKUP_END_POSITIVE-GEGL_LOOKUP_START_POSITIVE)
+#define GEGL_LOOKUP_SUM_NEGATIVE    (GEGL_LOOKUP_END_NEGATIVE-GEGL_LOOKUP_START_NEGATIVE)
+
+#if GEGL_LOOKUP_NEGATIVE
+#define GEGL_LOOKUP_SUM             (GEGL_LOOKUP_SUM_POSITIVE+GEGL_LOOKUP_SUM_NEGATIVE)
+#else
+#define GEGL_LOOKUP_SUM             (GEGL_LOOKUP_SUM_NEGATIVE)
+#endif
+
+typedef     gfloat (GeglLookupFunction) (float, gpointer data);
+
+typedef struct GeglLookup
+{
+  GeglLookupFunction *function; 
+  gpointer            data;
+  guint32             bitmask[(GEGL_LOOKUP_SUM+31)/32];
+  gfloat              table[GEGL_LOOKUP_SUM];
+} GeglLookup;
+
+GeglLookup *gegl_lookup_new  (GeglLookupFunction   *function,
+                              gpointer              data);
+void        gegl_lookup_free (GeglLookup           *lookup);
+
+static inline gfloat
+gegl_lookup (GeglLookup *lookup,
+             gfloat      number)
+{
+  union
+  {
+    float   f;
+    guint32 i;
+  } u;
+  guint index;
+
+  u.f = number;
+  index = u.i >> GEGL_LOOKUP_SHIFT_RIGHT;
+  if (index > GEGL_LOOKUP_START_POSITIVE && index < GEGL_LOOKUP_END_POSITIVE)
+    index = index-GEGL_LOOKUP_START_POSITIVE;
+#if GEGL_LOOKUP_NEGATIVE
+  else if (index > GEGL_LOOKUP_START_NEGATIVE && index < GEGL_LOOKUP_END_NEGATIVE)
+    index = index-GEGL_LOOKUP_START_NEGATIVE+GEGL_LOOKUP_SUM_POSITIVE;
+#endif
+  else
+    return lookup->function (number, lookup->data);
+
+  if (!(lookup->bitmask[index/32] & (1<<(index & 31))))
+    {
+      lookup->table[index]= lookup->function (number, lookup->data);
+      lookup->bitmask[index/32] |= (1<<(index & 31));
+    } 
+  return lookup->table[index];
+}
+
+G_END_DECLS
+
+#endif
diff --git a/gegl/gegl-plugin.h b/gegl/gegl-plugin.h
index d365624..cb8c18b 100644
--- a/gegl/gegl-plugin.h
+++ b/gegl/gegl-plugin.h
@@ -103,4 +103,6 @@ const gchar   * gegl_extension_handler_get         (const gchar         *extensi
 #include <operation/gegl-operation-meta.h>
 #include <gegl-simd.h>
 
+#include <gegl-lookup.h>
+
 #endif  /* __GEGL_PLUGIN_H__ */
diff --git a/gegl/gegl-types.h b/gegl/gegl-types.h
index 935baa5..f42e6ca 100644
--- a/gegl/gegl-types.h
+++ b/gegl/gegl-types.h
@@ -64,7 +64,6 @@ GType gegl_processor_get_type  (void) G_GNUC_CONST;
 #define GEGL_PROCESSOR(obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEGL_TYPE_PROCESSOR, GeglProcessor))
 #define GEGL_IS_PROCESSOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEGL_TYPE_PROCESSOR))
 
-typedef struct _GeglLookup  GeglLookup;
 
 G_END_DECLS
 
diff --git a/gegl/gegl-utils.c b/gegl/gegl-utils.c
index af29f27..b87731b 100644
--- a/gegl/gegl-utils.c
+++ b/gegl/gegl-utils.c
@@ -26,222 +26,223 @@
 #include "gegl-types-internal.h"
 
 
-inline gint
-_gegl_float_epsilon_zero (float value)
-{
-  return value > -GEGL_FLOAT_EPSILON && value < GEGL_FLOAT_EPSILON;
-}
-
-gint
-_gegl_float_epsilon_equal (float v1, float v2)
-{
-  register float diff = v1 - v2;
-
-  return diff > -GEGL_FLOAT_EPSILON && diff < GEGL_FLOAT_EPSILON;
-}
-
-void
-gegl_rectangle_set (GeglRectangle *r,
-                    gint           x,
-                    gint           y,
-                    guint          w,
-                    guint          h)
-{
-  r->x      = x;
-  r->y      = y;
-  r->width  = w;
-  r->height = h;
-}
-
-void
-gegl_rectangle_bounding_box (GeglRectangle       *dest,
-                             const GeglRectangle *src1,
-                             const GeglRectangle *src2)
-{
-  gboolean s1_has_area = src1->width && src1->height;
-  gboolean s2_has_area = src2->width && src2->height;
-
-  if (!s1_has_area && !s2_has_area)
-    gegl_rectangle_set (dest, 0, 0, 0, 0);
-  else if (!s1_has_area)
-    gegl_rectangle_copy (dest, src2);
-  else if (!s2_has_area)
-    gegl_rectangle_copy (dest, src1);
-  else
-    {
-      gint x1 = MIN (src1->x, src2->x);
-      gint x2 = MAX (src1->x + src1->width, src2->x + src2->width);
-      gint y1 = MIN (src1->y, src2->y);
-      gint y2 = MAX (src1->y + src1->height, src2->y + src2->height);
-
-      dest->x      = x1;
-      dest->y      = y1;
-      dest->width  = x2 - x1;
-      dest->height = y2 - y1;
-    }
-}
-
-gboolean
-gegl_rectangle_intersect (GeglRectangle       *dest,
-                          const GeglRectangle *src1,
-                          const GeglRectangle *src2)
-{
-  gint x1, x2, y1, y2;
-
-  x1 = MAX (src1->x, src2->x);
-  x2 = MIN (src1->x + src1->width, src2->x + src2->width);
-
-  if (x2 <= x1)
-    {
-      if (dest)
-        gegl_rectangle_set (dest, 0, 0, 0, 0);
+  inline gint
+  _gegl_float_epsilon_zero (float value)
+  {
+    return value > -GEGL_FLOAT_EPSILON && value < GEGL_FLOAT_EPSILON;
+  }
+
+  gint
+  _gegl_float_epsilon_equal (float v1, float v2)
+  {
+    register float diff = v1 - v2;
+
+    return diff > -GEGL_FLOAT_EPSILON && diff < GEGL_FLOAT_EPSILON;
+  }
+
+  void
+  gegl_rectangle_set (GeglRectangle *r,
+                      gint           x,
+                      gint           y,
+                      guint          w,
+                      guint          h)
+  {
+    r->x      = x;
+    r->y      = y;
+    r->width  = w;
+    r->height = h;
+  }
+
+  void
+  gegl_rectangle_bounding_box (GeglRectangle       *dest,
+                               const GeglRectangle *src1,
+                               const GeglRectangle *src2)
+  {
+    gboolean s1_has_area = src1->width && src1->height;
+    gboolean s2_has_area = src2->width && src2->height;
+
+    if (!s1_has_area && !s2_has_area)
+      gegl_rectangle_set (dest, 0, 0, 0, 0);
+    else if (!s1_has_area)
+      gegl_rectangle_copy (dest, src2);
+    else if (!s2_has_area)
+      gegl_rectangle_copy (dest, src1);
+    else
+      {
+        gint x1 = MIN (src1->x, src2->x);
+        gint x2 = MAX (src1->x + src1->width, src2->x + src2->width);
+        gint y1 = MIN (src1->y, src2->y);
+        gint y2 = MAX (src1->y + src1->height, src2->y + src2->height);
+
+        dest->x      = x1;
+        dest->y      = y1;
+        dest->width  = x2 - x1;
+        dest->height = y2 - y1;
+      }
+  }
+
+  gboolean
+  gegl_rectangle_intersect (GeglRectangle       *dest,
+                            const GeglRectangle *src1,
+                            const GeglRectangle *src2)
+  {
+    gint x1, x2, y1, y2;
+
+    x1 = MAX (src1->x, src2->x);
+    x2 = MIN (src1->x + src1->width, src2->x + src2->width);
+
+    if (x2 <= x1)
+      {
+        if (dest)
+          gegl_rectangle_set (dest, 0, 0, 0, 0);
+        return FALSE;
+      }
+
+    y1 = MAX (src1->y, src2->y);
+    y2 = MIN (src1->y + src1->height, src2->y + src2->height);
+
+    if (y2 <= y1)
+      {
+        if (dest)
+          gegl_rectangle_set (dest, 0, 0, 0, 0);
+        return FALSE;
+      }
+
+    if (dest)
+      gegl_rectangle_set (dest, x1, y1, x2 - x1, y2 - y1);
+    return TRUE;
+  }
+
+  void
+  gegl_rectangle_copy (GeglRectangle       *to,
+                       const GeglRectangle *from)
+  {
+    to->x      = from->x;
+    to->y      = from->y;
+    to->width  = from->width;
+    to->height = from->height;
+  }
+
+  gboolean
+  gegl_rectangle_contains (const GeglRectangle *r,
+                           const GeglRectangle *s)
+  {
+    if (s->x >= r->x &&
+        s->y >= r->y &&
+        (s->x + s->width) <= (r->x + r->width) &&
+        (s->y + s->height) <= (r->y + r->height))
+      return TRUE;
+    else
       return FALSE;
-    }
-
-  y1 = MAX (src1->y, src2->y);
-  y2 = MIN (src1->y + src1->height, src2->y + src2->height);
-
-  if (y2 <= y1)
-    {
-      if (dest)
-        gegl_rectangle_set (dest, 0, 0, 0, 0);
+  }
+
+  gboolean
+  gegl_rectangle_equal (const GeglRectangle *r,
+                        const GeglRectangle *s)
+  {
+    if (r->x == s->x &&
+        r->y == s->y &&
+        r->width == s->width &&
+        r->height == s->height)
+      return TRUE;
+    else
       return FALSE;
-    }
-
-  if (dest)
-    gegl_rectangle_set (dest, x1, y1, x2 - x1, y2 - y1);
-  return TRUE;
-}
-
-void
-gegl_rectangle_copy (GeglRectangle       *to,
-                     const GeglRectangle *from)
-{
-  to->x      = from->x;
-  to->y      = from->y;
-  to->width  = from->width;
-  to->height = from->height;
-}
-
-gboolean
-gegl_rectangle_contains (const GeglRectangle *r,
-                         const GeglRectangle *s)
-{
-  if (s->x >= r->x &&
-      s->y >= r->y &&
-      (s->x + s->width) <= (r->x + r->width) &&
-      (s->y + s->height) <= (r->y + r->height))
-    return TRUE;
-  else
-    return FALSE;
-}
-
-gboolean
-gegl_rectangle_equal (const GeglRectangle *r,
-                      const GeglRectangle *s)
-{
-  if (r->x == s->x &&
-      r->y == s->y &&
-      r->width == s->width &&
-      r->height == s->height)
-    return TRUE;
-  else
-    return FALSE;
-}
-
-gboolean
-gegl_rectangle_equal_coords (const GeglRectangle *r,
-                             gint                 x,
-                             gint                 y,
-                             gint                 w,
-                             gint                 h)
-{
-  if (r->x == x &&
-      r->y == y &&
-      r->width == w &&
-      r->height == h)
-    return TRUE;
-  else
-    return FALSE;
-}
-
-static GeglRectangle *
-gegl_rectangle_dup (const GeglRectangle *rectangle)
-{
-  GeglRectangle *result = g_new (GeglRectangle, 1);
-
-  *result = *rectangle;
-
-  return result;
-}
-
-GeglRectangle
-gegl_rectangle_infinite_plane (void)
-{
-  GeglRectangle infinite_plane_rect = {G_MININT / 2, G_MININT / 2, G_MAXINT, G_MAXINT};
-  return infinite_plane_rect;
-}
-
-gboolean
-gegl_rectangle_is_infinite_plane (const GeglRectangle *rectangle)
-{
-  return (rectangle->x      == G_MININT / 2 &&
-          rectangle->y      == G_MININT / 2 &&
-          rectangle->width  == G_MAXINT     &&
-          rectangle->height == G_MAXINT);
-}
-
-void
-gegl_rectangle_dump (const GeglRectangle *rectangle)
-{
-  g_print ("%d, %d, %dÃ?%d\n",
-           rectangle->x,
-           rectangle->y,
-           rectangle->width,
-           rectangle->height);
-}
-
-GType
-gegl_rectangle_get_type (void)
-{
-  static GType our_type = 0;
-
-  if (our_type == 0)
-    our_type = g_boxed_type_register_static (g_intern_static_string ("GeglRectangle"),
-                                             (GBoxedCopyFunc) gegl_rectangle_dup,
-                                             (GBoxedFreeFunc) g_free);
-  return our_type;
-}
+  }
+
+  gboolean
+  gegl_rectangle_equal_coords (const GeglRectangle *r,
+                               gint                 x,
+                               gint                 y,
+                               gint                 w,
+                               gint                 h)
+  {
+    if (r->x == x &&
+        r->y == y &&
+        r->width == w &&
+        r->height == h)
+      return TRUE;
+    else
+      return FALSE;
+  }
+
+  static GeglRectangle *
+  gegl_rectangle_dup (const GeglRectangle *rectangle)
+  {
+    GeglRectangle *result = g_new (GeglRectangle, 1);
+
+    *result = *rectangle;
+
+    return result;
+  }
+
+  GeglRectangle
+  gegl_rectangle_infinite_plane (void)
+  {
+    GeglRectangle infinite_plane_rect = {G_MININT / 2, G_MININT / 2, G_MAXINT, G_MAXINT};
+    return infinite_plane_rect;
+  }
+
+  gboolean
+  gegl_rectangle_is_infinite_plane (const GeglRectangle *rectangle)
+  {
+    return (rectangle->x      == G_MININT / 2 &&
+            rectangle->y      == G_MININT / 2 &&
+            rectangle->width  == G_MAXINT     &&
+            rectangle->height == G_MAXINT);
+  }
+
+  void
+  gegl_rectangle_dump (const GeglRectangle *rectangle)
+  {
+    g_print ("%d, %d, %dÃ?%d\n",
+             rectangle->x,
+             rectangle->y,
+             rectangle->width,
+             rectangle->height);
+  }
+
+  GType
+  gegl_rectangle_get_type (void)
+  {
+    static GType our_type = 0;
+
+    if (our_type == 0)
+      our_type = g_boxed_type_register_static (g_intern_static_string ("GeglRectangle"),
+                                               (GBoxedCopyFunc) gegl_rectangle_dup,
+                                               (GBoxedFreeFunc) g_free);
+    return our_type;
+  }
 
 #define GEGL_ALIGN 16
 
-gpointer
-gegl_malloc (gsize size);
-
-/* utility call that makes sure allocations are 16 byte aligned.
- * making RGBA float buffers have aligned access for pixels.
- */ 
-gpointer gegl_malloc (gsize size)
-{
-  gchar *mem;
-  gchar *ret;
-  gint   offset;
-
-  mem    = g_malloc (size + GEGL_ALIGN + sizeof(gpointer));
-  offset = GEGL_ALIGN - (((guint)mem) + sizeof(gpointer)) % GEGL_ALIGN;
-  ret    = (gpointer)(mem + sizeof(gpointer) + offset);
-
-  /* store the real malloc one pointer in front of this malloc */
-  *(gpointer*)(ret-sizeof(gpointer))=mem;
-  return (gpointer) ret;
-}
-
-void
-gegl_free (gpointer buf);
-void
-gegl_free (gpointer buf)
-{
-  g_assert (buf);
-  g_free (*((gpointer*)buf -1));
-}
+  gpointer
+  gegl_malloc (gsize size);
+
+  /* utility call that makes sure allocations are 16 byte aligned.
+   * making RGBA float buffers have aligned access for pixels.
+   */ 
+  gpointer gegl_malloc (gsize size)
+  {
+    gchar *mem;
+    gchar *ret;
+    gint   offset;
+
+    mem    = g_malloc (size + GEGL_ALIGN + sizeof(gpointer));
+    offset = GEGL_ALIGN - (((guint)mem) + sizeof(gpointer)) % GEGL_ALIGN;
+    ret    = (gpointer)(mem + sizeof(gpointer) + offset);
+
+    /* store the real malloc one pointer in front of this malloc */
+    *(gpointer*)(ret-sizeof(gpointer))=mem;
+    return (gpointer) ret;
+  }
+
+  void
+  gegl_free (gpointer buf);
+  void
+  gegl_free (gpointer buf)
+  {
+    g_assert (buf);
+    g_free (*((gpointer*)buf -1));
+  }
+
 
diff --git a/gegl/gegl-utils.h b/gegl/gegl-utils.h
index eb3b435..10c038c 100644
--- a/gegl/gegl-utils.h
+++ b/gegl/gegl-utils.h
@@ -202,86 +202,6 @@ inline gint _gegl_float_epsilon_zero  (float     value);
 gint        _gegl_float_epsilon_equal (float     v1,
                                        float     v2);
 
-
-typedef     gfloat (GeglLookupFunction) (float, gpointer data);
-
-GeglLookup *gegl_lookup_new  (GeglLookupFunction   *function,
-                              gpointer              data);
-void        gegl_lookup_free (GeglLookup           *lookup);
-
-#define INDEX_SHIFT  14 /* 
-                        Valid values here are:
-                        value  tablesize          average error 
-                          16    5108              0.001298
-                          15   10316              0.000649
-                          14   20432              0.000324
-                         */
-
-#if INDEX_SHIFT == 16
-
-#define INDEX_START_POSITIVE   13702
-#define INDEX_END_POSITIVE     16256
-#define INDEX_START_NEGATIVE   46470
-#define INDEX_END_NEGATIVE     49024
-
-#elif INDEX_SHIFT == 15
-
-#define INDEX_START_POSITIVE   27404
-#define INDEX_END_POSITIVE     32512
-#define INDEX_START_NEGATIVE   92940
-#define INDEX_END_NEGATIVE     98048
-
-#elif INDEX_SHIFT == 14
-
-#define INDEX_START_POSITIVE   54808
-#define INDEX_END_POSITIVE     65024
-#define INDEX_START_NEGATIVE   185880
-#define INDEX_END_NEGATIVE     196096
-
-#endif
-
-#define INDEX_SUM_POSITIVE    (INDEX_END_POSITIVE-INDEX_START_POSITIVE)
-#define INDEX_SUM_NEGATIVE    (INDEX_END_NEGATIVE-INDEX_START_NEGATIVE)
-#define INDEX_SUM             (INDEX_SUM_POSITIVE+INDEX_SUM_NEGATIVE)
-
-typedef struct _GeglLookup
-{
-  GeglLookupFunction *function;     /* the lookup function to execute */
-  gpointer            data;
-  guint32             bitmask[(INDEX_SUM+31)/32];
-  gfloat              table[INDEX_SUM];
-} _GeglLookup;
-
-static inline gfloat
-gegl_lookup (GeglLookup *lookup,
-             gfloat      number)
-{
-  union
-  {
-    float   f;
-    guint32 i;
-  } u;
-  guint index;
-
-  u.f = number;
-  index = u.i >> INDEX_SHIFT;
-  if (index > INDEX_START_POSITIVE && index < INDEX_END_POSITIVE)
-    index = index-INDEX_START_POSITIVE;
-  else if (index > INDEX_START_NEGATIVE && index < INDEX_END_NEGATIVE)
-    index = index-INDEX_START_NEGATIVE+INDEX_SUM_POSITIVE;
-  else
-    return lookup->function (number, lookup->data);
-
-  g_assert (index >= 0 && index < INDEX_SUM);
-
-  if (!(lookup->bitmask[index/32] & (1<<(index & 31))))
-    {
-      lookup->table[index]= lookup->function (number, lookup->data);
-      lookup->bitmask[index/32] |= (1<<(index & 31));
-    } 
-  return lookup->table[index];
-}
-
 G_END_DECLS
 
 #endif /* __GEGL_UTILS_H__ */



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