Blame ext/gl/effects/gstgleffectrgbtocurve.c

Packit 971217
/*
Packit 971217
 * GStreamer
Packit 971217
 * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
#include "config.h"
Packit 971217
#endif
Packit 971217
Packit 971217
#include "../gstgleffects.h"
Packit 971217
#include "gstgleffectscurves.h"
Packit 971217
Packit 971217
static void
Packit 971217
gst_gl_effects_rgb_to_curve (GstGLEffects * effects,
Packit 971217
    const GstGLEffectsCurve * curve, gint curve_index, GstGLMemory * in_tex,
Packit 971217
    GstGLMemory * out_tex)
Packit 971217
{
Packit 971217
  GstGLContext *context = GST_GL_BASE_FILTER (effects)->context;
Packit 971217
  GstGLFilter *filter = GST_GL_FILTER (effects);
Packit 971217
  const GstGLFuncs *gl = context->gl_vtable;
Packit 971217
  GstGLShader *shader;
Packit 971217
Packit 971217
  shader = gst_gl_effects_get_fragment_shader (effects, "rgb_to_curve",
Packit 971217
      rgb_to_curve_fragment_source_gles2);
Packit 971217
Packit 971217
  if (!shader)
Packit 971217
    return;
Packit 971217
Packit 971217
#if GST_GL_HAVE_OPENGL
Packit 971217
  if (USING_OPENGL (context)) {
Packit 971217
    gl->MatrixMode (GL_PROJECTION);
Packit 971217
    gl->LoadIdentity ();
Packit 971217
  }
Packit 971217
#endif
Packit 971217
Packit 971217
  if (effects->curve[curve_index] == 0) {
Packit 971217
    /* this parameters are needed to have a right, predictable, mapping */
Packit 971217
    gl->GenTextures (1, &effects->curve[curve_index]);
Packit 971217
Packit 971217
    gl->BindTexture (GL_TEXTURE_2D, effects->curve[curve_index]);
Packit 971217
    gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
Packit 971217
    gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Packit 971217
    gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
Packit 971217
    gl->TexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Packit 971217
Packit 971217
    gl->TexImage2D (GL_TEXTURE_2D, 0, GL_RGB,
Packit 971217
        curve->width, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, curve->pixel_data);
Packit 971217
  }
Packit 971217
Packit 971217
  gst_gl_shader_use (shader);
Packit 971217
  gl->ActiveTexture (GL_TEXTURE2);
Packit 971217
  gl->BindTexture (GL_TEXTURE_2D, effects->curve[curve_index]);
Packit 971217
Packit 971217
  gst_gl_shader_set_uniform_1i (shader, "curve", 2);
Packit 971217
Packit 971217
  gst_gl_filter_render_to_target_with_shader (filter, in_tex, out_tex, shader);
Packit 971217
}
Packit 971217
Packit 971217
void
Packit 971217
gst_gl_effects_xpro (GstGLEffects * effects)
Packit 971217
{
Packit 971217
  gst_gl_effects_rgb_to_curve (effects, &xpro_curve, GST_GL_EFFECTS_CURVE_XPRO,
Packit 971217
      effects->intexture, effects->outtexture);
Packit 971217
}