effectv: port shagadelictv to 0.11

This commit is contained in:
Wim Taymans 2011-07-07 16:38:10 +02:00
parent 6aea70a8a1
commit 39f689dc97
3 changed files with 83 additions and 62 deletions

View file

@ -329,7 +329,6 @@ gst_agingtv_transform (GstBaseTransform * trans, GstBuffer * in,
GstAgingTV *agingtv = GST_AGINGTV (trans);
GstVideoFrame in_frame, out_frame;
gint area_scale;
GstFlowReturn ret = GST_FLOW_OK;
GstClockTime timestamp, stream_time;
gint width, height, stride, video_size;
guint32 *src, *dest;
@ -377,7 +376,7 @@ gst_agingtv_transform (GstBaseTransform * trans, GstBuffer * in,
gst_video_frame_unmap (&in_frame);
gst_video_frame_unmap (&out_frame);
return ret;
return GST_FLOW_OK;
/* ERRORS */
invalid_in:

View file

@ -45,21 +45,19 @@
#include "gstshagadelic.h"
#include "gsteffectv.h"
#include <gst/video/video.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
GST_BOILERPLATE (GstShagadelicTV, gst_shagadelictv, GstVideoFilter,
GST_TYPE_VIDEO_FILTER);
#define gst_shagadelictv_parent_class parent_class
G_DEFINE_TYPE (GstShagadelicTV, gst_shagadelictv, GST_TYPE_VIDEO_FILTER);
static void gst_shagadelic_initialize (GstShagadelicTV * filter);
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
#define CAPS_STR GST_VIDEO_CAPS_BGRx
#define CAPS_STR GST_VIDEO_CAPS_MAKE ("BGRx")
#else
#define CAPS_STR GST_VIDEO_CAPS_xRGB
#define CAPS_STR GST_VIDEO_CAPS_MAKE ("xRGB")
#endif
static GstStaticPadTemplate gst_shagadelictv_src_template =
@ -81,48 +79,57 @@ gst_shagadelictv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
GstCaps * outcaps)
{
GstShagadelicTV *filter = GST_SHAGADELICTV (btrans);
GstStructure *structure;
gboolean ret = FALSE;
GstVideoInfo info;
gint width, height, area;
structure = gst_caps_get_structure (incaps, 0);
if (!gst_video_info_from_caps (&info, incaps))
goto invalid_caps;
GST_OBJECT_LOCK (filter);
if (gst_structure_get_int (structure, "width", &filter->width) &&
gst_structure_get_int (structure, "height", &filter->height)) {
gint area = filter->width * filter->height;
filter->info = info;
g_free (filter->ripple);
g_free (filter->spiral);
width = GST_VIDEO_INFO_WIDTH (&info);
height = GST_VIDEO_INFO_HEIGHT (&info);
filter->ripple = (guint8 *) g_malloc (area * 4);
filter->spiral = (guint8 *) g_malloc (area);
area = width * height;
gst_shagadelic_initialize (filter);
ret = TRUE;
g_free (filter->ripple);
g_free (filter->spiral);
filter->ripple = (guint8 *) g_malloc (area * 4);
filter->spiral = (guint8 *) g_malloc (area);
gst_shagadelic_initialize (filter);
return TRUE;
/* ERRORS */
invalid_caps:
{
GST_DEBUG_OBJECT (filter, "invalid caps received");
return FALSE;
}
GST_OBJECT_UNLOCK (filter);
return ret;
}
static void
gst_shagadelic_initialize (GstShagadelicTV * filter)
{
int i, x, y;
#ifdef PS2
float xx, yy;
#else
double xx, yy;
#endif
gint width, height;
width = GST_VIDEO_INFO_WIDTH (&filter->info);
height = GST_VIDEO_INFO_HEIGHT (&filter->info);
i = 0;
for (y = 0; y < filter->height * 2; y++) {
yy = y - filter->height;
for (y = 0; y < height * 2; y++) {
yy = y - height;
yy *= yy;
for (x = 0; x < filter->width * 2; x++) {
xx = x - filter->width;
for (x = 0; x < width * 2; x++) {
xx = x - width;
#ifdef PS2
filter->ripple[i++] = ((unsigned int) (sqrtf (xx * xx + yy) * 8)) & 255;
#else
@ -132,11 +139,11 @@ gst_shagadelic_initialize (GstShagadelicTV * filter)
}
i = 0;
for (y = 0; y < filter->height; y++) {
yy = y - filter->height / 2;
for (y = 0; y < height; y++) {
yy = y - height / 2;
for (x = 0; x < filter->width; x++) {
xx = x - filter->width / 2;
for (x = 0; x < width; x++) {
xx = x - width / 2;
#ifdef PS2
filter->spiral[i++] = ((unsigned int)
((atan2f (xx,
@ -152,10 +159,10 @@ gst_shagadelic_initialize (GstShagadelicTV * filter)
*/
}
}
filter->rx = fastrand () % filter->width;
filter->ry = fastrand () % filter->height;
filter->bx = fastrand () % filter->width;
filter->by = fastrand () % filter->height;
filter->rx = fastrand () % width;
filter->ry = fastrand () % height;
filter->bx = fastrand () % width;
filter->by = fastrand () % height;
filter->rvx = -2;
filter->rvy = -2;
filter->bvx = 2;
@ -172,15 +179,20 @@ gst_shagadelictv_transform (GstBaseTransform * trans, GstBuffer * in,
gint x, y;
guint32 v;
guint8 r, g, b;
GstVideoFrame in_frame, out_frame;
gint width, height;
GstFlowReturn ret = GST_FLOW_OK;
src = (guint32 *) GST_BUFFER_DATA (in);
dest = (guint32 *) GST_BUFFER_DATA (out);
if (!gst_video_frame_map (&in_frame, &filter->info, in, GST_MAP_READ))
goto invalid_in;
GST_OBJECT_LOCK (filter);
width = filter->width;
height = filter->height;
if (!gst_video_frame_map (&out_frame, &filter->info, out, GST_MAP_WRITE))
goto invalid_out;
src = GST_VIDEO_FRAME_PLANE_DATA (&in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, 0);
width = GST_VIDEO_FRAME_WIDTH (&in_frame);
height = GST_VIDEO_FRAME_HEIGHT (&in_frame);
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
@ -213,9 +225,24 @@ gst_shagadelictv_transform (GstBaseTransform * trans, GstBuffer * in,
filter->ry += filter->rvy;
filter->bx += filter->bvx;
filter->by += filter->bvy;
GST_OBJECT_UNLOCK (filter);
return ret;
gst_video_frame_unmap (&in_frame);
gst_video_frame_unmap (&out_frame);
return GST_FLOW_OK;
/* ERRORS */
invalid_in:
{
GST_DEBUG_OBJECT (filter, "invalid input frame");
return GST_FLOW_ERROR;
}
invalid_out:
{
GST_DEBUG_OBJECT (filter, "invalid output frame");
gst_video_frame_unmap (&in_frame);
return GST_FLOW_ERROR;
}
}
static void
@ -235,35 +262,30 @@ gst_shagadelictv_finalize (GObject * object)
}
static void
gst_shagadelictv_base_init (gpointer g_class)
gst_shagadelictv_class_init (GstShagadelicTVClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
GObjectClass *gobject_class = (GObjectClass *) klass;
GstElementClass *gstelement_class = (GstElementClass *) klass;
GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
gst_element_class_set_details_simple (element_class, "ShagadelicTV",
gobject_class->finalize = gst_shagadelictv_finalize;
gst_element_class_set_details_simple (gstelement_class, "ShagadelicTV",
"Filter/Effect/Video",
"Oh behave, ShagedelicTV makes images shagadelic!",
"Wim Taymans <wim.taymans@chello.be>");
gst_element_class_add_pad_template (element_class,
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_shagadelictv_sink_template));
gst_element_class_add_pad_template (element_class,
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_shagadelictv_src_template));
}
static void
gst_shagadelictv_class_init (GstShagadelicTVClass * klass)
{
GObjectClass *gobject_class = (GObjectClass *) klass;
GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
gobject_class->finalize = gst_shagadelictv_finalize;
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_shagadelictv_set_caps);
trans_class->transform = GST_DEBUG_FUNCPTR (gst_shagadelictv_transform);
}
static void
gst_shagadelictv_init (GstShagadelicTV * filter, GstShagadelicTVClass * klass)
gst_shagadelictv_init (GstShagadelicTV * filter)
{
filter->ripple = NULL;
filter->spiral = NULL;

View file

@ -27,6 +27,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/gstvideofilter.h>
G_BEGIN_DECLS
@ -50,9 +51,8 @@ struct _GstShagadelicTV
GstVideoFilter videofilter;
/* < private > */
GstVideoInfo info;
gint width, height;
gint stat;
guint8 *ripple;
guint8 *spiral;
guint8 phase;