diff --git a/gst/gl/Makefile.am b/gst/gl/Makefile.am index 7779bac2a8..0cc1e2fb47 100644 --- a/gst/gl/Makefile.am +++ b/gst/gl/Makefile.am @@ -35,6 +35,7 @@ libgstopengl_la_SOURCES = \ effects/gstgleffectsqueeze.c \ effects/gstgleffectstretch.c \ effects/gstgleffectlumatocurve.c \ + effects/gstgleffectrgbtocurve.c \ effects/gstgleffectglow.c diff --git a/gst/gl/effects/gstgleffectrgbtocurve.c b/gst/gl/effects/gstgleffectrgbtocurve.c new file mode 100644 index 0000000000..ef8cd32f1b --- /dev/null +++ b/gst/gl/effects/gstgleffectrgbtocurve.c @@ -0,0 +1,91 @@ +/* + * GStreamer + * Copyright (C) 2008 Filippo Argiolas + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +static void gst_gl_effects_rgb_to_curve (GstGLEffects *effects, + GstGLEffectsCurve curve, + gint curve_index, + gint width, gint height, + GLuint texture) +{ + GstGLShader *shader; + + shader = g_hash_table_lookup (effects->shaderstable, "lumamap0"); + + if (!shader) { + shader = gst_gl_shader_new (); + g_hash_table_insert (effects->shaderstable, "lumamap0", shader); + } + + g_return_if_fail ( + gst_gl_shader_compile_and_check (shader, rgb_to_curve_fragment_source, + GST_GL_SHADER_FRAGMENT_SOURCE)); + + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + + gst_gl_shader_use (shader); + + if (effects->curve[curve_index] == 0) { + /* this parameters are needed to have a right, predictable, mapping */ + glGenTextures(1, &effects->curve[curve_index]); + glEnable(GL_TEXTURE_1D); + glBindTexture (GL_TEXTURE_1D, effects->curve[curve_index]); + glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP); + + glTexImage1D(GL_TEXTURE_1D, 0, curve.bytes_per_pixel, + curve.width, 0, + GL_RGB, GL_UNSIGNED_BYTE, + curve.pixel_data); + + glDisable(GL_TEXTURE_1D); + } + + glActiveTexture (GL_TEXTURE5); + glEnable (GL_TEXTURE_1D); + glBindTexture (GL_TEXTURE_1D, effects->curve[curve_index]); + + gst_gl_shader_set_uniform_1i (shader, "curve", 5); + + glDisable (GL_TEXTURE_1D); + + gst_gl_effects_draw_texture (effects, texture); +} + +static void gst_gl_effects_xpro_callback (gint width, gint height, guint texture, gpointer data) +{ + GstGLEffects* effects = GST_GL_EFFECTS (data); + + gst_gl_effects_rgb_to_curve (effects, xpro_curve, GST_GL_EFFECTS_CURVE_XPRO, + width, height, texture); +} + +void +gst_gl_effects_xpro (GstGLEffects *effects) { + GstGLFilter *filter = GST_GL_FILTER (effects); + + gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture, + gst_gl_effects_xpro_callback, effects); +} diff --git a/gst/gl/effects/gstgleffectscurves.h b/gst/gl/effects/gstgleffectscurves.h index 0efe049dd6..b9b619b827 100644 --- a/gst/gl/effects/gstgleffectscurves.h +++ b/gst/gl/effects/gstgleffectscurves.h @@ -31,6 +31,45 @@ struct _GstGLEffectsCurve { typedef struct _GstGLEffectsCurve GstGLEffectsCurve; +/* GIMP RGB C-Source image dump (xpro.c) */ + +static const GstGLEffectsCurve xpro_curve = { + 256, 1, 3, + "\0\0)\0\0)\0\2*\1\2*\1\2-\1\5-\2\6.\2\6.\2\7/\4\11""1\4\12""1\4\12""1\5\13" + """3\5\14""4\5\16""5\6\17""5\6\20""6\6\20""9\6\21""9\7\23:\11\24;\11\25;\11" + "\26<\11\31<\12\31?\12\32@\13\32@\13\33@\14\35A\14\36B\14\37B\14\40D\16\"" + "E\17$F\17%F\17&G\20&H\20(J\21)K\21*K\23*M\23+M\24-N\24.N\25""1O\25""1Q\26" + """4R\30""4R\30""5S\31""8T\31""8T\32""9V\33;V\33;X\35Y\36?Z\37A[\40" + "B[\"D\\#E]#G_$G_%J`&Ka(La(Ob*Oc*Qd+Rd-Te.Ug/Vh0Yh1Zi3[j4]k5_k6am9bm;dn;h" + "neffect = (GstGLEffectProcessFunc) gst_gl_effects_sepia; break; + case GST_GL_EFFECT_XPRO: + effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_xpro; + break; case GST_GL_EFFECT_GLOW: effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_glow; break; diff --git a/gst/gl/gstgleffects.h b/gst/gl/gstgleffects.h index b5844474e5..5440f65277 100644 --- a/gst/gl/gstgleffects.h +++ b/gst/gl/gstgleffects.h @@ -48,6 +48,7 @@ typedef void (* GstGLEffectProcessFunc) (GstGLEffects *effects); enum { GST_GL_EFFECTS_CURVE_HEAT, GST_GL_EFFECTS_CURVE_SEPIA, + GST_GL_EFFECTS_CURVE_XPRO, GST_GL_EFFECTS_N_CURVES }; @@ -89,6 +90,7 @@ void gst_gl_effects_squeeze (GstGLEffects *effects); void gst_gl_effects_stretch (GstGLEffects *effects); void gst_gl_effects_heat (GstGLEffects *effects); void gst_gl_effects_sepia (GstGLEffects *effects); +void gst_gl_effects_xpro (GstGLEffects *effects); void gst_gl_effects_glow (GstGLEffects *effects); G_END_DECLS