[gst-cvs] gst-plugins-bad: geometrictransform: Rename some variables for clarity

Thiago Sousa Santos thiagoss at kemper.freedesktop.org
Fri Jun 4 12:16:40 PDT 2010


Module: gst-plugins-bad
Branch: master
Commit: 525aae23dc6d4f9c3de6b8a4d2457b63db9dbb01
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/?id=525aae23dc6d4f9c3de6b8a4d2457b63db9dbb01

Author: Thiago Santos <thiago.sousa.santos at collabora.co.uk>
Date:   Wed May 26 18:22:02 2010 -0300

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

---

 gst/geometrictransform/gstgeometrictransform.c |   21 +++++++++++++--------
 gst/geometrictransform/gstgeometrictransform.h |   18 +++++++++++++++++-
 gst/geometrictransform/gstpinch.c              |   19 ++++++++++---------
 3 files changed, 40 insertions(+), 18 deletions(-)

diff --git a/gst/geometrictransform/gstgeometrictransform.c b/gst/geometrictransform/gstgeometrictransform.c
index f70468f..28200dc 100644
--- a/gst/geometrictransform/gstgeometrictransform.c
+++ b/gst/geometrictransform/gstgeometrictransform.c
@@ -47,12 +47,18 @@ static gboolean
 gst_geometric_transform_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
     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,
-      &vf->height);
+  ret = gst_video_format_parse_caps (incaps, &gt->format, &gt->width,
+      &gt->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
@@ -64,12 +70,11 @@ gst_geometric_transform_do_map (GstGeometricTransform * gt, GstBuffer * inbuf,
   gint in_offset;
   gint out_offset;
 
-  /* NOP */
-  out_offset = (y * gt->width + x) * 3;
-  in_offset = (trunc_y * gt->width + trunc_x) * 3;
+  out_offset = y * gt->row_stride + x * gt->pixel_stride;
+  in_offset = trunc_y * gt->row_stride + trunc_x * gt->pixel_stride;
 
   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
diff --git a/gst/geometrictransform/gstgeometrictransform.h b/gst/geometrictransform/gstgeometrictransform.h
index e1d5ffa..ab8e0e3 100644
--- a/gst/geometrictransform/gstgeometrictransform.h
+++ b/gst/geometrictransform/gstgeometrictransform.h
@@ -41,8 +41,22 @@ G_BEGIN_DECLS
 typedef struct _GstGeometricTransform GstGeometricTransform;
 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,
-    gint x, gint y, gdouble * _out_x, gdouble *_out_y);
+    gint x, gint y, gdouble * _input_x, gdouble *_input_y);
 
 /**
  * GstGeometricTransform:
@@ -54,6 +68,8 @@ struct _GstGeometricTransform {
 
   gint width, height;
   GstVideoFormat format;
+  gint pixel_stride;
+  gint row_stride;
 };
 
 struct _GstGeometricTransformClass {
diff --git a/gst/geometrictransform/gstpinch.c b/gst/geometrictransform/gstpinch.c
index e81562f..6d7a7d6 100644
--- a/gst/geometrictransform/gstpinch.c
+++ b/gst/geometrictransform/gstpinch.c
@@ -155,8 +155,8 @@ gst_pinch_base_init (gpointer gclass)
 /* 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 * ox,
-    gdouble * oy)
+dummy_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x,
+    gdouble * in_y)
 {
   GstPinch *pinch = GST_PINCH (gt);
   gdouble r2;
@@ -181,8 +181,8 @@ dummy_map (GstGeometricTransform * gt, gint x, gint y, gdouble * ox,
       ", dy=%lf", x, y, distance, r2, dx, dy);
 
   if (distance > r2 || distance == 0) {
-    *ox = x;
-    *oy = y;
+    *in_x = x;
+    *in_y = y;
   } else {
     gdouble d = sqrt (distance / r2);
     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);
 
-    *ox = x_center + dx;
-    *oy = y_center + dy;
+    *in_x = x_center + dx;
+    *in_y = y_center + dy;
 
-    *ox = CLAMP (*ox, 0, gt->width - 1);
-    *oy = CLAMP (*oy, 0, gt->height - 1);
+    *in_x = CLAMP (*in_x, 0, gt->width - 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;
 }





More information about the Gstreamer-commits mailing list