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

View file

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

View file

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