2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2003> David Schleef <ds@schleef.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * This file was (probably) generated from gstvideoflip.c,
23 * gstvideoflip.c,v 1.7 2003/11/08 02:48:59 dschleef Exp
30 /*#define DEBUG_ENABLED */
31 #include <gstvideoflip.h>
34 /* GstVideoflip signals and args */
46 static void gst_videoflip_base_init (gpointer g_class);
47 static void gst_videoflip_class_init (gpointer g_class, gpointer class_data);
48 static void gst_videoflip_init (GTypeInstance *instance, gpointer g_class);
50 static void gst_videoflip_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
51 static void gst_videoflip_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
53 static void gst_videoflip_planar411(GstVideofilter *videofilter, void *dest, void *src);
54 static void gst_videoflip_setup(GstVideofilter *videofilter);
56 #define GST_TYPE_VIDEOFLIP_METHOD (gst_videoflip_method_get_type())
59 gst_videoflip_method_get_type(void)
61 static GType videoflip_method_type = 0;
62 static GEnumValue videoflip_methods[] = {
63 { GST_VIDEOFLIP_METHOD_IDENTITY, "0", "Identity (no rotation)" },
64 { GST_VIDEOFLIP_METHOD_90R, "1", "Rotate clockwise 90 degrees" },
65 { GST_VIDEOFLIP_METHOD_180, "2", "Rotate 180 degrees" },
66 { GST_VIDEOFLIP_METHOD_90L, "3", "Rotate counter-clockwise 90 degrees" },
67 { GST_VIDEOFLIP_METHOD_HORIZ, "4", "Flip horizontally" },
68 { GST_VIDEOFLIP_METHOD_VERT, "5", "Flip vertically" },
69 { GST_VIDEOFLIP_METHOD_TRANS, "6", "Flip across upper left/lower right diagonal" },
70 { GST_VIDEOFLIP_METHOD_OTHER, "7", "Flip across upper right/lower left diagonal" },
73 if(!videoflip_method_type){
74 videoflip_method_type = g_enum_register_static("GstVideoflipMethod",
77 return videoflip_method_type;
81 gst_videoflip_get_type (void)
83 static GType videoflip_type = 0;
85 if (!videoflip_type) {
86 static const GTypeInfo videoflip_info = {
87 sizeof(GstVideoflipClass),
88 gst_videoflip_base_init,
90 gst_videoflip_class_init,
97 videoflip_type = g_type_register_static(GST_TYPE_VIDEOFILTER,
98 "GstVideoflip", &videoflip_info, 0);
100 return videoflip_type;
103 static GstVideofilterFormat gst_videoflip_formats[] = {
105 { "YV12", 12, gst_videoflip_planar411, },
106 { "I420", 12, gst_videoflip_planar411, },
107 { "IYUV", 12, gst_videoflip_planar411, },
111 gst_videoflip_base_init (gpointer g_class)
113 static GstElementDetails videoflip_details = GST_ELEMENT_DETAILS (
115 "Filter/Effect/Video",
116 "Flips and rotates video",
117 "David Schleef <ds@schleef.org>"
119 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
120 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
123 gst_element_class_set_details (element_class, &videoflip_details);
125 for(i=0;i<G_N_ELEMENTS(gst_videoflip_formats);i++){
126 gst_videofilter_class_add_format(videofilter_class,
127 gst_videoflip_formats + i);
130 gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
134 gst_videoflip_class_init (gpointer g_class, gpointer class_data)
136 GObjectClass *gobject_class;
137 GstVideofilterClass *videofilter_class;
139 gobject_class = G_OBJECT_CLASS (g_class);
140 videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
142 g_object_class_install_property(gobject_class, ARG_METHOD,
143 g_param_spec_enum("method","method","method",
144 GST_TYPE_VIDEOFLIP_METHOD, GST_VIDEOFLIP_METHOD_90R,
147 gobject_class->set_property = gst_videoflip_set_property;
148 gobject_class->get_property = gst_videoflip_get_property;
150 videofilter_class->setup = gst_videoflip_setup;
154 gst_videoflip_init (GTypeInstance *instance, gpointer g_class)
156 GstVideoflip *videoflip = GST_VIDEOFLIP (instance);
157 GstVideofilter *videofilter;
159 GST_DEBUG("gst_videoflip_init");
161 videofilter = GST_VIDEOFILTER(videoflip);
167 gst_videoflip_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
171 /* it's not null if we got it, but it might not be ours */
172 g_return_if_fail(GST_IS_VIDEOFLIP(object));
173 src = GST_VIDEOFLIP(object);
175 GST_DEBUG("gst_videoflip_set_property");
178 src->method = g_value_get_enum (value);
179 /* FIXME is this ok? (threading issues) */
180 gst_videoflip_setup(GST_VIDEOFILTER(src));
188 gst_videoflip_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
192 /* it's not null if we got it, but it might not be ours */
193 g_return_if_fail(GST_IS_VIDEOFLIP(object));
194 src = GST_VIDEOFLIP(object);
198 g_value_set_enum (value, src->method);
201 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
206 static gboolean plugin_init (GstPlugin *plugin)
208 if(!gst_library_load("gstvideofilter"))
211 return gst_element_register (plugin, "videoflip", GST_RANK_NONE,
219 "Flips and rotates video",
227 static void gst_videoflip_flip(GstVideoflip *videoflip, unsigned char *dest,
228 unsigned char *src, int sw, int sh, int dw, int dh);
231 static void gst_videoflip_setup (GstVideofilter *videofilter)
233 int from_width, from_height;
234 GstVideoflip *videoflip;
236 GST_DEBUG("gst_videoflip_setup");
238 videoflip = GST_VIDEOFLIP(videofilter);
240 from_width = gst_videofilter_get_input_width(videofilter);
241 from_height = gst_videofilter_get_input_height(videofilter);
243 if(from_width==0 || from_height==0){
247 switch(videoflip->method){
248 case GST_VIDEOFLIP_METHOD_90R:
249 case GST_VIDEOFLIP_METHOD_90L:
250 case GST_VIDEOFLIP_METHOD_TRANS:
251 case GST_VIDEOFLIP_METHOD_OTHER:
252 gst_videofilter_set_output_size(videofilter, from_height, from_width);
254 case GST_VIDEOFLIP_METHOD_IDENTITY:
255 case GST_VIDEOFLIP_METHOD_180:
256 case GST_VIDEOFLIP_METHOD_HORIZ:
257 case GST_VIDEOFLIP_METHOD_VERT:
258 gst_videofilter_set_output_size(videofilter, from_width, from_height);
261 g_assert_not_reached();
265 GST_DEBUG ("format=%p \"%s\" from %dx%d to %dx%d",
266 videofilter->format, videofilter->format->fourcc,
267 from_width, from_height,
268 videofilter->to_width, videofilter->to_height);
270 if(videoflip->method == GST_VIDEOFLIP_METHOD_IDENTITY){
271 GST_DEBUG ("videoflip: using passthru");
272 videofilter->passthru = TRUE;
274 videofilter->passthru = FALSE;
277 videofilter->from_buf_size = (videofilter->from_width * videofilter->from_height
278 * videofilter->format->depth) / 8;
279 videofilter->to_buf_size = (videofilter->to_width * videofilter->to_height
280 * videofilter->format->depth) / 8;
282 videofilter->inited = TRUE;
285 static void gst_videoflip_planar411(GstVideofilter *videofilter,
286 void *dest, void *src)
288 GstVideoflip *videoflip;
294 g_return_if_fail(GST_IS_VIDEOFLIP(videofilter));
295 videoflip = GST_VIDEOFLIP(videofilter);
297 sw = videofilter->from_width;
298 sh = videofilter->from_height;
299 dw = videofilter->to_width;
300 dh = videofilter->to_height;
302 GST_DEBUG ("videoflip: scaling planar 4:1:1 %dx%d to %dx%d", sw, sh, dw, dh);
304 gst_videoflip_flip(videoflip, dest, src, sw, sh, dw, dh);
314 gst_videoflip_flip(videoflip, dest, src, sw, sh, dw, dh);
319 gst_videoflip_flip(videoflip, dest, src, sw, sh, dw, dh);
323 gst_videoflip_flip(GstVideoflip *videoflip, unsigned char *dest,
324 unsigned char *src, int sw, int sh, int dw, int dh)
328 switch(videoflip->method){
329 case GST_VIDEOFLIP_METHOD_90R:
332 dest[y*dw + x] = src[(sh - 1 - x)*sw + y];
336 case GST_VIDEOFLIP_METHOD_90L:
339 dest[y*dw + x] = src[x*sw + (sw - 1 - y)];
343 case GST_VIDEOFLIP_METHOD_180:
346 dest[y*dw + x] = src[(sh - 1 - y)*sw + (sw - 1 - x)];
350 case GST_VIDEOFLIP_METHOD_HORIZ:
353 dest[y*dw + x] = src[y*sw + (sw - 1 - x)];
357 case GST_VIDEOFLIP_METHOD_VERT:
360 dest[y*dw + x] = src[(sh - 1 - y)*sw + x];
364 case GST_VIDEOFLIP_METHOD_TRANS:
367 dest[y*dw + x] = src[x*sw + y];
371 case GST_VIDEOFLIP_METHOD_OTHER:
374 dest[y*dw + x] = src[(sh - 1 - x)*sw + (sw - 1 - y)];