mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 09:55:36 +00:00
gleffects: Merge sobel filter into effects
https://bugzilla.gnome.org/show_bug.cgi?id=746209
This commit is contained in:
parent
208b5f999e
commit
befbf3733b
7 changed files with 207 additions and 340 deletions
|
@ -29,6 +29,7 @@ libgstopengl_la_SOURCES = \
|
|||
effects/gstgleffectxray.c \
|
||||
effects/gstgleffectglow.c \
|
||||
effects/gstgleffectblur.c \
|
||||
effects/gstgleffectsobel.c \
|
||||
gstglcolorscale.c \
|
||||
gstglmixer.c \
|
||||
gstglvideomixer.c \
|
||||
|
@ -57,7 +58,6 @@ noinst_HEADERS = \
|
|||
# full opengl required
|
||||
if USE_OPENGL
|
||||
libgstopengl_la_SOURCES += \
|
||||
gstglfiltersobel.c \
|
||||
gstglfilterlaplacian.c \
|
||||
gstglfilterglass.c \
|
||||
gstgldeinterlace.c \
|
||||
|
@ -66,7 +66,6 @@ libgstopengl_la_SOURCES += \
|
|||
gstglmosaic.c
|
||||
|
||||
noinst_HEADERS += \
|
||||
gstglfiltersobel.h \
|
||||
gstglfilterlaplacian.h \
|
||||
gstglfilterglass.h \
|
||||
gstgldeinterlace.h \
|
||||
|
|
180
ext/gl/effects/gstgleffectsobel.c
Normal file
180
ext/gl/effects/gstgleffectsobel.c
Normal file
|
@ -0,0 +1,180 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2008-2010 Filippo Argiolas <filippo.argiolas@gmail.com>
|
||||
* Copyright (C) 2015 Michał Dębski <debski.mi.zd@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "../gstgleffects.h"
|
||||
|
||||
static void
|
||||
gst_gl_effects_sobel_callback_desaturate (gint width, gint height,
|
||||
guint texture, gpointer data)
|
||||
{
|
||||
GstGLShader *shader = NULL;
|
||||
GstGLEffects *effects = GST_GL_EFFECTS (data);
|
||||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
|
||||
if (NULL != (shader = gst_gl_effects_get_fragment_shader (effects, "desat0",
|
||||
desaturate_fragment_source_gles2,
|
||||
desaturate_fragment_source_opengl))) {
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
|
||||
#if GST_GL_HAVE_OPENGL
|
||||
if (USING_OPENGL (GST_GL_BASE_FILTER (filter)->context)) {
|
||||
gl->MatrixMode (GL_PROJECTION);
|
||||
gl->LoadIdentity ();
|
||||
}
|
||||
#endif
|
||||
|
||||
gst_gl_shader_use (shader);
|
||||
|
||||
gl->ActiveTexture (GL_TEXTURE0);
|
||||
gl->Enable (GL_TEXTURE_2D);
|
||||
gl->BindTexture (GL_TEXTURE_2D, texture);
|
||||
gl->Disable (GL_TEXTURE_2D);
|
||||
|
||||
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
|
||||
|
||||
gst_gl_filter_draw_texture (filter, texture, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_effects_sobel_callback_hconv (gint width, gint height, guint texture,
|
||||
gpointer data)
|
||||
{
|
||||
GstGLShader *shader = NULL;
|
||||
GstGLEffects *effects = GST_GL_EFFECTS (data);
|
||||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
|
||||
if (NULL != (shader = gst_gl_effects_get_fragment_shader (effects, "hconv0",
|
||||
sep_sobel_hconv3_fragment_source_gles2,
|
||||
sep_sobel_hconv3_fragment_source_opengl))) {
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
|
||||
#if GST_GL_HAVE_OPENGL
|
||||
if (USING_OPENGL (GST_GL_BASE_FILTER (filter)->context)) {
|
||||
gl->MatrixMode (GL_PROJECTION);
|
||||
gl->LoadIdentity ();
|
||||
}
|
||||
#endif
|
||||
|
||||
gst_gl_shader_use (shader);
|
||||
|
||||
gl->ActiveTexture (GL_TEXTURE0);
|
||||
gl->Enable (GL_TEXTURE_2D);
|
||||
gl->BindTexture (GL_TEXTURE_2D, texture);
|
||||
gl->Disable (GL_TEXTURE_2D);
|
||||
|
||||
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
|
||||
gst_gl_shader_set_uniform_1f (shader, "width", width);
|
||||
|
||||
gst_gl_filter_draw_texture (filter, texture, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_effects_sobel_callback_vconv (gint width, gint height, guint texture,
|
||||
gpointer data)
|
||||
{
|
||||
GstGLShader *shader = NULL;
|
||||
GstGLEffects *effects = GST_GL_EFFECTS (data);
|
||||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
|
||||
if (NULL != (shader = gst_gl_effects_get_fragment_shader (effects, "vconv0",
|
||||
sep_sobel_vconv3_fragment_source_gles2,
|
||||
sep_sobel_vconv3_fragment_source_opengl))) {
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
|
||||
#if GST_GL_HAVE_OPENGL
|
||||
if (USING_OPENGL (GST_GL_BASE_FILTER (filter)->context)) {
|
||||
gl->MatrixMode (GL_PROJECTION);
|
||||
gl->LoadIdentity ();
|
||||
}
|
||||
#endif
|
||||
|
||||
gst_gl_shader_use (shader);
|
||||
|
||||
gl->ActiveTexture (GL_TEXTURE0);
|
||||
gl->Enable (GL_TEXTURE_2D);
|
||||
gl->BindTexture (GL_TEXTURE_2D, texture);
|
||||
gl->Disable (GL_TEXTURE_2D);
|
||||
|
||||
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
|
||||
gst_gl_shader_set_uniform_1f (shader, "height", height);
|
||||
|
||||
gst_gl_filter_draw_texture (filter, texture, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_effects_sobel_callback_length (gint width, gint height, guint texture,
|
||||
gpointer data)
|
||||
{
|
||||
GstGLShader *shader = NULL;
|
||||
GstGLEffects *effects = GST_GL_EFFECTS (data);
|
||||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
|
||||
if (NULL != (shader = gst_gl_effects_get_fragment_shader (effects, "len0",
|
||||
sep_sobel_length_fragment_source_gles2,
|
||||
sep_sobel_length_fragment_source_opengl))) {
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
|
||||
#if GST_GL_HAVE_OPENGL
|
||||
if (USING_OPENGL (GST_GL_BASE_FILTER (filter)->context)) {
|
||||
gl->MatrixMode (GL_PROJECTION);
|
||||
gl->LoadIdentity ();
|
||||
}
|
||||
#endif
|
||||
|
||||
gst_gl_shader_use (shader);
|
||||
|
||||
gl->ActiveTexture (GL_TEXTURE0);
|
||||
gl->Enable (GL_TEXTURE_2D);
|
||||
gl->BindTexture (GL_TEXTURE_2D, texture);
|
||||
gl->Disable (GL_TEXTURE_2D);
|
||||
|
||||
gst_gl_shader_set_uniform_1i (shader, "tex", 0);
|
||||
gst_gl_shader_set_uniform_1i (shader, "invert", effects->invert);
|
||||
|
||||
gst_gl_filter_draw_texture (filter, texture, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gst_gl_effects_sobel (GstGLEffects * effects)
|
||||
{
|
||||
GstGLFilter *filter = GST_GL_FILTER (effects);
|
||||
|
||||
gst_gl_filter_render_to_target (filter, TRUE,
|
||||
effects->intexture, effects->midtexture[0],
|
||||
gst_gl_effects_sobel_callback_desaturate, effects);
|
||||
gst_gl_filter_render_to_target (filter, FALSE,
|
||||
effects->midtexture[0], effects->midtexture[1],
|
||||
gst_gl_effects_sobel_callback_hconv, effects);
|
||||
gst_gl_filter_render_to_target (filter, FALSE,
|
||||
effects->midtexture[1], effects->midtexture[0],
|
||||
gst_gl_effects_sobel_callback_vconv, effects);
|
||||
gst_gl_filter_render_to_target (filter, FALSE,
|
||||
effects->midtexture[0], effects->outtexture,
|
||||
gst_gl_effects_sobel_callback_length, effects);
|
||||
}
|
|
@ -90,6 +90,7 @@ typedef enum
|
|||
GST_GL_EFFECT_XRAY,
|
||||
GST_GL_EFFECT_SIN,
|
||||
GST_GL_EFFECT_GLOW,
|
||||
GST_GL_EFFECT_SOBEL,
|
||||
GST_GL_EFFECT_BLUR,
|
||||
GST_GL_N_EFFECTS
|
||||
} GstGLEffectsEffect;
|
||||
|
@ -116,6 +117,7 @@ gst_gl_effects_effect_get_type (void)
|
|||
{GST_GL_EFFECT_XRAY, "Glowing negative effect", "xray"},
|
||||
{GST_GL_EFFECT_SIN, "All Grey but Red Effect", "sin"},
|
||||
{GST_GL_EFFECT_GLOW, "Glow Lighting Effect", "glow"},
|
||||
{GST_GL_EFFECT_SOBEL, "Sobel edge detection Effect", "sobel"},
|
||||
{GST_GL_EFFECT_BLUR, "Blur with 9x9 separable convolution Effect", "blur"},
|
||||
{0, NULL, NULL}
|
||||
};
|
||||
|
@ -229,6 +231,12 @@ gst_gl_effects_set_effect (GstGLEffects * effects, gint effect_type)
|
|||
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
||||
effects->current_effect = effect_type;
|
||||
break;
|
||||
case GST_GL_EFFECT_SOBEL:
|
||||
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_sobel;
|
||||
filter_class->supported_gl_api =
|
||||
GST_GL_API_GLES2 | GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
||||
effects->current_effect = effect_type;
|
||||
break;
|
||||
case GST_GL_EFFECT_BLUR:
|
||||
effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_blur;
|
||||
filter_class->supported_gl_api =
|
||||
|
@ -322,6 +330,13 @@ gst_gl_effects_class_init (GstGLEffectsClass * klass)
|
|||
"Horizontal Swap",
|
||||
"Switch video texture left to right, useful with webcams",
|
||||
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
/* FIXME: make it work on every effect */
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_INVERT,
|
||||
g_param_spec_boolean ("invert",
|
||||
"Invert the colours for sobel effect",
|
||||
"Invert colors to get dark edges on bright background when using sobel effect",
|
||||
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
gst_element_class_set_metadata (element_class,
|
||||
"Gstreamer OpenGL Effects", "Filter/Effect/Video",
|
||||
|
@ -355,6 +370,7 @@ gst_gl_effects_init (GstGLEffects * effects)
|
|||
{
|
||||
effects->effect = gst_gl_effects_identity;
|
||||
effects->horizontal_swap = FALSE;
|
||||
effects->invert = FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -398,6 +414,9 @@ gst_gl_effects_set_property (GObject * object, guint prop_id,
|
|||
case PROP_HSWAP:
|
||||
effects->horizontal_swap = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_INVERT:
|
||||
effects->invert = g_value_get_boolean (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
@ -417,6 +436,9 @@ gst_gl_effects_get_property (GObject * object, guint prop_id,
|
|||
case PROP_HSWAP:
|
||||
g_value_set_boolean (value, effects->horizontal_swap);
|
||||
break;
|
||||
case PROP_INVERT:
|
||||
g_value_set_boolean (value, effects->invert);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
|
|
@ -72,6 +72,7 @@ struct _GstGLEffects
|
|||
GHashTable *shaderstable;
|
||||
|
||||
gboolean horizontal_swap; /* switch left to right */
|
||||
gboolean invert; /* colours */
|
||||
};
|
||||
|
||||
struct _GstGLEffectsClass
|
||||
|
@ -83,7 +84,8 @@ enum
|
|||
{
|
||||
PROP_0,
|
||||
PROP_EFFECT,
|
||||
PROP_HSWAP
|
||||
PROP_HSWAP,
|
||||
PROP_INVERT
|
||||
};
|
||||
|
||||
|
||||
|
@ -107,6 +109,7 @@ void gst_gl_effects_xray (GstGLEffects *effects);
|
|||
void gst_gl_effects_luma_xpro (GstGLEffects *effects);
|
||||
void gst_gl_effects_sin (GstGLEffects *effects);
|
||||
void gst_gl_effects_glow (GstGLEffects *effects);
|
||||
void gst_gl_effects_sobel (GstGLEffects *effects);
|
||||
void gst_gl_effects_blur (GstGLEffects *effects);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
|
@ -1,275 +0,0 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2008-2010 Filippo Argiolas <filippo.argiolas@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:element-glfiltersobel.
|
||||
*
|
||||
* Sobel Edge Detection.
|
||||
*
|
||||
* <refsect2>
|
||||
* <title>Examples</title>
|
||||
* |[
|
||||
* gst-launch videotestsrc ! glupload ! glfiltersobel ! glimagesink
|
||||
* ]|
|
||||
* FBO (Frame Buffer Object) and GLSL (OpenGL Shading Language) are required.
|
||||
* </refsect2>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gstglfiltersobel.h"
|
||||
#include "effects/gstgleffectssources.h"
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_INVERT
|
||||
};
|
||||
|
||||
#define GST_CAT_DEFAULT gst_gl_filtersobel_debug
|
||||
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
||||
|
||||
#define DEBUG_INIT \
|
||||
GST_DEBUG_CATEGORY_INIT (gst_gl_filtersobel_debug, "glfiltersobel", 0, "glfiltersobel element");
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GstGLFilterSobel, gst_gl_filtersobel,
|
||||
GST_TYPE_GL_FILTER, DEBUG_INIT);
|
||||
|
||||
static void gst_gl_filtersobel_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_gl_filtersobel_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec);
|
||||
static void gst_gl_filter_filtersobel_reset (GstGLFilter * filter);
|
||||
|
||||
static gboolean gst_gl_filtersobel_init_shader (GstGLFilter * filter);
|
||||
static gboolean gst_gl_filtersobel_filter_texture (GstGLFilter * filter,
|
||||
guint in_tex, guint out_tex);
|
||||
|
||||
static void gst_gl_filtersobel_length (gint width, gint height, guint texture,
|
||||
gpointer stuff);
|
||||
|
||||
static void
|
||||
gst_gl_filtersobel_init_resources (GstGLFilter * filter)
|
||||
{
|
||||
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (filter);
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
gl->GenTextures (1, &filtersobel->midtexture[i]);
|
||||
gl->BindTexture (GL_TEXTURE_2D, filtersobel->midtexture[i]);
|
||||
gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8,
|
||||
GST_VIDEO_INFO_WIDTH (&filter->out_info),
|
||||
GST_VIDEO_INFO_HEIGHT (&filter->out_info),
|
||||
0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_filtersobel_reset_resources (GstGLFilter * filter)
|
||||
{
|
||||
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (filter);
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
gl->DeleteTextures (1, &filtersobel->midtexture[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_filtersobel_class_init (GstGLFilterSobelClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GstElementClass *element_class;
|
||||
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
element_class = GST_ELEMENT_CLASS (klass);
|
||||
|
||||
gobject_class->set_property = gst_gl_filtersobel_set_property;
|
||||
gobject_class->get_property = gst_gl_filtersobel_get_property;
|
||||
|
||||
GST_GL_FILTER_CLASS (klass)->filter_texture =
|
||||
gst_gl_filtersobel_filter_texture;
|
||||
GST_GL_FILTER_CLASS (klass)->display_init_cb =
|
||||
gst_gl_filtersobel_init_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)->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 | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
gst_element_class_set_metadata (element_class,
|
||||
"Gstreamer OpenGL Sobel", "Filter/Effect/Video", "Sobel edge detection",
|
||||
"Filippo Argiolas <filippo.argiolas@gmail.com>");
|
||||
|
||||
GST_GL_BASE_FILTER_CLASS (klass)->supported_gl_api = GST_GL_API_OPENGL;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_filtersobel_init (GstGLFilterSobel * filtersobel)
|
||||
{
|
||||
int i;
|
||||
filtersobel->hconv = NULL;
|
||||
filtersobel->vconv = NULL;
|
||||
filtersobel->invert = FALSE;
|
||||
for (i = 0; i < 2; i++) {
|
||||
filtersobel->midtexture[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_filter_filtersobel_reset (GstGLFilter * filter)
|
||||
{
|
||||
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (filter);
|
||||
|
||||
//blocking call, wait the opengl thread has destroyed the shader
|
||||
if (filtersobel->desat)
|
||||
gst_gl_context_del_shader (GST_GL_BASE_FILTER (filter)->context,
|
||||
filtersobel->desat);
|
||||
filtersobel->desat = NULL;
|
||||
|
||||
if (filtersobel->hconv)
|
||||
gst_gl_context_del_shader (GST_GL_BASE_FILTER (filter)->context,
|
||||
filtersobel->hconv);
|
||||
filtersobel->hconv = NULL;
|
||||
|
||||
if (filtersobel->vconv)
|
||||
gst_gl_context_del_shader (GST_GL_BASE_FILTER (filter)->context,
|
||||
filtersobel->vconv);
|
||||
filtersobel->vconv = NULL;
|
||||
|
||||
if (filtersobel->len)
|
||||
gst_gl_context_del_shader (GST_GL_BASE_FILTER (filter)->context,
|
||||
filtersobel->len);
|
||||
filtersobel->len = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_filtersobel_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_INVERT:
|
||||
filtersobel->invert = g_value_get_boolean (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_filtersobel_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_INVERT:
|
||||
g_value_set_boolean (value, filtersobel->invert);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_gl_filtersobel_init_shader (GstGLFilter * filter)
|
||||
{
|
||||
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (filter);
|
||||
gboolean ret = TRUE;
|
||||
|
||||
//blocking call, wait the opengl thread has compiled the shader
|
||||
ret =
|
||||
gst_gl_context_gen_shader (GST_GL_BASE_FILTER (filter)->context, 0,
|
||||
desaturate_fragment_source_opengl, &filtersobel->desat);
|
||||
ret &=
|
||||
gst_gl_context_gen_shader (GST_GL_BASE_FILTER (filter)->context, 0,
|
||||
sep_sobel_hconv3_fragment_source_opengl, &filtersobel->hconv);
|
||||
ret &=
|
||||
gst_gl_context_gen_shader (GST_GL_BASE_FILTER (filter)->context, 0,
|
||||
sep_sobel_vconv3_fragment_source_opengl, &filtersobel->vconv);
|
||||
ret &=
|
||||
gst_gl_context_gen_shader (GST_GL_BASE_FILTER (filter)->context, 0,
|
||||
sep_sobel_length_fragment_source_opengl, &filtersobel->len);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_gl_filtersobel_filter_texture (GstGLFilter * filter, guint in_tex,
|
||||
guint out_tex)
|
||||
{
|
||||
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (filter);
|
||||
|
||||
gst_gl_filter_render_to_target_with_shader (filter, TRUE, in_tex,
|
||||
filtersobel->midtexture[0], filtersobel->desat);
|
||||
gst_gl_filter_render_to_target_with_shader (filter, FALSE,
|
||||
filtersobel->midtexture[0], filtersobel->midtexture[1],
|
||||
filtersobel->hconv);
|
||||
gst_gl_filter_render_to_target_with_shader (filter, FALSE,
|
||||
filtersobel->midtexture[1], filtersobel->midtexture[0],
|
||||
filtersobel->vconv);
|
||||
gst_gl_filter_render_to_target (filter, FALSE, filtersobel->midtexture[0],
|
||||
out_tex, gst_gl_filtersobel_length, filtersobel);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_gl_filtersobel_length (gint width, gint height, guint texture,
|
||||
gpointer stuff)
|
||||
{
|
||||
GstGLFilter *filter = GST_GL_FILTER (stuff);
|
||||
GstGLFuncs *gl = GST_GL_BASE_FILTER (filter)->context->gl_vtable;
|
||||
GstGLFilterSobel *filtersobel = GST_GL_FILTERSOBEL (filter);
|
||||
|
||||
glMatrixMode (GL_PROJECTION);
|
||||
glLoadIdentity ();
|
||||
|
||||
gst_gl_shader_use (filtersobel->len);
|
||||
|
||||
gl->ActiveTexture (GL_TEXTURE1);
|
||||
gl->Enable (GL_TEXTURE_2D);
|
||||
gl->BindTexture (GL_TEXTURE_2D, texture);
|
||||
gl->Disable (GL_TEXTURE_2D);
|
||||
|
||||
gst_gl_shader_set_uniform_1i (filtersobel->len, "tex", 1);
|
||||
gst_gl_shader_set_uniform_1i (filtersobel->len, "invert",
|
||||
filtersobel->invert);
|
||||
|
||||
gst_gl_filter_draw_texture (filter, texture, width, height);
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef _GST_GL_FILTERSOBEL_H_
|
||||
#define _GST_GL_FILTERSOBEL_H_
|
||||
|
||||
#include <gst/gl/gstglfilter.h>
|
||||
|
||||
#define GST_TYPE_GL_FILTERSOBEL (gst_gl_filtersobel_get_type())
|
||||
#define GST_GL_FILTERSOBEL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_GL_FILTERSOBEL,GstGLFilterSobel))
|
||||
#define GST_IS_GL_FILTERSOBEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_GL_FILTERSOBEL))
|
||||
#define GST_GL_FILTERSOBEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_GL_FILTERSOBEL,GstGLFilterSobelClass))
|
||||
#define GST_IS_GL_FILTERSOBEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_GL_FILTERSOBEL))
|
||||
#define GST_GL_FILTERSOBEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_GL_FILTERSOBEL,GstGLFilterSobelClass))
|
||||
|
||||
typedef struct _GstGLFilterSobel GstGLFilterSobel;
|
||||
typedef struct _GstGLFilterSobelClass GstGLFilterSobelClass;
|
||||
|
||||
struct _GstGLFilterSobel
|
||||
{
|
||||
GstGLFilter filter;
|
||||
GstGLShader *hconv;
|
||||
GstGLShader *vconv;
|
||||
GstGLShader *len;
|
||||
GstGLShader *desat;
|
||||
|
||||
GLuint midtexture[5];
|
||||
|
||||
gboolean invert;
|
||||
};
|
||||
|
||||
struct _GstGLFilterSobelClass
|
||||
{
|
||||
GstGLFilterClass filter_class;
|
||||
};
|
||||
|
||||
GType gst_gl_filtersobel_get_type (void);
|
||||
|
||||
#endif /* _GST_GL_FILTERSOBEL_H_ */
|
|
@ -72,7 +72,6 @@
|
|||
#include "gstglfilterlaplacian.h"
|
||||
#include "gstglfilterglass.h"
|
||||
/* #include "gstglfilterreflectedscreen.h" */
|
||||
#include "gstglfiltersobel.h"
|
||||
#include "gstgldeinterlace.h"
|
||||
#include "gstglmosaic.h"
|
||||
#if HAVE_PNG
|
||||
|
@ -201,11 +200,6 @@ plugin_init (GstPlugin * plugin)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_element_register (plugin, "glfiltersobel",
|
||||
GST_RANK_NONE, gst_gl_filtersobel_get_type ())) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!gst_element_register (plugin, "glfilterlaplacian",
|
||||
GST_RANK_NONE, GST_TYPE_GL_FILTER_LAPLACIAN)) {
|
||||
return FALSE;
|
||||
|
|
Loading…
Reference in a new issue