From c921067208414c47a0c961e604b4d777f2d40b34 Mon Sep 17 00:00:00 2001 From: Filippo Argiolas Date: Tue, 3 Aug 2010 10:08:34 +0200 Subject: [PATCH] geometrictransform: make ciclegt "radius" property relative Make the "radius" property of CircleGeometricTransform relative. This is more coherent with the way [x,y]-center properties are handled and allow to set a radius without knowing the video size. Radius is defined with respect to the circle circumscribed about the video rectangle so that a point in the center has radius 0.0 and one in a vertex has radius 1.0. Note that this is not a regression from the previous absolute way of defining the radius as a user who knows the video size can easily calculate the relative radius and set that. https://bugzilla.gnome.org/show_bug.cgi?id=625959 --- gst/geometrictransform/gstcircle.c | 3 ++- gst/geometrictransform/gstcirclegeometrictransform.c | 9 ++++++--- gst/geometrictransform/gstcirclegeometrictransform.h | 1 + gst/geometrictransform/gstkaleidoscope.c | 4 ++-- gst/geometrictransform/gsttwirl.c | 3 ++- gst/geometrictransform/gstwaterripple.c | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/gst/geometrictransform/gstcircle.c b/gst/geometrictransform/gstcircle.c index fe6a99e..7cfe67c 100644 --- a/gst/geometrictransform/gstcircle.c +++ b/gst/geometrictransform/gstcircle.c @@ -183,7 +183,8 @@ circle_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x, *in_x = gt->width * theta / (circle->spread_angle + 0.0001); *in_y = - gt->height * (1 - (distance - cgt->radius) / (circle->height + 0.0001)); + gt->height * (1 - (distance - cgt->precalc_radius) / (circle->height + + 0.0001)); GST_DEBUG_OBJECT (circle, "Inversely mapped %d %d into %lf %lf", x, y, *in_x, *in_y); diff --git a/gst/geometrictransform/gstcirclegeometrictransform.c b/gst/geometrictransform/gstcirclegeometrictransform.c index 7f8cf2e..19e0dde 100644 --- a/gst/geometrictransform/gstcirclegeometrictransform.c +++ b/gst/geometrictransform/gstcirclegeometrictransform.c @@ -72,7 +72,7 @@ enum #define DEFAULT_X_CENTER 0.5 #define DEFAULT_Y_CENTER 0.5 -#define DEFAULT_RADIUS 100 +#define DEFAULT_RADIUS 0.35 static void gst_circle_geometric_transform_set_property (GObject * object, guint prop_id, @@ -155,7 +155,10 @@ circle_geometric_transform_precalc (GstGeometricTransform * gt) cgt->precalc_x_center = cgt->x_center * gt->width; cgt->precalc_y_center = cgt->y_center * gt->height; - cgt->precalc_radius2 = cgt->radius * cgt->radius; + cgt->precalc_radius = + cgt->radius * 0.5 * sqrt (gt->width * gt->width + + gt->height * gt->height); + cgt->precalc_radius2 = cgt->precalc_radius * cgt->precalc_radius; return TRUE; } @@ -195,7 +198,7 @@ gst_circle_geometric_transform_class_init (GstCircleGeometricTransformClass * GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (gobject_class, PROP_RADIUS, g_param_spec_double ("radius", "radius", - "radius of the circle_geometric_transform effect", 0.0, G_MAXDOUBLE, + "radius of the circle_geometric_transform effect", 0.0, 1.0, DEFAULT_RADIUS, GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); diff --git a/gst/geometrictransform/gstcirclegeometrictransform.h b/gst/geometrictransform/gstcirclegeometrictransform.h index a9539ad..b8b484a 100644 --- a/gst/geometrictransform/gstcirclegeometrictransform.h +++ b/gst/geometrictransform/gstcirclegeometrictransform.h @@ -76,6 +76,7 @@ struct _GstCircleGeometricTransform gdouble precalc_x_center; gdouble precalc_y_center; + gdouble precalc_radius; gdouble precalc_radius2; }; diff --git a/gst/geometrictransform/gstkaleidoscope.c b/gst/geometrictransform/gstkaleidoscope.c index ecc3690..384037b 100644 --- a/gst/geometrictransform/gstkaleidoscope.c +++ b/gst/geometrictransform/gstkaleidoscope.c @@ -180,8 +180,8 @@ kaleidoscope_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x, theta = geometric_math_triangle (theta / G_PI * kaleidoscope->sides * 0.5); - if (cgt->radius != 0) { - gdouble radiusc = cgt->radius / cos (theta); + if (cgt->precalc_radius != 0) { + gdouble radiusc = cgt->precalc_radius / cos (theta); distance = radiusc * geometric_math_triangle (distance / radiusc); } diff --git a/gst/geometrictransform/gsttwirl.c b/gst/geometrictransform/gsttwirl.c index 51302d4..8d31d8e 100644 --- a/gst/geometrictransform/gsttwirl.c +++ b/gst/geometrictransform/gsttwirl.c @@ -155,7 +155,8 @@ twirl_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x, *in_y = y; } else { gdouble d = sqrt (distance); - gdouble a = atan2 (dy, dx) + twirl->angle * (cgt->radius - d) / cgt->radius; + gdouble a = atan2 (dy, + dx) + twirl->angle * (cgt->precalc_radius - d) / cgt->precalc_radius; *in_x = cgt->precalc_x_center + d * cos (a); *in_y = cgt->precalc_y_center + d * sin (a); diff --git a/gst/geometrictransform/gstwaterripple.c b/gst/geometrictransform/gstwaterripple.c index d66d983..7e911df 100644 --- a/gst/geometrictransform/gstwaterripple.c +++ b/gst/geometrictransform/gstwaterripple.c @@ -183,7 +183,7 @@ water_ripple_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x, water->amplitude * sin (d / water->wavelength * G_PI * 2 - water->phase); - amount *= (cgt->radius - d) / cgt->radius; + amount *= (cgt->precalc_radius - d) / cgt->precalc_radius; if (d != 0) amount *= water->wavelength / d; *in_x = x + dx * amount; -- 2.7.4