2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 * Copyright (C) 2001-2002 FUKUCHI Kentarou
8 * QuarkTV - motion disolver.
10 * EffecTV is free software. This library is free software;
11 * you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
28 * SECTION:element-quarktv
30 * QuarkTV disolves moving objects. It picks up pixels from
31 * the last frames randomly.
34 * <title>Example launch line</title>
36 * gst-launch -v videotestsrc ! quarktv ! ffmpegcolorspace ! autovideosink
37 * ]| This pipeline shows the effect of quarktv on a test stream.
49 #include "gsteffectv.h"
51 #include <gst/video/video.h>
53 /* number of frames of time-buffer. It should be as a configurable paramater */
54 /* This number also must be 2^n just for the speed. */
63 GST_BOILERPLATE (GstQuarkTV, gst_quarktv, GstVideoFilter,
64 GST_TYPE_VIDEO_FILTER);
66 static void gst_quarktv_planetable_clear (GstQuarkTV * filter);
68 static GstStaticPadTemplate gst_quarktv_src_template =
69 GST_STATIC_PAD_TEMPLATE ("src",
72 GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR ";"
73 GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx)
76 static GstStaticPadTemplate gst_quarktv_sink_template =
77 GST_STATIC_PAD_TEMPLATE ("sink",
80 GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR ";"
81 GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx)
85 gst_quarktv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
88 GstQuarkTV *filter = GST_QUARKTV (btrans);
89 GstStructure *structure;
92 structure = gst_caps_get_structure (incaps, 0);
94 if (gst_structure_get_int (structure, "width", &filter->width) &&
95 gst_structure_get_int (structure, "height", &filter->height)) {
96 gst_quarktv_planetable_clear (filter);
97 filter->area = filter->width * filter->height;
105 gst_quarktv_transform (GstBaseTransform * trans, GstBuffer * in,
108 GstQuarkTV *filter = GST_QUARKTV (trans);
111 GstFlowReturn ret = GST_FLOW_OK;
114 src = (guint32 *) GST_BUFFER_DATA (in);
115 dest = (guint32 *) GST_BUFFER_DATA (out);
117 if (G_UNLIKELY (filter->planetable == NULL))
118 return GST_FLOW_WRONG_STATE;
120 if (filter->planetable[filter->current_plane])
121 gst_buffer_unref (filter->planetable[filter->current_plane]);
123 filter->planetable[filter->current_plane] = gst_buffer_ref (in);
129 /* pick a random buffer */
131 filter->planetable[(filter->current_plane +
132 (fastrand () >> 24)) % filter->planes];
134 /* Copy the pixel from the random buffer to dest */
136 (rand ? ((guint32 *) GST_BUFFER_DATA (rand))[area] : src[area]);
139 filter->current_plane--;
140 if (filter->current_plane < 0)
141 filter->current_plane = filter->planes - 1;
147 gst_quarktv_planetable_clear (GstQuarkTV * filter)
151 if (filter->planetable == NULL)
154 for (i = 0; i < filter->planes; i++) {
155 if (GST_IS_BUFFER (filter->planetable[i])) {
156 gst_buffer_unref (filter->planetable[i]);
158 filter->planetable[i] = NULL;
163 gst_quarktv_start (GstBaseTransform * trans)
165 GstQuarkTV *filter = GST_QUARKTV (trans);
167 if (filter->planetable) {
168 gst_quarktv_planetable_clear (filter);
169 g_free (filter->planetable);
172 (GstBuffer **) g_malloc0 (filter->planes * sizeof (GstBuffer *));
178 gst_quarktv_finalize (GObject * object)
180 GstQuarkTV *filter = GST_QUARKTV (object);
182 if (filter->planetable) {
183 gst_quarktv_planetable_clear (filter);
184 g_free (filter->planetable);
185 filter->planetable = NULL;
188 G_OBJECT_CLASS (parent_class)->finalize (object);
192 gst_quarktv_set_property (GObject * object, guint prop_id, const GValue * value,
195 GstQuarkTV *filter = GST_QUARKTV (object);
200 gint new_n_planes = g_value_get_int (value);
201 GstBuffer **new_planetable;
204 /* If the number of planes changed, copy across any existing planes */
205 if (new_n_planes != filter->planes) {
207 (GstBuffer **) g_malloc0 (new_n_planes * sizeof (GstBuffer *));
209 if (filter->planetable) {
210 for (i = 0; (i < new_n_planes) && (i < filter->planes); i++) {
211 new_planetable[i] = filter->planetable[i];
213 for (; i < filter->planes; i++) {
214 if (filter->planetable[i])
215 gst_buffer_unref (filter->planetable[i]);
217 g_free (filter->planetable);
220 filter->planetable = new_planetable;
221 filter->planes = new_n_planes;
222 filter->current_plane = filter->planes - 1;
227 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
233 gst_quarktv_get_property (GObject * object, guint prop_id, GValue * value,
236 GstQuarkTV *filter = GST_QUARKTV (object);
240 g_value_set_int (value, filter->planes);
243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
249 gst_quarktv_base_init (gpointer g_class)
251 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
253 gst_element_class_set_details_simple (element_class, "QuarkTV effect",
254 "Filter/Effect/Video",
255 "Motion dissolver", "FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>");
257 gst_element_class_add_pad_template (element_class,
258 gst_static_pad_template_get (&gst_quarktv_sink_template));
259 gst_element_class_add_pad_template (element_class,
260 gst_static_pad_template_get (&gst_quarktv_src_template));
264 gst_quarktv_class_init (GstQuarkTVClass * klass)
266 GObjectClass *gobject_class = (GObjectClass *) klass;
267 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
269 gobject_class->set_property = gst_quarktv_set_property;
270 gobject_class->get_property = gst_quarktv_get_property;
272 gobject_class->finalize = gst_quarktv_finalize;
274 g_object_class_install_property (gobject_class, PROP_PLANES,
275 g_param_spec_int ("planes", "Planes",
276 "Number of planes", 0, 64, PLANES,
277 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
279 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_quarktv_set_caps);
280 trans_class->transform = GST_DEBUG_FUNCPTR (gst_quarktv_transform);
281 trans_class->start = GST_DEBUG_FUNCPTR (gst_quarktv_start);
285 gst_quarktv_init (GstQuarkTV * filter, GstQuarkTVClass * klass)
287 filter->planes = PLANES;
288 filter->current_plane = filter->planes - 1;