effectv: Add streaktv effect filter element

This combines the StreakTV and BaltanTV filters from the
effectv project.

Kindly relicensed to LGPL2+ by Kentaro Fukuchi <fukuchi@megaui.net>.

Fixes bug #588368.
This commit is contained in:
Sebastian Dröge 2009-07-12 15:42:35 +02:00
parent f981bec99d
commit 433255304e
4 changed files with 354 additions and 2 deletions

View file

@ -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

View file

@ -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},
};

275
gst/effectv/gststreak.c Normal file
View file

@ -0,0 +1,275 @@
/* GStreamer
* Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
*
* 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.
*
* <refsect2>
* <title>Example launch line</title>
* |[
* gst-launch -v videotestsrc ! streaktv ! ffmpegcolorspace ! autovideosink
* ]| This pipeline shows the effect of streaktv on a test stream.
* </refsect2>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <math.h>
#include <string.h>
#include "gststreak.h"
#include "gsteffectv.h"
#include <gst/video/video.h>
#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 <fukuchi@users.sourceforge.net>, "
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
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;
}

75
gst/effectv/gststreak.h Normal file
View file

@ -0,0 +1,75 @@
/* GStreamer
* Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
*
* 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 <gst/gst.h>
#include <gst/video/gstvideofilter.h>
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__ */