[gegl] buffer: add gegl-buffer-formats.h and gegl-bufefr-matrix2.h



commit 4fdf9ebfb4f852d2e7e32ddf95b6041d90c21757
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu Sep 27 23:19:36 2018 +0200

    buffer: add gegl-buffer-formats.h and gegl-bufefr-matrix2.h
    
    The 2x2 matrix is only used by GeglBuffer and its API, gimp-2.10 does not
    use the symbols - we are remaining abi compatible but are rearranging
    locations of symbols.

 gegl/Makefile.am                            |  1 +
 gegl/buffer/Makefile.am                     |  3 ++
 gegl/buffer/gegl-algorithms.c               |  2 +-
 gegl/buffer/gegl-buffer-access.c            |  2 +-
 gegl/buffer/gegl-buffer-formats.h           | 84 +++++++++++++++++++++++++++++
 gegl/buffer/gegl-buffer-linear.c            |  2 +-
 gegl/buffer/gegl-buffer-matrix2.c           | 35 ++++++++++++
 gegl/buffer/gegl-buffer-matrix2.h           | 56 +++++++++++++++++++
 gegl/buffer/gegl-buffer.c                   |  6 +--
 gegl/buffer/gegl-buffer.h                   | 71 +++++++++++-------------
 gegl/buffer/gegl-sampler-cubic.c            | 16 +++---
 gegl/buffer/gegl-sampler-linear.c           | 12 ++---
 gegl/buffer/gegl-sampler-lohalo.c           |  6 +--
 gegl/buffer/gegl-sampler-nearest.c          |  6 +--
 gegl/buffer/gegl-sampler-nohalo.c           |  6 +--
 gegl/buffer/gegl-sampler.c                  | 66 +++++++++++------------
 gegl/buffer/gegl-sampler.h                  |  6 +--
 gegl/gegl-matrix.c                          | 14 -----
 gegl/gegl-matrix.h                          | 26 +--------
 gegl/gegl-utils.h                           | 13 +++++
 operations/common-gpl3+/fractal-trace.c     |  2 +-
 operations/common-gpl3+/polar-coordinates.c |  2 +-
 operations/common-gpl3+/whirl-pinch.c       |  2 +-
 operations/common/little-planet.c           |  4 +-
 operations/common/panorama-projection.c     |  4 +-
 operations/transform/transform-core.c       |  4 +-
 26 files changed, 295 insertions(+), 156 deletions(-)
---
diff --git a/gegl/Makefile.am b/gegl/Makefile.am
index e0dbe7c9b..8b0b5a7a5 100644
--- a/gegl/Makefile.am
+++ b/gegl/Makefile.am
@@ -58,6 +58,7 @@ GEGL_introspectable_headers = \
        gegl-init.h                     \
        gegl-version.h                  \
        buffer/gegl-buffer.h            \
+       buffer/gegl-buffer-matrix2.h    \
        buffer/gegl-buffer-iterator.h   \
        buffer/gegl-buffer-iterator2.h  \
        buffer/gegl-buffer-backend.h    \
diff --git a/gegl/buffer/Makefile.am b/gegl/buffer/Makefile.am
index 14d38e644..2bea1db40 100644
--- a/gegl/buffer/Makefile.am
+++ b/gegl/buffer/Makefile.am
@@ -29,6 +29,8 @@ libbuffer_la_SOURCES = \
     gegl-buffer-access.c       \
     gegl-buffer-config.c       \
     gegl-buffer-config.h       \
+    gegl-buffer-matrix2.c      \
+    gegl-buffer-matrix2.h      \
     gegl-buffer-index.h                \
     gegl-buffer-iterator.c     \
     gegl-buffer-iterator2.c    \
@@ -63,6 +65,7 @@ libbuffer_la_SOURCES = \
     gegl-buffer-iterator2.h    \
     gegl-buffer-iterator-private.h     \
     gegl-buffer-types.h                \
+    gegl-buffer-formats.h      \
     gegl-sampler.h             \
     gegl-sampler-cubic.h       \
     gegl-sampler-linear.h      \
diff --git a/gegl/buffer/gegl-algorithms.c b/gegl/buffer/gegl-algorithms.c
index 36ccaa323..fe525d7cf 100644
--- a/gegl/buffer/gegl-algorithms.c
+++ b/gegl/buffer/gegl-algorithms.c
@@ -27,7 +27,7 @@
 
 #include "gegl-buffer.h"
 #include "gegl-types.h"
-#include "gegl-types-internal.h"
+#include "gegl-buffer-formats.h"
 #include "gegl-utils.h"
 #include "gegl-algorithms.h"
 
diff --git a/gegl/buffer/gegl-buffer-access.c b/gegl/buffer/gegl-buffer-access.c
index 5e90d1c29..66dec4dec 100644
--- a/gegl/buffer/gegl-buffer-access.c
+++ b/gegl/buffer/gegl-buffer-access.c
@@ -38,7 +38,7 @@
 #include "gegl-tile-backend.h"
 #include "gegl-buffer-iterator.h"
 #include "gegl-buffer-iterator-private.h"
-#include "gegl-types-internal.h"
+#include "gegl-buffer-formats.h"
 
 static void gegl_buffer_iterate_read_fringed (GeglBuffer                *buffer,
                                               const GeglBufferRectangle *roi,
diff --git a/gegl/buffer/gegl-buffer-formats.h b/gegl/buffer/gegl-buffer-formats.h
new file mode 100644
index 000000000..738110eac
--- /dev/null
+++ b/gegl/buffer/gegl-buffer-formats.h
@@ -0,0 +1,84 @@
+/* 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 <https://www.gnu.org/licenses/>.
+ *
+ * Copyright 2018 Øyvind Kolås
+ */
+
+#ifndef __GEGL_BUFFER_FORMATS_H__
+#define __GEGL_BUFFER_FORMATS_H__
+
+#include <babl/babl.h>
+
+G_BEGIN_DECLS
+
+/* the code in babl for looking up models, formats and types is quick -
+   but when formats end up being used as consts for comparisons in the core of
+   GEGL, it is good to have even better caching, hence this way of generating
+   and accessing per compilation unit caches of formats.
+ */
+
+#define GEGL_CACHED_BABL(klass, typ, name)  \
+static inline const Babl *gegl_babl_##typ (void) { static const Babl *type = NULL; if (!type) type = 
babl_##klass (name); return type; }
+
+GEGL_CACHED_BABL(type, half, "half")
+GEGL_CACHED_BABL(type, float, "float")
+GEGL_CACHED_BABL(type, u8, "u8")
+GEGL_CACHED_BABL(type, u16, "u16")
+GEGL_CACHED_BABL(type, u32, "u32")
+GEGL_CACHED_BABL(type, double, "double")
+
+GEGL_CACHED_BABL(model, rgb_linear, "RGB")
+GEGL_CACHED_BABL(model, rgba_linear, "RGBA")
+GEGL_CACHED_BABL(model, rgbA_linear, "RaGaBaA")
+GEGL_CACHED_BABL(model, y_linear, "Y")
+GEGL_CACHED_BABL(model, ya_linear, "YA")
+GEGL_CACHED_BABL(model, yA_linear, "YaA")
+
+static inline gboolean gegl_babl_model_is_linear (const Babl *babl)
+{
+  if (babl == gegl_babl_rgba_linear() ||
+      babl == gegl_babl_rgbA_linear() ||
+      babl == gegl_babl_rgb_linear()  ||
+      babl == gegl_babl_y_linear()    ||
+      babl == gegl_babl_ya_linear()   ||
+      babl == gegl_babl_yA_linear())
+    return TRUE;
+  return FALSE;
+}
+
+GEGL_CACHED_BABL(format, rgba_float, "R'G'B'A float")
+GEGL_CACHED_BABL(format, rgba_u8, "R'G'B'A u8")
+GEGL_CACHED_BABL(format, rgb_u8, "R'G'B' u8")
+GEGL_CACHED_BABL(format, rgbA_float, "R'aG'aB'aA float")
+GEGL_CACHED_BABL(format, rgba_linear_float, "RGBA float")
+GEGL_CACHED_BABL(format, rgba_linear_u16, "RGBA u16")
+GEGL_CACHED_BABL(format, rgbA_linear_float, "RaGaBaA float")
+GEGL_CACHED_BABL(format, ya_float, "Y'A float")
+GEGL_CACHED_BABL(format, yA_float, "Y'aA float")
+GEGL_CACHED_BABL(format, ya_linear_float, "Y float")
+GEGL_CACHED_BABL(format, yA_linear_float, "YaA float")
+
+
+#ifdef G_OS_WIN32
+  /* one use 16kb of stack before an exception triggered warning on win32 */
+  #define GEGL_ALLOCA_THRESHOLD  8192
+#else
+/* on linux/OSX 0.5mb is reasonable, the stack size of new threads is 2MB */
+  #define GEGL_ALLOCA_THRESHOLD  (1024*1024/2)
+#endif
+
+G_END_DECLS
+
+#endif /* __GEGL_BUFFER_FORMATS_H__ */
diff --git a/gegl/buffer/gegl-buffer-linear.c b/gegl/buffer/gegl-buffer-linear.c
index 22a971be9..c2df4bed9 100644
--- a/gegl/buffer/gegl-buffer-linear.c
+++ b/gegl/buffer/gegl-buffer-linear.c
@@ -6,7 +6,7 @@
 #include <glib/gprintf.h>
 
 #include "gegl.h"
-#include "gegl-types-internal.h"
+#include "gegl-buffer-formats.h"
 #include "gegl-buffer-types.h"
 #include "gegl-buffer-private.h"
 #include "gegl-tile-storage.h"
diff --git a/gegl/buffer/gegl-buffer-matrix2.c b/gegl/buffer/gegl-buffer-matrix2.c
new file mode 100644
index 000000000..0842e9781
--- /dev/null
+++ b/gegl/buffer/gegl-buffer-matrix2.c
@@ -0,0 +1,35 @@
+/* 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 <https://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include <math.h>
+
+#include "gegl-buffer-matrix2.h"
+
+
+gboolean
+gegl_buffer_matrix2_is_scale (GeglBufferMatrix2 *matrix)
+{
+  return matrix->coeff[0][1] == 0.0 && matrix->coeff[1][0] == 0.0;
+}
+
+gdouble
+gegl_buffer_matrix2_determinant (GeglBufferMatrix2 *matrix)
+{
+  return matrix->coeff[0][0] * matrix->coeff[1][1] -
+         matrix->coeff[1][0] * matrix->coeff[0][1];
+}
+
diff --git a/gegl/buffer/gegl-buffer-matrix2.h b/gegl/buffer/gegl-buffer-matrix2.h
new file mode 100644
index 000000000..da99a6a2a
--- /dev/null
+++ b/gegl/buffer/gegl-buffer-matrix2.h
@@ -0,0 +1,56 @@
+/* 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 <https://www.gnu.org/licenses/>.
+ *
+ * Copyright 2006-2018 GEGL developers
+ */
+
+#ifndef __GEGL_BUFFER_MATRIX2_H__
+#define __GEGL_BUFFER_MATRIX2_H__
+
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/* Currenly only used internally.
+ * Note: If making use of this in public API, add a boxed type for introspection
+ */
+typedef struct {
+    gdouble coeff[2][2];
+} GeglBufferMatrix2;
+
+/*
+ * gegl_buffer_matrix2_is_scale:
+ * @matrix: a #GeglBufferMatrix2
+ *
+ * Check if a matrix only does scaling.
+ *
+ * Returns TRUE if the matrix only does scaling.
+ */
+gboolean   gegl_buffer_matrix2_is_scale        (GeglBufferMatrix2 *matrix);
+
+/*
+ * gegl_buffer_matrix2_determinant:
+ * @matrix: a #GeglBufferMatrix2
+ *
+ * Returns the determinant of @matrix.
+ */
+gdouble    gegl_buffer_matrix2_determinant     (GeglBufferMatrix2 *matrix);
+
+
+G_END_DECLS
+
+#endif
diff --git a/gegl/buffer/gegl-buffer.c b/gegl/buffer/gegl-buffer.c
index 687c754a0..0938daabd 100644
--- a/gegl/buffer/gegl-buffer.c
+++ b/gegl/buffer/gegl-buffer.c
@@ -40,15 +40,11 @@
 #include "gegl-buffer-types.h"
 #include "gegl-buffer-config.h"
 #include "gegl-buffer-private.h"
-#include "gegl-debug.h"
 #include "gegl-tile-storage.h"
 #include "gegl-tile-backend-file.h"
 #include "gegl-tile-backend-swap.h"
 #include "gegl-tile-backend-ram.h"
-
-//#include "opencl/gegl-cl.h"
-
-#include "gegl-types-internal.h"
+#include "gegl-buffer-formats.h"
 
 #ifdef GEGL_ENABLE_DEBUG
 #define DEBUG_ALLOCATIONS (gegl_debug_flags & GEGL_DEBUG_BUFFER_ALLOC)
diff --git a/gegl/buffer/gegl-buffer.h b/gegl/buffer/gegl-buffer.h
index a3e85c931..0a32a8301 100644
--- a/gegl/buffer/gegl-buffer.h
+++ b/gegl/buffer/gegl-buffer.h
@@ -21,7 +21,7 @@
 
 #include <glib-object.h>
 #include <babl/babl.h>
-#include <gegl-matrix.h>
+#include "gegl-buffer-matrix2.h"
 #include <gegl-types.h>
 
 #define GEGL_AUTO_ROWSTRIDE 0
@@ -321,17 +321,6 @@ void            gegl_buffer_set               (GeglBuffer                *buffer
                                                gint                       rowstride);
 
 
-/**
- * gegl_buffer_set_color:
- * @buffer: a #GeglBuffer
- * @rect: a rectangular region to fill with a color.
- * @color: the GeglColor to fill with.
- *
- * Sets the region covered by rect to the specified color.
- */
-void            gegl_buffer_set_color         (GeglBuffer                *buffer,
-                                               const GeglBufferRectangle *rect,
-                                               GeglColor                 *color);
 
 
 /**
@@ -476,15 +465,15 @@ GeglBuffer *    gegl_buffer_dup               (GeglBuffer       *buffer);
  * is more efficient.
  */
 
-void              gegl_buffer_sample_at_level (GeglBuffer       *buffer,
-                                               gdouble           x,
-                                               gdouble           y,
-                                               GeglMatrix2      *scale,
-                                               gpointer          dest,
-                                               const Babl       *format,
-                                               gint              level,
-                                               GeglSamplerType   sampler_type,
-                                               GeglAbyssPolicy   repeat_mode);
+void              gegl_buffer_sample_at_level (GeglBuffer        *buffer,
+                                               gdouble            x,
+                                               gdouble            y,
+                                               GeglBufferMatrix2 *scale,
+                                               gpointer           dest,
+                                               const Babl        *format,
+                                               gint               level,
+                                               GeglSamplerType    sampler_type,
+                                               GeglAbyssPolicy    repeat_mode);
 
 /**
  * gegl_buffer_sample: (skip)
@@ -512,14 +501,14 @@ void              gegl_buffer_sample_at_level (GeglBuffer       *buffer,
  * gegl_buffer_sampler_new() to create a sampler object instead, which is more
  * efficient.
  */
-void              gegl_buffer_sample          (GeglBuffer       *buffer,
-                                               gdouble           x,
-                                               gdouble           y,
-                                               GeglMatrix2      *scale,
-                                               gpointer          dest,
-                                               const Babl       *format,
-                                               GeglSamplerType   sampler_type,
-                                               GeglAbyssPolicy   repeat_mode);
+void              gegl_buffer_sample          (GeglBuffer        *buffer,
+                                               gdouble            x,
+                                               gdouble            y,
+                                               GeglBufferMatrix2 *scale,
+                                               gpointer           dest,
+                                               const Babl        *format,
+                                               GeglSamplerType    sampler_type,
+                                               GeglAbyssPolicy    repeat_mode);
 
 
 
@@ -535,12 +524,12 @@ void              gegl_buffer_sample          (GeglBuffer       *buffer,
 G_DEPRECATED
 void            gegl_buffer_sample_cleanup    (GeglBuffer *buffer);
 
-typedef void (*GeglSamplerGetFun)  (GeglSampler     *self,
-                                    gdouble          x,
-                                    gdouble          y,
-                                    GeglMatrix2     *scale,
-                                    void            *output,
-                                    GeglAbyssPolicy  repeat_mode);
+typedef void (*GeglSamplerGetFun)  (GeglSampler       *self,
+                                    gdouble            x,
+                                    gdouble            y,
+                                    GeglBufferMatrix2 *scale,
+                                    void              *output,
+                                    GeglAbyssPolicy    repeat_mode);
 
 /**
  * gegl_sampler_get_fun: (skip)
@@ -607,12 +596,12 @@ GeglSampler *    gegl_buffer_sampler_new_at_level (GeglBuffer       *buffer,
  *
  * Perform a sampling with the provided @sampler.
  */
-void              gegl_sampler_get            (GeglSampler    *sampler,
-                                               gdouble         x,
-                                               gdouble         y,
-                                               GeglMatrix2    *scale,
-                                               void           *output,
-                                               GeglAbyssPolicy repeat_mode);
+void              gegl_sampler_get            (GeglSampler       *sampler,
+                                               gdouble            x,
+                                               gdouble            y,
+                                               GeglBufferMatrix2 *scale,
+                                               void              *output,
+                                               GeglAbyssPolicy   repeat_mode);
 
 /* code template utility, updates the jacobian matrix using
  * a user defined mapping function for displacement, example
diff --git a/gegl/buffer/gegl-sampler-cubic.c b/gegl/buffer/gegl-sampler-cubic.c
index 54cae222e..6ea47f8e1 100644
--- a/gegl/buffer/gegl-sampler-cubic.c
+++ b/gegl/buffer/gegl-sampler-cubic.c
@@ -22,7 +22,7 @@
 #include <math.h>
 
 #include "gegl.h"
-#include "gegl-types-internal.h"
+#include "gegl-buffer-formats.h"
 #include "gegl-sampler-cubic.h"
 
 enum
@@ -38,7 +38,7 @@ static void gegl_sampler_cubic_finalize (      GObject         *gobject);
 static void gegl_sampler_cubic_get      (      GeglSampler     *sampler,
                                          const gdouble          absolute_x,
                                          const gdouble          absolute_y,
-                                               GeglMatrix2     *scale,
+                                               GeglBufferMatrix2*scale,
                                                void            *output,
                                                GeglAbyssPolicy  repeat_mode);
 static void get_property                (      GObject         *gobject,
@@ -152,12 +152,12 @@ gegl_sampler_cubic_init (GeglSamplerCubic *self)
 }
 
 void
-gegl_sampler_cubic_get (      GeglSampler     *self,
-                        const gdouble          absolute_x,
-                        const gdouble          absolute_y,
-                              GeglMatrix2     *scale,
-                              void            *output,
-                              GeglAbyssPolicy  repeat_mode)
+gegl_sampler_cubic_get (      GeglSampler       *self,
+                        const gdouble            absolute_x,
+                        const gdouble            absolute_y,
+                              GeglBufferMatrix2 *scale,
+                              void              *output,
+                              GeglAbyssPolicy    repeat_mode)
 {
   if (! _gegl_sampler_box_get (self, absolute_x, absolute_y, scale,
                                output, repeat_mode,
diff --git a/gegl/buffer/gegl-sampler-linear.c b/gegl/buffer/gegl-sampler-linear.c
index dfe7bf001..25aa4622b 100644
--- a/gegl/buffer/gegl-sampler-linear.c
+++ b/gegl/buffer/gegl-sampler-linear.c
@@ -22,7 +22,7 @@
 #include <math.h>
 
 #include "gegl.h"
-#include "gegl-types-internal.h"
+#include "gegl-buffer-formats.h"
 #include "gegl-sampler-linear.h"
 
 enum
@@ -34,7 +34,7 @@ enum
 static void gegl_sampler_linear_get (      GeglSampler* restrict  self,
                                      const gdouble                absolute_x,
                                      const gdouble                absolute_y,
-                                           GeglMatrix2           *scale,
+                                           GeglBufferMatrix2     *scale,
                                            void*        restrict  output,
                                            GeglAbyssPolicy        repeat_mode);
 
@@ -73,10 +73,10 @@ gegl_sampler_linear_init (GeglSamplerLinear *self)
 }
 
 void
-gegl_sampler_linear_get (     GeglSampler     *self,
-                        const gdouble          absolute_x,
-                        const gdouble          absolute_y,
-                              GeglMatrix2     *scale,
+gegl_sampler_linear_get (     GeglSampler       *self,
+                        const gdouble            absolute_x,
+                        const gdouble            absolute_y,
+                              GeglBufferMatrix2 *scale,
                               void            *output,
                               GeglAbyssPolicy  repeat_mode)
 {
diff --git a/gegl/buffer/gegl-sampler-lohalo.c b/gegl/buffer/gegl-sampler-lohalo.c
index 04c8047f5..0c2f6e331 100644
--- a/gegl/buffer/gegl-sampler-lohalo.c
+++ b/gegl/buffer/gegl-sampler-lohalo.c
@@ -115,7 +115,7 @@
 #include <math.h>
 
 #include "gegl.h"
-#include "gegl-types-internal.h"
+#include "gegl-buffer-formats.h"
 #include "gegl-sampler-lohalo.h"
 
 /*
@@ -134,7 +134,7 @@ enum
 static void gegl_sampler_lohalo_get (      GeglSampler* restrict  self,
                                      const gdouble                absolute_x,
                                      const gdouble                absolute_y,
-                                           GeglMatrix2           *scale,
+                                           GeglBufferMatrix2     *scale,
                                            void*        restrict  output,
                                            GeglAbyssPolicy        repeat_mode);
 
@@ -383,7 +383,7 @@ static void
 gegl_sampler_lohalo_get (      GeglSampler*    restrict  self,
                          const gdouble                   absolute_x,
                          const gdouble                   absolute_y,
-                               GeglMatrix2              *scale,
+                               GeglBufferMatrix2        *scale,
                                void*           restrict  output,
                                GeglAbyssPolicy           repeat_mode)
 {
diff --git a/gegl/buffer/gegl-sampler-nearest.c b/gegl/buffer/gegl-sampler-nearest.c
index b3d3261d7..2f924eebd 100644
--- a/gegl/buffer/gegl-sampler-nearest.c
+++ b/gegl/buffer/gegl-sampler-nearest.c
@@ -20,7 +20,7 @@
 #include <string.h>
 
 #include "gegl.h"
-#include "gegl-types-internal.h"
+#include "gegl-buffer-formats.h"
 #include "gegl-buffer-types.h"
 #include "gegl-buffer.h"
 #include "gegl-buffer-private.h"
@@ -41,7 +41,7 @@ static void
 gegl_sampler_nearest_get (GeglSampler*    restrict self,
                           const gdouble            absolute_x,
                           const gdouble            absolute_y,
-                          GeglMatrix2             *scale,
+                          GeglBufferMatrix2       *scale,
                           void*           restrict output,
                           GeglAbyssPolicy          repeat_mode);
 
@@ -206,7 +206,7 @@ static void
 gegl_sampler_nearest_get (      GeglSampler*    restrict  sampler,
                           const gdouble                   absolute_x,
                           const gdouble                   absolute_y,
-                                GeglMatrix2              *scale,
+                                GeglBufferMatrix2        *scale,
                                 void*           restrict  output,
                                 GeglAbyssPolicy           repeat_mode)
 {
diff --git a/gegl/buffer/gegl-sampler-nohalo.c b/gegl/buffer/gegl-sampler-nohalo.c
index d41618df7..e7c590333 100644
--- a/gegl/buffer/gegl-sampler-nohalo.c
+++ b/gegl/buffer/gegl-sampler-nohalo.c
@@ -152,7 +152,7 @@
 #include <math.h>
 
 #include "gegl.h"
-#include "gegl-types-internal.h"
+#include "gegl-buffer-formats.h"
 #include "gegl-sampler-nohalo.h"
 
 /*
@@ -240,7 +240,7 @@ enum
 static void gegl_sampler_nohalo_get (      GeglSampler* restrict  self,
                                      const gdouble                absolute_x,
                                      const gdouble                absolute_y,
-                                           GeglMatrix2           *scale,
+                                           GeglBufferMatrix2     *scale,
                                            void*        restrict  output,
                                            GeglAbyssPolicy        repeat_mode);
 
@@ -1217,7 +1217,7 @@ static void
 gegl_sampler_nohalo_get (      GeglSampler*    restrict  self,
                          const gdouble                   absolute_x,
                          const gdouble                   absolute_y,
-                               GeglMatrix2              *scale,
+                               GeglBufferMatrix2        *scale,
                                void*           restrict  output,
                                GeglAbyssPolicy           repeat_mode)
 {
diff --git a/gegl/buffer/gegl-sampler.c b/gegl/buffer/gegl-sampler.c
index e017eb6bd..f4513a92a 100644
--- a/gegl/buffer/gegl-sampler.c
+++ b/gegl/buffer/gegl-sampler.c
@@ -34,7 +34,7 @@
 #include "gegl-sampler-cubic.h"
 #include "gegl-sampler-nohalo.h"
 #include "gegl-sampler-lohalo.h"
-#include "gegl-types-internal.h"
+#include "gegl-buffer-formats.h"
 
 
 enum
@@ -148,12 +148,12 @@ constructed (GObject *self)
 }
 
 void
-gegl_sampler_get (GeglSampler     *self,
-                  gdouble          x,
-                  gdouble          y,
-                  GeglMatrix2     *scale,
-                  void            *output,
-                  GeglAbyssPolicy  repeat_mode)
+gegl_sampler_get (GeglSampler       *self,
+                  gdouble            x,
+                  gdouble            y,
+                  GeglBufferMatrix2 *scale,
+                  void              *output,
+                  GeglAbyssPolicy    repeat_mode)
 {
   if (G_UNLIKELY(!isfinite (x)))
     x = 0.0;
@@ -416,15 +416,15 @@ gegl_sampler_gtype_from_enum (GeglSamplerType sampler_type)
 }
 
 static inline void
-_gegl_buffer_sample_at_level (GeglBuffer       *buffer,
-                              gdouble           x,
-                              gdouble           y,
-                              GeglMatrix2      *scale,
-                              gpointer          dest,
-                              const Babl       *format,
-                              gint              level,
-                              GeglSamplerType   sampler_type,
-                              GeglAbyssPolicy   repeat_mode)
+_gegl_buffer_sample_at_level (GeglBuffer        *buffer,
+                              gdouble            x,
+                              gdouble            y,
+                              GeglBufferMatrix2 *scale,
+                              gpointer           dest,
+                              const Babl        *format,
+                              gint               level,
+                              GeglSamplerType    sampler_type,
+                              GeglAbyssPolicy    repeat_mode)
 {
   GeglSampler *sampler;
 
@@ -450,15 +450,15 @@ _gegl_buffer_sample_at_level (GeglBuffer       *buffer,
 }
 
 void
-gegl_buffer_sample_at_level (GeglBuffer       *buffer,
-                             gdouble           x,
-                             gdouble           y,
-                             GeglMatrix2      *scale,
-                             gpointer          dest,
-                             const Babl       *format,
-                             gint              level,
-                             GeglSamplerType   sampler_type,
-                             GeglAbyssPolicy   repeat_mode)
+gegl_buffer_sample_at_level (GeglBuffer        *buffer,
+                             gdouble            x,
+                             gdouble            y,
+                             GeglBufferMatrix2 *scale,
+                             gpointer           dest,
+                             const Babl        *format,
+                             gint               level,
+                             GeglSamplerType    sampler_type,
+                             GeglAbyssPolicy    repeat_mode)
 {
   _gegl_buffer_sample_at_level (buffer, x, y, scale, dest,
                                 format, level, sampler_type, repeat_mode);
@@ -466,14 +466,14 @@ gegl_buffer_sample_at_level (GeglBuffer       *buffer,
 
 
 void
-gegl_buffer_sample (GeglBuffer       *buffer,
-                    gdouble           x,
-                    gdouble           y,
-                    GeglMatrix2      *scale,
-                    gpointer          dest,
-                    const Babl       *format,
-                    GeglSamplerType   sampler_type,
-                    GeglAbyssPolicy   repeat_mode)
+gegl_buffer_sample (GeglBuffer        *buffer,
+                    gdouble            x,
+                    gdouble            y,
+                    GeglBufferMatrix2 *scale,
+                    gpointer           dest,
+                    const Babl        *format,
+                    GeglSamplerType    sampler_type,
+                    GeglAbyssPolicy    repeat_mode)
 {
   _gegl_buffer_sample_at_level (buffer, x, y, scale, dest, format, 0, sampler_type, repeat_mode);
 }
diff --git a/gegl/buffer/gegl-sampler.h b/gegl/buffer/gegl-sampler.h
index 667b3a57d..fd691a0ac 100644
--- a/gegl/buffer/gegl-sampler.h
+++ b/gegl/buffer/gegl-sampler.h
@@ -223,13 +223,13 @@ static inline gboolean
 _gegl_sampler_box_get (GeglSampler*    restrict  self,
                        const gdouble             absolute_x,
                        const gdouble             absolute_y,
-                       GeglMatrix2              *scale,
+                       GeglBufferMatrix2        *scale,
                        void*           restrict  output,
                        GeglAbyssPolicy           repeat_mode,
                        GeglSamplerType           point_sampler_type,
                        gint                      n_samples)
 {
-  if (scale && fabs (gegl_matrix2_determinant (scale)) >= 4.0)
+  if (scale && fabs (gegl_buffer_matrix2_determinant (scale)) >= 4.0)
     {
       gfloat  result[4] = {0,0,0,0};
       gdouble uv_samples_inv;
@@ -243,7 +243,7 @@ _gegl_sampler_box_get (GeglSampler*    restrict  self,
             gegl_sampler_get_fun (self->point_sampler);
         }
 
-      if (gegl_matrix2_is_scale (scale))
+      if (gegl_buffer_matrix2_is_scale (scale))
         {
           const gdouble u_norm         = fabs (scale->coeff[0][0]);
           const gdouble v_norm         = fabs (scale->coeff[1][1]);
diff --git a/gegl/gegl-matrix.c b/gegl/gegl-matrix.c
index d759a19fc..89703be29 100644
--- a/gegl/gegl-matrix.c
+++ b/gegl/gegl-matrix.c
@@ -23,20 +23,6 @@
 
 #include "gegl-matrix.h"
 
-
-gboolean
-gegl_matrix2_is_scale (GeglMatrix2 *matrix)
-{
-  return matrix->coeff[0][1] == 0.0 && matrix->coeff[1][0] == 0.0;
-}
-
-gdouble
-gegl_matrix2_determinant (GeglMatrix2 *matrix)
-{
-  return matrix->coeff[0][0] * matrix->coeff[1][1] -
-         matrix->coeff[1][0] * matrix->coeff[0][1];
-}
-
 #if 0
 static void gegl_matrix3_debug (GeglMatrix3 *matrix)
 {
diff --git a/gegl/gegl-matrix.h b/gegl/gegl-matrix.h
index 8347a11f5..53b06f7ba 100644
--- a/gegl/gegl-matrix.h
+++ b/gegl/gegl-matrix.h
@@ -22,34 +22,10 @@
 
 #include <glib.h>
 #include <glib-object.h>
+#include <gegl-buffer-matrix2.h>
 
 G_BEGIN_DECLS
 
-/* Currenly only used internally.
- * Note: If making use of this in public API, add a boxed type for introspection
- */
-typedef struct {
-    gdouble coeff[2][2];
-} GeglMatrix2;
-
-/*
- * gegl_matrix2_is_scale:
- * @matrix: a #GeglMatrix2
- *
- * Check if a matrix only does scaling.
- *
- * Returns TRUE if the matrix only does scaling.
- */
-gboolean   gegl_matrix2_is_scale        (GeglMatrix2 *matrix);
-
-/*
- * gegl_matrix2_determinant:
- * @matrix: a #GeglMatrix2
- *
- * Returns the determinant of @matrix.
- */
-gdouble    gegl_matrix2_determinant     (GeglMatrix2 *matrix);
-
 /***
  * GeglMatrix3:
  *
diff --git a/gegl/gegl-utils.h b/gegl/gegl-utils.h
index a4d65c0cb..f9331ee43 100644
--- a/gegl/gegl-utils.h
+++ b/gegl/gegl-utils.h
@@ -348,6 +348,19 @@ GeglNode *gegl_node_new_from_serialized (const gchar *chaindata,
                                          const gchar *path_root);
 
 
+/**
+ * gegl_buffer_set_color:
+ * @buffer: a #GeglBuffer
+ * @rect: a rectangular region to fill with a color.
+ * @color: the GeglColor to fill with.
+ *
+ * Sets the region covered by rect to the specified color.
+ */
+void            gegl_buffer_set_color         (GeglBuffer                *buffer,
+                                               const GeglBufferRectangle *rect,
+                                               GeglColor                 *color);
+
+
 G_END_DECLS
 
 #endif /* __GEGL_UTILS_H__ */
diff --git a/operations/common-gpl3+/fractal-trace.c b/operations/common-gpl3+/fractal-trace.c
index a0fdd8546..a41936251 100644
--- a/operations/common-gpl3+/fractal-trace.c
+++ b/operations/common-gpl3+/fractal-trace.c
@@ -121,7 +121,7 @@ fractaltrace (GeglBuffer            *input,
               const Babl            *format,
               gint                   level)
 {
-  GeglMatrix2  scale;        /* a matrix indicating scaling factors around the
+  GeglBufferMatrix2  scale;   /* a matrix indicating scaling factors around the
                                 current center pixel.
                               */
   gint         x, i, offset;
diff --git a/operations/common-gpl3+/polar-coordinates.c b/operations/common-gpl3+/polar-coordinates.c
index ed20f33f8..7862837ad 100644
--- a/operations/common-gpl3+/polar-coordinates.c
+++ b/operations/common-gpl3+/polar-coordinates.c
@@ -330,7 +330,7 @@ process (GeglOperation       *operation,
   gdouble   px, py;
   gdouble   cen_x, cen_y;
 
-  GeglMatrix2  scale;        /* a matrix indicating scaling factors around the
+  GeglBufferMatrix2  scale;  /* a matrix indicating scaling factors around the
                                 current center pixel.
                              */
 
diff --git a/operations/common-gpl3+/whirl-pinch.c b/operations/common-gpl3+/whirl-pinch.c
index bb10ef300..112ac5764 100644
--- a/operations/common-gpl3+/whirl-pinch.c
+++ b/operations/common-gpl3+/whirl-pinch.c
@@ -167,7 +167,7 @@ apply_whirl_pinch (gdouble              whirl,
 
   for (row = 0; row < roi->height; row++) {
     for (col = 0; col < roi->width; col++) {
-        GeglMatrix2 scale;
+        GeglBufferMatrix2 scale;
 #define gegl_unmap(u,v,du,dv) \
         { \
           calc_undistorted_coords (u, v,\
diff --git a/operations/common/little-planet.c b/operations/common/little-planet.c
index d7f73f584..9b55fbc24 100644
--- a/operations/common/little-planet.c
+++ b/operations/common/little-planet.c
@@ -321,8 +321,8 @@ process (GeglOperation       *operation,
   GeglSampler        *sampler;
   gint                factor       = 1 << level;
   GeglBufferIterator *it;
-  GeglMatrix2         scale_matrix;
-  GeglMatrix2        *scale        = NULL;
+  GeglBufferMatrix2  scale_matrix;
+  GeglBufferMatrix2  *scale        = NULL;
   gint                sampler_type = o->sampler_type;
   const Babl         *format_io    = gegl_operation_get_format (operation, "output");
   GeglSamplerGetFun   getfun;
diff --git a/operations/common/panorama-projection.c b/operations/common/panorama-projection.c
index 6f97c7dec..87277e381 100644
--- a/operations/common/panorama-projection.c
+++ b/operations/common/panorama-projection.c
@@ -331,8 +331,8 @@ process (GeglOperation       *operation,
   GeglSampler        *sampler;
   gint                factor       = 1 << level;
   GeglBufferIterator *it;
-  GeglMatrix2         scale_matrix;
-  GeglMatrix2        *scale        = NULL;
+  GeglBufferMatrix2   scale_matrix;
+  GeglBufferMatrix2  *scale        = NULL;
   gint                sampler_type = o->sampler_type;
   const Babl         *format_io    = gegl_operation_get_format (operation, "output");
   GeglSamplerGetFun   getfun;
diff --git a/operations/transform/transform-core.c b/operations/transform/transform-core.c
index 9be1d9b4a..e11dc34b1 100644
--- a/operations/transform/transform-core.c
+++ b/operations/transform/transform-core.c
@@ -1120,7 +1120,7 @@ transform_affine (GeglOperation       *operation,
   const Babl      *format = babl_format_with_space ("RaGaBaA float", space);
   GeglMatrix3      inverse;
   gdouble          inverse_near_z = 1.0 / transform->near_z;
-  GeglMatrix2      inverse_jacobian;
+  GeglBufferMatrix2 inverse_jacobian;
   GeglAbyssPolicy  abyss_policy = gegl_transform_get_abyss_policy (transform);
   GeglSampler     *sampler = gegl_buffer_sampler_new_at_level (src,
                                          format,
@@ -1376,7 +1376,7 @@ transform_generic (GeglOperation       *operation,
                 gdouble u = u_float * w_recip;
                 gdouble v = v_float * w_recip;
 
-                GeglMatrix2 inverse_jacobian;
+                GeglBufferMatrix2 inverse_jacobian;
                 inverse_jacobian.coeff [0][0] =
                   (inverse.coeff [0][0] - inverse.coeff [2][0] * u) * w_recip;
                 inverse_jacobian.coeff [0][1] =


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