3 * Copyright (C) <2010-2015> Luis de Bethencourt <luis@debethencourt.com>
5 * Dodge - saturation video effect.
6 * Based on Pete Warden's FreeFrame plugin with the same name.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * Alternatively, the contents of this file may be used under the
27 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
28 * which case the following provisions apply instead of the ones
31 * This library is free software; you can redistribute it and/or
32 * modify it under the terms of the GNU Library General Public
33 * License as published by the Free Software Foundation; either
34 * version 2 of the License, or (at your option) any later version.
36 * This library is distributed in the hope that it will be useful,
37 * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
39 * Library General Public License for more details.
41 * You should have received a copy of the GNU Library General Public
42 * License along with this library; if not, write to the
43 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
44 * Boston, MA 02110-1301, USA.
48 * SECTION:element-dodge
51 * Dodge saturates the colors of a video stream in realtime.
53 * ## Example launch line
55 * gst-launch-1.0 -v videotestsrc ! dodge ! videoconvert ! autovideosink
56 * ]| This pipeline shows the effect of dodge on a test stream
67 #include "gstplugin.h"
70 GST_DEBUG_CATEGORY_STATIC (gst_dodge_debug);
71 #define GST_CAT_DEFAULT gst_dodge_debug
73 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
74 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ BGRx, RGBx }")
76 #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ xBGR, xRGB }")
79 #define gst_dodge_parent_class parent_class
80 G_DEFINE_TYPE (GstDodge, gst_dodge, GST_TYPE_VIDEO_FILTER);
82 /* Filter signals and args. */
95 static void transform (guint32 * src, guint32 * dest, gint video_area);
97 /* The capabilities of the inputs and outputs. */
99 static GstStaticPadTemplate gst_dodge_sink_template =
100 GST_STATIC_PAD_TEMPLATE ("sink",
103 GST_STATIC_CAPS (CAPS_STR)
106 static GstStaticPadTemplate gst_dodge_src_template =
107 GST_STATIC_PAD_TEMPLATE ("src",
110 GST_STATIC_CAPS (CAPS_STR)
113 static void gst_dodge_set_property (GObject * object, guint prop_id,
114 const GValue * value, GParamSpec * pspec);
115 static void gst_dodge_get_property (GObject * object, guint prop_id,
116 GValue * value, GParamSpec * pspec);
117 static void gst_dodge_finalize (GObject * object);
119 static GstFlowReturn gst_dodge_transform_frame (GstVideoFilter * vfilter,
120 GstVideoFrame * in_frame, GstVideoFrame * out_frame);
122 /* GObject vmethod implementations */
124 /* Initialize the dodge's class. */
126 gst_dodge_class_init (GstDodgeClass * klass)
128 GObjectClass *gobject_class = (GObjectClass *) klass;
129 GstElementClass *gstelement_class = (GstElementClass *) klass;
130 GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
132 gst_element_class_set_static_metadata (gstelement_class,
134 "Filter/Effect/Video",
135 "Dodge saturates the colors in the video signal.",
136 "Luis de Bethencourt <luis@debethencourt.com>");
138 gst_element_class_add_static_pad_template (gstelement_class,
139 &gst_dodge_sink_template);
140 gst_element_class_add_static_pad_template (gstelement_class,
141 &gst_dodge_src_template);
143 gobject_class->set_property = gst_dodge_set_property;
144 gobject_class->get_property = gst_dodge_get_property;
145 gobject_class->finalize = gst_dodge_finalize;
147 vfilter_class->transform_frame =
148 GST_DEBUG_FUNCPTR (gst_dodge_transform_frame);
151 /* Initialize the element,
152 * instantiate pads and add them to element,
153 * set pad calback functions, and
154 * initialize instance structure.
157 gst_dodge_init (GstDodge * filter)
162 gst_dodge_set_property (GObject * object, guint prop_id,
163 const GValue * value, GParamSpec * pspec)
167 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
173 gst_dodge_get_property (GObject * object, guint prop_id,
174 GValue * value, GParamSpec * pspec)
178 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
184 gst_dodge_finalize (GObject * object)
186 G_OBJECT_CLASS (parent_class)->finalize (object);
189 /* GstElement vmethod implementations */
191 /* Actual processing. */
193 gst_dodge_transform_frame (GstVideoFilter * vfilter,
194 GstVideoFrame * in_frame, GstVideoFrame * out_frame)
196 GstDodge *filter = GST_DODGE (vfilter);
200 GstClockTime timestamp;
203 src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
204 dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
206 /* GstController: update the properties */
207 timestamp = GST_BUFFER_TIMESTAMP (in_frame->buffer);
209 gst_segment_to_stream_time (&GST_BASE_TRANSFORM (filter)->segment,
210 GST_FORMAT_TIME, timestamp);
212 GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
213 GST_TIME_ARGS (timestamp));
215 if (GST_CLOCK_TIME_IS_VALID (stream_time))
216 gst_object_sync_values (GST_OBJECT (filter), stream_time);
218 video_size = GST_VIDEO_FRAME_WIDTH (in_frame) *
219 GST_VIDEO_FRAME_HEIGHT (in_frame);
221 transform (src, dest, video_size);
226 /* Entry point to initialize the plug-in.
227 * Register the element factories and other features. */
229 gst_dodge_plugin_init (GstPlugin * dodge)
231 /* debug category for fltering log messages */
232 GST_DEBUG_CATEGORY_INIT (gst_dodge_debug, "dodge", 0, "Template dodge");
234 return gst_element_register (dodge, "dodge", GST_RANK_NONE, GST_TYPE_DODGE);
237 /*** Now the image processing work.... ***/
239 /* Transform processes each frame. */
241 transform (guint32 * src, guint32 * dest, gint video_area)
244 gint x, red, green, blue;
246 for (x = 0; x < video_area; x++) {
249 red = (in >> 16) & 0xff;
250 green = (in >> 8) & 0xff;
253 red = (256 * red) / (256 - red);
254 green = (256 * green) / (256 - green);
255 blue = (256 * blue) / (256 - blue);
257 red = CLAMP (red, 0, 255);
258 green = CLAMP (green, 0, 255);
259 blue = CLAMP (blue, 0, 255);
261 *dest++ = (red << 16) | (green << 8) | blue;