mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-28 12:41:05 +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 sampler2DRect tex;"
|
||||||
"uniform float hkern[9];"
|
"uniform float hkern[9];"
|
||||||
"uniform float vkern[9];"
|
"uniform float vkern[9];"
|
||||||
|
"uniform bool invert;"
|
||||||
"void main () {"
|
"void main () {"
|
||||||
" vec2 offset[9] = vec2[9] ( vec2(-1.0,-1.0), vec2( 0.0,-1.0), vec2( 1.0,-1.0),"
|
" 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),"
|
" 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);"
|
" float g = sqrt(gx*gx + gy*gy);"
|
||||||
|
" if (invert) g = 1.0 - g;"
|
||||||
" gl_FragColor = vec4(vec3(g), 1.0);"
|
" gl_FragColor = vec4(vec3(g), 1.0);"
|
||||||
"}";
|
"}";
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,8 @@ struct _GstGLFilterSobel
|
||||||
GstGLFilter filter;
|
GstGLFilter filter;
|
||||||
GstGLShader *shader0;
|
GstGLShader *shader0;
|
||||||
|
|
||||||
|
gboolean invert;
|
||||||
|
|
||||||
GLuint midtexture;
|
GLuint midtexture;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -48,6 +50,12 @@ struct _GstGLFilterSobelClass
|
||||||
GstGLFilterClass filter_class;
|
GstGLFilterClass filter_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
PROP_INVERT,
|
||||||
|
};
|
||||||
|
|
||||||
GType gst_gl_glfiltersobel_get_type (void);
|
GType gst_gl_glfiltersobel_get_type (void);
|
||||||
|
|
||||||
#define GST_CAT_DEFAULT gst_gl_filtersobel_debug
|
#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)->display_reset_cb = gst_gl_filtersobel_reset_resources;
|
||||||
GST_GL_FILTER_CLASS (klass)->onInitFBO = gst_gl_filtersobel_init_shader;
|
GST_GL_FILTER_CLASS (klass)->onInitFBO = gst_gl_filtersobel_init_shader;
|
||||||
GST_GL_FILTER_CLASS (klass)->onReset = gst_gl_filter_filtersobel_reset;
|
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
|
static void
|
||||||
|
@ -129,6 +146,7 @@ gst_gl_filtersobel_init (GstGLFilterSobel * filtersobel, GstGLFilterSobelClass *
|
||||||
{
|
{
|
||||||
filtersobel->shader0 = NULL;
|
filtersobel->shader0 = NULL;
|
||||||
filtersobel->midtexture = 0;
|
filtersobel->midtexture = 0;
|
||||||
|
filtersobel->invert = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -144,12 +162,15 @@ static void
|
||||||
gst_gl_filtersobel_set_property (GObject * object, guint prop_id,
|
gst_gl_filtersobel_set_property (GObject * object, guint prop_id,
|
||||||
const GValue * value, GParamSpec * pspec)
|
const GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
/* GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (object); */
|
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (object);
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
default:
|
case PROP_INVERT:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
filtersobel->invert = g_value_get_boolean (value);
|
||||||
break;
|
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,
|
gst_gl_filtersobel_get_property (GObject * object, guint prop_id,
|
||||||
GValue * value, GParamSpec * pspec)
|
GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
/* GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (object); */
|
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (object);
|
||||||
|
|
||||||
switch (prop_id) {
|
switch (prop_id) {
|
||||||
default:
|
case PROP_INVERT:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
g_value_set_boolean (value, filtersobel->invert);
|
||||||
break;
|
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, "hkern", 9, hkern);
|
||||||
gst_gl_shader_set_uniform_1fv (filtersobel->shader0, "vkern", 9, vkern);
|
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);
|
gst_gl_filtersobel_draw_texture (filtersobel, texture);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue