mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 10:41:04 +00:00
[245/906] Add invert property to sobel filter
Add an invert property to sobel_fragment_source and Sobel filter. Useful to have dark edges with white background.
This commit is contained in:
parent
b9cd64e83c
commit
a729d080f4
2 changed files with 36 additions and 8 deletions
|
@ -192,6 +192,7 @@ const gchar *sobel_fragment_source =
|
|||
"uniform sampler2DRect tex;"
|
||||
"uniform float hkern[9];"
|
||||
"uniform float vkern[9];"
|
||||
"uniform bool invert;"
|
||||
"void main () {"
|
||||
" vec2 offset[9] = vec2[9] ( vec2(-1.0,-1.0), vec2( 0.0,-1.0), vec2( 1.0,-1.0),"
|
||||
" vec2(-1.0, 0.0), vec2( 0.0, 0.0), vec2( 1.0, 0.0),"
|
||||
|
@ -210,6 +211,7 @@ const gchar *sobel_fragment_source =
|
|||
" }"
|
||||
" }"
|
||||
" float g = sqrt(gx*gx + gy*gy);"
|
||||
" if (invert) g = 1.0 - g;"
|
||||
" gl_FragColor = vec4(vec3(g), 1.0);"
|
||||
"}";
|
||||
|
||||
|
|
|
@ -40,6 +40,8 @@ struct _GstGLFilterSobel
|
|||
GstGLFilter filter;
|
||||
GstGLShader *shader0;
|
||||
|
||||
gboolean invert;
|
||||
|
||||
GLuint midtexture;
|
||||
};
|
||||
|
||||
|
@ -48,6 +50,12 @@ struct _GstGLFilterSobelClass
|
|||
GstGLFilterClass filter_class;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_INVERT,
|
||||
};
|
||||
|
||||
GType gst_gl_glfiltersobel_get_type (void);
|
||||
|
||||
#define GST_CAT_DEFAULT gst_gl_filtersobel_debug
|
||||
|
@ -122,6 +130,15 @@ gst_gl_filtersobel_class_init (GstGLFilterSobelClass * klass)
|
|||
GST_GL_FILTER_CLASS (klass)->display_reset_cb = gst_gl_filtersobel_reset_resources;
|
||||
GST_GL_FILTER_CLASS (klass)->onInitFBO = gst_gl_filtersobel_init_shader;
|
||||
GST_GL_FILTER_CLASS (klass)->onReset = gst_gl_filter_filtersobel_reset;
|
||||
|
||||
g_object_class_install_property (
|
||||
gobject_class,
|
||||
PROP_INVERT,
|
||||
g_param_spec_boolean ("invert",
|
||||
"Invert the colors",
|
||||
"Invert colors to get dark edges on bright background",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -129,6 +146,7 @@ gst_gl_filtersobel_init (GstGLFilterSobel * filtersobel, GstGLFilterSobelClass *
|
|||
{
|
||||
filtersobel->shader0 = NULL;
|
||||
filtersobel->midtexture = 0;
|
||||
filtersobel->invert = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -144,12 +162,15 @@ static void
|
|||
gst_gl_filtersobel_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
/* GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (object); */
|
||||
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (object);
|
||||
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
case PROP_INVERT:
|
||||
filtersobel->invert = g_value_get_boolean (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,12 +178,15 @@ static void
|
|||
gst_gl_filtersobel_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
/* GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (object); */
|
||||
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (object);
|
||||
|
||||
switch (prop_id) {
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
case PROP_INVERT:
|
||||
g_value_set_boolean (value, filtersobel->invert);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,5 +284,7 @@ gst_gl_filtersobel_callback (gint width, gint height, guint texture, gpointer st
|
|||
gst_gl_shader_set_uniform_1fv (filtersobel->shader0, "hkern", 9, hkern);
|
||||
gst_gl_shader_set_uniform_1fv (filtersobel->shader0, "vkern", 9, vkern);
|
||||
|
||||
gst_gl_shader_set_uniform_1i (filtersobel->shader0, "invert", filtersobel->invert);
|
||||
|
||||
gst_gl_filtersobel_draw_texture (filtersobel, texture);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue