geometrictransform: make square "width" and "height" customizable
https://bugzilla.gnome.org/show_bug.cgi?id=625908
This commit is contained in:
parent
2a9b456dab
commit
4cec7d10cd
@ -53,11 +53,78 @@
|
|||||||
GST_DEBUG_CATEGORY_STATIC (gst_square_debug);
|
GST_DEBUG_CATEGORY_STATIC (gst_square_debug);
|
||||||
#define GST_CAT_DEFAULT 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_BOILERPLATE (GstSquare, gst_square, GstGeometricTransform,
|
||||||
GST_TYPE_GEOMETRIC_TRANSFORM);
|
GST_TYPE_GEOMETRIC_TRANSFORM);
|
||||||
|
|
||||||
/* GObject vmethod implementations */
|
/* 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
|
static void
|
||||||
gst_square_base_init (gpointer gclass)
|
gst_square_base_init (gpointer gclass)
|
||||||
{
|
{
|
||||||
@ -78,6 +145,7 @@ square_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x,
|
|||||||
gdouble norm_x;
|
gdouble norm_x;
|
||||||
gdouble norm_y;
|
gdouble norm_y;
|
||||||
|
|
||||||
|
/* frame size */
|
||||||
gdouble width = gt->width;
|
gdouble width = gt->width;
|
||||||
gdouble height = gt->height;
|
gdouble height = gt->height;
|
||||||
|
|
||||||
@ -87,8 +155,12 @@ square_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x,
|
|||||||
|
|
||||||
/* transform */
|
/* transform */
|
||||||
/* zoom at the center, smoothstep around half quadrant and get back to normal */
|
/* 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_x *=
|
||||||
norm_y *= 0.5 * (1.0 + smoothstep (0.375, 0.625, ABS (norm_y)));
|
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 */
|
/* unnormalize */
|
||||||
*in_x = 0.5 * (norm_x + 1.0) * width;
|
*in_x = 0.5 * (norm_x + 1.0) * width;
|
||||||
@ -110,6 +182,19 @@ gst_square_class_init (GstSquareClass * klass)
|
|||||||
gstgt_class = (GstGeometricTransformClass *) klass;
|
gstgt_class = (GstGeometricTransformClass *) klass;
|
||||||
|
|
||||||
parent_class = g_type_class_peek_parent (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;
|
gstgt_class->map_func = square_map;
|
||||||
}
|
}
|
||||||
@ -119,6 +204,8 @@ gst_square_init (GstSquare * filter, GstSquareClass * gclass)
|
|||||||
{
|
{
|
||||||
GstGeometricTransform *gt = GST_GEOMETRIC_TRANSFORM (filter);
|
GstGeometricTransform *gt = GST_GEOMETRIC_TRANSFORM (filter);
|
||||||
|
|
||||||
|
filter->width = DEFAULT_WIDTH;
|
||||||
|
filter->height = DEFAULT_HEIGHT;
|
||||||
gt->off_edge_pixels = GST_GT_OFF_EDGES_PIXELS_CLAMP;
|
gt->off_edge_pixels = GST_GT_OFF_EDGES_PIXELS_CLAMP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +68,8 @@ typedef struct _GstSquareClass GstSquareClass;
|
|||||||
struct _GstSquare
|
struct _GstSquare
|
||||||
{
|
{
|
||||||
GstGeometricTransform element;
|
GstGeometricTransform element;
|
||||||
|
|
||||||
|
gdouble width, height;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstSquareClass
|
struct _GstSquareClass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user