/*
* GStreamer
- * Copyright (C) 2010 Luis de Bethencourt <luis@debethencourt.com>
- *
+ * Copyright (C) <2010-2015> Luis de Bethencourt <luis@debethencourt.com>
+ *
* Solarize - curve adjustment video effect.
* Based on Pete Warden's FreeFrame plugin with the same name.
*
*
* 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.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*/
/**
* SECTION:element-solarize
+ * @title: solarize
*
* Solarize does a smart inverse in a video stream in realtime.
*
- * <refsect2>
- * <title>Example launch line</title>
+ * ## Example launch line
* |[
- * gst-launch -v videotestsrc ! solarize ! ffmpegcolorspace ! autovideosink
+ * gst-launch-1.0 -v videotestsrc ! solarize ! videoconvert ! autovideosink
* ]| This pipeline shows the effect of solarize on a test stream
- * </refsect2>
+ *
*/
#ifdef HAVE_CONFIG_H
#include "gstplugin.h"
#include "gstsolarize.h"
-#include <gst/video/video.h>
-
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
+#define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ BGRx, RGBx }")
#else
-#define CAPS_STR GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR
+#define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ xBGR, xRGB }")
#endif
/* Filter signals and args. */
PROP_THRESHOLD,
PROP_START,
PROP_END,
- PROP_SILENT
};
/* Initializations */
#define DEFAULT_START 50
#define DEFAULT_END 185
-static gint gate_int (gint value, gint min, gint max);
static void transform (guint32 * src, guint32 * dest, gint video_area,
gint threshold, gint start, gint end);
/* The capabilities of the inputs and outputs. */
-static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
+static GstStaticPadTemplate gst_solarize_sink_template =
+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",
+static GstStaticPadTemplate gst_solarize_src_template =
+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);
+#define gst_solarize_parent_class parent_class
+G_DEFINE_TYPE (GstSolarize, gst_solarize, 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 void gst_solarize_finalize (GObject * object);
-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);
+static GstFlowReturn gst_solarize_transform_frame (GstVideoFilter * vfilter,
+ GstVideoFrame * in_frame, GstVideoFrame * out_frame);
/* GObject vmethod implementations */
+/* Initialize the solarize's class. */
static void
-gst_solarize_base_init (gpointer gclass)
+gst_solarize_class_init (GstSolarizeClass * klass)
{
- GstElementClass *element_class = GST_ELEMENT_CLASS (gclass);
+ GObjectClass *gobject_class = (GObjectClass *) klass;
+ GstElementClass *gstelement_class = (GstElementClass *) klass;
+ GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
- gst_element_class_set_details_simple (element_class,
+ gst_element_class_set_static_metadata (gstelement_class,
"Solarize",
"Filter/Effect/Video",
"Solarize tunable inverse in the video signal.",
"Luis de Bethencourt <luis@debethencourt.com>");
- 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;
+ gst_element_class_add_static_pad_template (gstelement_class,
+ &gst_solarize_sink_template);
+ gst_element_class_add_static_pad_template (gstelement_class,
+ &gst_solarize_src_template);
gobject_class->set_property = gst_solarize_set_property;
gobject_class->get_property = gst_solarize_get_property;
+ gobject_class->finalize = gst_solarize_finalize;
g_object_class_install_property (gobject_class, PROP_THRESHOLD,
g_param_spec_uint ("threshold", "Threshold",
"End parameter", 0, 256, DEFAULT_END,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
- g_object_class_install_property (gobject_class, PROP_SILENT,
- g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?",
- FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-
- trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_solarize_set_caps);
- trans_class->transform = GST_DEBUG_FUNCPTR (gst_solarize_transform);
+ vfilter_class->transform_frame =
+ GST_DEBUG_FUNCPTR (gst_solarize_transform_frame);
}
/* Initialize the element,
* instantiate pads and add them to element,
- * set pad calback functions, and
+ * set pad callback functions, and
* initialize instance structure.
*/
static void
-gst_solarize_init (GstSolarize * filter, GstSolarizeClass * gclass)
+gst_solarize_init (GstSolarize * filter)
{
filter->threshold = DEFAULT_THRESHOLD;
filter->start = DEFAULT_START;
filter->end = DEFAULT_END;
- filter->silent = FALSE;
}
static void
GstSolarize *filter = GST_SOLARIZE (object);
switch (prop_id) {
- case PROP_SILENT:
- filter->silent = g_value_get_boolean (value);
- break;
case PROP_THRESHOLD:
filter->threshold = g_value_get_uint (value);
break;
GST_OBJECT_LOCK (filter);
switch (prop_id) {
- case PROP_SILENT:
- g_value_set_boolean (value, filter->silent);
- break;
case PROP_THRESHOLD:
g_value_set_uint (value, filter->threshold);
break;
GST_OBJECT_UNLOCK (filter);
}
-/* GstElement vmethod implementations */
-
-/* Handle the link with other elements. */
-static gboolean
-gst_solarize_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
- GstCaps * outcaps)
+static void
+gst_solarize_finalize (GObject * object)
{
- GstSolarize *filter = GST_SOLARIZE (btrans);
- GstStructure *structure;
- gboolean ret = FALSE;
-
- GST_OBJECT_LOCK (filter);
- structure = gst_caps_get_structure (incaps, 0);
- if (gst_structure_get_int (structure, "width", &filter->width) &&
- gst_structure_get_int (structure, "height", &filter->height)) {
- ret = TRUE;
- }
- GST_OBJECT_UNLOCK (filter);
-
- return ret;
+ G_OBJECT_CLASS (parent_class)->finalize (object);
}
+/* GstElement vmethod implementations */
+
/* Actual processing. */
static GstFlowReturn
-gst_solarize_transform (GstBaseTransform * btrans,
- GstBuffer * in_buf, GstBuffer * out_buf)
+gst_solarize_transform_frame (GstVideoFilter * vfilter,
+ GstVideoFrame * in_frame, GstVideoFrame * out_frame)
{
- GstSolarize *filter = GST_SOLARIZE (btrans);
+ GstSolarize *filter = GST_SOLARIZE (vfilter);
gint video_size, threshold, start, end;
- guint32 *src = (guint32 *) GST_BUFFER_DATA (in_buf);
- guint32 *dest = (guint32 *) GST_BUFFER_DATA (out_buf);
+ guint32 *src, *dest;
GstClockTime timestamp;
gint64 stream_time;
+ src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
+ dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
+
/* GstController: update the properties */
- timestamp = GST_BUFFER_TIMESTAMP (in_buf);
+ timestamp = GST_BUFFER_TIMESTAMP (in_frame->buffer);
stream_time =
- gst_segment_to_stream_time (&btrans->segment, GST_FORMAT_TIME, timestamp);
+ gst_segment_to_stream_time (&GST_BASE_TRANSFORM (filter)->segment,
+ GST_FORMAT_TIME, timestamp);
GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
GST_TIME_ARGS (timestamp));
end = filter->end;
GST_OBJECT_UNLOCK (filter);
- video_size = filter->width * filter->height;
+ video_size = GST_VIDEO_FRAME_WIDTH (in_frame) *
+ GST_VIDEO_FRAME_HEIGHT (in_frame);
+
transform (src, dest, video_size, threshold, start, end);
return GST_FLOW_OK;
}
/*** 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
{
guint32 in;
guint32 color[3];
+ gint period = 1, up_length = 1, down_length = 1;
gint x, c;
- gint floor = 0;
- gint ceiling = 255;
+ gint param;
+ static const guint ceiling = 255;
- gint period, up_length, down_length, height_scale, param;
+ if (end != start)
+ period = end - start;
- period = end - start;
- if (period == 0) {
- period = 1;
- }
+ if (threshold != start)
+ up_length = threshold - start;
- 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;
+ if (threshold != end)
+ down_length = end - threshold;
/* Loop through pixels. */
for (x = 0; x < video_area; x++) {
color[1] = (in >> 8) & 0xff;
color[2] = (in) & 0xff;
-
/* Loop through colors. */
for (c = 0; c < 3; c++) {
param = color[c];
param %= period;
if (param < up_length) {
- color[c] = param * height_scale;
+ color[c] = param * ceiling;
color[c] /= up_length;
- color[c] += floor;
} else {
color[c] = down_length - (param - up_length);
- color[c] *= height_scale;
+ color[c] *= ceiling;
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);
+ /* Clamp colors */
+ for (c = 0; c < 3; c++) {
+ if (G_UNLIKELY (color[c] > 255))
+ color[c] = 255;
+ }
*dest++ = (color[0] << 16) | (color[1] << 8) | color[2];
}