mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
geometrictransform: add a "zoom" parameter to bulge filter
Rework bulge mapping function to give more predictable results. Now the bulge is done dividing by a scale factor that smoothsteps from "zoom" at the center to 1.0 at "radius". https://bugzilla.gnome.org/show_bug.cgi?id=625908
This commit is contained in:
parent
58b76ac56c
commit
a72b2f5849
2 changed files with 81 additions and 6 deletions
|
@ -54,9 +54,62 @@
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_bulge_debug);
|
GST_DEBUG_CATEGORY_STATIC (gst_bulge_debug);
|
||||||
#define GST_CAT_DEFAULT gst_bulge_debug
|
#define GST_CAT_DEFAULT gst_bulge_debug
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
PROP_ZOOM
|
||||||
|
};
|
||||||
|
|
||||||
|
#define DEFAULT_ZOOM 3.0
|
||||||
|
|
||||||
GST_BOILERPLATE (GstBulge, gst_bulge, GstCircleGeometricTransform,
|
GST_BOILERPLATE (GstBulge, gst_bulge, GstCircleGeometricTransform,
|
||||||
GST_TYPE_CIRCLE_GEOMETRIC_TRANSFORM);
|
GST_TYPE_CIRCLE_GEOMETRIC_TRANSFORM);
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_bulge_set_property (GObject * object, guint prop_id, const GValue * value,
|
||||||
|
GParamSpec * pspec)
|
||||||
|
{
|
||||||
|
GstBulge *bulge;
|
||||||
|
GstGeometricTransform *gt;
|
||||||
|
gdouble v;
|
||||||
|
|
||||||
|
gt = GST_GEOMETRIC_TRANSFORM_CAST (object);
|
||||||
|
bulge = GST_BULGE_CAST (object);
|
||||||
|
|
||||||
|
GST_OBJECT_LOCK (gt);
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_ZOOM:
|
||||||
|
v = g_value_get_double (value);
|
||||||
|
if (v != bulge->zoom) {
|
||||||
|
bulge->zoom = v;
|
||||||
|
gst_geometric_transform_set_need_remap (gt);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
GST_OBJECT_UNLOCK (gt);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_bulge_get_property (GObject * object, guint prop_id,
|
||||||
|
GValue * value, GParamSpec * pspec)
|
||||||
|
{
|
||||||
|
GstBulge *bulge;
|
||||||
|
|
||||||
|
bulge = GST_BULGE_CAST (object);
|
||||||
|
|
||||||
|
switch (prop_id) {
|
||||||
|
case PROP_ZOOM:
|
||||||
|
g_value_set_double (value, bulge->zoom);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Clean up */
|
/* Clean up */
|
||||||
static void
|
static void
|
||||||
gst_bulge_finalize (GObject * obj)
|
gst_bulge_finalize (GObject * obj)
|
||||||
|
@ -87,6 +140,7 @@ bulge_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x,
|
||||||
|
|
||||||
gdouble norm_x, norm_y;
|
gdouble norm_x, norm_y;
|
||||||
gdouble r;
|
gdouble r;
|
||||||
|
gdouble scale;
|
||||||
|
|
||||||
gdouble width = gt->width;
|
gdouble width = gt->width;
|
||||||
gdouble height = gt->height;
|
gdouble height = gt->height;
|
||||||
|
@ -98,12 +152,20 @@ bulge_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x,
|
||||||
/* calculate radius, normalize to 1 for future convenience */
|
/* calculate radius, normalize to 1 for future convenience */
|
||||||
r = sqrt (0.5 * (norm_x * norm_x + norm_y * norm_y));
|
r = sqrt (0.5 * (norm_x * norm_x + norm_y * norm_y));
|
||||||
|
|
||||||
/* maps r to r^2 in the step region */
|
/* zoom in the center region and smoothly get back to no zoom while
|
||||||
/* interpolating from negative values limits the amount of zoom at
|
* r increases */
|
||||||
* the center so the first edge could be used as intensity
|
|
||||||
* parameter */
|
/* the scale factor goes from bulge->zoom when r == 0 to 1.0
|
||||||
norm_x *= smoothstep (-0.15, cgt->radius, r);
|
* when r == cgt->radius using Hermite interpolation */
|
||||||
norm_y *= smoothstep (-0.15, cgt->radius, r);
|
/* scale is inverted because we're doing an inverse transform so
|
||||||
|
* zoom is achieved dividing */
|
||||||
|
|
||||||
|
scale =
|
||||||
|
1.0 / (bulge->zoom + ((1.0 - bulge->zoom) * smoothstep (0, cgt->radius,
|
||||||
|
r)));
|
||||||
|
|
||||||
|
norm_x *= scale;
|
||||||
|
norm_y *= scale;
|
||||||
|
|
||||||
/* unnormalize */
|
/* unnormalize */
|
||||||
*in_x = (0.5 * norm_x + cgt->x_center) * width;
|
*in_x = (0.5 * norm_x + cgt->x_center) * width;
|
||||||
|
@ -126,6 +188,16 @@ gst_bulge_class_init (GstBulgeClass * 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_bulge_set_property);
|
||||||
|
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_bulge_get_property);
|
||||||
|
|
||||||
|
|
||||||
|
g_object_class_install_property (gobject_class, PROP_ZOOM,
|
||||||
|
g_param_spec_double ("zoom", "zoom",
|
||||||
|
"Zoom of the bulge effect",
|
||||||
|
1.0, 100.0, DEFAULT_ZOOM,
|
||||||
|
GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_bulge_finalize);
|
gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_bulge_finalize);
|
||||||
|
|
||||||
gstgt_class->map_func = bulge_map;
|
gstgt_class->map_func = bulge_map;
|
||||||
|
@ -136,6 +208,7 @@ gst_bulge_init (GstBulge * filter, GstBulgeClass * gclass)
|
||||||
{
|
{
|
||||||
GstGeometricTransform *gt = GST_GEOMETRIC_TRANSFORM (filter);
|
GstGeometricTransform *gt = GST_GEOMETRIC_TRANSFORM (filter);
|
||||||
|
|
||||||
|
filter->zoom = DEFAULT_ZOOM;
|
||||||
gt->off_edge_pixels = GST_GT_OFF_EDGES_PIXELS_CLAMP;
|
gt->off_edge_pixels = GST_GT_OFF_EDGES_PIXELS_CLAMP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,8 @@ typedef struct _GstBulgeClass GstBulgeClass;
|
||||||
struct _GstBulge
|
struct _GstBulge
|
||||||
{
|
{
|
||||||
GstCircleGeometricTransform element;
|
GstCircleGeometricTransform element;
|
||||||
|
|
||||||
|
gdouble zoom;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstBulgeClass
|
struct _GstBulgeClass
|
||||||
|
|
Loading…
Reference in a new issue