3 * Copyright (C) 2010 Thiago Santos <thiago.sousa.santos@collabora.co.uk>
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., 59 Temple Place - Suite 330,
41 * Boston, MA 02111-1307, USA.
45 * Thanks to Jerry Huxtable <http://www.jhlabs.com> work on its java
46 * image editor and filters. The algorithms here were extracted from
58 #include "gstcirclegeometrictransform.h"
60 GST_DEBUG_CATEGORY_STATIC (gst_circle_geometric_transform_debug);
61 #define GST_CAT_DEFAULT gst_circle_geometric_transform_debug
63 GstGeometricTransformClass *parent_class;
73 #define DEFAULT_X_CENTER 0.5
74 #define DEFAULT_Y_CENTER 0.5
75 #define DEFAULT_RADIUS 0.35
78 gst_circle_geometric_transform_set_property (GObject * object, guint prop_id,
79 const GValue * value, GParamSpec * pspec)
81 GstCircleGeometricTransform *cgt;
82 GstGeometricTransform *gt;
85 gt = GST_GEOMETRIC_TRANSFORM_CAST (object);
86 cgt = GST_CIRCLE_GEOMETRIC_TRANSFORM_CAST (object);
88 GST_OBJECT_LOCK (cgt);
91 v = g_value_get_double (value);
92 if (v != cgt->x_center) {
94 gst_geometric_transform_set_need_remap (gt);
98 v = g_value_get_double (value);
99 if (v != cgt->y_center) {
101 gst_geometric_transform_set_need_remap (gt);
105 v = g_value_get_double (value);
106 if (v != cgt->radius) {
108 gst_geometric_transform_set_need_remap (gt);
112 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
115 GST_OBJECT_UNLOCK (cgt);
119 gst_circle_geometric_transform_get_property (GObject * object, guint prop_id,
120 GValue * value, GParamSpec * pspec)
122 GstCircleGeometricTransform *cgt;
124 cgt = GST_CIRCLE_GEOMETRIC_TRANSFORM_CAST (object);
128 g_value_set_double (value, cgt->x_center);
131 g_value_set_double (value, cgt->y_center);
134 g_value_set_double (value, cgt->radius);
137 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
144 gst_circle_geometric_transform_finalize (GObject * obj)
146 G_OBJECT_CLASS (parent_class)->finalize (obj);
149 /* GObject vmethod implementations */
152 circle_geometric_transform_precalc (GstGeometricTransform * gt)
154 GstCircleGeometricTransform *cgt = GST_CIRCLE_GEOMETRIC_TRANSFORM_CAST (gt);
156 cgt->precalc_x_center = cgt->x_center * gt->width;
157 cgt->precalc_y_center = cgt->y_center * gt->height;
158 cgt->precalc_radius =
159 cgt->radius * 0.5 * sqrt (gt->width * gt->width +
160 gt->height * gt->height);
161 cgt->precalc_radius2 = cgt->precalc_radius * cgt->precalc_radius;
167 gst_circle_geometric_transform_class_init (GstCircleGeometricTransformClass *
170 GObjectClass *gobject_class;
171 GstGeometricTransformClass *gstgt_class;
173 gobject_class = (GObjectClass *) klass;
174 gstgt_class = (GstGeometricTransformClass *) klass;
176 parent_class = g_type_class_peek_parent (klass);
178 gobject_class->finalize =
179 GST_DEBUG_FUNCPTR (gst_circle_geometric_transform_finalize);
180 gobject_class->set_property =
181 GST_DEBUG_FUNCPTR (gst_circle_geometric_transform_set_property);
182 gobject_class->get_property =
183 GST_DEBUG_FUNCPTR (gst_circle_geometric_transform_get_property);
186 /* FIXME I don't like the idea of x-center and y-center being in % and
187 * radius and intensity in absolute values, I think no one likes it, but
188 * I can't see a way to have nice default values without % */
189 g_object_class_install_property (gobject_class, PROP_X_CENTER,
190 g_param_spec_double ("x-center", "x center",
191 "X axis center of the circle_geometric_transform effect",
192 0.0, 1.0, DEFAULT_X_CENTER,
193 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
194 g_object_class_install_property (gobject_class, PROP_Y_CENTER,
195 g_param_spec_double ("y-center", "y center",
196 "Y axis center of the circle_geometric_transform effect",
197 0.0, 1.0, DEFAULT_Y_CENTER,
198 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
199 g_object_class_install_property (gobject_class, PROP_RADIUS,
200 g_param_spec_double ("radius", "radius",
201 "radius of the circle_geometric_transform effect", 0.0, 1.0,
203 GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
205 gstgt_class->prepare_func = circle_geometric_transform_precalc;
209 gst_circle_geometric_transform_init (GstCircleGeometricTransform * filter,
210 GstCircleGeometricTransformClass * gclass)
212 filter->x_center = DEFAULT_X_CENTER;
213 filter->y_center = DEFAULT_Y_CENTER;
214 filter->radius = DEFAULT_RADIUS;
218 gst_circle_geometric_transform_get_type (void)
220 static GType circle_geometric_transform_type = 0;
222 if (!circle_geometric_transform_type) {
223 static const GTypeInfo circle_geometric_transform_info = {
224 sizeof (GstCircleGeometricTransformClass),
227 (GClassInitFunc) gst_circle_geometric_transform_class_init,
230 sizeof (GstCircleGeometricTransform),
232 (GInstanceInitFunc) gst_circle_geometric_transform_init,
235 circle_geometric_transform_type =
236 g_type_register_static (GST_TYPE_GEOMETRIC_TRANSFORM,
237 "GstCircleGeometricTransform", &circle_geometric_transform_info,
238 G_TYPE_FLAG_ABSTRACT);
240 GST_DEBUG_CATEGORY_INIT (gst_circle_geometric_transform_debug,
241 "circlegeometrictransform", 0,
242 "Base class for geometric transform elements that operate "
243 "on a circular area");
245 return circle_geometric_transform_type;