1 /*
2 * GStreamer
3 * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
4 * Copyright (C) 2015 Michał Dębski <debski.mi.zd@gmail.com>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "../gstgleffects.h"
27
28 static gpointer
init_kernel(gpointer data)29 init_kernel (gpointer data)
30 {
31 float *kernel = g_malloc (sizeof (gfloat) * 9);
32 fill_gaussian_kernel (kernel, 7, 3.f);
33 return kernel;
34 }
35
36 static float *
gst_gl_effects_blur_kernel(void)37 gst_gl_effects_blur_kernel (void)
38 {
39 /* gaussian kernel (well, actually vector), size 9, standard
40 * deviation 3.0 */
41 /* FIXME: make this a runtime property */
42 static GOnce my_once = G_ONCE_INIT;
43
44 g_once (&my_once, init_kernel, NULL);
45 return my_once.retval;
46 }
47
48 void
gst_gl_effects_blur(GstGLEffects * effects)49 gst_gl_effects_blur (GstGLEffects * effects)
50 {
51 GstGLFilter *filter = GST_GL_FILTER (effects);
52 GstGLShader *shader;
53
54 shader = gst_gl_effects_get_fragment_shader (effects, "hconv0",
55 hconv7_fragment_source_gles2);
56 gst_gl_shader_use (shader);
57 gst_gl_shader_set_uniform_1f (shader, "gauss_width",
58 GST_VIDEO_INFO_WIDTH (&filter->in_info));
59 gst_gl_shader_set_uniform_1fv (shader, "kernel", 7,
60 gst_gl_effects_blur_kernel ());
61 gst_gl_filter_render_to_target_with_shader (filter, effects->intexture,
62 effects->midtexture[0], shader);
63
64 shader = gst_gl_effects_get_fragment_shader (effects, "vconv0",
65 vconv7_fragment_source_gles2);
66 gst_gl_shader_use (shader);
67 gst_gl_shader_set_uniform_1f (shader, "gauss_height",
68 GST_VIDEO_INFO_HEIGHT (&filter->in_info));
69 gst_gl_shader_set_uniform_1fv (shader, "kernel", 7,
70 gst_gl_effects_blur_kernel ());
71 gst_gl_filter_render_to_target_with_shader (filter, effects->midtexture[0],
72 effects->outtexture, shader);
73 }
74