mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 10:11:08 +00:00
geometrictransform: Rename some variables for clarity
Renames some variables and adds a minimum doc to the mapping function for a little clarity. Also uses gstvideo functions for the row and pixel strides instead of hardcoded values
This commit is contained in:
parent
b7660b122c
commit
525aae23dc
3 changed files with 40 additions and 18 deletions
|
@ -47,12 +47,18 @@ static gboolean
|
||||||
gst_geometric_transform_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
|
gst_geometric_transform_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
|
||||||
GstCaps * outcaps)
|
GstCaps * outcaps)
|
||||||
{
|
{
|
||||||
GstGeometricTransform *vf;
|
GstGeometricTransform *gt;
|
||||||
|
gboolean ret;
|
||||||
|
|
||||||
vf = GST_GEOMETRIC_TRANSFORM (btrans);
|
gt = GST_GEOMETRIC_TRANSFORM (btrans);
|
||||||
|
|
||||||
return gst_video_format_parse_caps (incaps, &vf->format, &vf->width,
|
ret = gst_video_format_parse_caps (incaps, >->format, >->width,
|
||||||
&vf->height);
|
>->height);
|
||||||
|
if (ret) {
|
||||||
|
gt->row_stride = gst_video_format_get_row_stride (gt->format, 0, gt->width);
|
||||||
|
gt->pixel_stride = gst_video_format_get_pixel_stride (gt->format, 0);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -64,12 +70,11 @@ gst_geometric_transform_do_map (GstGeometricTransform * gt, GstBuffer * inbuf,
|
||||||
gint in_offset;
|
gint in_offset;
|
||||||
gint out_offset;
|
gint out_offset;
|
||||||
|
|
||||||
/* NOP */
|
out_offset = y * gt->row_stride + x * gt->pixel_stride;
|
||||||
out_offset = (y * gt->width + x) * 3;
|
in_offset = trunc_y * gt->row_stride + trunc_x * gt->pixel_stride;
|
||||||
in_offset = (trunc_y * gt->width + trunc_x) * 3;
|
|
||||||
|
|
||||||
memcpy (GST_BUFFER_DATA (outbuf) + out_offset,
|
memcpy (GST_BUFFER_DATA (outbuf) + out_offset,
|
||||||
GST_BUFFER_DATA (inbuf) + in_offset, 3);
|
GST_BUFFER_DATA (inbuf) + in_offset, gt->pixel_stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
|
|
|
@ -41,8 +41,22 @@ G_BEGIN_DECLS
|
||||||
typedef struct _GstGeometricTransform GstGeometricTransform;
|
typedef struct _GstGeometricTransform GstGeometricTransform;
|
||||||
typedef struct _GstGeometricTransformClass GstGeometricTransformClass;
|
typedef struct _GstGeometricTransformClass GstGeometricTransformClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GstGeometricTransformMapFunc:
|
||||||
|
*
|
||||||
|
* Given the output pixel position, this function calculates the input pixel
|
||||||
|
* position. The element using this function will then copy the input pixel
|
||||||
|
* data to the output pixel.
|
||||||
|
*
|
||||||
|
* @gt: The #GstGeometricTransform
|
||||||
|
* @x: The output pixel x coordinate
|
||||||
|
* @y: The output pixel y coordinate
|
||||||
|
* @_input_x: The input pixel x coordinate
|
||||||
|
* @_input_y: The input pixel y coordinate
|
||||||
|
* Returns: True on success, false otherwise
|
||||||
|
*/
|
||||||
typedef gboolean (*GstGeometricTransformMapFunc) (GstGeometricTransform * gt,
|
typedef gboolean (*GstGeometricTransformMapFunc) (GstGeometricTransform * gt,
|
||||||
gint x, gint y, gdouble * _out_x, gdouble *_out_y);
|
gint x, gint y, gdouble * _input_x, gdouble *_input_y);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GstGeometricTransform:
|
* GstGeometricTransform:
|
||||||
|
@ -54,6 +68,8 @@ struct _GstGeometricTransform {
|
||||||
|
|
||||||
gint width, height;
|
gint width, height;
|
||||||
GstVideoFormat format;
|
GstVideoFormat format;
|
||||||
|
gint pixel_stride;
|
||||||
|
gint row_stride;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstGeometricTransformClass {
|
struct _GstGeometricTransformClass {
|
||||||
|
|
|
@ -155,8 +155,8 @@ gst_pinch_base_init (gpointer gclass)
|
||||||
/* FIXME optimize a little using cast macro and pre calculating some
|
/* FIXME optimize a little using cast macro and pre calculating some
|
||||||
* values so we don't need them every mapping */
|
* values so we don't need them every mapping */
|
||||||
static gboolean
|
static gboolean
|
||||||
dummy_map (GstGeometricTransform * gt, gint x, gint y, gdouble * ox,
|
dummy_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x,
|
||||||
gdouble * oy)
|
gdouble * in_y)
|
||||||
{
|
{
|
||||||
GstPinch *pinch = GST_PINCH (gt);
|
GstPinch *pinch = GST_PINCH (gt);
|
||||||
gdouble r2;
|
gdouble r2;
|
||||||
|
@ -181,8 +181,8 @@ dummy_map (GstGeometricTransform * gt, gint x, gint y, gdouble * ox,
|
||||||
", dy=%lf", x, y, distance, r2, dx, dy);
|
", dy=%lf", x, y, distance, r2, dx, dy);
|
||||||
|
|
||||||
if (distance > r2 || distance == 0) {
|
if (distance > r2 || distance == 0) {
|
||||||
*ox = x;
|
*in_x = x;
|
||||||
*oy = y;
|
*in_y = y;
|
||||||
} else {
|
} else {
|
||||||
gdouble d = sqrt (distance / r2);
|
gdouble d = sqrt (distance / r2);
|
||||||
gdouble t = pow (sin (G_PI * 0.5 * d), -pinch->intensity);
|
gdouble t = pow (sin (G_PI * 0.5 * d), -pinch->intensity);
|
||||||
|
@ -192,14 +192,15 @@ dummy_map (GstGeometricTransform * gt, gint x, gint y, gdouble * ox,
|
||||||
|
|
||||||
GST_LOG_OBJECT (pinch, "D=%lf, t=%lf, dx=%lf" ", dy=%lf", d, t, dx, dy);
|
GST_LOG_OBJECT (pinch, "D=%lf, t=%lf, dx=%lf" ", dy=%lf", d, t, dx, dy);
|
||||||
|
|
||||||
*ox = x_center + dx;
|
*in_x = x_center + dx;
|
||||||
*oy = y_center + dy;
|
*in_y = y_center + dy;
|
||||||
|
|
||||||
*ox = CLAMP (*ox, 0, gt->width - 1);
|
*in_x = CLAMP (*in_x, 0, gt->width - 1);
|
||||||
*oy = CLAMP (*oy, 0, gt->height - 1);
|
*in_y = CLAMP (*in_y, 0, gt->height - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (pinch, "Mapped %d %d into %lf %lf", x, y, *ox, *oy);
|
GST_DEBUG_OBJECT (pinch, "Inversely mapped %d %d into %lf %lf",
|
||||||
|
x, y, *in_x, *in_y);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue