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.
35 #include "gsteffectv.h"
37 #include <gst/video/video.h>
39 /* number of frames of time-buffer. It should be as a configurable paramater */
40 /* This number also must be 2^n just for the speed. */
49 GST_BOILERPLATE (GstQuarkTV, gst_quarktv, GstVideoFilter,
50 GST_TYPE_VIDEO_FILTER);
52 static void gst_quarktv_planetable_clear (GstQuarkTV * filter);
54 static GstStaticPadTemplate gst_quarktv_src_template =
55 GST_STATIC_PAD_TEMPLATE ("src",
58 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx)
61 static GstStaticPadTemplate gst_quarktv_sink_template =
62 GST_STATIC_PAD_TEMPLATE ("sink",
65 GST_STATIC_CAPS (GST_VIDEO_CAPS_BGRx "; " GST_VIDEO_CAPS_RGBx)
69 gst_quarktv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
72 GstQuarkTV *filter = GST_QUARKTV (btrans);
73 GstStructure *structure;
76 structure = gst_caps_get_structure (incaps, 0);
78 if (gst_structure_get_int (structure, "width", &filter->width) &&
79 gst_structure_get_int (structure, "height", &filter->height)) {
80 gst_quarktv_planetable_clear (filter);
81 filter->area = filter->width * filter->height;
89 gst_quarktv_transform (GstBaseTransform * trans, GstBuffer * in,
92 GstQuarkTV *filter = GST_QUARKTV (trans);
95 GstFlowReturn ret = GST_FLOW_OK;
98 src = (guint32 *) GST_BUFFER_DATA (in);
99 dest = (guint32 *) GST_BUFFER_DATA (out);
101 if (G_UNLIKELY (filter->planetable == NULL))
102 return GST_FLOW_WRONG_STATE;
104 if (filter->planetable[filter->current_plane])
105 gst_buffer_unref (filter->planetable[filter->current_plane]);
107 filter->planetable[filter->current_plane] = gst_buffer_ref (in);
113 /* pick a random buffer */
115 filter->planetable[(filter->current_plane +
116 (fastrand () >> 24)) % filter->planes];
118 /* Copy the pixel from the random buffer to dest */
120 (rand ? ((guint32 *) GST_BUFFER_DATA (rand))[area] : src[area]);
123 filter->current_plane--;
124 if (filter->current_plane < 0)
125 filter->current_plane = filter->planes - 1;
131 gst_quarktv_planetable_clear (GstQuarkTV * filter)
135 if (filter->planetable == NULL)
138 for (i = 0; i < filter->planes; i++) {
139 if (GST_IS_BUFFER (filter->planetable[i])) {
140 gst_buffer_unref (filter->planetable[i]);
142 filter->planetable[i] = NULL;
147 gst_quarktv_start (GstBaseTransform * trans)
149 GstQuarkTV *filter = GST_QUARKTV (trans);
151 if (filter->planetable) {
152 gst_quarktv_planetable_clear (filter);
153 g_free (filter->planetable);
156 (GstBuffer **) g_malloc0 (filter->planes * sizeof (GstBuffer *));
162 gst_quarktv_finalize (GObject * object)
164 GstQuarkTV *filter = GST_QUARKTV (object);
166 if (filter->planetable) {
167 gst_quarktv_planetable_clear (filter);
168 g_free (filter->planetable);
169 filter->planetable = NULL;
172 G_OBJECT_CLASS (parent_class)->finalize (object);
176 gst_quarktv_set_property (GObject * object, guint prop_id, const GValue * value,
179 GstQuarkTV *filter = GST_QUARKTV (object);
184 gint new_n_planes = g_value_get_int (value);
185 GstBuffer **new_planetable;
188 /* If the number of planes changed, copy across any existing planes */
189 if (new_n_planes != filter->planes) {
191 (GstBuffer **) g_malloc0 (new_n_planes * sizeof (GstBuffer *));
193 if (filter->planetable) {
194 for (i = 0; (i < new_n_planes) && (i < filter->planes); i++) {
195 new_planetable[i] = filter->planetable[i];
197 for (; i < filter->planes; i++) {
198 if (filter->planetable[i])
199 gst_buffer_unref (filter->planetable[i]);
201 g_free (filter->planetable);
204 filter->planetable = new_planetable;
205 filter->planes = new_n_planes;
206 filter->current_plane = filter->planes - 1;
211 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
217 gst_quarktv_get_property (GObject * object, guint prop_id, GValue * value,
220 GstQuarkTV *filter = GST_QUARKTV (object);
224 g_value_set_int (value, filter->planes);
227 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
233 gst_quarktv_base_init (gpointer g_class)
235 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
237 gst_element_class_set_details_simple (element_class, "QuarkTV effect",
238 "Filter/Effect/Video",
239 "Motion dissolver", "FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>");
241 gst_element_class_add_pad_template (element_class,
242 gst_static_pad_template_get (&gst_quarktv_sink_template));
243 gst_element_class_add_pad_template (element_class,
244 gst_static_pad_template_get (&gst_quarktv_src_template));
248 gst_quarktv_class_init (GstQuarkTVClass * klass)
250 GObjectClass *gobject_class = (GObjectClass *) klass;
251 GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
253 gobject_class->set_property = gst_quarktv_set_property;
254 gobject_class->get_property = gst_quarktv_get_property;
256 gobject_class->finalize = gst_quarktv_finalize;
258 g_object_class_install_property (gobject_class, PROP_PLANES,
259 g_param_spec_int ("planes", "Planes",
260 "Number of planes", 0, 64, PLANES,
261 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
263 trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_quarktv_set_caps);
264 trans_class->transform = GST_DEBUG_FUNCPTR (gst_quarktv_transform);
265 trans_class->start = GST_DEBUG_FUNCPTR (gst_quarktv_start);
269 gst_quarktv_init (GstQuarkTV * filter, GstQuarkTVClass * klass)
271 filter->planes = PLANES;
272 filter->current_plane = filter->planes - 1;