3 * Copyright (C) 2010 Filippo Argiolas <filippo.argiolas@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 * Alternatively, the contents of this file may be used under the
24 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
25 * which case the following provisions apply instead of the ones
28 * This library is free software; you can redistribute it and/or
29 * modify it under the terms of the GNU Library General Public
30 * License as published by the Free Software Foundation; either
31 * version 2 of the License, or (at your option) any later version.
33 * This library is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
36 * Library General Public License for more details.
38 * You should have received a copy of the GNU Library General Public
39 * License along with this library; if not, write to the
40 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
41 * Boston, MA 02110-1301, USA.
45 * SECTION:element-mirror
47 * @see_also: geometrictransform
49 * Mirror is a geometric transform element. It splits the image into two halves
50 * and reflects one over each other.
52 * ## Example launch line
54 * gst-launch-1.0 -v videotestsrc ! mirror ! videoconvert ! autovideosink
66 #include "gstmirror.h"
68 GST_DEBUG_CATEGORY_STATIC (gst_mirror_debug);
69 #define GST_CAT_DEFAULT gst_mirror_debug
77 #define DEFAULT_PROP_MODE GST_MIRROR_MODE_LEFT
79 #define gst_mirror_parent_class parent_class
80 G_DEFINE_TYPE (GstMirror, gst_mirror, GST_TYPE_GEOMETRIC_TRANSFORM);
81 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (mirror, "mirror", GST_RANK_NONE,
82 GST_TYPE_MIRROR, GST_DEBUG_CATEGORY_INIT (gst_mirror_debug, "mirror", 0,
85 #define GST_TYPE_MIRROR_MODE (gst_mirror_mode_get_type())
87 gst_mirror_mode_get_type (void)
89 static GType mode_type = 0;
91 static const GEnumValue modes[] = {
92 {GST_MIRROR_MODE_LEFT, "Split horizontally and reflect left into right",
94 {GST_MIRROR_MODE_RIGHT, "Split horizontally and reflect right into left",
96 {GST_MIRROR_MODE_TOP, "Split vertically and reflect top into bottom",
98 {GST_MIRROR_MODE_BOTTOM, "Split vertically and reflect bottom into top",
104 mode_type = g_enum_register_static ("GstMirrorMode", modes);
111 gst_mirror_set_property (GObject * object, guint prop_id,
112 const GValue * value, GParamSpec * pspec)
114 GstMirror *filter = GST_MIRROR_CAST (object);
121 GST_OBJECT_LOCK (filter);
122 mode = g_value_get_enum (value);
124 if (mode != filter->mode) {
125 GstGeometricTransform *gt;
127 gt = GST_GEOMETRIC_TRANSFORM_CAST (object);
129 gst_geometric_transform_set_need_remap (gt);
132 GST_OBJECT_UNLOCK (filter);
136 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
142 gst_mirror_get_property (GObject * object, guint prop_id,
143 GValue * value, GParamSpec * pspec)
145 GstMirror *filter = GST_MIRROR_CAST (object);
149 g_value_set_enum (value, filter->mode);
152 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
158 mirror_map (GstGeometricTransform * gt, gint x, gint y, gdouble * in_x,
161 GstMirror *mirror = GST_MIRROR_CAST (gt);
163 gdouble hw = gt->width / 2.0 - 1.0;
164 gdouble hh = gt->height / 2.0 - 1.0;
166 switch (mirror->mode) {
167 case GST_MIRROR_MODE_LEFT:
169 *in_x = gt->width - 1.0 - x;
174 case GST_MIRROR_MODE_RIGHT:
178 *in_x = gt->width - 1.0 - x;
181 case GST_MIRROR_MODE_TOP:
183 *in_y = gt->height - 1.0 - y;
188 case GST_MIRROR_MODE_BOTTOM:
192 *in_y = gt->height - 1.0 - y;
196 g_assert_not_reached ();
199 GST_DEBUG_OBJECT (mirror, "Inversely mapped %d %d into %lf %lf",
206 gst_mirror_class_init (GstMirrorClass * klass)
208 GObjectClass *gobject_class;
209 GstElementClass *gstelement_class;
210 GstGeometricTransformClass *gstgt_class;
212 gobject_class = (GObjectClass *) klass;
213 gstelement_class = (GstElementClass *) klass;
214 gstgt_class = (GstGeometricTransformClass *) klass;
216 gst_element_class_set_static_metadata (gstelement_class,
218 "Transform/Effect/Video",
219 "Split the image into two halves and reflect one over each other",
220 "Filippo Argiolas <filippo.argiolas@gmail.com>");
222 gobject_class->set_property = gst_mirror_set_property;
223 gobject_class->get_property = gst_mirror_get_property;
225 g_object_class_install_property (gobject_class, PROP_MODE,
226 g_param_spec_enum ("mode", "Mirror Mode",
227 "How to split the video frame and which side reflect",
228 GST_TYPE_MIRROR_MODE, DEFAULT_PROP_MODE,
229 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
231 gstgt_class->map_func = mirror_map;
233 gst_type_mark_as_plugin_api (GST_TYPE_MIRROR_MODE, 0);
237 gst_mirror_init (GstMirror * filter)
239 GstGeometricTransform *gt = GST_GEOMETRIC_TRANSFORM (filter);
241 filter->mode = DEFAULT_PROP_MODE;
242 gt->off_edge_pixels = GST_GT_OFF_EDGES_PIXELS_CLAMP;