summaryrefslogtreecommitdiffstats
path: root/gst/smooth
diff options
context:
space:
mode:
authorThomas Vander Stichele <thomas@apestaart.org>2004-03-14 22:34:33 +0000
committerThomas Vander Stichele <thomas@apestaart.org>2004-03-14 22:34:33 +0000
commit7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2 (patch)
treef863b467dea9559a6ec9c48affbfae11f8104164 /gst/smooth
parenta19db4bbdc4a15ea0d8f4d28e9a1302c9c3d1657 (diff)
downloadgst-plugins-bad-7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2.tar.gz
gst-plugins-bad-7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2.tar.bz2
gst-plugins-bad-7a778ee4b7ec09a1f5b2185c9cceee3910dfbdf2.zip
gst-indent
Original commit message from CVS: gst-indent
Diffstat (limited to 'gst/smooth')
-rw-r--r--gst/smooth/gstsmooth.c236
-rw-r--r--gst/smooth/gstsmooth.h45
2 files changed, 139 insertions, 142 deletions
diff --git a/gst/smooth/gstsmooth.c b/gst/smooth/gstsmooth.c
index 286786e8..0302c7e0 100644
--- a/gst/smooth/gstsmooth.c
+++ b/gst/smooth/gstsmooth.c
@@ -34,12 +34,14 @@ static GstElementDetails smooth_details = {
/* Smooth signals and args */
-enum {
+enum
+{
/* FILL ME */
LAST_SIGNAL
};
-enum {
+enum
+{
ARG_0,
ARG_ACTIVE,
ARG_TOLERANCE,
@@ -48,37 +50,36 @@ enum {
};
static GstStaticPadTemplate gst_smooth_src_template =
-GST_STATIC_PAD_TEMPLATE (
- "src",
- GST_PAD_SRC,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (
- GST_VIDEO_CAPS_YUV("I420")
- )
-);
+GST_STATIC_PAD_TEMPLATE ("src",
+ GST_PAD_SRC,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")
+ )
+ );
static GstStaticPadTemplate gst_smooth_sink_template =
-GST_STATIC_PAD_TEMPLATE (
- "sink",
- GST_PAD_SINK,
- GST_PAD_ALWAYS,
- GST_STATIC_CAPS (
- GST_VIDEO_CAPS_YUV("I420")
- )
-);
-
-static void gst_smooth_class_init (GstSmoothClass *klass);
-static void gst_smooth_base_init (GstSmoothClass *klass);
-static void gst_smooth_init (GstSmooth *smooth);
-
-static void gst_smooth_chain (GstPad *pad, GstData *_data);
-static void smooth_filter (unsigned char* dest, unsigned char* src,
- int width, int height, int tolerance, int filtersize);
-
-static void gst_smooth_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
-static void gst_smooth_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
+GST_STATIC_PAD_TEMPLATE ("sink",
+ GST_PAD_SINK,
+ GST_PAD_ALWAYS,
+ GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")
+ )
+ );
+
+static void gst_smooth_class_init (GstSmoothClass * klass);
+static void gst_smooth_base_init (GstSmoothClass * klass);
+static void gst_smooth_init (GstSmooth * smooth);
+
+static void gst_smooth_chain (GstPad * pad, GstData * _data);
+static void smooth_filter (unsigned char *dest, unsigned char *src,
+ int width, int height, int tolerance, int filtersize);
+
+static void gst_smooth_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec);
+static void gst_smooth_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec);
static GstElementClass *parent_class = NULL;
+
/*static guint gst_smooth_signals[LAST_SIGNAL] = { 0 }; */
GType
@@ -88,23 +89,24 @@ gst_smooth_get_type (void)
if (!smooth_type) {
static const GTypeInfo smooth_info = {
- sizeof(GstSmoothClass),
- (GBaseInitFunc)gst_smooth_base_init,
+ sizeof (GstSmoothClass),
+ (GBaseInitFunc) gst_smooth_base_init,
NULL,
- (GClassInitFunc)gst_smooth_class_init,
+ (GClassInitFunc) gst_smooth_class_init,
NULL,
NULL,
- sizeof(GstSmooth),
+ sizeof (GstSmooth),
0,
- (GInstanceInitFunc)gst_smooth_init,
+ (GInstanceInitFunc) gst_smooth_init,
};
- smooth_type = g_type_register_static(GST_TYPE_ELEMENT, "GstSmooth", &smooth_info, 0);
+ smooth_type =
+ g_type_register_static (GST_TYPE_ELEMENT, "GstSmooth", &smooth_info, 0);
}
return smooth_type;
}
static void
-gst_smooth_base_init (GstSmoothClass *klass)
+gst_smooth_base_init (GstSmoothClass * klass)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
@@ -116,25 +118,19 @@ gst_smooth_base_init (GstSmoothClass *klass)
}
static void
-gst_smooth_class_init (GstSmoothClass *klass)
+gst_smooth_class_init (GstSmoothClass * klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
- gobject_class = (GObjectClass*)klass;
- gstelement_class = (GstElementClass*)klass;
+ gobject_class = (GObjectClass *) klass;
+ gstelement_class = (GstElementClass *) klass;
- parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
+ parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
- g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_ACTIVE,
- g_param_spec_boolean("active","active","active",
- TRUE,G_PARAM_READWRITE)); /* CHECKME */
- g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_TOLERANCE,
- g_param_spec_int("tolerance","tolerance","tolerance",
- G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */
- g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FILTERSIZE,
- g_param_spec_int("filtersize","filtersize","filtersize",
- G_MININT,G_MAXINT,0,G_PARAM_READWRITE)); /* CHECKME */
+ g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_ACTIVE, g_param_spec_boolean ("active", "active", "active", TRUE, G_PARAM_READWRITE)); /* CHECKME */
+ g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_TOLERANCE, g_param_spec_int ("tolerance", "tolerance", "tolerance", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */
+ g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FILTERSIZE, g_param_spec_int ("filtersize", "filtersize", "filtersize", G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* CHECKME */
gobject_class->set_property = gst_smooth_set_property;
gobject_class->get_property = gst_smooth_get_property;
@@ -142,7 +138,7 @@ gst_smooth_class_init (GstSmoothClass *klass)
}
static GstPadLinkReturn
-gst_smooth_link (GstPad *pad, const GstCaps *caps)
+gst_smooth_link (GstPad * pad, const GstCaps * caps)
{
GstSmooth *filter;
GstStructure *structure;
@@ -154,22 +150,25 @@ gst_smooth_link (GstPad *pad, const GstCaps *caps)
ret = gst_structure_get_int (structure, "width", &filter->width);
ret &= gst_structure_get_int (structure, "height", &filter->height);
- if (!ret) return GST_PAD_LINK_REFUSED;
+ if (!ret)
+ return GST_PAD_LINK_REFUSED;
return gst_pad_try_set_caps (filter->srcpad, caps);
}
static void
-gst_smooth_init (GstSmooth *smooth)
+gst_smooth_init (GstSmooth * smooth)
{
- smooth->sinkpad = gst_pad_new_from_template (
- gst_static_pad_template_get (&gst_smooth_sink_template), "sink");
+ smooth->sinkpad =
+ gst_pad_new_from_template (gst_static_pad_template_get
+ (&gst_smooth_sink_template), "sink");
gst_pad_set_link_function (smooth->sinkpad, gst_smooth_link);
gst_pad_set_chain_function (smooth->sinkpad, gst_smooth_chain);
gst_element_add_pad (GST_ELEMENT (smooth), smooth->sinkpad);
- smooth->srcpad = gst_pad_new_from_template (
- gst_static_pad_template_get (&gst_smooth_sink_template), "src");
+ smooth->srcpad =
+ gst_pad_new_from_template (gst_static_pad_template_get
+ (&gst_smooth_sink_template), "src");
gst_pad_set_link_function (smooth->srcpad, gst_smooth_link);
gst_element_add_pad (GST_ELEMENT (smooth), smooth->srcpad);
@@ -180,55 +179,53 @@ gst_smooth_init (GstSmooth *smooth)
}
static void
-smooth_filter (unsigned char* dest, unsigned char* src, int width, int height, int tolerance, int filtersize)
+smooth_filter (unsigned char *dest, unsigned char *src, int width, int height,
+ int tolerance, int filtersize)
{
int refval, aktval, upperval, lowerval, numvalues, sum;
int x, y, fx, fy, fy1, fy2, fx1, fx2;
unsigned char *srcp = src;
fy1 = 0;
- fy2 = MIN(filtersize+1, height) * width;
+ fy2 = MIN (filtersize + 1, height) * width;
- for(y = 0; y < height; y++)
- {
- if (y>(filtersize+1)) fy1 += width;
- if (y<height-(filtersize+1)) fy2 += width;
+ for (y = 0; y < height; y++) {
+ if (y > (filtersize + 1))
+ fy1 += width;
+ if (y < height - (filtersize + 1))
+ fy2 += width;
- for(x = 0; x < width; x++)
- {
- refval = *src;
- upperval = refval + tolerance;
- lowerval = refval - tolerance;
+ for (x = 0; x < width; x++) {
+ refval = *src;
+ upperval = refval + tolerance;
+ lowerval = refval - tolerance;
numvalues = 1;
- sum = refval;
-
- fx1 = MAX(x-filtersize, 0) + fy1;
- fx2 = MIN(x+filtersize+1, width) + fy1;
-
- for (fy = fy1; fy<fy2; fy+=width)
- {
- for (fx = fx1; fx<fx2; fx++)
- {
- aktval = srcp[fx];
- if ((lowerval-aktval)*(upperval-aktval)<0)
- {
- numvalues ++;
- sum += aktval;
- }
- } /*for fx */
- fx1 += width;
- fx2 += width;
- } /*for fy */
+ sum = refval;
+
+ fx1 = MAX (x - filtersize, 0) + fy1;
+ fx2 = MIN (x + filtersize + 1, width) + fy1;
+
+ for (fy = fy1; fy < fy2; fy += width) {
+ for (fx = fx1; fx < fx2; fx++) {
+ aktval = srcp[fx];
+ if ((lowerval - aktval) * (upperval - aktval) < 0) {
+ numvalues++;
+ sum += aktval;
+ }
+ } /*for fx */
+ fx1 += width;
+ fx2 += width;
+ } /*for fy */
src++;
- *dest++ = sum/numvalues;
+ *dest++ = sum / numvalues;
}
}
}
static void
-gst_smooth_chain (GstPad *pad, GstData *_data)
+gst_smooth_chain (GstPad * pad, GstData * _data)
{
GstBuffer *buf = GST_BUFFER (_data);
GstSmooth *smooth;
@@ -244,7 +241,7 @@ gst_smooth_chain (GstPad *pad, GstData *_data)
smooth = GST_SMOOTH (GST_OBJECT_PARENT (pad));
if (!smooth->active) {
- gst_pad_push(smooth->srcpad,GST_DATA (buf));
+ gst_pad_push (smooth->srcpad, GST_DATA (buf));
return;
}
@@ -253,23 +250,24 @@ gst_smooth_chain (GstPad *pad, GstData *_data)
GST_DEBUG ("smooth: have buffer of %d", GST_BUFFER_SIZE (buf));
- outbuf = gst_buffer_new();
+ outbuf = gst_buffer_new ();
GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (buf));
GST_BUFFER_SIZE (outbuf) = GST_BUFFER_SIZE (buf);
- lumsize = smooth->width*smooth->height;
- chromsize = lumsize/4;
+ lumsize = smooth->width * smooth->height;
+ chromsize = lumsize / 4;
- smooth_filter (GST_BUFFER_DATA (outbuf), data, smooth->width, smooth->height,
- smooth->tolerance, smooth->filtersize);
+ smooth_filter (GST_BUFFER_DATA (outbuf), data, smooth->width, smooth->height,
+ smooth->tolerance, smooth->filtersize);
if (!smooth->lum_only) {
- smooth_filter (GST_BUFFER_DATA (outbuf)+lumsize, data+lumsize, smooth->width/2, smooth->height/2,
- smooth->tolerance, smooth->filtersize/2);
- smooth_filter (GST_BUFFER_DATA (outbuf)+lumsize+chromsize, data+lumsize+chromsize, smooth->width/2,
- smooth->height/2, smooth->tolerance, smooth->filtersize/2);
- }
- else {
- memcpy (GST_BUFFER_DATA (outbuf)+lumsize, data+lumsize, chromsize*2);
+ smooth_filter (GST_BUFFER_DATA (outbuf) + lumsize, data + lumsize,
+ smooth->width / 2, smooth->height / 2, smooth->tolerance,
+ smooth->filtersize / 2);
+ smooth_filter (GST_BUFFER_DATA (outbuf) + lumsize + chromsize,
+ data + lumsize + chromsize, smooth->width / 2, smooth->height / 2,
+ smooth->tolerance, smooth->filtersize / 2);
+ } else {
+ memcpy (GST_BUFFER_DATA (outbuf) + lumsize, data + lumsize, chromsize * 2);
}
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
@@ -280,13 +278,14 @@ gst_smooth_chain (GstPad *pad, GstData *_data)
}
static void
-gst_smooth_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+gst_smooth_set_property (GObject * object, guint prop_id, const GValue * value,
+ GParamSpec * pspec)
{
GstSmooth *smooth;
/* it's not null if we got it, but it might not be ours */
- g_return_if_fail(GST_IS_SMOOTH(object));
- smooth = GST_SMOOTH(object);
+ g_return_if_fail (GST_IS_SMOOTH (object));
+ smooth = GST_SMOOTH (object);
switch (prop_id) {
case ARG_ACTIVE:
@@ -307,13 +306,14 @@ gst_smooth_set_property (GObject *object, guint prop_id, const GValue *value, GP
}
static void
-gst_smooth_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+gst_smooth_get_property (GObject * object, guint prop_id, GValue * value,
+ GParamSpec * pspec)
{
GstSmooth *smooth;
/* it's not null if we got it, but it might not be ours */
- g_return_if_fail(GST_IS_SMOOTH(object));
- smooth = GST_SMOOTH(object);
+ g_return_if_fail (GST_IS_SMOOTH (object));
+ smooth = GST_SMOOTH (object);
switch (prop_id) {
case ARG_ACTIVE:
@@ -336,20 +336,14 @@ gst_smooth_get_property (GObject *object, guint prop_id, GValue *value, GParamSp
static gboolean
-plugin_init (GstPlugin *plugin)
+plugin_init (GstPlugin * plugin)
{
- return gst_element_register(plugin, "smooth",
- GST_RANK_NONE, GST_TYPE_SMOOTH);
+ return gst_element_register (plugin, "smooth",
+ GST_RANK_NONE, GST_TYPE_SMOOTH);
}
-GST_PLUGIN_DEFINE (
- GST_VERSION_MAJOR,
- GST_VERSION_MINOR,
- "smooth",
- "Apply a smooth filter to an image",
- plugin_init,
- VERSION,
- "LGPL",
- GST_PACKAGE,
- GST_ORIGIN
-)
+GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
+ GST_VERSION_MINOR,
+ "smooth",
+ "Apply a smooth filter to an image",
+ plugin_init, VERSION, "LGPL", GST_PACKAGE, GST_ORIGIN)
diff --git a/gst/smooth/gstsmooth.h b/gst/smooth/gstsmooth.h
index eb32de36..aae3cc21 100644
--- a/gst/smooth/gstsmooth.h
+++ b/gst/smooth/gstsmooth.h
@@ -25,8 +25,9 @@
#include <gst/gst.h>
#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
+extern "C"
+{
+#endif /* __cplusplus */
#define GST_TYPE_SMOOTH \
@@ -40,34 +41,36 @@ extern "C" {
#define GST_IS_SMOOTH_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SMOOTH))
-typedef struct _GstSmooth GstSmooth;
-typedef struct _GstSmoothClass GstSmoothClass;
+ typedef struct _GstSmooth GstSmooth;
+ typedef struct _GstSmoothClass GstSmoothClass;
-struct _GstSmooth {
- GstElement element;
+ struct _GstSmooth
+ {
+ GstElement element;
- int format;
- int width;
- int height;
+ int format;
+ int width;
+ int height;
- gboolean active;
- int tolerance;
- int filtersize;
- gboolean lum_only;
+ gboolean active;
+ int tolerance;
+ int filtersize;
+ gboolean lum_only;
- GstPad *sinkpad,*srcpad;
-};
+ GstPad *sinkpad, *srcpad;
+ };
-struct _GstSmoothClass {
- GstElementClass parent_class;
-};
+ struct _GstSmoothClass
+ {
+ GstElementClass parent_class;
+ };
-GType gst_smooth_get_type(void);
+ GType gst_smooth_get_type (void);
#ifdef __cplusplus
}
-#endif /* __cplusplus */
+#endif /* __cplusplus */
-#endif /* __GST_SMOOTH_H__ */
+#endif /* __GST_SMOOTH_H__ */