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 */
48 GST_DEBUG_CATEGORY_STATIC (gst_videoflip_debug);
49 #define GST_CAT_DEFAULT gst_videoflip_debug
51 static void gst_videoflip_base_init (gpointer g_class);
52 static void gst_videoflip_class_init (gpointer g_class, gpointer class_data);
53 static void gst_videoflip_init (GTypeInstance * instance, gpointer g_class);
55 static void gst_videoflip_set_property (GObject * object, guint prop_id,
56 const GValue * value, GParamSpec * pspec);
57 static void gst_videoflip_get_property (GObject * object, guint prop_id,
58 GValue * value, GParamSpec * pspec);
60 static void gst_videoflip_planar411 (GstVideofilter * videofilter, void *dest,
62 static void gst_videoflip_setup (GstVideofilter * videofilter);
64 #define GST_TYPE_VIDEOFLIP_METHOD (gst_videoflip_method_get_type())
67 gst_videoflip_method_get_type (void)
69 static GType videoflip_method_type = 0;
70 static GEnumValue videoflip_methods[] = {
71 {GST_VIDEOFLIP_METHOD_IDENTITY, "Identity (no rotation)", "none"},
72 {GST_VIDEOFLIP_METHOD_90R, "Rotate clockwise 90 degrees", "clockwise"},
73 {GST_VIDEOFLIP_METHOD_180, "Rotate 180 degrees", "rotate-180"},
74 {GST_VIDEOFLIP_METHOD_90L, "Rotate counter-clockwise 90 degrees",
76 {GST_VIDEOFLIP_METHOD_HORIZ, "Flip horizontally", "horizontal-flip"},
77 {GST_VIDEOFLIP_METHOD_VERT, "Flip vertically", "vertical-flip"},
78 {GST_VIDEOFLIP_METHOD_TRANS,
79 "Flip across upper left/lower right diagonal", "upper-left-diagonal"},
80 {GST_VIDEOFLIP_METHOD_OTHER,
81 "Flip across upper right/lower left diagonal", "upper-right-diagonal"},
85 if (!videoflip_method_type) {
86 videoflip_method_type = g_enum_register_static ("GstVideoflipMethod",
89 return videoflip_method_type;
93 gst_videoflip_get_type (void)
95 static GType videoflip_type = 0;
97 if (!videoflip_type) {
98 static const GTypeInfo videoflip_info = {
99 sizeof (GstVideoflipClass),
100 gst_videoflip_base_init,
102 gst_videoflip_class_init,
105 sizeof (GstVideoflip),
110 videoflip_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
111 "GstVideoflip", &videoflip_info, 0);
113 return videoflip_type;
116 static GstVideofilterFormat gst_videoflip_formats[] = {
118 {"YV12", 12, gst_videoflip_planar411,},
119 {"I420", 12, gst_videoflip_planar411,},
120 {"IYUV", 12, gst_videoflip_planar411,},
124 gst_videoflip_base_init (gpointer g_class)
126 static GstElementDetails videoflip_details =
127 GST_ELEMENT_DETAILS ("Video Flipper",
128 "Filter/Effect/Video",
129 "Flips and rotates video",
130 "David Schleef <ds@schleef.org>");
131 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
132 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
135 gst_element_class_set_details (element_class, &videoflip_details);
137 for (i = 0; i < G_N_ELEMENTS (gst_videoflip_formats); i++) {
138 gst_videofilter_class_add_format (videofilter_class,
139 gst_videoflip_formats + i);
142 gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
146 gst_videoflip_class_init (gpointer g_class, gpointer class_data)
148 GObjectClass *gobject_class;
149 GstVideofilterClass *videofilter_class;
151 gobject_class = G_OBJECT_CLASS (g_class);
152 videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
154 gobject_class->set_property = gst_videoflip_set_property;
155 gobject_class->get_property = gst_videoflip_get_property;
157 g_object_class_install_property (gobject_class, ARG_METHOD,
158 g_param_spec_enum ("method", "method", "method",
159 GST_TYPE_VIDEOFLIP_METHOD, GST_VIDEOFLIP_METHOD_90R,
162 videofilter_class->setup = gst_videoflip_setup;
166 gst_videoflip_init (GTypeInstance * instance, gpointer g_class)
168 GstVideoflip *videoflip = GST_VIDEOFLIP (instance);
169 GstVideofilter *videofilter;
171 GST_DEBUG_OBJECT (videoflip, "gst_videoflip_init");
173 videofilter = GST_VIDEOFILTER (videoflip);
179 gst_videoflip_set_property (GObject * object, guint prop_id,
180 const GValue * value, GParamSpec * pspec)
182 GstVideoflip *videoflip;
183 GstVideofilter *videofilter;
185 g_return_if_fail (GST_IS_VIDEOFLIP (object));
186 videoflip = GST_VIDEOFLIP (object);
187 videofilter = GST_VIDEOFILTER (object);
189 GST_DEBUG_OBJECT (videoflip, "gst_videoflip_set_property");
192 videoflip->method = g_value_get_enum (value);
193 if (videofilter->inited) {
194 GST_DEBUG_OBJECT (videoflip, "setting up videoflip again");
195 gst_videofilter_setup (videofilter);
204 gst_videoflip_get_property (GObject * object, guint prop_id, GValue * value,
207 GstVideoflip *videoflip;
209 g_return_if_fail (GST_IS_VIDEOFLIP (object));
210 videoflip = GST_VIDEOFLIP (object);
214 g_value_set_enum (value, videoflip->method);
217 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
223 plugin_init (GstPlugin * plugin)
225 GST_DEBUG_CATEGORY_INIT (gst_videoflip_debug, "videoflip", 0, "videoflip");
227 return gst_element_register (plugin, "videoflip", GST_RANK_NONE,
231 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
234 "Flips and rotates video",
235 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
237 static void gst_videoflip_flip (GstVideoflip * videoflip,
238 unsigned char *dest, unsigned char *src, int sw, int sh, int dw, int dh);
242 gst_videoflip_setup (GstVideofilter * videofilter)
244 int from_width, from_height;
245 GstVideoflip *videoflip;
247 videoflip = GST_VIDEOFLIP (videofilter);
248 GST_DEBUG_OBJECT (videoflip, "gst_videoflip_setup");
250 from_width = gst_videofilter_get_input_width (videofilter);
251 from_height = gst_videofilter_get_input_height (videofilter);
253 if (from_width == 0 || from_height == 0) {
257 switch (videoflip->method) {
258 case GST_VIDEOFLIP_METHOD_90R:
259 case GST_VIDEOFLIP_METHOD_90L:
260 case GST_VIDEOFLIP_METHOD_TRANS:
261 case GST_VIDEOFLIP_METHOD_OTHER:
262 gst_videofilter_set_output_size (videofilter, from_height, from_width);
264 case GST_VIDEOFLIP_METHOD_IDENTITY:
265 case GST_VIDEOFLIP_METHOD_180:
266 case GST_VIDEOFLIP_METHOD_HORIZ:
267 case GST_VIDEOFLIP_METHOD_VERT:
268 gst_videofilter_set_output_size (videofilter, from_width, from_height);
271 g_assert_not_reached ();
275 GST_DEBUG_OBJECT (videoflip, "format=%p \"%s\" from %dx%d to %dx%d",
276 videofilter->format, videofilter->format->fourcc,
277 from_width, from_height, videofilter->to_width, videofilter->to_height);
279 if (videoflip->method == GST_VIDEOFLIP_METHOD_IDENTITY) {
280 GST_DEBUG_OBJECT (videoflip, "videoflip: using passthru");
281 videofilter->passthru = TRUE;
283 videofilter->passthru = FALSE;
288 gst_videoflip_planar411 (GstVideofilter * videofilter, void *dest, void *src)
290 GstVideoflip *videoflip;
296 g_return_if_fail (GST_IS_VIDEOFLIP (videofilter));
297 videoflip = GST_VIDEOFLIP (videofilter);
299 sw = videofilter->from_width;
300 sh = videofilter->from_height;
301 dw = videofilter->to_width;
302 dh = videofilter->to_height;
304 GST_LOG_OBJECT (videoflip, "videoflip: scaling planar 4:1:1 %dx%d to %dx%d",
307 gst_videoflip_flip (videoflip, dest, src, sw, sh, dw, dh);
317 gst_videoflip_flip (videoflip, dest, src, sw, sh, dw, dh);
322 gst_videoflip_flip (videoflip, dest, src, sw, sh, dw, dh);
326 gst_videoflip_flip (GstVideoflip * videoflip, unsigned char *dest,
327 unsigned char *src, int sw, int sh, int dw, int dh)
331 switch (videoflip->method) {
332 case GST_VIDEOFLIP_METHOD_90R:
333 for (y = 0; y < dh; y++) {
334 for (x = 0; x < dw; x++) {
335 dest[y * dw + x] = src[(sh - 1 - x) * sw + y];
339 case GST_VIDEOFLIP_METHOD_90L:
340 for (y = 0; y < dh; y++) {
341 for (x = 0; x < dw; x++) {
342 dest[y * dw + x] = src[x * sw + (sw - 1 - y)];
346 case GST_VIDEOFLIP_METHOD_180:
347 for (y = 0; y < dh; y++) {
348 for (x = 0; x < dw; x++) {
349 dest[y * dw + x] = src[(sh - 1 - y) * sw + (sw - 1 - x)];
353 case GST_VIDEOFLIP_METHOD_HORIZ:
354 for (y = 0; y < dh; y++) {
355 for (x = 0; x < dw; x++) {
356 dest[y * dw + x] = src[y * sw + (sw - 1 - x)];
360 case GST_VIDEOFLIP_METHOD_VERT:
361 for (y = 0; y < dh; y++) {
362 for (x = 0; x < dw; x++) {
363 dest[y * dw + x] = src[(sh - 1 - y) * sw + x];
367 case GST_VIDEOFLIP_METHOD_TRANS:
368 for (y = 0; y < dh; y++) {
369 for (x = 0; x < dw; x++) {
370 dest[y * dw + x] = src[x * sw + y];
374 case GST_VIDEOFLIP_METHOD_OTHER:
375 for (y = 0; y < dh; y++) {
376 for (x = 0; x < dw; x++) {
377 dest[y * dw + x] = src[(sh - 1 - x) * sw + (sw - 1 - y)];