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_BGRx "; " GST_VIDEO_CAPS_RGBx)
75 static GstStaticPadTemplate gst_quarktv_sink_template =
76 GST_STATIC_PAD_TEMPLATE ("sink",
79 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx)
83 gst_quarktv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
86 GstQuarkTV *filter = GST_QUARKTV (btrans);
87 GstStructure *structure;
90 structure = gst_caps_get_structure (incaps, 0);
92 if (gst_structure_get_int (structure, "width", &filter->width) &&
93 gst_structure_get_int (structure, "height", &filter->height)) {
94 gst_quarktv_planetable_clear (filter);
95 filter->area = filter->width * filter->height;
103 gst_quarktv_transform (GstBaseTransform * trans, GstBuffer * in,
106 GstQuarkTV *filter = GST_QUARKTV (trans);
109 GstFlowReturn ret = GST_FLOW_OK;
112 src = (guint32 *) GST_BUFFER_DATA (in);
113 dest = (guint32 *) GST_BUFFER_DATA (out);
115 if (G_UNLIKELY (filter->planetable == NULL))
116 return GST_FLOW_WRONG_STATE;
118 if (filter->planetable[filter->current_plane])
119 gst_buffer_unref (filter->planetable[filter->current_plane]);
121 filter->planetable[filter->current_plane] = gst_buffer_ref (in);
127 /* pick a random buffer */
129 filter->planetable[(filter->current_plane +
130 (fastrand () >> 24)) % filter->planes];
132 /* Copy the pixel from the random buffer to dest */
134 (rand ? ((guint32 *) GST_BUFFER_DATA (rand))[area] : src[area]);
137 filter->current_plane--;
138 if (filter->current_plane < 0)
139 filter->current_plane = filter->planes - 1;
145 gst_quarktv_planetable_clear (GstQuarkTV * filter)
149 if (filter->planetable == NULL)
152 for (i = 0; i < filter->planes; i++) {
153 if (GST_IS_BUFFER (filter->planetable[i])) {
154 gst_buffer_unref (filter->planetable[i]);
156 filter->planetable[i] = NULL;
161 gst_quarktv_start (GstBaseTransform * trans)
163 GstQuarkTV *filter = GST_QUARKTV (trans);
165 if (filter->planetable) {
166 gst_quarktv_planetable_clear (filter);
167 g_free (filter->planetable);
170 (GstBuffer **) g_malloc0 (filter->planes * sizeof (GstBuffer *));
176 gst_quarktv_finalize (GObject * object)
178 GstQuarkTV *filter = GST_QUARKTV (object);
180 if (filter->planetable) {
181 gst_quarktv_planetable_clear (filter);
182 g_free (filter->planetable);
183 filter->planetable = NULL;
186 G_OBJECT_CLASS (parent_class)->finalize (object);
190 gst_quarktv_set_property (GObject * object, guint prop_id, const GValue * value,
193 GstQuarkTV *filter = GST_QUARKTV (object);
198 gint new_n_planes = g_value_get_int (value);
199 GstBuffer **new_planetable;
202 /* If the number of planes changed, copy across any existing planes */
203 if (new_n_planes != filter->planes) {
205 (GstBuffer **) g_malloc0 (new_n_planes * sizeof (GstBuffer *));
207 if (filter->planetable) {
208 for (i = 0; (i < new_n_planes) && (i < filter->planes); i++) {
209 new_planetable[i] = filter->planetable[i];
211 for (; i < filter->planes; i++) {
212 if (filter->planetable[i])
213 gst_buffer_unref (filter->planetable[i]);
215 g_free (filter->planetable);
218 filter->planetable = new_planetable;
219 filter->planes = new_n_planes;
220 filter->current_plane = filter->planes - 1;
225 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
231 gst_quarktv_get_property (GObject * object, guint prop_id, GValue * value,
234 GstQuarkTV *filter = GST_QUARKTV (object);
238 g_value_set_int (value, filter->planes);
241 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
247 gst_quarktv_base_init (gpointer g_class)
249 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
251 gst_element_class_set_details_simple (element_class, "QuarkTV effect",
252 "Filter/Effect/Video",
253 "Motion dissolver", "FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>");
255 gst_element_class_add_pad_template (element_class,
256 gst_static_pad_template_get (&gst_quarktv_sink_template));
257 gst_element_class_add_pad_template (element_class,
258 gst_static_pad_template_get (&gst_quarktv_src_template));
262 gst_quarktv_class_init (GstQuarkTVClass * klass)
264 GObjectClass *gobject_class = (GObjectClass *) klass;
265 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
267 gobject_class->set_property = gst_quarktv_set_property;
268 gobject_class->get_property = gst_quarktv_get_property;
270 gobject_class->finalize = gst_quarktv_finalize;
272 g_object_class_install_property (gobject_class, PROP_PLANES,
273 g_param_spec_int ("planes", "Planes",
274 "Number of planes", 0, 64, PLANES,
275 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
277 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_quarktv_set_caps);
278 trans_class->transform = GST_DEBUG_FUNCPTR (gst_quarktv_transform);
279 trans_class->start = GST_DEBUG_FUNCPTR (gst_quarktv_start);
283 gst_quarktv_init (GstQuarkTV * filter, GstQuarkTVClass * klass)
285 filter->planes = PLANES;
286 filter->current_plane = filter->planes - 1;