diff options
Diffstat (limited to 'gst/virtualdub')
-rw-r--r-- | gst/virtualdub/gstvirtualdub.c | 97 | ||||
-rw-r--r-- | gst/virtualdub/gstvirtualdub.h | 12 | ||||
-rw-r--r-- | gst/virtualdub/gstxsharpen.c | 349 |
3 files changed, 217 insertions, 241 deletions
diff --git a/gst/virtualdub/gstvirtualdub.c b/gst/virtualdub/gstvirtualdub.c index c6091233..2495d449 100644 --- a/gst/virtualdub/gstvirtualdub.c +++ b/gst/virtualdub/gstvirtualdub.c @@ -25,69 +25,68 @@ #include "gstvirtualdub.h" -struct _elements_entry { +struct _elements_entry +{ gchar *name; - GType (*type) (void); + GType (*type) (void); GstElementDetails *details; - gboolean (*factoryinit) (GstElementFactory *factory); + gboolean (*factoryinit) (GstElementFactory * factory); }; static struct _elements_entry _elements[] = { - { "xsharpen", gst_xsharpen_get_type, &gst_xsharpen_details, NULL }, - { NULL, 0 }, + {"xsharpen", gst_xsharpen_get_type, &gst_xsharpen_details, NULL}, + {NULL, 0}, }; -GstPadTemplate* +GstPadTemplate * gst_virtualdub_src_factory (void) { static GstPadTemplate *templ = NULL; + if (!templ) { - templ = GST_PAD_TEMPLATE_NEW ( - "src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_CAPS_NEW ( - "virtualdub_src", - "video/x-raw-rgb", - "bpp", GST_PROPS_INT (32), - "depth", GST_PROPS_INT (32), - "endianness", GST_PROPS_INT (G_BYTE_ORDER), - "red_mask", GST_PROPS_INT (0xff0000), - "green_mask", GST_PROPS_INT (0xff00), - "blue_mask", GST_PROPS_INT (0xff), - "width", GST_PROPS_INT_RANGE (16, 4096), - "height", GST_PROPS_INT_RANGE (16, 4096), - "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT) - ) - ); + templ = GST_PAD_TEMPLATE_NEW ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_CAPS_NEW ("virtualdub_src", + "video/x-raw-rgb", + "bpp", GST_PROPS_INT (32), + "depth", GST_PROPS_INT (32), + "endianness", GST_PROPS_INT (G_BYTE_ORDER), + "red_mask", GST_PROPS_INT (0xff0000), + "green_mask", GST_PROPS_INT (0xff00), + "blue_mask", GST_PROPS_INT (0xff), + "width", GST_PROPS_INT_RANGE (16, 4096), + "height", GST_PROPS_INT_RANGE (16, 4096), + "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT) + ) + ); } return templ; } -GstPadTemplate* +GstPadTemplate * gst_virtualdub_sink_factory (void) { static GstPadTemplate *templ = NULL; + if (!templ) { - templ = GST_PAD_TEMPLATE_NEW ( - "sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_CAPS_NEW ( - "virtualdub_sink", - "video/x-raw-rgb", - "bpp", GST_PROPS_INT (32), - "depth", GST_PROPS_INT (32), - "endianness", GST_PROPS_INT (G_BYTE_ORDER), - "red_mask", GST_PROPS_INT (0xff0000), - "green_mask", GST_PROPS_INT (0xff00), - "blue_mask", GST_PROPS_INT (0xff), - "width", GST_PROPS_INT_RANGE (16, 4096), - "height", GST_PROPS_INT_RANGE (16, 4096), - "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT) - ) - ); + templ = GST_PAD_TEMPLATE_NEW ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_CAPS_NEW ("virtualdub_sink", + "video/x-raw-rgb", + "bpp", GST_PROPS_INT (32), + "depth", GST_PROPS_INT (32), + "endianness", GST_PROPS_INT (G_BYTE_ORDER), + "red_mask", GST_PROPS_INT (0xff0000), + "green_mask", GST_PROPS_INT (0xff00), + "blue_mask", GST_PROPS_INT (0xff), + "width", GST_PROPS_INT_RANGE (16, 4096), + "height", GST_PROPS_INT_RANGE (16, 4096), + "framerate", GST_PROPS_FLOAT_RANGE (0, G_MAXFLOAT) + ) + ); } return templ; } @@ -100,16 +99,16 @@ plugin_init (GModule * module, GstPlugin * plugin) while (_elements[i].name) { factory = gst_element_factory_new (_elements[i].name, - (_elements[i].type) (), - _elements[i].details); + (_elements[i].type) (), _elements[i].details); if (!factory) { - g_warning ("gst_virtualdub_new failed for `%s'", - _elements[i].name); + g_warning ("gst_virtualdub_new failed for `%s'", _elements[i].name); continue; } - gst_element_factory_add_pad_template (factory, gst_virtualdub_src_factory ()); - gst_element_factory_add_pad_template (factory, gst_virtualdub_sink_factory ()); + gst_element_factory_add_pad_template (factory, + gst_virtualdub_src_factory ()); + gst_element_factory_add_pad_template (factory, + gst_virtualdub_sink_factory ()); gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory)); if (_elements[i].factoryinit) { diff --git a/gst/virtualdub/gstvirtualdub.h b/gst/virtualdub/gstvirtualdub.h index f55d85e8..286aa39d 100644 --- a/gst/virtualdub/gstvirtualdub.h +++ b/gst/virtualdub/gstvirtualdub.h @@ -18,12 +18,12 @@ #include <gst/gst.h> -typedef unsigned int Pixel; -typedef unsigned int Pixel32; -typedef unsigned char Pixel8; -typedef int PixCoord; -typedef int PixDim; -typedef int PixOffset; +typedef unsigned int Pixel; +typedef unsigned int Pixel32; +typedef unsigned char Pixel8; +typedef int PixCoord; +typedef int PixDim; +typedef int PixOffset; #define R_MASK (0x00ff0000) diff --git a/gst/virtualdub/gstxsharpen.c b/gst/virtualdub/gstxsharpen.c index bc83ed62..df4d4547 100644 --- a/gst/virtualdub/gstxsharpen.c +++ b/gst/virtualdub/gstxsharpen.c @@ -57,8 +57,7 @@ GstElementDetails gst_xsharpen_details = { "", "Filter/Video/Effect", "LGPL", - "Apply a sharpen effect on video" - VERSION, + "Apply a sharpen effect on video" VERSION, "Jeremy SIMON <jsimon13@yahoo.fr>", "(C) 2000 Donald Graft", }; @@ -78,19 +77,20 @@ enum ARG_0, }; -static void gst_xsharpen_class_init (GstXsharpenClass * klass); -static void gst_xsharpen_init (GstXsharpen * sharpen); +static void gst_xsharpen_class_init (GstXsharpenClass * klass); +static void gst_xsharpen_init (GstXsharpen * sharpen); -static void gst_xsharpen_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec); -static void gst_xsharpen_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec); +static void gst_xsharpen_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_xsharpen_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); -static void gst_xsharpen_chain (GstPad * pad, GstData *_data); +static void gst_xsharpen_chain (GstPad * pad, GstData * _data); static GstElementClass *parent_class = NULL; -GType gst_xsharpen_get_type (void) +GType +gst_xsharpen_get_type (void) { static GType xsharpen_type = 0; @@ -106,7 +106,9 @@ GType gst_xsharpen_get_type (void) (GInstanceInitFunc) gst_xsharpen_init, }; - xsharpen_type = g_type_register_static (GST_TYPE_ELEMENT, "GstXsharpen", &xsharpen_info, 0); + xsharpen_type = + g_type_register_static (GST_TYPE_ELEMENT, "GstXsharpen", &xsharpen_info, + 0); } return xsharpen_type; } @@ -122,13 +124,13 @@ gst_xsharpen_class_init (GstXsharpenClass * klass) parent_class = g_type_class_ref (GST_TYPE_ELEMENT); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_STRENGTH, - g_param_spec_int("strength", "strength", "strength", - 0, 255, 255, (GParamFlags)G_PARAM_READWRITE )); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_STRENGTH, + g_param_spec_int ("strength", "strength", "strength", + 0, 255, 255, (GParamFlags) G_PARAM_READWRITE)); - g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_THRESHOLD, - g_param_spec_int("threshold", "threshold", "threshold", - 0, 255, 255, (GParamFlags)G_PARAM_READWRITE )); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_THRESHOLD, + g_param_spec_int ("threshold", "threshold", "threshold", + 0, 255, 255, (GParamFlags) G_PARAM_READWRITE)); gobject_class->set_property = gst_xsharpen_set_property; gobject_class->get_property = gst_xsharpen_get_property; @@ -147,7 +149,7 @@ gst_xsharpen_sinkconnect (GstPad * pad, GstCaps * caps) gst_caps_get_int (caps, "width", &sharpen->width); gst_caps_get_int (caps, "height", &sharpen->height); - sharpen->strengthinv = 255 - sharpen->strength; + sharpen->strengthinv = 255 - sharpen->strength; sharpen->dstpitch = sharpen->srcpitch = sharpen->width * sizeof (Pixel32); @@ -157,72 +159,74 @@ gst_xsharpen_sinkconnect (GstPad * pad, GstCaps * caps) static void gst_xsharpen_init (GstXsharpen * sharpen) { - sharpen->sinkpad = gst_pad_new_from_template (gst_virtualdub_sink_factory (), "sink"); + sharpen->sinkpad = + gst_pad_new_from_template (gst_virtualdub_sink_factory (), "sink"); gst_pad_set_chain_function (sharpen->sinkpad, gst_xsharpen_chain); gst_pad_set_link_function (sharpen->sinkpad, gst_xsharpen_sinkconnect); gst_element_add_pad (GST_ELEMENT (sharpen), sharpen->sinkpad); - sharpen->srcpad = gst_pad_new_from_template (gst_virtualdub_src_factory (), "src"); + sharpen->srcpad = + gst_pad_new_from_template (gst_virtualdub_src_factory (), "src"); gst_element_add_pad (GST_ELEMENT (sharpen), sharpen->srcpad); } static void -gst_xsharpen_chain (GstPad * pad, GstData *_data) +gst_xsharpen_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstXsharpen *xsharpen; - GstBuffer *outbuf; - gint x, y; - gint r, g, b, R, G, B; - Pixel32 p, min, max; - gint luma, lumac, lumamax, lumamin, mindiff, maxdiff; - Pixel32 *src_buf, *dst_buf, *src, *dst; + GstBuffer *outbuf; + gint x, y; + gint r, g, b, R, G, B; + Pixel32 p, min, max; + gint luma, lumac, lumamax, lumamin, mindiff, maxdiff; + Pixel32 *src_buf, *dst_buf, *src, *dst; xsharpen = GST_XSHARPEN (gst_pad_get_parent (pad)); - outbuf = gst_buffer_new (); - GST_BUFFER_SIZE (outbuf) = ( xsharpen->width * xsharpen->height * sizeof (Pixel32)); + outbuf = gst_buffer_new (); + GST_BUFFER_SIZE (outbuf) = + (xsharpen->width * xsharpen->height * sizeof (Pixel32)); GST_BUFFER_DATA (outbuf) = g_malloc (GST_BUFFER_SIZE (outbuf)); GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf); - - src_buf = (Pixel32 *)GST_BUFFER_DATA (buf); - dst_buf = (Pixel32 *)GST_BUFFER_DATA (outbuf); + + src_buf = (Pixel32 *) GST_BUFFER_DATA (buf); + dst_buf = (Pixel32 *) GST_BUFFER_DATA (outbuf); min = max = 0; /* First copy through the four border lines. */ src = src_buf; dst = dst_buf; - for (x = 0; x < xsharpen->width; x++) - { + for (x = 0; x < xsharpen->width; x++) { dst[x] = src[x]; } - - src = (Pixel *)((char *)src_buf + (xsharpen->height - 1) * xsharpen->srcpitch); - dst = (Pixel *)((char *)dst_buf + (xsharpen->height - 1) * xsharpen->dstpitch); - - for (x = 0; x < xsharpen->width; x++) - { + + src = + (Pixel *) ((char *) src_buf + (xsharpen->height - + 1) * xsharpen->srcpitch); + dst = + (Pixel *) ((char *) dst_buf + (xsharpen->height - + 1) * xsharpen->dstpitch); + + for (x = 0; x < xsharpen->width; x++) { dst[x] = src[x]; } - + src = src_buf; dst = dst_buf; - - for (y = 0; y < xsharpen->height; y++) - { + + for (y = 0; y < xsharpen->height; y++) { dst[0] = src[0]; - dst[xsharpen->width-1] = src[xsharpen->width-1]; - src = (Pixel *)((char *)src + xsharpen->srcpitch); - dst = (Pixel *)((char *)dst + xsharpen->dstpitch); + dst[xsharpen->width - 1] = src[xsharpen->width - 1]; + src = (Pixel *) ((char *) src + xsharpen->srcpitch); + dst = (Pixel *) ((char *) dst + xsharpen->dstpitch); } /* Now calculate and store the pixel luminances for the remaining pixels. */ src = src_buf; - for (y = 0; y < xsharpen->height; y++) - { - for (x = 0; x < xsharpen->width; x++) - { + for (y = 0; y < xsharpen->height; y++) { + for (x = 0; x < xsharpen->width; x++) { r = (src[x] >> 16) & 0xff; g = (src[x] >> 8) & 0xff; b = src[x] & 0xff; @@ -230,138 +234,118 @@ gst_xsharpen_chain (GstPad * pad, GstData *_data) src[x] &= 0x00ffffff; src[x] |= (luma << 24); } - src = (Pixel *)((char *)src + xsharpen->srcpitch); + src = (Pixel *) ((char *) src + xsharpen->srcpitch); } /* Finally run the 3x3 rank-order sharpening kernel over the pixels. */ - src = (Pixel *)((char *)src_buf + xsharpen->srcpitch); - dst = (Pixel *)((char *)dst_buf + xsharpen->dstpitch); - - for (y = 1; y < xsharpen->height - 1; y++) - { - for (x = 1; x < xsharpen->width - 1; x++) - { + src = (Pixel *) ((char *) src_buf + xsharpen->srcpitch); + dst = (Pixel *) ((char *) dst_buf + xsharpen->dstpitch); + + for (y = 1; y < xsharpen->height - 1; y++) { + for (x = 1; x < xsharpen->width - 1; x++) { /* Find the brightest and dimmest pixels in the 3x3 window surrounding the current pixel. */ - + lumamax = -1; lumamin = 1000; - - p = ((Pixel32 *)((char *)src - xsharpen->srcpitch))[x-1]; + + p = ((Pixel32 *) ((char *) src - xsharpen->srcpitch))[x - 1]; luma = p >> 24; - if (luma > lumamax) - { - lumamax = luma; - max = p; + if (luma > lumamax) { + lumamax = luma; + max = p; } - if (luma < lumamin) - { - lumamin = luma; - min = p; + if (luma < lumamin) { + lumamin = luma; + min = p; } - p = ((Pixel32 *)((char *)src - xsharpen->srcpitch))[x]; + p = ((Pixel32 *) ((char *) src - xsharpen->srcpitch))[x]; luma = p >> 24; - if (luma > lumamax) - { - lumamax = luma; - max = p; + if (luma > lumamax) { + lumamax = luma; + max = p; } - if (luma < lumamin) - { - lumamin = luma; - min = p; + if (luma < lumamin) { + lumamin = luma; + min = p; } - - p = ((Pixel32 *)((char *)src - xsharpen->srcpitch))[x+1]; + + p = ((Pixel32 *) ((char *) src - xsharpen->srcpitch))[x + 1]; luma = p >> 24; - if (luma > lumamax) - { - lumamax = luma; - max = p; + if (luma > lumamax) { + lumamax = luma; + max = p; } - if (luma < lumamin) - { - lumamin = luma; - min = p; + if (luma < lumamin) { + lumamin = luma; + min = p; } - - p = src[x-1]; + + p = src[x - 1]; luma = p >> 24; - if (luma > lumamax) - { - lumamax = luma; - max = p; + if (luma > lumamax) { + lumamax = luma; + max = p; } - if (luma < lumamin) - { - lumamin = luma; - min = p; + if (luma < lumamin) { + lumamin = luma; + min = p; } p = src[x]; lumac = luma = p >> 24; - if (luma > lumamax) - { - lumamax = luma; - max = p; + if (luma > lumamax) { + lumamax = luma; + max = p; } - if (luma < lumamin) - { - lumamin = luma; - min = p; + if (luma < lumamin) { + lumamin = luma; + min = p; } - p = src[x+1]; + p = src[x + 1]; luma = p >> 24; - if (luma > lumamax) - { - lumamax = luma; - max = p; + if (luma > lumamax) { + lumamax = luma; + max = p; } - if (luma < lumamin) - { - lumamin = luma; - min = p; + if (luma < lumamin) { + lumamin = luma; + min = p; } - - p = ((Pixel32 *)((char *)src + xsharpen->srcpitch))[x-1]; + + p = ((Pixel32 *) ((char *) src + xsharpen->srcpitch))[x - 1]; luma = p >> 24; - if (luma > lumamax) - { - lumamax = luma; - max = p; + if (luma > lumamax) { + lumamax = luma; + max = p; } - if (luma < lumamin) - { - lumamin = luma; - min = p; + if (luma < lumamin) { + lumamin = luma; + min = p; } - p = ((Pixel32 *)((char *)src + xsharpen->srcpitch))[x]; + p = ((Pixel32 *) ((char *) src + xsharpen->srcpitch))[x]; luma = p >> 24; - if (luma > lumamax) - { - lumamax = luma; - max = p; + if (luma > lumamax) { + lumamax = luma; + max = p; } - if (luma < lumamin) - { - lumamin = luma; - min = p; + if (luma < lumamin) { + lumamin = luma; + min = p; } - p = ((Pixel32 *)((char *)src + xsharpen->srcpitch))[x+1]; + p = ((Pixel32 *) ((char *) src + xsharpen->srcpitch))[x + 1]; luma = p >> 24; - if (luma > lumamax) - { - lumamax = luma; - max = p; + if (luma > lumamax) { + lumamax = luma; + max = p; } - if (luma < lumamin) - { - lumamin = luma; - min = p; + if (luma < lumamin) { + lumamin = luma; + min = p; } /* Determine whether the current pixel is closer to the @@ -369,48 +353,39 @@ gst_xsharpen_chain (GstPad * pad, GstData *_data) pixel to that closest pixel. If the difference is within threshold, map the current pixel to the closest pixel; otherwise pass it through. */ - + p = -1; - if (xsharpen->strength != 0) - { - mindiff = lumac - lumamin; - maxdiff = lumamax - lumac; - if (mindiff > maxdiff) - { - if (maxdiff < xsharpen->threshold) - { - p = max; - } - } - else - { - if (mindiff < xsharpen->threshold) - { - p = min; - } - } + if (xsharpen->strength != 0) { + mindiff = lumac - lumamin; + maxdiff = lumamax - lumac; + if (mindiff > maxdiff) { + if (maxdiff < xsharpen->threshold) { + p = max; + } + } else { + if (mindiff < xsharpen->threshold) { + p = min; + } + } } - if (p == -1) - { - dst[x] = src[x]; - } - else - { - R = (src[x] >> 16) & 0xff; - G = (src[x] >> 8) & 0xff; - B = src[x] & 0xff; - r = (p >> 16) & 0xff; - g = (p >> 8) & 0xff; - b = p & 0xff; - r = (xsharpen->strength * r + xsharpen->strengthinv * R) / 255; - g = (xsharpen->strength * g + xsharpen->strengthinv * G) / 255; - b = (xsharpen->strength * b + xsharpen->strengthinv * B) / 255; - dst[x] = (r << 16) | (g << 8) | b; + if (p == -1) { + dst[x] = src[x]; + } else { + R = (src[x] >> 16) & 0xff; + G = (src[x] >> 8) & 0xff; + B = src[x] & 0xff; + r = (p >> 16) & 0xff; + g = (p >> 8) & 0xff; + b = p & 0xff; + r = (xsharpen->strength * r + xsharpen->strengthinv * R) / 255; + g = (xsharpen->strength * g + xsharpen->strengthinv * G) / 255; + b = (xsharpen->strength * b + xsharpen->strengthinv * B) / 255; + dst[x] = (r << 16) | (g << 8) | b; } } - src = (Pixel *)((char *)src + xsharpen->srcpitch); - dst = (Pixel *)((char *)dst + xsharpen->dstpitch); + src = (Pixel *) ((char *) src + xsharpen->srcpitch); + dst = (Pixel *) ((char *) dst + xsharpen->dstpitch); } gst_buffer_unref (buf); @@ -419,7 +394,8 @@ gst_xsharpen_chain (GstPad * pad, GstData *_data) } static void -gst_xsharpen_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) +gst_xsharpen_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec) { GstXsharpen *xsharpen; @@ -432,7 +408,7 @@ gst_xsharpen_set_property (GObject * object, guint prop_id, const GValue * value case ARG_STRENGTH: xsharpen->strength = g_value_get_int (value); xsharpen->strengthinv = 255 - xsharpen->strength; - case ARG_THRESHOLD: + case ARG_THRESHOLD: xsharpen->threshold = g_value_get_int (value); default: break; @@ -440,7 +416,8 @@ gst_xsharpen_set_property (GObject * object, guint prop_id, const GValue * value } static void -gst_xsharpen_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) +gst_xsharpen_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstXsharpen *xsharpen; @@ -451,10 +428,10 @@ gst_xsharpen_get_property (GObject * object, guint prop_id, GValue * value, GPar switch (prop_id) { case ARG_STRENGTH: - g_value_set_int (value, xsharpen->strength ); + g_value_set_int (value, xsharpen->strength); break; case ARG_THRESHOLD: - g_value_set_int (value, xsharpen->threshold ); + g_value_set_int (value, xsharpen->threshold); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |