[gegl] samplers: have two different defines for tile width and height
- From: Nicolas Robidoux <nrobidoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] samplers: have two different defines for tile width and height
- Date: Fri, 21 Dec 2012 17:34:24 +0000 (UTC)
commit b2b4aea27865a15bf6e20dc451cca50bab333e22
Author: Nicolas Robidoux <nrobidoux git gnome org>
Date: Fri Dec 21 12:34:14 2012 -0500
samplers: have two different defines for tile width and height
gegl/buffer/gegl-sampler-cubic.c | 26 ++--
gegl/buffer/gegl-sampler-linear.c | 2 +-
gegl/buffer/gegl-sampler-lohalo.c | 2 +-
gegl/buffer/gegl-sampler.c | 265 ++++++++++++++++--------------------
gegl/buffer/gegl-sampler.h | 9 +-
5 files changed, 139 insertions(+), 165 deletions(-)
---
diff --git a/gegl/buffer/gegl-sampler-cubic.c b/gegl/buffer/gegl-sampler-cubic.c
index 33ba4b5..01fdf44 100644
--- a/gegl/buffer/gegl-sampler-cubic.c
+++ b/gegl/buffer/gegl-sampler-cubic.c
@@ -165,17 +165,19 @@ gegl_sampler_cubic_get ( GeglSampler *self,
void *output,
GeglAbyssPolicy repeat_mode)
{
- GeglSamplerCubic *cubic = (GeglSamplerCubic*)(self);
- const gint offsets[16] =
- {-4-2*GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT *4, 4, 4, 4,
- (2*GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT-3)*4, 4, 4, 4,
- (2*GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT-3)*4, 4, 4, 4,
- (2*GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT-3)*4, 4, 4, 4};
+ GeglSamplerCubic *cubic = (GeglSamplerCubic*)(self);
+ const gint offsets[16] = {
+ -4-GEGL_SAMPLER_MAXIMUM_WIDTH *4, 4, 4, 4,
+ (GEGL_SAMPLER_MAXIMUM_WIDTH-3)*4, 4, 4, 4,
+ (GEGL_SAMPLER_MAXIMUM_WIDTH-3)*4, 4, 4, 4,
+ (GEGL_SAMPLER_MAXIMUM_WIDTH-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;
+ gfloat newval[4] = {0, 0, 0, 0};
+ gint i,
+ j,
+ k = 0;
/*
* The "-1/2"s are there because we want the index of the pixel
@@ -279,12 +281,12 @@ cubicKernel (const gfloat x,
if (x2 <= (gfloat) 1.) return ( (gfloat) ((12-9*b-6*c)/6) * ax +
(gfloat) ((-18+12*b+6*c)/6) ) * x2 +
- (gfloat) ((6-2*b)/6);
+ (gfloat) ((6-2*b)/6);
if (x2 < (gfloat) 4.) return ( (gfloat) ((-b-6*c)/6) * ax +
(gfloat) ((6*b+30*c)/6) ) * x2 +
- (gfloat) ((-12*b-48*c)/6) * ax +
- (gfloat) ((8*b+24*c)/6);
+ (gfloat) ((-12*b-48*c)/6) * ax +
+ (gfloat) ((8*b+24*c)/6);
return (gfloat) 0.;
}
diff --git a/gegl/buffer/gegl-sampler-linear.c b/gegl/buffer/gegl-sampler-linear.c
index 88c8da4..99d3a05 100644
--- a/gegl/buffer/gegl-sampler-linear.c
+++ b/gegl/buffer/gegl-sampler-linear.c
@@ -86,7 +86,7 @@ gegl_sampler_linear_get ( GeglSampler* restrict self,
void* restrict output,
GeglAbyssPolicy repeat_mode)
{
- const gint pixels_per_buffer_row = (gint) 2 * GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT;
+ const gint pixels_per_buffer_row = GEGL_SAMPLER_MAXIMUM_WIDTH;
const gint channels = 4;
/*
diff --git a/gegl/buffer/gegl-sampler-lohalo.c b/gegl/buffer/gegl-sampler-lohalo.c
index d853502..e05d11b 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 = (gint) 2 * GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT;
+ const gint pixels_per_row = GEGL_SAMPLER_MAXIMUM_WIDTH;
const gint row_skip = channels * pixels_per_row;
/*
diff --git a/gegl/buffer/gegl-sampler.c b/gegl/buffer/gegl-sampler.c
index 6c20883..c7973a2 100644
--- a/gegl/buffer/gegl-sampler.c
+++ b/gegl/buffer/gegl-sampler.c
@@ -46,27 +46,27 @@ enum
static void gegl_sampler_class_init (GeglSamplerClass *klass);
-static void gegl_sampler_init (GeglSampler *self);
+static void gegl_sampler_init (GeglSampler *self);
-static void finalize (GObject *gobject);
+static void finalize (GObject *gobject);
-static void dispose (GObject *gobject);
+static void dispose (GObject *gobject);
-static void get_property (GObject *gobject,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
+static void get_property (GObject *gobject,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
-static void set_property (GObject *gobject,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
+static void set_property (GObject *gobject,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
-static void set_buffer (GeglSampler *self,
- GeglBuffer *buffer);
+static void set_buffer (GeglSampler *self,
+ GeglBuffer *buffer);
GType
-gegl_sampler_gtype_from_enum (GeglSamplerType sampler_type);
+gegl_sampler_gtype_from_enum (GeglSamplerType sampler_type);
G_DEFINE_TYPE (GeglSampler, gegl_sampler, G_TYPE_OBJECT)
@@ -76,11 +76,11 @@ gegl_sampler_class_init (GeglSamplerClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = finalize;
- object_class->dispose = dispose;
+ object_class->dispose = dispose;
- klass->prepare = NULL;
- klass->get = NULL;
- klass->set_buffer = set_buffer;
+ klass->prepare = NULL;
+ klass->get = NULL;
+ klass->set_buffer = set_buffer;
object_class->set_property = set_property;
object_class->get_property = get_property;
@@ -106,24 +106,24 @@ gegl_sampler_class_init (GeglSamplerClass *klass)
static void
gegl_sampler_init (GeglSampler *self)
{
- int i;
+ int i = 0;
self->buffer = NULL;
- for (i=0; i<GEGL_SAMPLER_MIPMAP_LEVELS; ++i) {
- GeglRectangle context_rect = {0,0,1,1};
+ do {
+ GeglRectangle context_rect = {0,0,1,1};
GeglRectangle sampler_rectangle = {0,0,0,0};
- self->sampler_buffer[i] = NULL;
- self->context_rect[i] = context_rect;
- self->sampler_rectangle[i] = sampler_rectangle;
- }
+ self->sampler_buffer[i] = NULL;
+ self->context_rect[i] = context_rect;
+ self->sampler_rectangle[i] = sampler_rectangle;
+ } while ( ++i<GEGL_SAMPLER_MIPMAP_LEVELS );
}
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,
+ GeglMatrix2 *scale,
+ void *output,
+ GeglAbyssPolicy repeat_mode)
{
self->get (self, x, y, scale, output, repeat_mode);
}
@@ -140,7 +140,6 @@ gegl_sampler_prepare (GeglSampler *self)
if (klass->prepare)
klass->prepare (self);
-
self->fish = babl_fish (self->interpolate_format, self->format);
/*
@@ -177,16 +176,15 @@ gegl_sampler_set_buffer (GeglSampler *self, GeglBuffer *buffer)
static void
finalize (GObject *gobject)
{
- int i;
GeglSampler *sampler = GEGL_SAMPLER (gobject);
- for (i=0; i<GEGL_SAMPLER_MIPMAP_LEVELS; ++i)
- {
- if (sampler->sampler_buffer[i])
- {
- g_free (sampler->sampler_buffer[i]);
- sampler->sampler_buffer[i] = NULL;
- }
- }
+ int i = 0;
+ do {
+ if (sampler->sampler_buffer[i])
+ {
+ g_free (sampler->sampler_buffer[i]);
+ sampler->sampler_buffer[i] = NULL;
+ }
+ } while ( ++i<GEGL_SAMPLER_MIPMAP_LEVELS );
G_OBJECT_CLASS (gegl_sampler_parent_class)->finalize (gobject);
}
@@ -204,7 +202,7 @@ dispose (GObject *gobject)
/*
* Gets a pointer to the center pixel, within a buffer that has a
- * rowstride of 64px * 16bpp:
+ * rowstride of GEGL_SAMPLER_MAXIMUM_WIDTH px * bpp.
*/
gfloat *
gegl_sampler_get_ptr (GeglSampler *const sampler,
@@ -220,17 +218,10 @@ gegl_sampler_get_ptr (GeglSampler *const sampler,
const gint bpp =
babl_format_get_bytes_per_pixel (sampler->interpolate_format);
- /*
- * maximum_width_and_height is the largest number of pixels which
- * can be be requested in the horizontal or vertical directions (64
- * in GEGL).
- */
- const gint maximum_width_and_height =
- GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT;
- g_assert (sampler->context_rect[0].width <=
- (gint) 2 * maximum_width_and_height);
- g_assert (sampler->context_rect[0].height <=
- maximum_width_and_height);
+ const gint maximum_width = GEGL_SAMPLER_MAXIMUM_WIDTH;
+ const gint maximum_height = GEGL_SAMPLER_MAXIMUM_HEIGHT;
+ g_assert (sampler->context_rect[0].width <= maximum_width);
+ g_assert (sampler->context_rect[0].height <= maximum_height);
if ((sampler->sampler_buffer[0] == NULL)
||
@@ -251,6 +242,15 @@ gegl_sampler_get_ptr (GeglSampler *const sampler,
GeglRectangle fetch_rectangle;
/*
+ * Always request the same amount of pixels:
+ */
+ if (sampler->sampler_buffer[0] == NULL)
+ {
+ sampler->sampler_buffer[0] =
+ g_malloc0 (maximum_width * maximum_height * bpp);
+ }
+
+ /*
* Override the fetch rectangle needed by the sampler in order
* to prevent constant buffer creation, adding some elbow room
* at the top and left so that buffers are not constantly
@@ -258,36 +258,25 @@ gegl_sampler_get_ptr (GeglSampler *const sampler,
* into account that it is more likely that further access is to
* the right or down of our currently requested
* 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.
+ * context_rect, leaving an elbow room there which is typically
+ * just a bit more in the vertical direction than in the
+ * horizontal direction, which is desirable because the buffers'
+ * scanlines are longer than they are tall, which means they are
+ * more likely to escape the buffer than the beginning of the
+ * next scanline.
*
- * 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.
+ * Note that transform-core now works hard to have scanlines go
+ * left to right in input space, and then tries to have further
+ * scanlines below instead of above.
*/
+ fetch_rectangle.width = maximum_width;
+ fetch_rectangle.height = maximum_height;
fetch_rectangle.x =
x + sampler->context_rect[0].x -
- ((gint) 2 * maximum_width_and_height - sampler->context_rect[0].width ) /
- (gint) 8;
+ (maximum_width - sampler->context_rect[0].width ) / (gint) 8;
fetch_rectangle.y =
y + sampler->context_rect[0].y -
- (maximum_width_and_height - sampler->context_rect[0].height) /
- (gint) 4;
-
- fetch_rectangle.width = (gint) 2 * maximum_width_and_height;
- fetch_rectangle.height = maximum_width_and_height;
-
- if (sampler->sampler_buffer[0] == NULL)
- {
- /*
- * Always request the same amount of pixels:
- */
- sampler->sampler_buffer[0] =
- g_malloc0 (( (gint) 2 * maximum_width_and_height * maximum_width_and_height )
- * bpp);
- }
+ (maximum_height - sampler->context_rect[0].height) / (gint) 4;
gegl_buffer_get (sampler->buffer,
&fetch_rectangle,
@@ -300,10 +289,10 @@ gegl_sampler_get_ptr (GeglSampler *const sampler,
sampler->sampler_rectangle[0] = fetch_rectangle;
}
- dx = x - sampler->sampler_rectangle[0].x;
- dy = y - sampler->sampler_rectangle[0].y;
+ dx = x - sampler->sampler_rectangle[0].x;
+ dy = y - sampler->sampler_rectangle[0].y;
buffer_ptr = (guchar *)sampler->sampler_buffer[0];
- sof = ( dx + dy * sampler->sampler_rectangle[0].width ) * bpp;
+ sof = ( dx + dy * sampler->sampler_rectangle[0].width ) * bpp;
return (gfloat*)(buffer_ptr+sof);
}
@@ -322,15 +311,10 @@ gegl_sampler_get_from_buffer (GeglSampler *const sampler,
const gint bpp =
babl_format_get_bytes_per_pixel (sampler->interpolate_format);
- /*
- * maximum_width_and_height is the largest number of pixels which
- * can be be requested in the horizontal or vertical directions (64
- * in GEGL).
- */
- const gint maximum_width_and_height =
- GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT;
- g_assert (sampler->context_rect[0].width <= (gint) 2 * maximum_width_and_height);
- g_assert (sampler->context_rect[0].height <= maximum_width_and_height);
+ const gint maximum_width = GEGL_SAMPLER_MAXIMUM_WIDTH;
+ const gint maximum_height = GEGL_SAMPLER_MAXIMUM_HEIGHT;
+ g_assert (sampler->context_rect[0].width <= maximum_width);
+ g_assert (sampler->context_rect[0].height <= maximum_height);
if ((sampler->sampler_buffer[0] == NULL)
||
@@ -350,26 +334,22 @@ gegl_sampler_get_from_buffer (GeglSampler *const sampler,
*/
GeglRectangle fetch_rectangle;
- fetch_rectangle.x = x -
- ((gint) 2 * maximum_width_and_height - sampler->context_rect[0].width ) /
- (gint) 8;
- fetch_rectangle.y = y -
- (maximum_width_and_height - sampler->context_rect[0].height) /
- (gint) 4;
-
- fetch_rectangle.width = (gint) 2 * maximum_width_and_height;
- fetch_rectangle.height = maximum_width_and_height;
-
+ /*
+ * Always request the same amount of pixels:
+ */
if (sampler->sampler_buffer[0] == NULL)
{
- /*
- * Always request the same amount of pixels:
- */
sampler->sampler_buffer[0] =
- g_malloc0 (( (gint) 2 * maximum_width_and_height * maximum_width_and_height )
- * bpp);
+ g_malloc0 (maximum_width * maximum_height * bpp);
}
+ fetch_rectangle.width = maximum_width;
+ fetch_rectangle.height = maximum_height;
+ fetch_rectangle.x = x -
+ (maximum_width - sampler->context_rect[0].width ) / (gint) 8;
+ fetch_rectangle.y = y -
+ (maximum_height - sampler->context_rect[0].height) / (gint) 4;
+
gegl_buffer_get (sampler->buffer,
&fetch_rectangle,
1.0,
@@ -381,10 +361,10 @@ gegl_sampler_get_from_buffer (GeglSampler *const sampler,
sampler->sampler_rectangle[0] = fetch_rectangle;
}
- dx = x - sampler->sampler_rectangle[0].x;
- dy = y - sampler->sampler_rectangle[0].y;
+ dx = x - sampler->sampler_rectangle[0].x;
+ dy = y - sampler->sampler_rectangle[0].y;
buffer_ptr = (guchar *)sampler->sampler_buffer[0];
- sof = ( dx + dy * sampler->sampler_rectangle[0].width ) * bpp;
+ sof = ( dx + dy * sampler->sampler_rectangle[0].width ) * bpp;
return (gfloat*)(buffer_ptr+sof);
}
@@ -406,24 +386,17 @@ gegl_sampler_get_from_mipmap (GeglSampler *const sampler,
const gint bpp =
babl_format_get_bytes_per_pixel (sampler->interpolate_format);
- /*
- * maximum_width_and_height is the largest number of pixels which
- * can be be requested in the horizontal or vertical directions (64
- * in GEGL).
- */
- const gint maximum_width_and_height =
- GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT;
- g_assert (sampler->context_rect[level].width <= (gint) 2 * maximum_width_and_height);
- g_assert (sampler->context_rect[level].height <= maximum_width_and_height);
+ const gint maximum_width = GEGL_SAMPLER_MAXIMUM_WIDTH;
+ const gint maximum_height = GEGL_SAMPLER_MAXIMUM_HEIGHT;
g_assert (level >= 0 && level < GEGL_SAMPLER_MIPMAP_LEVELS);
+ g_assert (sampler->context_rect[level].width <= maximum_width);
+ g_assert (sampler->context_rect[level].height <= maximum_height);
if ((sampler->sampler_buffer[level] == NULL)
||
- (x + sampler->context_rect[level].x <
- sampler->sampler_rectangle[level].x)
+ (x + sampler->context_rect[level].x < sampler->sampler_rectangle[level].x)
||
- (y + sampler->context_rect[level].y <
- sampler->sampler_rectangle[level].y)
+ (y + sampler->context_rect[level].y < sampler->sampler_rectangle[level].y)
||
(x + sampler->context_rect[level].x +
sampler->context_rect[level].width >
@@ -441,28 +414,24 @@ gegl_sampler_get_from_mipmap (GeglSampler *const sampler,
*/
GeglRectangle fetch_rectangle;
- fetch_rectangle.x =
- x + sampler->context_rect[level].x -
- ((gint) 2 * maximum_width_and_height - sampler->context_rect[level].width ) /
- (gint) 8;
- fetch_rectangle.y =
- y + sampler->context_rect[level].y -
- (maximum_width_and_height - sampler->context_rect[level].height) /
- (gint) 4;
-
- fetch_rectangle.width = (gint) 2 * maximum_width_and_height;
- fetch_rectangle.height = maximum_width_and_height;
-
+ /*
+ * Always request the same amount of pixels:
+ */
if (sampler->sampler_buffer[level] == NULL)
{
- /*
- * Always request the same amount of pixels:
- */
sampler->sampler_buffer[level] =
- g_malloc0 (( (gint) 2 * maximum_width_and_height * maximum_width_and_height )
- * bpp);
+ g_malloc0 (maximum_width * maximum_height * bpp);
}
+ fetch_rectangle.width = maximum_width;
+ fetch_rectangle.height = maximum_height;
+ fetch_rectangle.x =
+ x + sampler->context_rect[level].x -
+ (maximum_width - sampler->context_rect[level].width ) / (gint) 8;
+ fetch_rectangle.y =
+ y + sampler->context_rect[level].y -
+ (maximum_height - sampler->context_rect[level].height) / (gint) 4;
+
gegl_buffer_get (sampler->buffer,
&fetch_rectangle,
scale,
@@ -474,10 +443,10 @@ gegl_sampler_get_from_mipmap (GeglSampler *const sampler,
sampler->sampler_rectangle[level] = fetch_rectangle;
}
- dx = x - sampler->sampler_rectangle[level].x;
- dy = y - sampler->sampler_rectangle[level].y;
+ dx = x - sampler->sampler_rectangle[level].x;
+ dy = y - sampler->sampler_rectangle[level].y;
buffer_ptr = (guchar *)sampler->sampler_buffer[level];
- sof = ( dx + dy * sampler->sampler_rectangle[level].width ) * bpp;
+ sof = ( dx + dy * sampler->sampler_rectangle[level].width ) * bpp;
return (gfloat*)(buffer_ptr+sof);
}
@@ -545,22 +514,19 @@ set_buffer (GeglSampler *self, GeglBuffer *buffer)
GeglSamplerType
gegl_sampler_type_from_string (const gchar *string)
{
- if (g_str_equal (string, "nearest") ||
- g_str_equal (string, "none"))
+ if (g_str_equal (string, "nearest") || g_str_equal (string, "none"))
return GEGL_SAMPLER_NEAREST;
- if (g_str_equal (string, "linear") ||
- g_str_equal (string, "bilinear"))
+ if (g_str_equal (string, "linear") || g_str_equal (string, "bilinear"))
return GEGL_SAMPLER_LINEAR;
- if (g_str_equal (string, "cubic") ||
- g_str_equal (string, "bicubic"))
+ if (g_str_equal (string, "cubic") || g_str_equal (string, "bicubic"))
return GEGL_SAMPLER_CUBIC;
if (g_str_equal (string, "lohalo"))
return GEGL_SAMPLER_LOHALO;
- return GEGL_SAMPLER_NEAREST;
+ return GEGL_SAMPLER_LINEAR;
}
GType
@@ -588,14 +554,19 @@ gegl_buffer_sampler_new (GeglBuffer *buffer,
{
GeglSampler *sampler;
GType desired_type;
+
if (format == NULL)
format = babl_format ("RaGaBaA float");
+
desired_type = gegl_sampler_gtype_from_enum (sampler_type);
+
sampler = g_object_new (desired_type,
"buffer", buffer,
"format", format,
NULL);
+
gegl_sampler_prepare (sampler);
+
return sampler;
}
diff --git a/gegl/buffer/gegl-sampler.h b/gegl/buffer/gegl-sampler.h
index c894067..bec1c1c 100644
--- a/gegl/buffer/gegl-sampler.h
+++ b/gegl/buffer/gegl-sampler.h
@@ -36,12 +36,13 @@ G_BEGIN_DECLS
* 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
+#define GEGL_SAMPLER_MIPMAP_LEVELS (4)
/*
- * The way the samplers use mipmap levels, square buffers are
- * preferable to rectangular ones.
+ * Best thing to do seems to use rectangular buffer tiles that are
+ * twice as wide as they are tall.
*/
-#define GEGL_SAMPLER_MAXIMUM_WIDTH_AND_HEIGHT 32
+#define GEGL_SAMPLER_MAXIMUM_HEIGHT (32)
+#define GEGL_SAMPLER_MAXIMUM_WIDTH (2*GEGL_SAMPLER_MAXIMUM_HEIGHT)
typedef struct _GeglSamplerClass GeglSamplerClass;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]