diff options
author | Thiago Santos <thiago.sousa.santos@collabora.co.uk> | 2010-05-30 12:50:56 -0300 |
---|---|---|
committer | Thiago Santos <thiago.sousa.santos@collabora.co.uk> | 2010-06-04 15:31:20 -0300 |
commit | dcda4b606c83a3af14668f073e9dcf2766eee558 (patch) | |
tree | 76da070f9926b34e96fae89fd43f6e2f27c9e222 | |
parent | 8c5360a55968c829b4e267e933fa3ba15ab5f290 (diff) |
pinch: Some optimization using the prepare func
Small optimization by precalculating the center of the effect,
also use newly added _CAST macro.
-rw-r--r-- | gst/geometrictransform/gstpinch.c | 44 | ||||
-rw-r--r-- | gst/geometrictransform/gstpinch.h | 5 |
2 files changed, 30 insertions, 19 deletions
diff --git a/gst/geometrictransform/gstpinch.c b/gst/geometrictransform/gstpinch.c index 6d7a7d634..13be3b342 100644 --- a/gst/geometrictransform/gstpinch.c +++ b/gst/geometrictransform/gstpinch.c @@ -83,7 +83,7 @@ gst_pinch_set_property (GObject * object, guint prop_id, const GValue * value, { GstPinch *pinch; - pinch = GST_PINCH (object); + pinch = GST_PINCH_CAST (object); switch (prop_id) { case PROP_X_CENTER: @@ -110,7 +110,7 @@ gst_pinch_get_property (GObject * object, guint prop_id, { GstPinch *pinch; - pinch = GST_PINCH (object); + pinch = GST_PINCH_CAST (object); switch (prop_id) { case PROP_X_CENTER: @@ -152,31 +152,35 @@ gst_pinch_base_init (gpointer gclass) "Thiago Santos<thiago.sousa.santos@collabora.co.uk>"); } -/* FIXME optimize a little using cast macro and pre calculating some - * values so we don't need them every mapping */ static gboolean -dummy_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x, +pinch_precalc (GstGeometricTransform * gt) +{ + GstPinch *pinch = GST_PINCH_CAST (gt); + + pinch->precalc_x_center = pinch->x_center * gt->width; + pinch->precalc_y_center = pinch->y_center * gt->height; + + return TRUE; +} + +static gboolean +pinch_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x, gdouble * in_y) { - GstPinch *pinch = GST_PINCH (gt); + GstPinch *pinch = GST_PINCH_CAST (gt); gdouble r2; gdouble distance; - gdouble x_center; - gdouble y_center; gdouble dx, dy; - /* get the center in pixels instead of % */ - x_center = pinch->x_center * gt->width; - y_center = pinch->y_center * gt->height; - - dx = x - x_center; - dy = y - y_center; + dx = x - pinch->precalc_x_center; + dy = y - pinch->precalc_y_center; distance = dx * dx + dy * dy; r2 = pinch->radius * pinch->radius; GST_LOG_OBJECT (pinch, "Center %0.5lf (%0.2lf) %0.5lf (%0.2lf)", - x_center, pinch->x_center, y_center, pinch->y_center); + pinch->precalc_x_center, pinch->x_center, pinch->precalc_y_center, + pinch->y_center); GST_LOG_OBJECT (pinch, "Input %d %d, distance=%lf, radius2=%lf, dx=%lf" ", dy=%lf", x, y, distance, r2, dx, dy); @@ -192,8 +196,8 @@ dummy_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x, GST_LOG_OBJECT (pinch, "D=%lf, t=%lf, dx=%lf" ", dy=%lf", d, t, dx, dy); - *in_x = x_center + dx; - *in_y = y_center + dy; + *in_x = pinch->precalc_x_center + dx; + *in_y = pinch->precalc_y_center + dy; *in_x = CLAMP (*in_x, 0, gt->width - 1); *in_y = CLAMP (*in_y, 0, gt->height - 1); @@ -222,7 +226,8 @@ gst_pinch_class_init (GstPinchClass * klass) /* FIXME I don't like the idea of x-center and y-center being in % and - * radius and intensity in absolute values, I think no one likes it. */ + * radius and intensity in absolute values, I think no one likes it, but + * I can't see a way to have nice default values without % */ g_object_class_install_property (gobject_class, PROP_X_CENTER, g_param_spec_double ("x-center", "x center", "X axis center of the pinch effect", @@ -243,7 +248,8 @@ gst_pinch_class_init (GstPinchClass * klass) 0.0, G_MAXDOUBLE, DEFAULT_INTENSITY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - gstgt_class->map_func = dummy_map; + gstgt_class->map_func = pinch_map; + gstgt_class->prepare_func = pinch_precalc; } static void diff --git a/gst/geometrictransform/gstpinch.h b/gst/geometrictransform/gstpinch.h index 207c90701..e9a0ddeb1 100644 --- a/gst/geometrictransform/gstpinch.h +++ b/gst/geometrictransform/gstpinch.h @@ -54,6 +54,8 @@ G_BEGIN_DECLS (gst_pinch_get_type()) #define GST_PINCH(obj) \ (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PINCH,GstPinch)) +#define GST_PINCH_CAST(obj) \ + ((GstPinch *)(obj)) #define GST_PINCH_CLASS(klass) \ (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PINCH,GstPinchClass)) #define GST_IS_PINCH(obj) \ @@ -72,6 +74,9 @@ struct _GstPinch gdouble y_center; gdouble radius; gdouble intensity; + + gdouble precalc_x_center; + gdouble precalc_y_center; }; struct _GstPinchClass |