diff --git a/configure.ac b/configure.ac index c878842d66..4259ab051d 100644 --- a/configure.ac +++ b/configure.ac @@ -278,6 +278,7 @@ AG_GST_CHECK_PLUGIN(dvdspu) AG_GST_CHECK_PLUGIN(festival) AG_GST_CHECK_PLUGIN(freeze) AG_GST_CHECK_PLUGIN(frei0r) +AG_GST_CHECK_PLUGIN(gaudieffects) AG_GST_CHECK_PLUGIN(geometrictransform) AG_GST_CHECK_PLUGIN(h264parse) AG_GST_CHECK_PLUGIN(hdvparse) @@ -1684,6 +1685,7 @@ gst/dvdspu/Makefile gst/festival/Makefile gst/freeze/Makefile gst/frei0r/Makefile +gst/gaudieffects/Makefile gst/geometrictransform/Makefile gst/h264parse/Makefile gst/hdvparse/Makefile diff --git a/gst/gaudieffects/Makefile.am b/gst/gaudieffects/Makefile.am new file mode 100644 index 0000000000..41b005ccdd --- /dev/null +++ b/gst/gaudieffects/Makefile.am @@ -0,0 +1,13 @@ +plugin_LTLIBRARIES = libgstgaudieffects.la + +libgstgaudieffects_la_SOURCES = gstburn.c gstchromium.c gstdilate.c \ + gstdodge.c gstexclusion.c gstsolarize.c gstplugin.c +libgstgaudieffects_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) +libgstgaudieffects_la_LIBADD = $(GST_LIBS) -lgstvideo-@GST_MAJORMINOR@ +libgstgaudieffects_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) +libgstgaudieffects_la_LIBTOOLFLAGS = --tag=disable-static + +# headers we need but don't want installed +noinst_HEADERS = \ + gstburn.h gstchromium.h gstdilate.h gstdodge.h \ + gstexclusion.h gstplugin.h gstsolarize.h diff --git a/gst/gaudieffects/gstburn.c b/gst/gaudieffects/gstburn.c new file mode 100644 index 0000000000..691c1cc9af --- /dev/null +++ b/gst/gaudieffects/gstburn.c @@ -0,0 +1,290 @@ +/* + * GStreamer + * Copyright (C) 2010 Luis de Bethencourt + * + * Burn - curve adjustment video effect. + * Based on Pete Warden's FreeFrame plugin with the same name. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * SECTION:element-burn + * + * Burn adjusts the colors of a video stream in realtime. + * + * + * Example launch line + * |[ + * gst-launch -v videotestsrc ! burn ! ffmpegcolorspace ! autovideosink + * ]| This pipeline shows the effect of burn on a test stream + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include "gstplugin.h" +#include "gstburn.h" + +#include +#include + +GST_DEBUG_CATEGORY_STATIC (gst_burn_debug); +#define GST_CAT_DEFAULT gst_burn_debug + +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +#define CAPS_STR GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_RGBx +#else +#define CAPS_STR GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR +#endif + +/* Filter signals and args. */ +enum +{ + LAST_SIGNAL +}; + +enum +{ + PROP_0, + PROP_SILENT +}; + +/* Initializations */ + +static gint gate_int (gint value, gint min, gint max); +static void transform (guint32 * src, guint32 * dest, gint video_area); + +/* The capabilities of the inputs and outputs. */ +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (CAPS_STR) + ); + +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (CAPS_STR) + ); + +GST_BOILERPLATE (Gstburn, gst_burn, GstVideoFilter, GST_TYPE_VIDEO_FILTER); + +static void gst_burn_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_burn_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + +static gboolean gst_burn_set_caps (GstBaseTransform * btrans, + GstCaps * incaps, GstCaps * outcaps); +static GstFlowReturn gst_burn_transform (GstBaseTransform * btrans, + GstBuffer * in_buf, GstBuffer * out_buf); + +/* GObject vmethod implementations */ + +static void +gst_burn_base_init (gpointer gclass) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); + + gst_element_class_set_details_simple (element_class, + "Burn", + "Filter/Effect/Video", + "Burn adjusts the colors in the video signal.", + "Luis de Bethencourt "); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_factory)); +} + +/* Initialize the burn's class. */ +static void +gst_burn_class_init (GstburnClass * klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass; + + gobject_class->set_property = gst_burn_set_property; + gobject_class->get_property = gst_burn_get_property; + + g_object_class_install_property (gobject_class, PROP_SILENT, + g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?", + FALSE, G_PARAM_READWRITE)); + + trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_burn_set_caps); + trans_class->transform = GST_DEBUG_FUNCPTR (gst_burn_transform); +} + +/* Initialize the new element, + * instantiate pads and add them to element, + * set pad calback functions, and + * initialize instance structure. + */ +static void +gst_burn_init (Gstburn * filter, GstburnClass * gclass) +{ + filter->silent = FALSE; +} + +static void +gst_burn_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + Gstburn *filter = GST_BURN (object); + + switch (prop_id) { + case PROP_SILENT: + filter->silent = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_burn_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + Gstburn *filter = GST_BURN (object); + + switch (prop_id) { + case PROP_SILENT: + g_value_set_boolean (value, filter->silent); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/* GstElement vmethod implementations */ + +/* Handle the link with other elements. */ +static gboolean +gst_burn_set_caps (GstBaseTransform * btrans, GstCaps * incaps, + GstCaps * outcaps) +{ + Gstburn *filter = GST_BURN (btrans); + GstStructure *structure; + gboolean ret = TRUE; + + structure = gst_caps_get_structure (incaps, 0); + + ret &= gst_structure_get_int (structure, "width", &filter->width); + ret &= gst_structure_get_int (structure, "height", &filter->height); + + return ret; +} + +/* Actual processing. */ +static GstFlowReturn +gst_burn_transform (GstBaseTransform * btrans, + GstBuffer * in_buf, GstBuffer * out_buf) +{ + Gstburn *filter = GST_BURN (btrans); + gint video_size; + guint32 *src = (guint32 *) GST_BUFFER_DATA (in_buf); + guint32 *dest = (guint32 *) GST_BUFFER_DATA (out_buf); + + video_size = filter->width * filter->height; + transform (src, dest, video_size); + + return GST_FLOW_OK; +} + +/* Entry point to initialize the plug-in. + * Register the element factories and other features. */ +gboolean +gst_burn_plugin_init (GstPlugin * burn) +{ + /* debug category for fltering log messages */ + GST_DEBUG_CATEGORY_INIT (gst_burn_debug, "burn", 0, "Template burn"); + + return gst_element_register (burn, "burn", GST_RANK_NONE, GST_TYPE_BURN); +} + +/*** Now the image processing work.... ***/ + +/* Keep the values inbounds. */ +static gint +gate_int (gint value, gint min, gint max) +{ + if (value < min) { + return min; + } else if (value > max) { + return max; + } else { + return value; + } +} + +/* Transform processes each frame. */ +static void +transform (guint32 * src, guint32 * dest, gint video_area) +{ + guint32 in, red, green, blue; + gint x; + gint adjustment = 175; + + for (x = 0; x < video_area; x++) { + in = *src++; + + red = (in >> 16) & 0xff; + green = (in >> 8) & 0xff; + blue = (in) & 0xff; + + red = 256 - ((256 * (255 - red)) / (red + adjustment)); + green = 256 - ((256 * (255 - green)) / (green + adjustment)); + blue = 256 - ((256 * (255 - blue)) / (blue + adjustment)); + + red = gate_int (red, 0, 255); + green = gate_int (green, 0, 255); + blue = gate_int (blue, 0, 255); + + *dest++ = (red << 16) | (green << 8) | blue; + } +} diff --git a/gst/gaudieffects/gstburn.h b/gst/gaudieffects/gstburn.h new file mode 100644 index 0000000000..21f734c158 --- /dev/null +++ b/gst/gaudieffects/gstburn.h @@ -0,0 +1,90 @@ +/* + * GStreamer + * Copyright (C) 2010 Luis de Bethencourt + * + * Burn - curve adjustment film video effect. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_BURN_H__ +#define __GST_BURN_H__ + +#include + +#include + +G_BEGIN_DECLS + +/* #defines don't like whitespacey bits */ +#define GST_TYPE_BURN \ + (gst_burn_get_type()) +#define GST_BURN(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_BURN,Gstburn)) +#define GST_BURN_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_BURN,GstburnClass)) +#define GST_IS_BURN(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_BURN)) +#define GST_IS_BURN_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_BURN)) + +typedef struct _Gstburn Gstburn; +typedef struct _GstburnClass GstburnClass; + +struct _Gstburn +{ + GstVideoFilter videofilter; + + /* < private > */ + + gint width, height; + + gboolean silent; +}; + +struct _GstburnClass +{ + GstVideoFilterClass parent_class; +}; + +GType gst_burn_get_type (void); + +G_END_DECLS + +#endif /* __GST_BURN_H__ */ diff --git a/gst/gaudieffects/gstchromium.c b/gst/gaudieffects/gstchromium.c new file mode 100644 index 0000000000..afb618b6fa --- /dev/null +++ b/gst/gaudieffects/gstchromium.c @@ -0,0 +1,343 @@ +/* + * GStreamer + * Copyright (C) 2010 Luis de Bethencourt + * + * Chromium - burning chrome video effect. + * Based on Pete Warden's FreeFrame plugin with the same name. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * SECTION:element-chromium + * + * Chromium breaks the colors of a video stream in realtime. + * + * + * Example launch line + * |[ + * gst-launch -v videotestsrc ! chromium ! ffmpegcolorspace ! autovideosink + * ]| This pipeline shows the effect of chromium on a test stream + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include "gstplugin.h" +#include "gstchromium.h" + +#include +#include + +GST_DEBUG_CATEGORY_STATIC (gst_chromium_debug); +#define GST_CAT_DEFAULT gst_chromium_debug + +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +#define CAPS_STR GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_RGBx +#else +#define CAPS_STR GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR +#endif + +/* Filter signals and args. */ +enum +{ + LAST_SIGNAL +}; + +enum +{ + PROP_0, + PROP_SILENT +}; + +/* Initializations */ + +const float pi = 3.141582f; + +gint cosTablePi = 512; +gint cosTableTwoPi = (2 * 512); +gint cosTableOne = 512; +gint cosTableMask = 1023; + +gint cosTable[2 * 512]; + +static gint gate_int (gint value, gint min, gint max); +void setup_cos_table (void); +static gint cos_from_table (int angle); +inline int abs_int (int val); +static void transform (guint32 * src, guint32 * dest, gint video_area); + +/* The capabilities of the inputs and outputs. */ + +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (CAPS_STR) + ); + +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (CAPS_STR) + ); + +GST_BOILERPLATE (Gstchromium, gst_chromium, GstVideoFilter, + GST_TYPE_VIDEO_FILTER); + +static void gst_chromium_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_chromium_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + +static gboolean gst_chromium_set_caps (GstBaseTransform * btrans, + GstCaps * incaps, GstCaps * outcaps); +static GstFlowReturn gst_chromium_transform (GstBaseTransform * btrans, + GstBuffer * in_buf, GstBuffer * out_buf); + +/* GObject vmethod implementations */ + +static void +gst_chromium_base_init (gpointer gclass) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); + + gst_element_class_set_details_simple (element_class, + "Chromium", + "Filter/Effect/Video", + "Chromium breaks the colors of the video signal.", + "Luis de Bethencourt "); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_factory)); +} + +/* Initialize the chromium's class. */ +static void +gst_chromium_class_init (GstchromiumClass * klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass; + + gobject_class->set_property = gst_chromium_set_property; + gobject_class->get_property = gst_chromium_get_property; + + g_object_class_install_property (gobject_class, PROP_SILENT, + g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?", + FALSE, G_PARAM_READWRITE)); + + trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_chromium_set_caps); + trans_class->transform = GST_DEBUG_FUNCPTR (gst_chromium_transform); +} + +/* Initialize the new element, + * instantiate pads and add them to element, + * set pad calback functions, and + * initialize instance structure. + */ +static void +gst_chromium_init (Gstchromium * filter, GstchromiumClass * gclass) +{ + filter->silent = FALSE; + + setup_cos_table (); +} + +static void +gst_chromium_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + Gstchromium *filter = GST_CHROMIUM (object); + + switch (prop_id) { + case PROP_SILENT: + filter->silent = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_chromium_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + Gstchromium *filter = GST_CHROMIUM (object); + + switch (prop_id) { + case PROP_SILENT: + g_value_set_boolean (value, filter->silent); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/* GstElement vmethod implementations */ + +/* Handle the link with other elements. */ +static gboolean +gst_chromium_set_caps (GstBaseTransform * btrans, GstCaps * incaps, + GstCaps * outcaps) +{ + Gstchromium *filter = GST_CHROMIUM (btrans); + GstStructure *structure; + gboolean ret = TRUE; + + structure = gst_caps_get_structure (incaps, 0); + + ret &= gst_structure_get_int (structure, "width", &filter->width); + ret &= gst_structure_get_int (structure, "height", &filter->height); + + return ret; +} + +/* Actual processing. */ +static GstFlowReturn +gst_chromium_transform (GstBaseTransform * btrans, + GstBuffer * in_buf, GstBuffer * out_buf) +{ + Gstchromium *filter = GST_CHROMIUM (btrans); + gint video_size; + guint32 *src = (guint32 *) GST_BUFFER_DATA (in_buf); + guint32 *dest = (guint32 *) GST_BUFFER_DATA (out_buf); + + video_size = filter->width * filter->height; + transform (src, dest, video_size); + + return GST_FLOW_OK; +} + +/* Entry point to initialize the plug-in. + * Register the element factories and other features. */ +gboolean +gst_chromium_plugin_init (GstPlugin * chromium) +{ + /* debug category for fltering log messages */ + GST_DEBUG_CATEGORY_INIT (gst_chromium_debug, "chromium", + 0, "Template chromium"); + + return gst_element_register (chromium, "chromium", GST_RANK_NONE, + GST_TYPE_CHROMIUM); +} + +/*** Now the image processing work.... ***/ + +/* Set up the cosine table. */ +void +setup_cos_table (void) +{ + int angle; + + for (angle = 0; angle < cosTableTwoPi; ++angle) { + float angleInRadians = ((float) (angle) / cosTablePi) * pi; + cosTable[angle] = (int) (cos (angleInRadians) * cosTableOne); + } +} + +/* Keep the values absolute. */ +inline int +abs_int (int val) +{ + if (val > 0) { + return val; + } else { + return -val; + } +} + +/* Keep the values inbounds. */ +static gint +gate_int (gint value, gint min, gint max) +{ + if (value < min) { + return min; + } else if (value > max) { + return max; + } else { + return value; + } +} + +/* Cosine from Table. */ +static gint +cos_from_table (int angle) +{ + angle &= cosTableMask; + return cosTable[angle]; +} + +/* Transform processes each frame. */ +static void +transform (guint32 * src, guint32 * dest, gint video_area) +{ + guint32 in, red, green, blue; + gint x; + guint32 edge_a, edge_b; + + edge_a = 200; + edge_b = 1; + + for (x = 0; x < video_area; x++) { + in = *src++; + + red = (in >> 16) & 0xff; + green = (in >> 8) & 0xff; + blue = (in) & 0xff; + + red = abs_int (cos_from_table ((red + edge_a) + ((red * edge_b) / 2))); + green = abs_int (cos_from_table ( + (green + edge_a) + ((green * edge_b) / 2))); + blue = abs_int (cos_from_table ((blue + edge_a) + ((blue * edge_b) / 2))); + + red = gate_int (red, 0, 255); + green = gate_int (green, 0, 255); + blue = gate_int (blue, 0, 255); + + *dest++ = (red << 16) | (green << 8) | blue; + } +} diff --git a/gst/gaudieffects/gstchromium.h b/gst/gaudieffects/gstchromium.h new file mode 100644 index 0000000000..74c73686a1 --- /dev/null +++ b/gst/gaudieffects/gstchromium.h @@ -0,0 +1,89 @@ +/* + * GStreamer + * Copyright (C) 2010 Luis de Bethencourt > + * + * Chromium - burning chrome video effect. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_CHROMIUM_H__ +#define __GST_CHROMIUM_H__ + +#include + +#include + +G_BEGIN_DECLS + +/* #defines don't like whitespacey bits */ +#define GST_TYPE_CHROMIUM \ + (gst_chromium_get_type()) +#define GST_CHROMIUM(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CHROMIUM,Gstchromium)) +#define GST_CHROMIUM_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CHROMIUM,GstchromiumClass)) +#define GST_IS_CHROMIUM(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CHROMIUM)) +#define GST_IS_CHROMIUM_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CHROMIUM)) + +typedef struct _Gstchromium Gstchromium; +typedef struct _GstchromiumClass GstchromiumClass; + +struct _Gstchromium +{ + GstVideoFilter videofilter; + + /* < private > */ + gint width, height; + + gboolean silent; +}; + +struct _GstchromiumClass +{ + GstVideoFilterClass parent_class; +}; + +GType gst_chromium_get_type (void); + +G_END_DECLS + +#endif /* __GST_CHROMIUM_H__ */ diff --git a/gst/gaudieffects/gstdilate.c b/gst/gaudieffects/gstdilate.c new file mode 100644 index 0000000000..7a68ccf595 --- /dev/null +++ b/gst/gaudieffects/gstdilate.c @@ -0,0 +1,342 @@ +/* + * GStreamer + * Copyright (C) 2010 Luis de Bethencourt + * + * Dilate - dilated eye video effect. + * Based on Pete Warden's FreeFrame plugin with the same name. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * SECTION:element-dilate + * + * Dilate adjusts the colors of a video stream in realtime. + * + * + * Example launch line + * |[ + * gst-launch -v videotestsrc ! dilate ! ffmpegcolorspace ! autovideosink + * ]| This pipeline shows the effect of dilate on a test stream + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include "gstplugin.h" +#include "gstdilate.h" + +#include +#include + +GST_DEBUG_CATEGORY_STATIC (gst_dilate_debug); +#define GST_CAT_DEFAULT gst_dilate_debug + +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +#define CAPS_STR GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_RGBx +#else +#define CAPS_STR GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR +#endif + +/* Filter signals and args. */ +enum +{ + LAST_SIGNAL +}; + +enum +{ + PROP_0, + PROP_SILENT +}; + +/* Initializations */ + +static void transform (guint32 * src, guint32 * dest, gint video_area, + gint width, gint height); +inline guint32 get_luminance (guint32 in); + +/* The capabilities of the inputs and outputs. */ + +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (CAPS_STR) + ); + +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (CAPS_STR) + ); + +GST_BOILERPLATE (Gstdilate, gst_dilate, GstVideoFilter, GST_TYPE_VIDEO_FILTER); + +static void gst_dilate_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_dilate_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + +static gboolean gst_dilate_set_caps (GstBaseTransform * btrans, + GstCaps * incaps, GstCaps * outcaps); +static GstFlowReturn gst_dilate_transform (GstBaseTransform * btrans, + GstBuffer * in_buf, GstBuffer * out_buf); + +/* GObject vmethod implementations */ + +static void +gst_dilate_base_init (gpointer gclass) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); + + gst_element_class_set_details_simple (element_class, + "Dilate", + "Filter/Effect/Video", + "Dilate copies the brightest pixel around.", + "Luis de Bethencourt "); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_factory)); +} + +/* Initialize the dilate's class. */ +static void +gst_dilate_class_init (GstdilateClass * klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass; + + gobject_class->set_property = gst_dilate_set_property; + gobject_class->get_property = gst_dilate_get_property; + + g_object_class_install_property (gobject_class, PROP_SILENT, + g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?", + FALSE, G_PARAM_READWRITE)); + + trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_dilate_set_caps); + trans_class->transform = GST_DEBUG_FUNCPTR (gst_dilate_transform); +} + +/* Initialize the new element, + * instantiate pads and add them to element, + * set pad calback functions, and + * initialize instance structure. + */ +static void +gst_dilate_init (Gstdilate * filter, GstdilateClass * gclass) +{ + filter->silent = FALSE; +} + +static void +gst_dilate_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + Gstdilate *filter = GST_DILATE (object); + + switch (prop_id) { + case PROP_SILENT: + filter->silent = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_dilate_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + Gstdilate *filter = GST_DILATE (object); + + switch (prop_id) { + case PROP_SILENT: + g_value_set_boolean (value, filter->silent); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/* GstElement vmethod implementations */ + +/* Handle the link with other elements. */ +static gboolean +gst_dilate_set_caps (GstBaseTransform * btrans, GstCaps * incaps, + GstCaps * outcaps) +{ + Gstdilate *filter = GST_DILATE (btrans); + GstStructure *structure; + gboolean ret = TRUE; + + structure = gst_caps_get_structure (incaps, 0); + ret &= gst_structure_get_int (structure, "width", &filter->width); + ret &= gst_structure_get_int (structure, "height", &filter->height); + + return ret; +} + +/* Actual processing. */ +static GstFlowReturn +gst_dilate_transform (GstBaseTransform * btrans, + GstBuffer * in_buf, GstBuffer * out_buf) +{ + Gstdilate *filter = GST_DILATE (btrans); + gint video_size; + + guint32 *src = (guint32 *) GST_BUFFER_DATA (in_buf); + guint32 *dest = (guint32 *) GST_BUFFER_DATA (out_buf); + + video_size = filter->width * filter->height; + + transform (src, dest, video_size, filter->width, filter->height); + + return GST_FLOW_OK; +} + +/* Entry point to initialize the plug-in. + * Register the element factories and other features. */ +gboolean +gst_dilate_plugin_init (GstPlugin * dilate) +{ + /* debug category for fltering log messages */ + GST_DEBUG_CATEGORY_INIT (gst_dilate_debug, "dilate", 0, "Template dilate"); + + return gst_element_register (dilate, "dilate", GST_RANK_NONE, + GST_TYPE_DILATE); +} + +/*** Now the image processing work.... ***/ + +/* Return luminance of the color */ +inline guint32 +get_luminance (guint32 in) +{ + guint32 red, green, blue, luminance; + + red = (in >> 16) & 0xff; + green = (in >> 8) & 0xff; + blue = (in) & 0xff; + + luminance = ((90 * red) + (115 * green) + (51 * blue)); + + return luminance; +} + +/* Transform processes each frame. */ +static void +transform (guint32 * src, guint32 * dest, gint video_area, gint width, + gint height) +{ + guint32 out_luminance, down_luminance, right_luminance; + guint32 up_luminance, left_luminance; + + guint32 *src_end = src + video_area; + + while (src != src_end) { + guint32 *src_line_start = src; + guint32 *src_line_end = src + width; + guint32 *up; + guint32 *left; + guint32 *down; + guint32 *right; + + while (src != src_line_end) { + + up = src - width; + if (up < src) { + up = src; + } + + left = src - 1; + if (left < src_line_start) { + left = src; + } + + down = src + width; + if (down >= src_end) { + down = src; + } + + right = src + 1; + if (right >= src_line_end) { + right = src; + } + + *dest = *src; + out_luminance = get_luminance (*src); + + down_luminance = get_luminance (*down); + if (down_luminance > out_luminance) { + *dest = *down; + out_luminance = down_luminance; + } + + right_luminance = get_luminance (*right); + if (right_luminance > out_luminance) { + *dest = *right; + out_luminance = right_luminance; + } + + up_luminance = get_luminance (*up); + if (up_luminance > out_luminance) { + *dest = *up; + out_luminance = up_luminance; + } + + left_luminance = get_luminance (*left); + if (left_luminance > out_luminance) { + *dest = *left; + out_luminance = left_luminance; + } + + src += 1; + dest += 1; + } + } +} diff --git a/gst/gaudieffects/gstdilate.h b/gst/gaudieffects/gstdilate.h new file mode 100644 index 0000000000..38fa0ff157 --- /dev/null +++ b/gst/gaudieffects/gstdilate.h @@ -0,0 +1,90 @@ +/* + * GStreamer + * Copyright (C) 2010 Luis de Bethencourt + * + * Dilate - curve adjustment film video effect. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_DILATE_H__ +#define __GST_DILATE_H__ + +#include + +#include + +G_BEGIN_DECLS + +/* #defines don't like whitespacey bits */ +#define GST_TYPE_DILATE \ + (gst_dilate_get_type()) +#define GST_DILATE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DILATE,Gstdilate)) +#define GST_DILATE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DILATE,GstdilateClass)) +#define GST_IS_DILATE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DILATE)) +#define GST_IS_DILATE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DILATE)) + +typedef struct _Gstdilate Gstdilate; +typedef struct _GstdilateClass GstdilateClass; + +struct _Gstdilate +{ + GstVideoFilter videofilter; + + /* < private > */ + + gint width, height; + + gboolean silent; +}; + +struct _GstdilateClass +{ + GstVideoFilterClass parent_class; +}; + +GType gst_dilate_get_type (void); + +G_END_DECLS + +#endif /* __GST_DILATE_H__ */ diff --git a/gst/gaudieffects/gstdodge.c b/gst/gaudieffects/gstdodge.c new file mode 100644 index 0000000000..db74dec884 --- /dev/null +++ b/gst/gaudieffects/gstdodge.c @@ -0,0 +1,290 @@ +/* + * GStreamer + * Copyright (C) 2010 Luis de Bethencourt + * + * Dodge - saturation video effect. + * Based on Pete Warden's FreeFrame plugin with the same name. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * SECTION:element-dodge + * + * Dodge saturates the colors of a video stream in realtime. + * + * + * Example launch line + * |[ + * gst-launch -v videotestsrc ! dodge ! ffmpegcolorspace ! autovideosink + * ]| This pipeline shows the effect of dodge on a test stream + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include "gstplugin.h" +#include "gstdodge.h" + +#include +#include + +GST_DEBUG_CATEGORY_STATIC (gst_dodge_debug); +#define GST_CAT_DEFAULT gst_dodge_debug + +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +#define CAPS_STR GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_RGBx +#else +#define CAPS_STR GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR +#endif + +/* Filter signals and args. */ +enum +{ + LAST_SIGNAL +}; + +enum +{ + PROP_0, + PROP_SILENT +}; + +/* Initializations */ + +static gint gate_int (gint value, gint min, gint max); +static void transform (guint32 * src, guint32 * dest, gint video_area); + +/* The capabilities of the inputs and outputs. */ + +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (CAPS_STR) + ); + +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (CAPS_STR) + ); + +GST_BOILERPLATE (Gstdodge, gst_dodge, GstVideoFilter, GST_TYPE_VIDEO_FILTER); + +static void gst_dodge_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_dodge_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + +static gboolean gst_dodge_set_caps (GstBaseTransform * btrans, + GstCaps * incaps, GstCaps * outcaps); +static GstFlowReturn gst_dodge_transform (GstBaseTransform * btrans, + GstBuffer * in_buf, GstBuffer * out_buf); + +/* GObject vmethod implementations */ + +static void +gst_dodge_base_init (gpointer gclass) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); + + gst_element_class_set_details_simple (element_class, + "Dodge", + "Filter/Effect/Video", + "Dodge saturates the colors in the video signal.", + "Luis de Bethencourt "); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_factory)); +} + +/* Initialize the dodge's class. */ +static void +gst_dodge_class_init (GstdodgeClass * klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass; + + gobject_class->set_property = gst_dodge_set_property; + gobject_class->get_property = gst_dodge_get_property; + + g_object_class_install_property (gobject_class, PROP_SILENT, + g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?", + FALSE, G_PARAM_READWRITE)); + + trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_dodge_set_caps); + trans_class->transform = GST_DEBUG_FUNCPTR (gst_dodge_transform); +} + +/* Initialize the new element, + * instantiate pads and add them to element, + * set pad calback functions, and + * initialize instance structure. + */ +static void +gst_dodge_init (Gstdodge * filter, GstdodgeClass * gclass) +{ + filter->silent = FALSE; +} + +static void +gst_dodge_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + Gstdodge *filter = GST_DODGE (object); + + switch (prop_id) { + case PROP_SILENT: + filter->silent = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_dodge_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + Gstdodge *filter = GST_DODGE (object); + + switch (prop_id) { + case PROP_SILENT: + g_value_set_boolean (value, filter->silent); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/* GstElement vmethod implementations */ + +/* Handle the link with other elements. */ +static gboolean +gst_dodge_set_caps (GstBaseTransform * btrans, GstCaps * incaps, + GstCaps * outcaps) +{ + Gstdodge *filter = GST_DODGE (btrans); + GstStructure *structure; + gboolean ret = TRUE; + + structure = gst_caps_get_structure (incaps, 0); + ret &= gst_structure_get_int (structure, "width", &filter->width); + ret &= gst_structure_get_int (structure, "height", &filter->height); + + return ret; +} + +/* Actual processing. */ +static GstFlowReturn +gst_dodge_transform (GstBaseTransform * btrans, + GstBuffer * in_buf, GstBuffer * out_buf) +{ + Gstdodge *filter = GST_DODGE (btrans); + guint32 *src = (guint32 *) GST_BUFFER_DATA (in_buf); + guint32 *dest = (guint32 *) GST_BUFFER_DATA (out_buf); + gint video_size; + + video_size = filter->width * filter->height; + + transform (src, dest, video_size); + + return GST_FLOW_OK; +} + +/* Entry point to initialize the plug-in. + * Register the element factories and other features. */ +gboolean +gst_dodge_plugin_init (GstPlugin * dodge) +{ + /* debug category for fltering log messages */ + GST_DEBUG_CATEGORY_INIT (gst_dodge_debug, "dodge", 0, "Template dodge"); + + return gst_element_register (dodge, "dodge", GST_RANK_NONE, GST_TYPE_DODGE); +} + +/*** Now the image processing work.... ***/ + +/* Keep the values inbounds. */ +static gint +gate_int (gint value, gint min, gint max) +{ + if (value < min) { + return min; + } else if (value > max) { + return max; + } else { + return value; + } +} + +/* Transform processes each frame. */ +static void +transform (guint32 * src, guint32 * dest, gint video_area) +{ + guint32 in, red, green, blue; + gint x; + + for (x = 0; x < video_area; x++) { + in = *src++; + + red = (in >> 16) & 0xff; + green = (in >> 8) & 0xff; + blue = (in) & 0xff; + + red = (256 * red) / (256 - red); + green = (256 * green) / (256 - green); + blue = (256 * blue) / (256 - blue); + + red = gate_int (red, 0, 255); + green = gate_int (green, 0, 255); + blue = gate_int (blue, 0, 255); + + *dest++ = (red << 16) | (green << 8) | blue; + } +} diff --git a/gst/gaudieffects/gstdodge.h b/gst/gaudieffects/gstdodge.h new file mode 100644 index 0000000000..a8d1e4c0fc --- /dev/null +++ b/gst/gaudieffects/gstdodge.h @@ -0,0 +1,90 @@ +/* + * GStreamer + * Copyright (C) 2010 Luis de Bethencourt > + * + * Dodge - saturation video effect. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_DODGE_H__ +#define __GST_DODGE_H__ + +#include + +#include + +G_BEGIN_DECLS + +/* #defines don't like whitespacey bits */ +#define GST_TYPE_DODGE \ + (gst_dodge_get_type()) +#define GST_DODGE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DODGE,Gstdodge)) +#define GST_DODGE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DODGE,GstdodgeClass)) +#define GST_IS_DODGE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DODGE)) +#define GST_IS_DODGE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DODGE)) + +typedef struct _Gstdodge Gstdodge; +typedef struct _GstdodgeClass GstdodgeClass; + +struct _Gstdodge +{ + GstVideoFilter videofilter; + + /* < private > */ + + gint width, height; + + gboolean silent; +}; + +struct _GstdodgeClass +{ + GstVideoFilterClass parent_class; +}; + +GType gst_dodge_get_type (void); + +G_END_DECLS + +#endif /* __GST_DODGE_H__ */ diff --git a/gst/gaudieffects/gstexclusion.c b/gst/gaudieffects/gstexclusion.c new file mode 100644 index 0000000000..364dd75645 --- /dev/null +++ b/gst/gaudieffects/gstexclusion.c @@ -0,0 +1,299 @@ +/* + * GStreamer + * Copyright (C) 2010 Luis de Bethencourt + * + * Exclusion - color exclusion video effect. + * Based on Pete Warden's FreeFrame plugin with the same name. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * SECTION:element-exclusion + * + * Exclusion saturates the colors of a video stream in realtime. + * + * + * Example launch line + * |[ + * gst-launch -v videotestsrc ! exclusion ! ffmpegcolorspace ! autovideosink + * ]| This pipeline shows the effect of exclusion on a test stream + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include "gstplugin.h" +#include "gstexclusion.h" + +#include +#include + +GST_DEBUG_CATEGORY_STATIC (gst_exclusion_debug); +#define GST_CAT_DEFAULT gst_exclusion_debug + +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +#define CAPS_STR GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_RGBx +#else +#define CAPS_STR GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR +#endif + +/* Filter signals and args. */ +enum +{ + LAST_SIGNAL +}; + +enum +{ + PROP_0, + PROP_SILENT +}; + +/* Initializations */ + +static gint gate_int (gint value, gint min, gint max); +static void transform (guint32 * src, guint32 * dest, gint video_area); + +/* The capabilities of the inputs and outputs. */ + +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (CAPS_STR) + ); + +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (CAPS_STR) + ); + +GST_BOILERPLATE (Gstexclusion, gst_exclusion, GstVideoFilter, + GST_TYPE_VIDEO_FILTER); + +static void gst_exclusion_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_exclusion_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + +static gboolean gst_exclusion_set_caps (GstBaseTransform * btrans, + GstCaps * incaps, GstCaps * outcaps); +static GstFlowReturn gst_exclusion_transform (GstBaseTransform * btrans, + GstBuffer * in_buf, GstBuffer * out_buf); + +/* GObject vmethod implementations */ + +static void +gst_exclusion_base_init (gpointer gclass) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); + + gst_element_class_set_details_simple (element_class, + "Exclusion", + "Filter/Effect/Video", + "Exclusion exclodes the colors in the video signal.", + "Luis de Bethencourt "); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_factory)); +} + +/* Initialize the exclusion's class. */ +static void +gst_exclusion_class_init (GstexclusionClass * klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass; + + gobject_class->set_property = gst_exclusion_set_property; + gobject_class->get_property = gst_exclusion_get_property; + + g_object_class_install_property (gobject_class, PROP_SILENT, + g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?", + FALSE, G_PARAM_READWRITE)); + + trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_exclusion_set_caps); + trans_class->transform = GST_DEBUG_FUNCPTR (gst_exclusion_transform); +} + +/* Initialize the new element, + * instantiate pads and add them to element, + * set pad calback functions, and + * initialize instance structure. + */ +static void +gst_exclusion_init (Gstexclusion * filter, GstexclusionClass * gclass) +{ + filter->silent = FALSE; +} + +static void +gst_exclusion_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + Gstexclusion *filter = GST_EXCLUSION (object); + + switch (prop_id) { + case PROP_SILENT: + filter->silent = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_exclusion_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + Gstexclusion *filter = GST_EXCLUSION (object); + + switch (prop_id) { + case PROP_SILENT: + g_value_set_boolean (value, filter->silent); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/* GstElement vmethod implementations */ + +/* Handle the link with other elements. */ +static gboolean +gst_exclusion_set_caps (GstBaseTransform * btrans, GstCaps * incaps, + GstCaps * outcaps) +{ + Gstexclusion *filter = GST_EXCLUSION (btrans); + GstStructure *structure; + gboolean ret = TRUE; + + structure = gst_caps_get_structure (incaps, 0); + ret &= gst_structure_get_int (structure, "width", &filter->width); + ret &= gst_structure_get_int (structure, "height", &filter->height); + + return ret; +} + +/* Actual processing. */ +static GstFlowReturn +gst_exclusion_transform (GstBaseTransform * btrans, + GstBuffer * in_buf, GstBuffer * out_buf) +{ + Gstexclusion *filter = GST_EXCLUSION (btrans); + gint video_size; + guint32 *src = (guint32 *) GST_BUFFER_DATA (in_buf); + guint32 *dest = (guint32 *) GST_BUFFER_DATA (out_buf); + + video_size = filter->width * filter->height; + + transform (src, dest, video_size); + + return GST_FLOW_OK; +} + +/* Entry point to initialize the plug-in. + * Register the element factories and other features. */ +gboolean +gst_exclusion_plugin_init (GstPlugin * exclusion) +{ + /* debug category for fltering log messages */ + GST_DEBUG_CATEGORY_INIT (gst_exclusion_debug, "exclusion", + 0, "Template exclusion"); + + return gst_element_register (exclusion, "exclusion", GST_RANK_NONE, + GST_TYPE_EXCLUSION); +} + +/*** Now the image processing work.... ***/ + +/* Keep the values inbounds. */ +static gint +gate_int (gint value, gint min, gint max) +{ + if (value < min) { + return min; + } else if (value > max) { + return max; + } else { + return value; + } +} + +/* Transform processes each frame. */ +static void +transform (guint32 * src, guint32 * dest, gint video_area) +{ + guint32 in, red, green, blue; + gint x; + gint factor = 175; + + for (x = 0; x < video_area; x++) { + in = *src++; + + red = (in >> 16) & 0xff; + green = (in >> 8) & 0xff; + blue = (in) & 0xff; + + red = factor - + (((factor - red) * (factor - red) / factor) + ((green * red) / factor)); + green = factor - + (((factor - green) * (factor - green) / factor) + + ((green * green) / factor)); + blue = factor - + (((factor - blue) * (factor - blue) / factor) + + ((blue * blue) / factor)); + + red = gate_int (red, 0, 255); + green = gate_int (green, 0, 255); + blue = gate_int (blue, 0, 255); + + *dest++ = (red << 16) | (green << 8) | blue; + } +} diff --git a/gst/gaudieffects/gstexclusion.h b/gst/gaudieffects/gstexclusion.h new file mode 100644 index 0000000000..8a6e1c74a5 --- /dev/null +++ b/gst/gaudieffects/gstexclusion.h @@ -0,0 +1,90 @@ +/* + * GStreamer + * Copyright (C) 2010 Luis de Bethencourt > + * + * Exclusion - color exclusion video effect. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_EXCLUSION_H__ +#define __GST_EXCLUSION_H__ + +#include + +#include + +G_BEGIN_DECLS + +/* #defines don't like whitespacey bits */ +#define GST_TYPE_EXCLUSION \ + (gst_exclusion_get_type()) +#define GST_EXCLUSION(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_EXCLUSION,Gstexclusion)) +#define GST_EXCLUSION_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_EXCLUSION,GstexclusionClass)) +#define GST_IS_EXCLUSION(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_EXCLUSION)) +#define GST_IS_EXCLUSION_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_EXCLUSION)) + +typedef struct _Gstexclusion Gstexclusion; +typedef struct _GstexclusionClass GstexclusionClass; + +struct _Gstexclusion +{ + GstVideoFilter videofilter; + + /* < private > */ + + gint width, height; + + gboolean silent; +}; + +struct _GstexclusionClass +{ + GstVideoFilterClass parent_class; +}; + +GType gst_exclusion_get_type (void); + +G_END_DECLS + +#endif /* __GST_EXCLUSION_H__ */ diff --git a/gst/gaudieffects/gstplugin.c b/gst/gaudieffects/gstplugin.c new file mode 100644 index 0000000000..d8cb57137c --- /dev/null +++ b/gst/gaudieffects/gstplugin.c @@ -0,0 +1,82 @@ +/* + * GStreamer + * Copyright (C) 2005 Thomas Vander Stichele + * Copyright (C) 2005 Ronald S. Bultje + * Copyright (C) 2010 Luis de Bethencourt + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include "gstplugin.h" + +/* PACKAGE: this is usually set by autotools depending on some _INIT macro + * in configure.ac and then written into and defined in config.h, but we can + * just set it ourselves here in case someone doesn't use autotools to + * compile this code. GST_PLUGIN_DEFINE needs PACKAGE to be defined. + */ +#ifndef PACKAGE +#define PACKAGE "gaudieffects" +#endif + +static gboolean +plugin_init (GstPlugin * plugin) +{ + gboolean ret = TRUE; + + ret &= gst_burn_plugin_init (plugin); + ret &= gst_chromium_plugin_init (plugin); + ret &= gst_dilate_plugin_init (plugin); + ret &= gst_dodge_plugin_init (plugin); + ret &= gst_exclusion_plugin_init (plugin); + ret &= gst_solarize_plugin_init (plugin); + + return ret; +} + +GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, + GST_VERSION_MINOR, + "gaudieffects", + "Gaudi video effects.", + plugin_init, VERSION, "LGPL", "GStreamer", "http://gstreamer.net/") diff --git a/gst/gaudieffects/gstplugin.h b/gst/gaudieffects/gstplugin.h new file mode 100644 index 0000000000..4794a39757 --- /dev/null +++ b/gst/gaudieffects/gstplugin.h @@ -0,0 +1,62 @@ +/* + * GStreamer + * Copyright (C) 2005 Thomas Vander Stichele + * Copyright (C) 2005 Ronald S. Bultje + * Copyright (C) 2010 Luis de Bethencourt + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_GAUDI_EFFECTS_H__ +#define __GST_GAUDI_EFFECTS_H__ + +#include + +G_BEGIN_DECLS + +gboolean gst_burn_plugin_init (GstPlugin * chromium); +gboolean gst_chromium_plugin_init (GstPlugin * chromium); +gboolean gst_dilate_plugin_init (GstPlugin * chromium); +gboolean gst_dodge_plugin_init (GstPlugin * chromium); +gboolean gst_exclusion_plugin_init (GstPlugin * chromium); +gboolean gst_solarize_plugin_init (GstPlugin * chromium); + +G_END_DECLS + +#endif /* __GST_GAUDI_EFFECTS_H__ */ diff --git a/gst/gaudieffects/gstsolarize.c b/gst/gaudieffects/gstsolarize.c new file mode 100644 index 0000000000..8b0bc2ca97 --- /dev/null +++ b/gst/gaudieffects/gstsolarize.c @@ -0,0 +1,334 @@ +/* + * GStreamer + * Copyright (C) 2010 Luis de Bethencourt + * + * Solarize - curve adjustment video effect. + * Based on Pete Warden's FreeFrame plugin with the same name. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * SECTION:element-solarize + * + * Solarize does a smart inverse in a video stream in realtime. + * + * + * Example launch line + * |[ + * gst-launch -v videotestsrc ! solarize ! ffmpegcolorspace ! autovideosink + * ]| This pipeline shows the effect of solarize on a test stream + * + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include + +#include "gstplugin.h" +#include "gstsolarize.h" + +#include +#include + +GST_DEBUG_CATEGORY_STATIC (gst_solarize_debug); +#define GST_CAT_DEFAULT gst_solarize_debug + +#if G_BYTE_ORDER == G_LITTLE_ENDIAN +#define CAPS_STR GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_RGBx +#else +#define CAPS_STR GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR +#endif + +/* Filter signals and args. */ +enum +{ + LAST_SIGNAL +}; + +enum +{ + PROP_0, + PROP_SILENT +}; + +/* Initializations */ + +static gint gate_int (gint value, gint min, gint max); +static void transform (guint32 * src, guint32 * dest, gint video_area); + +/* The capabilities of the inputs and outputs. */ + +static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (CAPS_STR) + ); + +static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (CAPS_STR) + ); + +GST_BOILERPLATE (Gstsolarize, gst_solarize, GstVideoFilter, + GST_TYPE_VIDEO_FILTER); + +static void gst_solarize_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_solarize_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); + +static gboolean gst_solarize_set_caps (GstBaseTransform * btrans, + GstCaps * incaps, GstCaps * outcaps); +static GstFlowReturn gst_solarize_transform (GstBaseTransform * btrans, + GstBuffer * in_buf, GstBuffer * out_buf); + +/* GObject vmethod implementations */ + +static void +gst_solarize_base_init (gpointer gclass) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (gclass); + + gst_element_class_set_details_simple (element_class, + "Solarize", + "Filter/Effect/Video", + "Solarize tunable inverse in the video signal.", + "Luis de Bethencourt "); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&src_factory)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&sink_factory)); +} + +/* Initialize the solarize's class. */ +static void +gst_solarize_class_init (GstsolarizeClass * klass) +{ + GObjectClass *gobject_class = (GObjectClass *) klass; + GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass; + + gobject_class->set_property = gst_solarize_set_property; + gobject_class->get_property = gst_solarize_get_property; + + g_object_class_install_property (gobject_class, PROP_SILENT, + g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?", + FALSE, G_PARAM_READWRITE)); + + trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_solarize_set_caps); + trans_class->transform = GST_DEBUG_FUNCPTR (gst_solarize_transform); +} + +/* Initialize the new element, + * instantiate pads and add them to element, + * set pad calback functions, and + * initialize instance structure. + */ +static void +gst_solarize_init (Gstsolarize * filter, GstsolarizeClass * gclass) +{ + filter->silent = FALSE; +} + +static void +gst_solarize_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) +{ + Gstsolarize *filter = GST_SOLARIZE (object); + + switch (prop_id) { + case PROP_SILENT: + filter->silent = g_value_get_boolean (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +gst_solarize_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec) +{ + Gstsolarize *filter = GST_SOLARIZE (object); + + switch (prop_id) { + case PROP_SILENT: + g_value_set_boolean (value, filter->silent); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +/* GstElement vmethod implementations */ + +/* Handle the link with other elements. */ +static gboolean +gst_solarize_set_caps (GstBaseTransform * btrans, GstCaps * incaps, + GstCaps * outcaps) +{ + Gstsolarize *filter = GST_SOLARIZE (btrans); + GstStructure *structure; + gboolean ret = TRUE; + + structure = gst_caps_get_structure (incaps, 0); + ret &= gst_structure_get_int (structure, "width", &filter->width); + ret &= gst_structure_get_int (structure, "height", &filter->height); + + return ret; +} + +/* Actual processing. */ +static GstFlowReturn +gst_solarize_transform (GstBaseTransform * btrans, + GstBuffer * in_buf, GstBuffer * out_buf) +{ + Gstsolarize *filter = GST_SOLARIZE (btrans); + gint video_size; + guint32 *src = (guint32 *) GST_BUFFER_DATA (in_buf); + guint32 *dest = (guint32 *) GST_BUFFER_DATA (out_buf); + + video_size = filter->width * filter->height; + + transform (src, dest, video_size); + + return GST_FLOW_OK; +} + +/* Entry point to initialize the plug-in. + * Register the element factories and other features. */ +gboolean +gst_solarize_plugin_init (GstPlugin * solarize) +{ + /* debug category for fltering log messages */ + GST_DEBUG_CATEGORY_INIT (gst_solarize_debug, "solarize", + 0, "Template solarize"); + + return gst_element_register (solarize, "solarize", GST_RANK_NONE, + GST_TYPE_SOLARIZE); +} + +/*** Now the image processing work.... ***/ + +/* Keep the values inbounds. */ +static gint +gate_int (gint value, gint min, gint max) +{ + if (value < min) { + return min; + } else if (value > max) { + return max; + } else { + return value; + } +} + +/* Transform processes each frame. */ +static void +transform (guint32 * src, guint32 * dest, gint video_area) +{ + guint32 in; + guint32 color[3]; + gint x, c; + gint threshold = 127; + gint start = 50; + gint end = 185; + gint floor = 0; + gint ceiling = 255; + + gint period, up_length, down_length, height_scale, param; + + period = end - start; + if (period == 0) { + period = 1; + } + + up_length = threshold - start; + if (up_length == 0) { + up_length = 1; + } + + down_length = end - threshold; + if (down_length == 0) { + down_length = 1; + } + + height_scale = ceiling - floor; + + /* Loop through pixels. */ + for (x = 0; x < video_area; x++) { + in = *src++; + + color[0] = (in >> 16) & 0xff; + color[1] = (in >> 8) & 0xff; + color[2] = (in) & 0xff; + + /* Loop through colors. */ + for (c = 0; c < 3; c++) { + param = color[c]; + param += 256; + param -= start; + param %= period; + + if (param < up_length) { + color[c] = param * height_scale; + color[c] /= up_length; + color[c] += floor; + } else { + color[c] = down_length - (param - up_length); + color[c] *= height_scale; + color[c] /= down_length; + color[c] += floor; + } + } + + color[0] = gate_int (color[0], 0, 255); + color[1] = gate_int (color[1], 0, 255); + color[2] = gate_int (color[2], 0, 255); + + *dest++ = (color[0] << 16) | (color[1] << 8) | color[2]; + } +} diff --git a/gst/gaudieffects/gstsolarize.h b/gst/gaudieffects/gstsolarize.h new file mode 100644 index 0000000000..739f01a89d --- /dev/null +++ b/gst/gaudieffects/gstsolarize.h @@ -0,0 +1,90 @@ +/* + * GStreamer + * Copyright (C) 2010 Luis de Bethencourt + * + * Solarize - smart inverse film video effect. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GST_SOLARIZE_H__ +#define __GST_SOLARIZE_H__ + +#include + +#include + +G_BEGIN_DECLS + +/* #defines don't like whitespacey bits */ +#define GST_TYPE_SOLARIZE \ + (gst_solarize_get_type()) +#define GST_SOLARIZE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SOLARIZE,Gstsolarize)) +#define GST_SOLARIZE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SOLARIZE,GstsolarizeClass)) +#define GST_IS_SOLARIZE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SOLARIZE)) +#define GST_IS_SOLARIZE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SOLARIZE)) + +typedef struct _Gstsolarize Gstsolarize; +typedef struct _GstsolarizeClass GstsolarizeClass; + +struct _Gstsolarize +{ + GstVideoFilter videofilter; + + /* < private > */ + + gint width, height; + + gboolean silent; +}; + +struct _GstsolarizeClass +{ + GstVideoFilterClass parent_class; +}; + +GType gst_solarize_get_type (void); + +G_END_DECLS + +#endif /* __GST_SOLARIZE_H__ */