ops: use relative coordinates for center of waves, mirrors and motion blurs

This makes default property values for center properties correspond to center
of buffer. Making default settings and reference compositions improve, the
property meta-data is also changed.
parent 2afeb1ff
......@@ -42,13 +42,13 @@ property_int (n_segs, _("Mirrors"), 6)
value_range (2, 24)
property_double (c_x, _("Offset X"), 0.5)
description (_("X offset of the result of mirroring"))
description (_("position of symmetry center in output"))
value_range (0.0, 1.0)
ui_meta ("unit", "relative-coordinate")
ui_meta ("axis", "x")
property_double (c_y, _("Offset Y"), 0.5)
description (_("Y offset of the result of mirroring"))
description (_("position of symmetry center in output"))
value_range (0.0, 1.0)
ui_meta ("unit", "relative-coordinate")
ui_meta ("axis", "y")
......@@ -56,10 +56,12 @@ property_double (c_y, _("Offset Y"), 0.5)
property_double (o_x, _("Center X"), 0.0)
description (_("X axis ratio for the center of mirroring"))
value_range (-1.0, 1.0)
ui_meta ("unit", "relative-coordinate")
property_double (o_y, _("Center Y"), 0.0)
description (_("Y axis ratio for the center of mirroring"))
value_range (-1.0, 1.0)
ui_meta ("unit", "relative-coordinate")
property_double (trim_x, _("Trim X"), 0.0)
description (_("X axis ratio for trimming mirror expanse"))
......
......@@ -38,14 +38,14 @@
#ifdef GEGL_PROPERTIES
property_double (center_x, _("Center X"), 20.0)
ui_range (-10000.0, 10000.0)
ui_meta ("unit", "pixel-coordinate")
property_double (center_x, _("Center X"), 0.5)
ui_range (0.0, 1.0)
ui_meta ("unit", "relative-coordinate")
ui_meta ("axis", "x")
property_double (center_y, _("Center Y"), 20.0)
ui_range (-10000.0, 10000.0)
ui_meta ("unit", "pixel-coordinate")
property_double (center_y, _("Center Y"), 0.5)
ui_range (0.0, 1.0)
ui_meta ("unit", "relative-coordinate")
ui_meta ("axis", "y")
/* FIXME: With a large angle, we lose AreaFilter's flavours */
......@@ -81,10 +81,14 @@ prepare (GeglOperation *operation)
if (whole_region != NULL)
{
gdouble maxr_x = MAX (fabs (o->center_x - whole_region->x),
fabs (o->center_x - whole_region->x - whole_region->width));
gdouble maxr_y = MAX (fabs (o->center_y - whole_region->y),
fabs (o->center_y - whole_region->y - whole_region->height));
gdouble center_x = gegl_coordinate_relative_to_pixel (o->center_x,
whole_region->width);
gdouble center_y = gegl_coordinate_relative_to_pixel (o->center_y,
whole_region->height);
gdouble maxr_x = MAX (fabs (center_x - whole_region->x),
fabs (center_x - whole_region->x - whole_region->width));
gdouble maxr_y = MAX (fabs (center_y - whole_region->y),
fabs (center_y - whole_region->y - whole_region->height));
if (angle >= G_PI)
angle = G_PI;
......@@ -154,15 +158,22 @@ process (GeglOperation *operation,
gint level)
{
GeglOperationAreaFilter *op_area = GEGL_OPERATION_AREA_FILTER (operation);
GeglProperties *o = GEGL_PROPERTIES (operation);
GeglProperties *o = GEGL_PROPERTIES (operation);
gfloat *in_buf, *out_buf, *out_pixel;
gint x, y;
GeglRectangle src_rect;
GeglRectangle *whole_region;
gdouble angle;
gdouble center_x, center_y;
whole_region = gegl_operation_source_get_bounding_box (operation, "input");
center_x = gegl_coordinate_relative_to_pixel (
o->center_x, whole_region->width);
center_y = gegl_coordinate_relative_to_pixel (
o->center_y, whole_region->height);
src_rect = *roi;
src_rect.x -= op_area->left;
src_rect.y -= op_area->top;
......@@ -190,8 +201,8 @@ process (GeglOperation *operation,
gfloat sum[] = {0, 0, 0, 0};
gint count = 0;
gdouble xr = x - o->center_x;
gdouble yr = y - o->center_y;
gdouble xr = x - center_x;
gdouble yr = y - center_y;
gdouble radius = sqrt (SQR (xr) + SQR (yr));
/* This is not the "real" length, a bit shorter */
......@@ -214,8 +225,8 @@ process (GeglOperation *operation,
gfloat s_val = sin (phi_start - i * phi_step);
gfloat c_val = cos (phi_start - i * phi_step);
gfloat ix = o->center_x + radius * c_val;
gfloat iy = o->center_y + radius * s_val;
gfloat ix = center_x + radius * c_val;
gfloat iy = center_y + radius * s_val;
if (ix >= whole_region->x && ix < whole_region->x + whole_region->width &&
iy >= whole_region->y && iy < whole_region->y + whole_region->height)
......
......@@ -37,20 +37,17 @@
#ifdef GEGL_PROPERTIES
property_double (center_x, _("Center X"), 20.0)
description (_("Horizontal center position"))
value_range (-10000, 10000)
ui_meta ("unit", "pixel-coordinate")
property_double (center_x, _("Center X"), 0.5)
ui_range (0.0, 1.0)
ui_meta ("unit", "relative-coordinate")
ui_meta ("axis", "x")
property_double (center_y, _("Center Y"), 20.0)
description (_("Vertical center position"))
value_range (-10000, 10000)
ui_meta ("unit", "pixel-coordinate")
property_double (center_y, _("Center Y"), 0.5)
ui_range (0.0, 1.0)
ui_meta ("unit", "relative-coordinate")
ui_meta ("axis", "y")
property_double (factor, _("Factor"), 0.1)
description (_("Bluring factor"))
property_double (factor, _("Blurring factor"), 0.1)
value_range (-10, 1.0)
ui_range (-0.5, 1.0)
ui_gamma (2.0)
......@@ -71,20 +68,27 @@ static void
prepare (GeglOperation *operation)
{
GeglOperationAreaFilter *op_area = GEGL_OPERATION_AREA_FILTER (operation);
GeglProperties *o = GEGL_PROPERTIES (operation);
GeglProperties *o = GEGL_PROPERTIES (operation);
GeglRectangle *whole_region;
whole_region = gegl_operation_source_get_bounding_box (operation, "input");
if (whole_region != NULL)
{
gdouble center_x, center_y;
center_x = gegl_coordinate_relative_to_pixel (
o->center_x, whole_region->width);
center_y = gegl_coordinate_relative_to_pixel (
o->center_y, whole_region->height);
op_area->left = op_area->right
= MAX (fabs (whole_region->x - o->center_x),
fabs (whole_region->width + whole_region->x - o->center_x)) * fabs (o->factor) +1;
= MAX (fabs (whole_region->x - center_x),
fabs (whole_region->width + whole_region->x - center_x)) * fabs (o->factor) +1;
op_area->top = op_area->bottom
= MAX (fabs (whole_region->y - o->center_y),
fabs (whole_region->height + whole_region->y - o->center_y)) * fabs (o->factor) +1;
= MAX (fabs (whole_region->y - center_y),
fabs (whole_region->height + whole_region->y - center_y)) * fabs (o->factor) +1;
}
else
{
......@@ -127,6 +131,15 @@ process (GeglOperation *operation,
gint x, y;
GeglRectangle src_rect;
GeglRectangle *whole_region;
gdouble center_x, center_y;
whole_region = gegl_operation_source_get_bounding_box (operation, "input");
center_x = gegl_coordinate_relative_to_pixel (
o->center_x, whole_region->width);
center_y = gegl_coordinate_relative_to_pixel (
o->center_y, whole_region->width);
src_rect = *roi;
src_rect.x -= op_area->left;
src_rect.y -= op_area->top;
......@@ -150,8 +163,8 @@ process (GeglOperation *operation,
gfloat x_start = x;
gfloat y_start = y;
gfloat x_end = x + (o->center_x - (gfloat) x) * o->factor;
gfloat y_end = y + (o->center_y - (gfloat) y) * o->factor;
gfloat x_end = x + (center_x - (gfloat) x) * o->factor;
gfloat y_end = y + (center_y - (gfloat) y) * o->factor;
gint dist = ceil (sqrt (SQR (x_end - x_start) + SQR (y_end - y_start)) +1);
......
......@@ -23,16 +23,14 @@
#ifdef GEGL_PROPERTIES
property_double (x, _("Center X"), 0.0)
description(_("X coordinate of the center of the waves"))
ui_range (0.0, 1024.0)
ui_meta ("unit", "pixel-coordinate") /* XXX: should be relative */
property_double (x, _("Center X"), 0.5)
ui_range (0.0, 1.0)
ui_meta ("unit", "relative-coordinate")
ui_meta ("axis", "x")
property_double (y, _("Center Y"), 0.0)
description(_("Y coordinate of the center of the waves"))
ui_range (0.0, 1024.0)
ui_meta ("unit", "pixel-coordinate")
property_double (y, _("Center Y"), 0.5)
ui_range (0.0, 1.0)
ui_meta ("unit", "relative-coordinate")
ui_meta ("axis", "y")
property_double (amplitude, _("Amplitude"), 25.0)
......@@ -87,14 +85,18 @@ process (GeglOperation *operation,
const GeglRectangle *result,
gint level)
{
GeglProperties *o = GEGL_PROPERTIES (operation);
GeglProperties *o = GEGL_PROPERTIES (operation);
GeglSampler *sampler = gegl_buffer_sampler_new (input,
babl_format ("RGBA float"),
o->sampler_type);
GeglRectangle *in_extent = gegl_operation_source_get_bounding_box (operation, "input");
GeglBufferIterator *iter;
GeglAbyssPolicy abyss = o->clamp ? GEGL_ABYSS_CLAMP : GEGL_ABYSS_NONE;
gdouble px_x = gegl_coordinate_relative_to_pixel (o->x, in_extent->width);
gdouble px_y = gegl_coordinate_relative_to_pixel (o->y, in_extent->height);
gdouble scalex;
gdouble scaley;
......@@ -133,8 +135,8 @@ process (GeglOperation *operation,
gdouble ux;
gdouble uy;
dx = (x - o->x) * scalex;
dy = (y - o->y) * scaley;
dx = (x - px_x) * scalex;
dy = (y - px_y) * scaley;
radius = sqrt (dx * dx + dy * dy);
......
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