[gegl] gegl: uniform dispatch api for downscale_2x2



commit a718c59f84eef82520ee1c46c171d01c76fb484f
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu Jan 18 19:13:58 2018 +0100

    gegl: uniform dispatch api for downscale_2x2
    
    By having all functions share the signature we enable caching of dispatchers to
    avoid branches in use.

 gegl/buffer/gegl-tile-handler-zoom.h   |    7 ++
 gegl/gegl-algorithms-2x2-downscale.inc |   15 +++--
 gegl/gegl-algorithms.c                 |   63 ++++++++++++---------
 gegl/gegl-algorithms.h                 |   96 ++++++++++++++++----------------
 4 files changed, 99 insertions(+), 82 deletions(-)
---
diff --git a/gegl/buffer/gegl-tile-handler-zoom.h b/gegl/buffer/gegl-tile-handler-zoom.h
index b3fa0f2..8624ca6 100644
--- a/gegl/buffer/gegl-tile-handler-zoom.h
+++ b/gegl/buffer/gegl-tile-handler-zoom.h
@@ -44,6 +44,13 @@ struct _GeglTileHandlerZoom
   GeglTileHandler       parent_instance;
   GeglTileBackend      *backend;
   GeglTileStorage      *tile_storage;
+  void (*downscale_2x2) (gint    bpp,
+                         gint    src_width,
+                         gint    dst_dst_width,
+                         guchar *src_data,
+                         gint    src_rowstride,
+                         guchar *dst_data,
+                         gint    dst_rowstride);
 };
 
 struct _GeglTileHandlerZoomClass
diff --git a/gegl/gegl-algorithms-2x2-downscale.inc b/gegl/gegl-algorithms-2x2-downscale.inc
index 51d4e1e..bdea195 100644
--- a/gegl/gegl-algorithms-2x2-downscale.inc
+++ b/gegl/gegl-algorithms-2x2-downscale.inc
@@ -1,15 +1,16 @@
 #define S(a)   ((DOWNSCALE_SUM)(a))
 
 void
-DOWNSCALE_FUNCNAME (gint    bpp,
-                    gint    src_width,
-                    gint    src_height,
-                    guchar *src_data,
-                    gint    src_rowstride,
-                    guchar *dst_data,
-                    gint    dst_rowstride)
+DOWNSCALE_FUNCNAME (const Babl *format,
+                    gint        src_width,
+                    gint        src_height,
+                    guchar     *src_data,
+                    gint        src_rowstride,
+                    guchar     *dst_data,
+                    gint        dst_rowstride)
 {
   gint y;
+  gint bpp = babl_format_get_bytes_per_pixel (format);
   gint diag = src_rowstride + bpp;
   const gint components = bpp / sizeof(DOWNSCALE_TYPE);
 
diff --git a/gegl/gegl-algorithms.c b/gegl/gegl-algorithms.c
index 82bd6f6..2337616 100644
--- a/gegl/gegl-algorithms.c
+++ b/gegl/gegl-algorithms.c
@@ -41,15 +41,16 @@ gegl_downscale_2x2_generic (const Babl *format,
                             guchar     *dst_data,
                             gint        dst_rowstride);
 
-void gegl_downscale_2x2 (const Babl *format,
-                         gint        src_width,
-                         gint        src_height,
-                         guchar     *src_data,
-                         gint        src_rowstride,
-                         guchar     *dst_data,
-                         gint        dst_rowstride)
+typedef void (*GeglDownscale2x2Fun) (const Babl *format,
+                                     gint    src_width,
+                                     gint    src_height,
+                                     guchar *src_data,
+                                     gint    src_rowstride,
+                                     guchar *dst_data,
+                                     gint    dst_rowstride);
+
+static GeglDownscale2x2Fun gegl_downscale_2x2_get_fun (const Babl *format)
 {
-  const gint  bpp = babl_format_get_bytes_per_pixel (format);
   const Babl *comp_type = babl_format_get_type (format, 0);
   const Babl *model     = babl_format_get_model (format);
 
@@ -57,32 +58,39 @@ void gegl_downscale_2x2 (const Babl *format,
   {
     if (comp_type == gegl_babl_float())
     {
-      gegl_downscale_2x2_float (bpp, src_width, src_height, src_data, src_rowstride, dst_data, 
dst_rowstride);
-      return;
+      return gegl_downscale_2x2_float;
     }
     else if (comp_type == gegl_babl_u8())
     {
-      gegl_downscale_2x2_u8 (bpp, src_width, src_height, src_data, src_rowstride, dst_data, dst_rowstride);
-      return;
+      return gegl_downscale_2x2_u8;
     }
     else if (comp_type == gegl_babl_u16())
     {
-      gegl_downscale_2x2_u16 (bpp, src_width, src_height, src_data, src_rowstride, dst_data, dst_rowstride);
-      return;
+      return gegl_downscale_2x2_u16;
     }
     else if (comp_type == gegl_babl_u32())
     {
-      gegl_downscale_2x2_u32 (bpp, src_width, src_height, src_data, src_rowstride, dst_data, dst_rowstride);
-      return;
+      return gegl_downscale_2x2_u32;
     }
     else if (comp_type == gegl_babl_double())
     {
-      gegl_downscale_2x2_double (bpp, src_width, src_height, src_data, src_rowstride, dst_data, 
dst_rowstride);
-      return;
+      return gegl_downscale_2x2_double;
     }
   }
+  return gegl_downscale_2x2_generic;
+}
 
-  gegl_downscale_2x2_generic (format, src_width, src_height, src_data, src_rowstride, dst_data, 
dst_rowstride);
+void gegl_downscale_2x2 (const Babl *format,
+                         gint        src_width,
+                         gint        src_height,
+                         guchar     *src_data,
+                         gint        src_rowstride,
+                         guchar     *dst_data,
+                         gint        dst_rowstride)
+{
+  gegl_downscale_2x2_get_fun (format)(format, src_width, src_height,
+                                              src_data, src_rowstride,
+                                              src_data, dst_rowstride);;
 }
 
 #include <stdio.h>
@@ -126,7 +134,7 @@ gegl_downscale_2x2_generic (const Babl *format,
                      src_data, src_rowstride,
                      in_tmp,   in_tmp_rowstride,
                      src_width, src_height);
-  gegl_downscale_2x2_float (tmp_bpp, src_width, src_height,
+  gegl_downscale_2x2_float (tmp_format, src_width, src_height,
                             in_tmp,  in_tmp_rowstride,
                             out_tmp, out_tmp_rowstride);
   babl_process_rows (to_fish,
@@ -142,14 +150,15 @@ gegl_downscale_2x2_generic (const Babl *format,
 }
 
 void
-gegl_downscale_2x2_nearest (gint    bpp,
-                            gint    src_width,
-                            gint    src_height,
-                            guchar *src_data,
-                            gint    src_rowstride,
-                            guchar *dst_data,
-                            gint    dst_rowstride)
+gegl_downscale_2x2_nearest (const Babl *format,
+                            gint        src_width,
+                            gint        src_height,
+                            guchar     *src_data,
+                            gint        src_rowstride,
+                            guchar     *dst_data,
+                            gint        dst_rowstride)
 {
+  gint bpp = babl_format_get_bytes_per_pixel (format);
   gint y;
 
   for (y = 0; y < src_height / 2; y++)
diff --git a/gegl/gegl-algorithms.h b/gegl/gegl-algorithms.h
index 9d9ff6e..f1887a7 100644
--- a/gegl/gegl-algorithms.h
+++ b/gegl/gegl-algorithms.h
@@ -24,60 +24,60 @@ G_BEGIN_DECLS
 #define GEGL_SCALE_EPSILON 1.e-6
 
 void gegl_downscale_2x2 (const Babl *format,
-                         gint    src_width,
-                         gint    src_height,
-                         guchar *src_data,
-                         gint    src_rowstride,
-                         guchar *dst_data,
-                         gint    dst_rowstride);
-
-void gegl_downscale_2x2_double (gint    bpp,
-                                gint    src_width,
-                                gint    src_height,
-                                guchar *src_data,
-                                gint    src_rowstride,
-                                guchar *dst_data,
-                                gint    dst_rowstride);
-
-void gegl_downscale_2x2_float (gint    bpp,
-                               gint    src_width,
-                               gint    src_height,
-                               guchar *src_data,
-                               gint    src_rowstride,
-                               guchar *dst_data,
-                               gint    dst_rowstride);
-
-void gegl_downscale_2x2_u32 (gint    bpp,
-                             gint    src_width,
-                             gint    src_height,
-                             guchar *src_data,
-                             gint    src_rowstride,
-                             guchar *dst_data,
-                             gint    dst_rowstride);
-
-void gegl_downscale_2x2_u16 (gint    bpp,
-                             gint    src_width,
-                             gint    src_height,
-                             guchar *src_data,
-                             gint    src_rowstride,
-                             guchar *dst_data,
-                             gint    dst_rowstride);
-
-void gegl_downscale_2x2_u8 (gint    bpp,
-                            gint    src_width,
-                            gint    src_height,
-                            guchar *src_data,
-                            gint    src_rowstride,
-                            guchar *dst_data,
-                            gint    dst_rowstride);
-
-void gegl_downscale_2x2_nearest (gint    bpp,
-                                 gint    src_width,
-                                 gint    src_height,
-                                 guchar *src_data,
-                                 gint    src_rowstride,
-                                 guchar *dst_data,
-                                 gint    dst_rowstride);
+                         gint        src_width,
+                         gint        src_height,
+                         guchar     *src_data,
+                         gint        src_rowstride,
+                         guchar     *dst_data,
+                         gint        dst_rowstride);
+
+void gegl_downscale_2x2_double (const Babl *format,
+                                gint        src_width,
+                                gint        src_height,
+                                guchar     *src_data,
+                                gint        src_rowstride,
+                                guchar     *dst_data,
+                                gint        dst_rowstride);
+
+void gegl_downscale_2x2_float (const Babl *format,
+                               gint        src_width,
+                               gint        src_height,
+                               guchar     *src_data,
+                               gint        src_rowstride,
+                               guchar     *dst_data,
+                               gint        dst_rowstride);
+
+void gegl_downscale_2x2_u32 (const Babl *format,
+                             gint        src_width,
+                             gint        src_height,
+                             guchar     *src_data,
+                             gint        src_rowstride,
+                             guchar     *dst_data,
+                             gint        dst_rowstride);
+
+void gegl_downscale_2x2_u16 (const Babl *format,
+                             gint        src_width,
+                             gint        src_height,
+                             guchar     *src_data,
+                             gint        src_rowstride,
+                             guchar     *dst_data,
+                             gint        dst_rowstride);
+
+void gegl_downscale_2x2_u8 (const Babl *format,
+                            gint        src_width,
+                            gint        src_height,
+                            guchar     *src_data,
+                            gint        src_rowstride,
+                            guchar     *dst_data,
+                            gint        dst_rowstride);
+
+void gegl_downscale_2x2_nearest (const Babl *format,
+                                 gint        src_width,
+                                 gint        src_height,
+                                 guchar     *src_data,
+                                 gint        src_rowstride,
+                                 guchar      *dst_data,
+                                 gint        dst_rowstride);
 
 /* Attempt to resample with a 3x3 boxfilter, if no boxfilter is
  * available for #format fall back to nearest neighbor.


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