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 (
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",
228 static void gst_videoflip_flip(GstVideoflip *videoflip, unsigned char *dest,
229 unsigned char *src, int sw, int sh, int dw, int dh);
232 static void gst_videoflip_setup (GstVideofilter *videofilter)
234 int from_width, from_height;
235 GstVideoflip *videoflip;
237 GST_DEBUG("gst_videoflip_setup");
239 videoflip = GST_VIDEOFLIP(videofilter);
241 from_width = gst_videofilter_get_input_width(videofilter);
242 from_height = gst_videofilter_get_input_height(videofilter);
244 if(from_width==0 || from_height==0){
248 switch(videoflip->method){
249 case GST_VIDEOFLIP_METHOD_90R:
250 case GST_VIDEOFLIP_METHOD_90L:
251 case GST_VIDEOFLIP_METHOD_TRANS:
252 case GST_VIDEOFLIP_METHOD_OTHER:
253 gst_videofilter_set_output_size(videofilter, from_height, from_width);
255 case GST_VIDEOFLIP_METHOD_IDENTITY:
256 case GST_VIDEOFLIP_METHOD_180:
257 case GST_VIDEOFLIP_METHOD_HORIZ:
258 case GST_VIDEOFLIP_METHOD_VERT:
259 gst_videofilter_set_output_size(videofilter, from_width, from_height);
262 g_assert_not_reached();
266 GST_DEBUG ("format=%p \"%s\" from %dx%d to %dx%d",
267 videofilter->format, videofilter->format->fourcc,
268 from_width, from_height,
269 videofilter->to_width, videofilter->to_height);
271 if(videoflip->method == GST_VIDEOFLIP_METHOD_IDENTITY){
272 GST_DEBUG ("videoflip: using passthru");
273 videofilter->passthru = TRUE;
275 videofilter->passthru = FALSE;
278 videofilter->from_buf_size = (videofilter->from_width * videofilter->from_height
279 * videofilter->format->depth) / 8;
280 videofilter->to_buf_size = (videofilter->to_width * videofilter->to_height
281 * videofilter->format->depth) / 8;
283 videofilter->inited = TRUE;
286 static void gst_videoflip_planar411(GstVideofilter *videofilter,
287 void *dest, void *src)
289 GstVideoflip *videoflip;
295 g_return_if_fail(GST_IS_VIDEOFLIP(videofilter));
296 videoflip = GST_VIDEOFLIP(videofilter);
298 sw = videofilter->from_width;
299 sh = videofilter->from_height;
300 dw = videofilter->to_width;
301 dh = videofilter->to_height;
303 GST_DEBUG ("videoflip: scaling planar 4:1:1 %dx%d to %dx%d", sw, sh, dw, dh);
305 gst_videoflip_flip(videoflip, dest, src, sw, sh, dw, dh);
315 gst_videoflip_flip(videoflip, dest, src, sw, sh, dw, dh);
320 gst_videoflip_flip(videoflip, dest, src, sw, sh, dw, dh);
324 gst_videoflip_flip(GstVideoflip *videoflip, unsigned char *dest,
325 unsigned char *src, int sw, int sh, int dw, int dh)
329 switch(videoflip->method){
330 case GST_VIDEOFLIP_METHOD_90R:
333 dest[y*dw + x] = src[(sh - 1 - x)*sw + y];
337 case GST_VIDEOFLIP_METHOD_90L:
340 dest[y*dw + x] = src[x*sw + (sw - 1 - y)];
344 case GST_VIDEOFLIP_METHOD_180:
347 dest[y*dw + x] = src[(sh - 1 - y)*sw + (sw - 1 - x)];
351 case GST_VIDEOFLIP_METHOD_HORIZ:
354 dest[y*dw + x] = src[y*sw + (sw - 1 - x)];
358 case GST_VIDEOFLIP_METHOD_VERT:
361 dest[y*dw + x] = src[(sh - 1 - y)*sw + x];
365 case GST_VIDEOFLIP_METHOD_TRANS:
368 dest[y*dw + x] = src[x*sw + y];
372 case GST_VIDEOFLIP_METHOD_OTHER:
375 dest[y*dw + x] = src[(sh - 1 - x)*sw + (sw - 1 - y)];