gegl: uniform dispatch api for downscale_2x2

By having all functions share the signature we enable caching of dispatchers to
avoid branches in use.
parent b02ee75c
......@@ -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
......
#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);
......
......@@ -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++)
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment