1 /*
2  * GStreamer
3  * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23 
24 #include "../gstgleffects.h"
25 #include "gstgleffectscurves.h"
26 
27 static void
gst_gl_effects_rgb_to_curve(GstGLEffects * effects,const GstGLEffectsCurve * curve,gint curve_index,GstGLMemory * in_tex,GstGLMemory * out_tex)28 gst_gl_effects_rgb_to_curve (GstGLEffects * effects,
29     const GstGLEffectsCurve * curve, gint curve_index, GstGLMemory * in_tex,
30     GstGLMemory * out_tex)
31 {
32   GstGLContext *context = GST_GL_BASE_FILTER (effects)->context;
33   GstGLFilter *filter = GST_GL_FILTER (effects);
34   const GstGLFuncs *gl = context->gl_vtable;
35   GstGLShader *shader;
36 
37   shader = gst_gl_effects_get_fragment_shader (effects, "rgb_to_curve",
38       rgb_to_curve_fragment_source_gles2);
39 
40   if (!shader)
41     return;
42 
43 #if GST_GL_HAVE_OPENGL
44   if (USING_OPENGL (context)) {
45     gl->MatrixMode (GL_PROJECTION);
46     gl->LoadIdentity ();
47   }
48 #endif
49 
50   if (effects->curve[curve_index] == 0) {
51     /* this parameters are needed to have a right, predictable, mapping */
52     gl->GenTextures (1, &effects->curve[curve_index]);
53 
54     gl->BindTexture (GL_TEXTURE_2D, effects->curve[curve_index]);
55     gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
56     gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
57     gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
58     gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
59 
60     gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGB,
61         curve->width, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, curve->pixel_data);
62   }
63 
64   gst_gl_shader_use (shader);
65   gl->ActiveTexture (GL_TEXTURE2);
66   gl->BindTexture (GL_TEXTURE_2D, effects->curve[curve_index]);
67 
68   gst_gl_shader_set_uniform_1i (shader, "curve", 2);
69 
70   gst_gl_filter_render_to_target_with_shader (filter, in_tex, out_tex, shader);
71 }
72 
73 void
gst_gl_effects_xpro(GstGLEffects * effects)74 gst_gl_effects_xpro (GstGLEffects * effects)
75 {
76   gst_gl_effects_rgb_to_curve (effects, &xpro_curve, GST_GL_EFFECTS_CURVE_XPRO,
77       effects->intexture, effects->outtexture);
78 }
79