diff --git a/gst/effectv/Makefile.am b/gst/effectv/Makefile.am index dc779af93e..0aed7960b1 100644 --- a/gst/effectv/Makefile.am +++ b/gst/effectv/Makefile.am @@ -3,7 +3,7 @@ plugin_LTLIBRARIES = libgsteffectv.la libgsteffectv_la_SOURCES = \ gsteffectv.c gstedge.c gstaging.c gstdice.c gstwarp.c \ gstshagadelic.c gstvertigo.c gstrev.c gstquark.c gstop.c \ - gstradioac.c + gstradioac.c gststreak.c libgsteffectv_la_CFLAGS = \ $(GST_PLUGINS_BASE_CFLAGS) \ $(GST_CONTROLLER_CFLAGS) \ @@ -21,4 +21,4 @@ libgsteffectv_la_LIBTOOLFLAGS = --tag=disable-static noinst_HEADERS = gsteffectv.h gstaging.h gstdice.h gstedge.h \ gstquark.h gstrev.h gstshagadelic.h gstvertigo.h gstwarp.h gstop.h \ - gstradioac.h + gstradioac.h gststreak.h diff --git a/gst/effectv/gsteffectv.c b/gst/effectv/gsteffectv.c index d183812245..57cbbca603 100644 --- a/gst/effectv/gsteffectv.c +++ b/gst/effectv/gsteffectv.c @@ -36,6 +36,7 @@ #include "gstwarp.h" #include "gstop.h" #include "gstradioac.h" +#include "gststreak.h" struct _elements_entry { @@ -54,6 +55,7 @@ static const struct _elements_entry _elements[] = { {"quarktv", gst_quarktv_get_type}, {"optv", gst_optv_get_type}, {"radioactv", gst_radioactv_get_type}, + {"streaktv", gst_streaktv_get_type}, {NULL, 0}, }; diff --git a/gst/effectv/gststreak.c b/gst/effectv/gststreak.c new file mode 100644 index 0000000000..0772e8d1bd --- /dev/null +++ b/gst/effectv/gststreak.c @@ -0,0 +1,275 @@ +/* GStreamer + * Copyright (C) <2009> Sebastian Dröge + * + * EffecTV - Realtime Digital Video Effector + * Copyright (C) 2001-2006 FUKUCHI Kentaro + * + * StreakTV - afterimage effector. + * Copyright (C) 2001-2002 FUKUCHI Kentaro + * + * This combines the StreakTV and BaltanTV effects, which are + * very similar. BaltanTV is used if the feedback property is set + * to TRUE, otherwise StreakTV is used. + * + * EffecTV is free software. This library is free software; + * you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * SECTION:element-streaktv + * + * StreakTV makes after images of moving objects. + * + * + * Example launch line + * |[ + * gst-launch -v videotestsrc ! streaktv ! ffmpegcolorspace ! autovideosink + * ]| This pipeline shows the effect of streaktv on a test stream. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include "gststreak.h" +#include "gsteffectv.h" + +#include + +#define DEFAULT_FEEDBACK FALSE + +enum +{ + PROP_0, + PROP_FEEDBACK +}; + +GST_BOILERPLATE (GstStreakTV, gst_streaktv, GstVideoFilter, + GST_TYPE_VIDEO_FILTER); + +static GstStaticPadTemplate gst_streaktv_src_template = + GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx ";" + GST_VIDEO_CAPS_xBGR "; " GST_VIDEO_CAPS_xRGB) + ); + +static GstStaticPadTemplate gst_streaktv_sink_template = + GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx ";" + GST_VIDEO_CAPS_xBGR "; " GST_VIDEO_CAPS_xRGB) + ); + + + +static GstFlowReturn +gst_streaktv_transform (GstBaseTransform * trans, GstBuffer * in, + GstBuffer * out) +{ + GstStreakTV *filter = GST_STREAKTV (trans); + guint32 *src, *dest; + GstFlowReturn ret = GST_FLOW_OK; + gint i, cf; + gint video_area = filter->width * filter->height; + guint32 **planetable = filter->planetable; + gint plane = filter->plane; + guint stride_mask, stride_shift, stride; + + if (filter->feedback) { + stride_mask = 0xfcfcfcfc; + stride = 8; + stride_shift = 2; + } else { + stride_mask = 0xf8f8f8f8; + stride = 4; + stride_shift = 3; + } + + src = (guint32 *) GST_BUFFER_DATA (in); + dest = (guint32 *) GST_BUFFER_DATA (out); + + for (i = 0; i < video_area; i++) { + planetable[plane][i] = (src[i] & stride_mask) >> stride_shift; + } + + cf = plane & (stride - 1); + if (filter->feedback) { + for (i = 0; i < video_area; i++) { + dest[i] = planetable[cf][i] + + planetable[cf + stride][i] + + planetable[cf + stride * 2][i] + + planetable[cf + stride * 3][i]; + planetable[plane][i] = (dest[i] & stride_mask) >> stride_shift; + } + } else { + for (i = 0; i < video_area; i++) { + dest[i] = planetable[cf][i] + + planetable[cf + stride][i] + + planetable[cf + stride * 2][i] + + planetable[cf + stride * 3][i] + + planetable[cf + stride * 4][i] + + planetable[cf + stride * 5][i] + + planetable[cf + stride * 6][i] + + planetable[cf + stride * 7][i]; + } + } + + plane++; + filter->plane = plane & (PLANES - 1); + + return ret; +} + +static gboolean +gst_streaktv_set_caps (GstBaseTransform * btrans, GstCaps * incaps, + GstCaps * outcaps) +{ + GstStreakTV *filter = GST_STREAKTV (btrans); + GstStructure *structure; + gboolean ret = FALSE; + + structure = gst_caps_get_structure (incaps, 0); + + if (gst_structure_get_int (structure, "width", &filter->width) && + gst_structure_get_int (structure, "height", &filter->height)) { + gint i; + + if (filter->planebuffer) + g_free (filter->planebuffer); + + filter->planebuffer = + g_new0 (guint32, filter->width * filter->height * 4 * PLANES); + for (i = 0; i < PLANES; i++) + filter->planetable[i] = + &filter->planebuffer[filter->width * filter->height * i]; + + ret = TRUE; + } + + return ret; +} + +static gboolean +gst_streaktv_start (GstBaseTransform * trans) +{ + GstStreakTV *filter = GST_STREAKTV (trans); + + filter->plane = 0; + + return TRUE; +} + +static void +gst_streaktv_finalize (GObject * object) +{ + GstStreakTV *filter = GST_STREAKTV (object); + + if (filter->planebuffer) { + g_free (filter->planebuffer); + filter->planebuffer = NULL; + } + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void +gst_streaktv_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + GstStreakTV *filter = GST_STREAKTV (object); + + switch (prop_id) { + case PROP_FEEDBACK: + if (G_UNLIKELY (GST_STATE (filter) >= GST_STATE_PAUSED)) { + g_warning ("Changing the \"feedback\" property only allowed " + "in state < PLAYING"); + return; + } + + filter->feedback = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_streaktv_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) +{ + GstStreakTV *filter = GST_STREAKTV (object); + + switch (prop_id) { + case PROP_FEEDBACK: + g_value_set_boolean (value, filter->feedback); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_streaktv_base_init (gpointer g_class) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + + gst_element_class_set_details_simple (element_class, "StreakTV effect", + "Filter/Effect/Video", + "StreakTV makes after images of moving objects", + "FUKUCHI, Kentarou , " + "Sebastian Dröge "); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_streaktv_sink_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_streaktv_src_template)); +} + +static void +gst_streaktv_class_init (GstStreakTVClass * klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass; + + gobject_class->set_property = gst_streaktv_set_property; + gobject_class->get_property = gst_streaktv_get_property; + + gobject_class->finalize = gst_streaktv_finalize; + + g_object_class_install_property (gobject_class, PROP_FEEDBACK, + g_param_spec_boolean ("feedback", "Feedback", + "Feedback", DEFAULT_FEEDBACK, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_streaktv_set_caps); + trans_class->transform = GST_DEBUG_FUNCPTR (gst_streaktv_transform); + trans_class->start = GST_DEBUG_FUNCPTR (gst_streaktv_start); +} + +static void +gst_streaktv_init (GstStreakTV * filter, GstStreakTVClass * klass) +{ + filter->feedback = DEFAULT_FEEDBACK; +} diff --git a/gst/effectv/gststreak.h b/gst/effectv/gststreak.h new file mode 100644 index 0000000000..0e49a002b6 --- /dev/null +++ b/gst/effectv/gststreak.h @@ -0,0 +1,75 @@ +/* GStreamer + * Copyright (C) <2009> Sebastian Dröge + * + * EffecTV - Realtime Digital Video Effector + * Copyright (C) 2001-2006 FUKUCHI Kentaro + * + * StreakTV - afterimage effector. + * Copyright (C) 2001-2002 FUKUCHI Kentaro + * + * EffecTV is free software. This library is free software; + * you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_STREAK_H__ +#define __GST_STREAK_H__ + +#include + +#include + +G_BEGIN_DECLS + +#define GST_TYPE_STREAKTV \ + (gst_streaktv_get_type()) +#define GST_STREAKTV(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_STREAKTV,GstStreakTV)) +#define GST_STREAKTV_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_STREAKTV,GstStreakTVClass)) +#define GST_IS_STREAKTV(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_STREAKTV)) +#define GST_IS_STREAKTV_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_STREAKTV)) + +typedef struct _GstStreakTV GstStreakTV; +typedef struct _GstStreakTVClass GstStreakTVClass; + +#define PLANES 32 + +struct _GstStreakTV +{ + GstVideoFilter element; + + /* < private > */ + gint width, height; + + gboolean feedback; + + guint32 *planebuffer; + guint32 *planetable[PLANES]; + gint plane; +}; + +struct _GstStreakTVClass +{ + GstVideoFilterClass parent_class; +}; + +GType gst_streaktv_get_type (void); + +G_END_DECLS + +#endif /* __GST_STREAK_H__ */