summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippo Argiolas <filippo.argiolas@gmail.com>2010-08-09 16:55:43 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2010-08-09 19:25:54 +0200
commit4cec7d10cd61b3887f01bb741bba5f9c54b808c3 (patch)
tree5b78562a830ab6e14989c887740fc4a5acde00c3
parent2a9b456dab89e090dbd1e4c3b02984f3a67de663 (diff)
geometrictransform: make square "width" and "height" customizable
https://bugzilla.gnome.org/show_bug.cgi?id=625908
-rw-r--r--gst/geometrictransform/gstsquare.c91
-rw-r--r--gst/geometrictransform/gstsquare.h2
2 files changed, 91 insertions, 2 deletions
diff --git a/gst/geometrictransform/gstsquare.c b/gst/geometrictransform/gstsquare.c
index c15b14d60..5b5db5579 100644
--- a/gst/geometrictransform/gstsquare.c
+++ b/gst/geometrictransform/gstsquare.c
@@ -53,12 +53,79 @@
GST_DEBUG_CATEGORY_STATIC (gst_square_debug);
#define GST_CAT_DEFAULT gst_square_debug
+enum
+{
+ PROP_0,
+ PROP_WIDTH,
+ PROP_HEIGHT,
+};
+
+#define DEFAULT_WIDTH 0.5
+#define DEFAULT_HEIGHT 0.5
+
GST_BOILERPLATE (GstSquare, gst_square, GstGeometricTransform,
GST_TYPE_GEOMETRIC_TRANSFORM);
/* GObject vmethod implementations */
static void
+gst_square_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstSquare *square;
+ GstGeometricTransform *gt;
+ gdouble v;
+
+ gt = GST_GEOMETRIC_TRANSFORM_CAST (object);
+ square = GST_SQUARE_CAST (gt);
+
+ GST_OBJECT_LOCK (square);
+ switch (prop_id) {
+ case PROP_WIDTH:
+ v = g_value_get_double (value);
+ if (v != square->width) {
+ square->width = v;
+ gst_geometric_transform_set_need_remap (gt);
+ }
+ break;
+ case PROP_HEIGHT:
+ v = g_value_get_double (value);
+ if (v != square->height) {
+ square->height = v;
+ gst_geometric_transform_set_need_remap (gt);
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+ GST_OBJECT_UNLOCK (square);
+}
+
+static void
+gst_square_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec)
+{
+ GstSquare *square;
+ GstGeometricTransform *gt;
+
+ gt = GST_GEOMETRIC_TRANSFORM_CAST (object);
+ square = GST_SQUARE_CAST (gt);
+
+ switch (prop_id) {
+ case PROP_WIDTH:
+ g_value_set_double (value, square->width);
+ break;
+ case PROP_HEIGHT:
+ g_value_set_double (value, square->height);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
gst_square_base_init (gpointer gclass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
@@ -78,6 +145,7 @@ square_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x,
gdouble norm_x;
gdouble norm_y;
+ /* frame size */
gdouble width = gt->width;
gdouble height = gt->height;
@@ -87,8 +155,12 @@ square_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x,
/* transform */
/* zoom at the center, smoothstep around half quadrant and get back to normal */
- norm_x *= 0.5 * (1.0 + smoothstep (0.375, 0.625, ABS (norm_x)));
- norm_y *= 0.5 * (1.0 + smoothstep (0.375, 0.625, ABS (norm_y)));
+ norm_x *=
+ 0.5 * (1.0 + smoothstep (square->width - 0.125, square->width + 0.125,
+ ABS (norm_x)));
+ norm_y *=
+ 0.5 * (1.0 + smoothstep (square->height - 0.125, square->height + 0.125,
+ ABS (norm_y)));
/* unnormalize */
*in_x = 0.5 * (norm_x + 1.0) * width;
@@ -110,6 +182,19 @@ gst_square_class_init (GstSquareClass * klass)
gstgt_class = (GstGeometricTransformClass *) klass;
parent_class = g_type_class_peek_parent (klass);
+ gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_square_set_property);
+ gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_square_get_property);
+
+ g_object_class_install_property (gobject_class, PROP_WIDTH,
+ g_param_spec_double ("width", "Width",
+ "Width of the square, relative to the frame width",
+ 0.0, 1.0, DEFAULT_WIDTH,
+ GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, PROP_HEIGHT,
+ g_param_spec_double ("height", "Height",
+ "Height of the square, relative to the frame height",
+ 0.0, 1.0, DEFAULT_HEIGHT,
+ GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gstgt_class->map_func = square_map;
}
@@ -119,6 +204,8 @@ gst_square_init (GstSquare * filter, GstSquareClass * gclass)
{
GstGeometricTransform *gt = GST_GEOMETRIC_TRANSFORM (filter);
+ filter->width = DEFAULT_WIDTH;
+ filter->height = DEFAULT_HEIGHT;
gt->off_edge_pixels = GST_GT_OFF_EDGES_PIXELS_CLAMP;
}
diff --git a/gst/geometrictransform/gstsquare.h b/gst/geometrictransform/gstsquare.h
index 1059aa22f..c9b3c35dd 100644
--- a/gst/geometrictransform/gstsquare.h
+++ b/gst/geometrictransform/gstsquare.h
@@ -68,6 +68,8 @@ typedef struct _GstSquareClass GstSquareClass;
struct _GstSquare
{
GstGeometricTransform element;
+
+ gdouble width, height;
};
struct _GstSquareClass