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, "0", "Identity (no rotation)"},
72 {GST_VIDEOFLIP_METHOD_90R, "1", "Rotate clockwise 90 degrees"},
73 {GST_VIDEOFLIP_METHOD_180, "2", "Rotate 180 degrees"},
74 {GST_VIDEOFLIP_METHOD_90L, "3", "Rotate counter-clockwise 90 degrees"},
75 {GST_VIDEOFLIP_METHOD_HORIZ, "4", "Flip horizontally"},
76 {GST_VIDEOFLIP_METHOD_VERT, "5", "Flip vertically"},
77 {GST_VIDEOFLIP_METHOD_TRANS, "6",
78 "Flip across upper left/lower right diagonal"},
79 {GST_VIDEOFLIP_METHOD_OTHER, "7",
80 "Flip across upper right/lower left diagonal"},
84 if (!videoflip_method_type) {
85 videoflip_method_type = g_enum_register_static ("GstVideoflipMethod",
88 return videoflip_method_type;
92 gst_videoflip_get_type (void)
94 static GType videoflip_type = 0;
96 if (!videoflip_type) {
97 static const GTypeInfo videoflip_info = {
98 sizeof (GstVideoflipClass),
99 gst_videoflip_base_init,
101 gst_videoflip_class_init,
104 sizeof (GstVideoflip),
109 videoflip_type = g_type_register_static (GST_TYPE_VIDEOFILTER,
110 "GstVideoflip", &videoflip_info, 0);
112 return videoflip_type;
115 static GstVideofilterFormat gst_videoflip_formats[] = {
117 {"YV12", 12, gst_videoflip_planar411,},
118 {"I420", 12, gst_videoflip_planar411,},
119 {"IYUV", 12, gst_videoflip_planar411,},
123 gst_videoflip_base_init (gpointer g_class)
125 static GstElementDetails videoflip_details =
126 GST_ELEMENT_DETAILS ("Video Flipper",
127 "Filter/Effect/Video",
128 "Flips and rotates video",
129 "David Schleef <ds@schleef.org>");
130 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
131 GstVideofilterClass *videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
134 gst_element_class_set_details (element_class, &videoflip_details);
136 for (i = 0; i < G_N_ELEMENTS (gst_videoflip_formats); i++) {
137 gst_videofilter_class_add_format (videofilter_class,
138 gst_videoflip_formats + i);
141 gst_videofilter_class_add_pad_templates (GST_VIDEOFILTER_CLASS (g_class));
145 gst_videoflip_class_init (gpointer g_class, gpointer class_data)
147 GObjectClass *gobject_class;
148 GstVideofilterClass *videofilter_class;
150 gobject_class = G_OBJECT_CLASS (g_class);
151 videofilter_class = GST_VIDEOFILTER_CLASS (g_class);
153 gobject_class->set_property = gst_videoflip_set_property;
154 gobject_class->get_property = gst_videoflip_get_property;
156 g_object_class_install_property (gobject_class, ARG_METHOD,
157 g_param_spec_enum ("method", "method", "method",
158 GST_TYPE_VIDEOFLIP_METHOD, GST_VIDEOFLIP_METHOD_90R,
161 videofilter_class->setup = gst_videoflip_setup;
165 gst_videoflip_init (GTypeInstance * instance, gpointer g_class)
167 GstVideoflip *videoflip = GST_VIDEOFLIP (instance);
168 GstVideofilter *videofilter;
170 GST_DEBUG_OBJECT (videoflip, "gst_videoflip_init");
172 videofilter = GST_VIDEOFILTER (videoflip);
178 gst_videoflip_set_property (GObject * object, guint prop_id,
179 const GValue * value, GParamSpec * pspec)
181 GstVideoflip *videoflip;
182 GstVideofilter *videofilter;
184 g_return_if_fail (GST_IS_VIDEOFLIP (object));
185 videoflip = GST_VIDEOFLIP (object);
186 videofilter = GST_VIDEOFILTER (object);
188 GST_DEBUG_OBJECT (videoflip, "gst_videoflip_set_property");
191 videoflip->method = g_value_get_enum (value);
192 if (videofilter->inited) {
193 GST_DEBUG_OBJECT (videoflip, "setting up videoflip again");
194 gst_videofilter_setup (videofilter);
203 gst_videoflip_get_property (GObject * object, guint prop_id, GValue * value,
206 GstVideoflip *videoflip;
208 g_return_if_fail (GST_IS_VIDEOFLIP (object));
209 videoflip = GST_VIDEOFLIP (object);
213 g_value_set_enum (value, videoflip->method);
216 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
222 plugin_init (GstPlugin * plugin)
224 GST_DEBUG_CATEGORY_INIT (gst_videoflip_debug, "videoflip", 0, "videoflip");
226 return gst_element_register (plugin, "videoflip", GST_RANK_NONE,
230 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
233 "Flips and rotates video",
234 plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
236 static void gst_videoflip_flip (GstVideoflip * videoflip,
237 unsigned char *dest, unsigned char *src, int sw, int sh, int dw, int dh);
241 gst_videoflip_setup (GstVideofilter * videofilter)
243 int from_width, from_height;
244 GstVideoflip *videoflip;
246 videoflip = GST_VIDEOFLIP (videofilter);
247 GST_DEBUG_OBJECT (videoflip, "gst_videoflip_setup");
249 from_width = gst_videofilter_get_input_width (videofilter);
250 from_height = gst_videofilter_get_input_height (videofilter);
252 if (from_width == 0 || from_height == 0) {
256 switch (videoflip->method) {
257 case GST_VIDEOFLIP_METHOD_90R:
258 case GST_VIDEOFLIP_METHOD_90L:
259 case GST_VIDEOFLIP_METHOD_TRANS:
260 case GST_VIDEOFLIP_METHOD_OTHER:
261 gst_videofilter_set_output_size (videofilter, from_height, from_width);
263 case GST_VIDEOFLIP_METHOD_IDENTITY:
264 case GST_VIDEOFLIP_METHOD_180:
265 case GST_VIDEOFLIP_METHOD_HORIZ:
266 case GST_VIDEOFLIP_METHOD_VERT:
267 gst_videofilter_set_output_size (videofilter, from_width, from_height);
270 g_assert_not_reached ();
274 GST_DEBUG_OBJECT (videoflip, "format=%p \"%s\" from %dx%d to %dx%d",
275 videofilter->format, videofilter->format->fourcc,
276 from_width, from_height, videofilter->to_width, videofilter->to_height);
278 if (videoflip->method == GST_VIDEOFLIP_METHOD_IDENTITY) {
279 GST_DEBUG_OBJECT (videoflip, "videoflip: using passthru");
280 videofilter->passthru = TRUE;
282 videofilter->passthru = FALSE;
287 gst_videoflip_planar411 (GstVideofilter * videofilter, 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_LOG_OBJECT (videoflip, "videoflip: scaling planar 4:1:1 %dx%d to %dx%d",
306 gst_videoflip_flip (videoflip, dest, src, sw, sh, dw, dh);
316 gst_videoflip_flip (videoflip, dest, src, sw, sh, dw, dh);
321 gst_videoflip_flip (videoflip, dest, src, sw, sh, dw, dh);
325 gst_videoflip_flip (GstVideoflip * videoflip, unsigned char *dest,
326 unsigned char *src, int sw, int sh, int dw, int dh)
330 switch (videoflip->method) {
331 case GST_VIDEOFLIP_METHOD_90R:
332 for (y = 0; y < dh; y++) {
333 for (x = 0; x < dw; x++) {
334 dest[y * dw + x] = src[(sh - 1 - x) * sw + y];
338 case GST_VIDEOFLIP_METHOD_90L:
339 for (y = 0; y < dh; y++) {
340 for (x = 0; x < dw; x++) {
341 dest[y * dw + x] = src[x * sw + (sw - 1 - y)];
345 case GST_VIDEOFLIP_METHOD_180:
346 for (y = 0; y < dh; y++) {
347 for (x = 0; x < dw; x++) {
348 dest[y * dw + x] = src[(sh - 1 - y) * sw + (sw - 1 - x)];
352 case GST_VIDEOFLIP_METHOD_HORIZ:
353 for (y = 0; y < dh; y++) {
354 for (x = 0; x < dw; x++) {
355 dest[y * dw + x] = src[y * sw + (sw - 1 - x)];
359 case GST_VIDEOFLIP_METHOD_VERT:
360 for (y = 0; y < dh; y++) {
361 for (x = 0; x < dw; x++) {
362 dest[y * dw + x] = src[(sh - 1 - y) * sw + x];
366 case GST_VIDEOFLIP_METHOD_TRANS:
367 for (y = 0; y < dh; y++) {
368 for (x = 0; x < dw; x++) {
369 dest[y * dw + x] = src[x * sw + y];
373 case GST_VIDEOFLIP_METHOD_OTHER:
374 for (y = 0; y < dh; y++) {
375 for (x = 0; x < dw; x++) {
376 dest[y * dw + x] = src[(sh - 1 - x) * sw + (sw - 1 - y)];