[gegl: 13/25] sampler-nearest.c: for some strange reason, enlarging width=height to 3 (from 1) make it interact be
- From: Nicolas Robidoux <nrobidoux src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl: 13/25] sampler-nearest.c: for some strange reason, enlarging width=height to 3 (from 1) make it interact be
- Date: Sun, 25 Nov 2012 02:20:35 +0000 (UTC)
commit cf4e6a55903507269f79b97d49e53672f42ee0d8
Author: Nicolas Robidoux <nrobidoux git gnome org>
Date: Fri Nov 23 23:30:45 2012 -0500
sampler-nearest.c: for some strange reason, enlarging width=height to 3 (from 1) make it interact better with GIMP: no half-pixel wide margin when enlarging
gegl/buffer/gegl-sampler-nearest.c | 13 +++++++++----
operations/transform/transform-core.c | 31 ++++++++++++-------------------
2 files changed, 21 insertions(+), 23 deletions(-)
---
diff --git a/gegl/buffer/gegl-sampler-nearest.c b/gegl/buffer/gegl-sampler-nearest.c
index 00ff137..06a60c7 100644
--- a/gegl/buffer/gegl-sampler-nearest.c
+++ b/gegl/buffer/gegl-sampler-nearest.c
@@ -51,13 +51,18 @@ gegl_sampler_nearest_class_init (GeglSamplerNearestClass *klass)
sampler_class->get = gegl_sampler_nearest_get;
}
+/*
+ * It would seem that x=y=0 and width=height=1 should be enough, but
+ * apparently safety w.r.t. round off or something else makes things
+ * work better with width=height=3 and centering.
+ */
static void
gegl_sampler_nearest_init (GeglSamplerNearest *self)
{
- GEGL_SAMPLER (self)->context_rect[0].x = 0;
- GEGL_SAMPLER (self)->context_rect[0].y = 0;
- GEGL_SAMPLER (self)->context_rect[0].width = 1;
- GEGL_SAMPLER (self)->context_rect[0].height = 1;
+ GEGL_SAMPLER (self)->context_rect[0].x = -1;
+ GEGL_SAMPLER (self)->context_rect[0].y = -1;
+ GEGL_SAMPLER (self)->context_rect[0].width = 3;
+ GEGL_SAMPLER (self)->context_rect[0].height = 3;
GEGL_SAMPLER (self)->interpolate_format = babl_format ("RGBA float");
}
diff --git a/operations/transform/transform-core.c b/operations/transform/transform-core.c
index 17501a9..56a0c5e 100644
--- a/operations/transform/transform-core.c
+++ b/operations/transform/transform-core.c
@@ -465,7 +465,7 @@ gegl_transform_get_bounding_box (GeglOperation *op)
{
OpTransform *transform = OP_TRANSFORM (op);
GeglMatrix3 matrix;
- GeglRectangle in_rect = {0,0,0,0},
+ GeglRectangle in_rect = {0,0,1,1},
have_rect;
gdouble have_points [8];
gint i;
@@ -475,10 +475,6 @@ gegl_transform_get_bounding_box (GeglOperation *op)
* "contained" instead of "container".
*/
- /*
- * See the comment below RE: no need for enlargement by context_rect
- */
-#if 0
GeglRectangle context_rect;
GeglSampler *sampler;
@@ -486,7 +482,6 @@ gegl_transform_get_bounding_box (GeglOperation *op)
gegl_sampler_type_from_string (transform->filter));
context_rect = *gegl_sampler_get_context_rect (sampler);
g_object_unref (sampler);
-#endif
if (gegl_operation_source_get_bounding_box (op, "input"))
in_rect = *gegl_operation_source_get_bounding_box (op, "input");
@@ -508,9 +503,8 @@ gegl_transform_get_bounding_box (GeglOperation *op)
* Assuming that have_points is supposed to give a rectangle that
* has to do with the area within the output image for which we have
* output data, there would appear to be no need to enlarge it by
- * context_rect.
+ * context_rect. And yet it's done.
*/
-#if 0
if (!gegl_transform_matrix3_allow_fast_translate (&matrix))
{
in_rect.x += context_rect.x;
@@ -520,16 +514,15 @@ gegl_transform_get_bounding_box (GeglOperation *op)
* height-1, but the absense of "-1" may match "in_rect =
* {*,*,0,0}" above.
*/
- in_rect.width += context_rect.width;
- in_rect.height += context_rect.height;
+ in_rect.width += (context_rect.width - (gint) 1);
+ in_rect.height += (context_rect.height - (gint) 1);
}
-#endif
/*
* Convert indices to absolute positions.
*/
- have_points [0] = in_rect.x - (gdouble) 0.5;
- have_points [1] = in_rect.y - (gdouble) 0.5;
+ have_points [0] = in_rect.x + (gdouble) 0.5;
+ have_points [1] = in_rect.y + (gdouble) 0.5;
/*
* Note that the horizontal distance between the first and last
@@ -571,8 +564,8 @@ gegl_transform_detect (GeglOperation *operation,
return gegl_operation_detect (source_node->operation, x, y);
}
- need_points [0] = x - (gdouble) 0.5;
- need_points [1] = y - (gdouble) 0.5;
+ need_points [0] = x + (gdouble) 0.5;
+ need_points [1] = y + (gdouble) 0.5;
gegl_transform_create_matrix (transform, &inverse);
gegl_matrix3_invert (&inverse);
@@ -614,8 +607,8 @@ gegl_transform_get_required_for_output (GeglOperation *op,
return requested_rect;
}
- need_points [0] = requested_rect.x - (gdouble) 0.5;
- need_points [1] = requested_rect.y - (gdouble) 0.5;
+ need_points [0] = requested_rect.x + (gdouble) 0.5;
+ need_points [1] = requested_rect.y + (gdouble) 0.5;
need_points [2] = need_points [0] + (requested_rect.width - (gint) 1);
need_points [3] = need_points [1];
@@ -684,8 +677,8 @@ gegl_transform_get_invalidated_by_change (GeglOperation *op,
region.width += context_rect.width;
region.height += context_rect.height;
- affected_points [0] = region.x - (gdouble) 0.5;
- affected_points [1] = region.y - (gdouble) 0.5;
+ affected_points [0] = region.x + (gdouble) 0.5;
+ affected_points [1] = region.y + (gdouble) 0.5;
affected_points [2] = affected_points [0] + (region.width - (gint) 1);
affected_points [3] = affected_points [1];
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]