[gst-devel] have written new "effect" for geometrictransform

Bert Douglas bertd at tplogic.com
Thu Sep 2 14:45:12 CEST 2010


Hi All,

I have written a new "effect" for geometrictransform.  It does image
rotation.
The code is appended below.
If there is any interest, I will do the work to push it upstream.
But I need a mentor to help guide the way.

On the code itself.
I modified the "circle" element, to do rotation.
The changes were confined to the "map" function.
I used the same parameters, but with different meaning.

Thanks,
Bert Douglas

------------------------------------------------------------------------

static gboolean
circle_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x,
    gdouble * in_y)
{
  //GstCircleGeometricTransform *cgt = GST_CIRCLE_GEOMETRIC_TRANSFORM_CAST
(gt);
  GstCircle *circle = GST_CIRCLE_CAST (gt);

  gint w, h;
  gdouble pad, sa;
  gdouble cix, ciy, cox, coy;   // centers, in/out x/y
  gdouble ai, ao, ar;           // angles, in/out/rotate  (radians)
  gdouble r;                    // radius
  gdouble xi, yi, xo, yo;       // positions in/out x/y

  // input and output image height and width
  w = gt->width;
  h = gt->height;

  // our parameters
  pad = circle->height;         // padding on bottom and right of input
image
  ar = circle->angle * M_PI / 180.0;    // angle of rotation, degrees to
radians
  sa = circle->spread_angle;    // not used

  // get in and out centers
  cox = 0.5 * w;
  coy = 0.5 * h;
  cix = 0.5 * (w - pad);
  ciy = 0.5 * (h - pad);

  // convert output image position to polar form
  xo = x - cox;
  yo = y - coy;
  ao = atan2 (yo, xo);
  r = sqrt (xo * xo + yo * yo);

  // perform rotation backward to get input image rotation
  // this seems wrong, but rotation from in-->out is counterclockwise
  ai = ao + ar;

  // back to rectangular for input image position
  xi = r * cos (ai);
  yi = r * sin (ai);

  // restore center offset, return values to caller
  *in_x = xi + cix;
  *in_y = yi + ciy;

  GST_DEBUG_OBJECT (circle, "Inversely mapped %d %d into %lf %lf",
      x, y, *in_x, *in_y);

  return TRUE;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20100902/c1a4b8c0/attachment.htm>


More information about the gstreamer-devel mailing list