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

View file

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