effectv: port agingtv

This commit is contained in:
Wim Taymans 2011-07-06 18:09:49 +02:00
parent da28ebfbe3
commit 50b0751799
2 changed files with 62 additions and 42 deletions

View file

@ -48,7 +48,6 @@
#include "gstaging.h"
#include "gsteffectv.h"
#include <gst/video/video.h>
#include <gst/controller/gstcontroller.h>
static const gint dx[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
@ -69,9 +68,9 @@ enum
#define DEFAULT_DUSTS TRUE
#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 ("{ xRGB, xBGR }")
#endif
static GstStaticPadTemplate gst_agingtv_src_template =
@ -88,27 +87,28 @@ GST_STATIC_PAD_TEMPLATE ("sink",
GST_STATIC_CAPS (CAPS_STR)
);
GST_BOILERPLATE (GstAgingTV, gst_agingtv, GstVideoFilter,
GST_TYPE_VIDEO_FILTER);
G_DEFINE_TYPE (GstAgingTV, gst_agingtv, GST_TYPE_VIDEO_FILTER);
static gboolean
gst_agingtv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
GstCaps * outcaps)
{
GstAgingTV *filter = GST_AGINGTV (btrans);
GstStructure *structure;
gboolean ret = FALSE;
GstVideoInfo info;
structure = gst_caps_get_structure (incaps, 0);
if (!gst_video_info_from_caps (&info, incaps))
goto invalid_caps;
GST_OBJECT_LOCK (filter);
if (gst_structure_get_int (structure, "width", &filter->width) &&
gst_structure_get_int (structure, "height", &filter->height)) {
ret = TRUE;
filter->info = info;
return TRUE;
/* ERRORS */
invalid_caps:
{
GST_ERROR_OBJECT (filter, "could not parse caps");
return GST_FLOW_ERROR;
}
GST_OBJECT_UNLOCK (filter);
return ret;
}
static void
@ -327,12 +327,12 @@ gst_agingtv_transform (GstBaseTransform * trans, GstBuffer * in,
GstBuffer * out)
{
GstAgingTV *agingtv = GST_AGINGTV (trans);
gint width, height, video_size;
guint32 *src = (guint32 *) GST_BUFFER_DATA (in);
guint32 *dest = (guint32 *) GST_BUFFER_DATA (out);
GstVideoFrame in_frame, out_frame;
gint area_scale;
GstFlowReturn ret = GST_FLOW_OK;
GstClockTime timestamp, stream_time;
gint width, height, stride, video_size;
guint32 *src, *dest;
timestamp = GST_BUFFER_TIMESTAMP (in);
stream_time =
@ -344,10 +344,20 @@ gst_agingtv_transform (GstBaseTransform * trans, GstBuffer * in,
if (GST_CLOCK_TIME_IS_VALID (stream_time))
gst_object_sync_values (G_OBJECT (agingtv), stream_time);
GST_OBJECT_LOCK (agingtv);
width = agingtv->width;
height = agingtv->height;
video_size = width * height;
if (!gst_video_frame_map (&in_frame, &agingtv->info, in, GST_MAP_READ))
goto invalid_in;
if (!gst_video_frame_map (&out_frame, &agingtv->info, out, GST_MAP_WRITE))
goto invalid_out;
width = GST_VIDEO_FRAME_WIDTH (&in_frame);
height = GST_VIDEO_FRAME_HEIGHT (&in_frame);
stride = GST_VIDEO_FRAME_PLANE_STRIDE (&in_frame, 0);
video_size = stride * height;
src = GST_VIDEO_FRAME_PLANE_DATA (&in_frame, 0);
dest = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, 0);
area_scale = width * height / 64 / 480;
if (area_scale <= 0)
@ -356,38 +366,38 @@ gst_agingtv_transform (GstBaseTransform * trans, GstBuffer * in,
if (agingtv->color_aging)
coloraging (src, dest, video_size, &agingtv->coloraging_state);
else
memcpy (dest, src, GST_BUFFER_SIZE (in));
memcpy (dest, src, video_size);
scratching (agingtv->scratches, agingtv->scratch_lines, dest, width, height);
if (agingtv->pits)
pits (dest, width, height, area_scale, &agingtv->pits_interval);
if (area_scale > 1 && agingtv->dusts)
dusts (dest, width, height, &agingtv->dust_interval, area_scale);
GST_OBJECT_UNLOCK (agingtv);
gst_video_frame_unmap (&in_frame);
gst_video_frame_unmap (&out_frame);
return ret;
}
static void
gst_agingtv_base_init (gpointer g_class)
/* ERRORS */
invalid_in:
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_set_details_simple (element_class, "AgingTV effect",
"Filter/Effect/Video",
"AgingTV adds age to video input using scratches and dust",
"Sam Lantinga <slouken@devolution.com>");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_agingtv_sink_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_agingtv_src_template));
GST_DEBUG_OBJECT (agingtv, "invalid input frame");
return GST_FLOW_ERROR;
}
invalid_out:
{
GST_DEBUG_OBJECT (agingtv, "invalid output frame");
gst_video_frame_unmap (&in_frame);
return GST_FLOW_ERROR;
}
}
static void
gst_agingtv_class_init (GstAgingTVClass * klass)
{
GObjectClass *gobject_class = (GObjectClass *) klass;
GstElementClass *gstelement_class = (GstElementClass *) klass;
GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
gobject_class->set_property = gst_agingtv_set_property;
@ -413,13 +423,23 @@ gst_agingtv_class_init (GstAgingTVClass * klass)
"Dusts", DEFAULT_DUSTS,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | GST_PARAM_CONTROLLABLE));
gst_element_class_set_details_simple (gstelement_class, "AgingTV effect",
"Filter/Effect/Video",
"AgingTV adds age to video input using scratches and dust",
"Sam Lantinga <slouken@devolution.com>");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_agingtv_sink_template));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_agingtv_src_template));
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_agingtv_set_caps);
trans_class->transform = GST_DEBUG_FUNCPTR (gst_agingtv_transform);
trans_class->start = GST_DEBUG_FUNCPTR (gst_agingtv_start);
}
static void
gst_agingtv_init (GstAgingTV * agingtv, GstAgingTVClass * klass)
gst_agingtv_init (GstAgingTV * agingtv)
{
agingtv->scratch_lines = DEFAULT_SCRATCH_LINES;
agingtv->color_aging = DEFAULT_COLOR_AGING;

View file

@ -29,6 +29,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/gstvideofilter.h>
G_BEGIN_DECLS
@ -61,8 +62,7 @@ struct _GstAgingTV
GstVideoFilter videofilter;
/* < private > */
gint width, height;
GstVideoInfo info;
gboolean color_aging;
gboolean pits;