diff --git a/gst/gl/Makefile.am b/gst/gl/Makefile.am index 279e05600d..7779bac2a8 100644 --- a/gst/gl/Makefile.am +++ b/gst/gl/Makefile.am @@ -29,10 +29,12 @@ libgstopengl_la_SOURCES = \ gstgleffects.h \ effects/gstgleffectssources.c \ effects/gstgleffectssources.h \ + effects/gstgleffectscurves.h \ effects/gstgleffectidentity.c \ effects/gstgleffectmirror.c \ effects/gstgleffectsqueeze.c \ effects/gstgleffectstretch.c \ + effects/gstgleffectlumatocurve.c \ effects/gstgleffectglow.c diff --git a/gst/gl/effects/gstgleffectlumatocurve.c b/gst/gl/effects/gstgleffectlumatocurve.c new file mode 100644 index 0000000000..21739add27 --- /dev/null +++ b/gst/gl/effects/gstgleffectlumatocurve.c @@ -0,0 +1,107 @@ +/* + * 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_luma_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, luma_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_heat_callback (gint width, gint height, guint texture, gpointer data) +{ + GstGLEffects* effects = GST_GL_EFFECTS (data); + + gst_gl_effects_luma_to_curve (effects, heat_curve, GST_GL_EFFECTS_CURVE_HEAT, + width, height, texture); +} + +void +gst_gl_effects_heat (GstGLEffects *effects) { + GstGLFilter *filter = GST_GL_FILTER (effects); + + gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture, + gst_gl_effects_heat_callback, effects); +} + +static void gst_gl_effects_sepia_callback (gint width, gint height, guint texture, gpointer data) +{ + GstGLEffects* effects = GST_GL_EFFECTS (data); + + gst_gl_effects_luma_to_curve (effects, sepia_curve, GST_GL_EFFECTS_CURVE_SEPIA, + width, height, texture); +} + +void +gst_gl_effects_sepia (GstGLEffects *effects) { + GstGLFilter *filter = GST_GL_FILTER (effects); + + gst_gl_filter_render_to_target (filter, effects->intexture, effects->outtexture, + gst_gl_effects_sepia_callback, effects); +} diff --git a/gst/gl/effects/gstgleffectscurves.h b/gst/gl/effects/gstgleffectscurves.h new file mode 100644 index 0000000000..0efe049dd6 --- /dev/null +++ b/gst/gl/effects/gstgleffectscurves.h @@ -0,0 +1,182 @@ +/* + * 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. + */ + +#ifndef __GST_GL_EFFECTS_TEXTURES__ +#define __GST_GL_EFFECTS_TEXTURES__ + + +struct _GstGLEffectsCurve { + guint width; + guint height; + guint bytes_per_pixel; /* 3:RGB */ + guint8 pixel_data[256 * 1 * 3 + 1]; +}; + +typedef struct _GstGLEffectsCurve GstGLEffectsCurve; + +/* CURVE for the cross processing effect */ +static const GstGLEffectsCurve cross_curve = { + 256, 1, 3, + "\0\0\1\0\1\1\0\1\2\0\1\2\0\1\2\0\1\2\0\1\3\0\2\3\0\2\4\0\2\4\0\2\5\0\2\6" + "\0\3\6\0\3\6\0\3\7\0\3\10\0\4\10\0\4\11\0\4\12\0\4\12\1\4\13\1\5\14\1\5\15" + "\1\5\15\1\5\16\1\5\17\1\6\17\1\6\20\1\7\21\1\7\23\2\10\23\2\10\24\2\10\24" + "\2\11\26\2\11\27\2\11\30\3\11\31\3\12\31\3\13\32\3\13\33\4\13\34\4\14\35" + "\4\14\36\4\15\37\5\15\40\5\15\"\6\16#\6\17#\6\20$\7\20%\7\20%\10\21&\10\22" + "'\10\22)\11\24*\11\24*\12\24+\12\26.\13\26.\14\27.\14\30/\15\31""1\15\31" + """2\16\32""3\16\33""3\20\33""5\20\35""6\20\36""7\22\37""7\23\"9\23#9\24$" + ":\25$<\27&<\27'=\31'?\31)?\32*@\35+B\35-C\36.C\37""1E\"2F#3H$5H&6I'7I)7K" + "+:M-\324S?\327P@\332LA\335IB\337FC\342CE\344@F\347=G\351;I\3538I\3558M\357" + "3P\3610S\363.V\365+Y\366)\\\370'`\371%d\372#g\373\"l\374\40p\374\37t\374" + "\35t\375\34}\376\33\202\376\32\202\375\31\213\375\30\220\375\27\225\375\27" + "\232\373\26\237\372\25\244\371\24\251\370\23\256\367\23\262\367\22\267\364" + "\21\274\362\20\300\361\20\305\357\17\311\355\16\311\353\16\322\351\15\326" + "\346\15\332\346\14\336\344\14\341\337\13\341\335\13\350\332\12\353\330\11" + "\356\330\11\360\322\10\362\320\10\364\320\10\364\312\7\366\307\7\366\304" + "\7\367\302\6\367\277\6\370\274\5\367\271\5\367\271\5\367\263\4\365\260\4" + "\364\255\4\363\253\3\362\250\3\361\245\3\360\242\3\357\240\3\357\235\2\355" + "\232\2\355\227\2\354\225\2\353\221\1\353\216\1\353\216\1\353\213\1\353\204" + "\1\353\201\1\354}\1\354y\0\354v\0\355r\0\355n\0\355j\0\356f\0\356b\0\357" + "_\0\357[\0\357W\0\357S\0\360O\0\360O\0\361K\0\361C\0\362@\0\363<\0\3638\0" + "\3648\0\3641\0\365.\0\366+\0\366'\0\367'\0\370!\0\370\36\0\370\33\0\371\30" + "\0\371\26\0\373\26\0\373\23\0\374\15\0\374\13\0\375\10\0\375\5\0\376\3\0", +}; + +static const GstGLEffectsCurve sepia_curve = { + 256, 1, 3, + "\0\0\0\0\0\0\1\2\1\2\3\2\3\3\3\4\5\3\6\6\5\7\6\5\7\7\6\12\10\7\12\12\7\13" + "\12\10\15\13\11\15\14\12\16\14\13\21\16\14\21\17\14\21\20\16\23\21\16\24" + "\21\20\27\22\21\27\24\21\27\25\22\30\27\22\33\27\24\34\30\25\35\30\25\36" + "\32\26\37\33\27\37\34\30\40\35\30!\36\31#\36\32%!\33%\"\34&#\35'#\36($\36" + "*%\40*'\40+'\",'\".($.)$0,%1,&2.'3.'4/(51)61*82,94,:4-;5.<6/=70>82@92A:2" + "C;3C=5E=5F>6G?8J@8JB9LB:LC;MESI?TJ@UKAVLAWMBXNEZOE]PF]SG^SG`TH" + "`VIaVJbWJdXKfYLhZMi[Ni]Nj^Ok_Pl`RmaSpcSqcTrdUsfVtgVuhWvhXwiYxjYzlZ{l[|m]" + "~n^\177p_\200q_\201r`\202sa\204tc\205uc\206vd\207wf\210xf\211zg\212{h\213" + "|i\214}j\216~k\217\177l\220\200m\221\201n\222\202p\223\204q\224\205r\225" + "\206s\226\207t\230\210u\231\211v\232\212w\233\213x\234\214z\235\216{\236" + "\217|\240\217}\241\220~\242\221\177\243\222\200\244\223\201\245\224\202\246" + "\225\204\247\226\205\251\230\206\252\231\207\253\232\211\253\233\211\254" + "\234\213\255\235\214\256\236\216\257\240\217\261\241\220\262\242\221\263" + "\243\222\264\244\223\265\245\224\266\246\225\266\247\226\267\247\230\267" + "\252\231\272\253\232\273\253\233\273\254\234\275\255\236\276\256\240\277" + "\256\241\277\261\242\300\262\243\301\263\244\303\264\245\304\265\246\305" + "\265\247\306\267\251\306\270\252\307\272\253\310\273\254\311\274\256\311" + "\275\257\313\276\261\315\277\262\315\277\263\316\300\263\317\303\265\317" + "\304\265\321\304\267\322\305\270\322\305\270\323\307\273\324\310\275\325" + "\310\276\325\312\277\326\313\300\326\315\300\331\316\303\331\317\304\332" + "\320\305\334\321\306\334\321\307\334\323\311\336\324\312\337\325\312\340" + "\326\315\340\330\316\341\331\317\342\332\320\343\332\320\343\333\322\344" + "\334\324\346\335\325\347\336\326\350\337\330\351\340\331\351\340\332\352" + "\341\333\353\343\334\353\344\335\354\346\335\355\347\340\355\350\341\357" + "\351\342\360\352\343\360\353\344\361\354\346\361\355\346\363\356\350\363" + "\356\350\363\357\353\364\360\353\366\361\355\366\361\356\367\362\357\367" + "\364\360\370\365\361\371\366\361\371\367\364\372\367\364\372\370\366\372" + "\371\367\373\372\370\373\372\370\374\372\371\374\373\371\375\374\373\375" + "\374\373\375\374\374\375\375\374\376\375\375\376\375\375\376\376\375\376" + "\376\376\377\376\376\377\377\377\377\377\377", +}; + +#if 0 + +static const struct { + guint width; + guint height; + guint bytes_per_pixel; /* 3:RGB, 4:RGBA */ + guint8 pixel_data[256 * 1 * 3 + 1]; +} cross_curve = { + 256, 1, 3, + "\0\0\31\0\0\31\0\1\32\0\2\33\0\2\34\0\3\34\0\3\36\0\3\36\0\4\37\0\5\37\0" + "\6\37\0\6\40\0\7!\0\7\"\0\10\"\0\11#\0\11$\0\12%\0\13%\0\14'\0\14(\0\15(" + "\0\15)\1\17)\1\17*\1\20+\1\20+\1\21,\1\22,\1\22.\1\22.\1\23/\1\24""0\2\26" + """0\2\27""1\2\30""2\2\30""3\2\30""4\2\30""5\2\32""5\2\32""7\2\33""7\3\34" + """8\3\35""8\3\37""9\3\37:\3\40;\4\40;\4!<\4#=\5#>\5$?\5&?\6&@\6'A\7(B\7)" + "C\7)D\7*D\7+F\10,G\10/H\11/H\12""0I\12""1K\13""2K\13""4K\15""4M\15""6N\15" + """7O\15""8P\16""9P\16;Q\17U\21@U\22AV\22BY\23DY\25FZ\25HZ\26H" + "[\30J]\30N^\30N_\31O_\32P`\33Sb\35Tc\36Ud\36Xd\37Ye\40[g!]h#^i$bi%bj'dl(" + "em)gm*jn,jo-mq/nr1rr2rs4tt6uu7ww9yw;zx=}y?~{@\200{B\201{D\203}G\204~I\206" + "\177K\207\177N\212\200P\213\201S\214\202U\216\203X\217\203Z\221\204]\222" + "\205_\224\206b\225\207d\227\207g\230\211i\232\212l\233\213n\234\214q\236" + "\214s\237\215w\241\216y\242\217{\244\220~\245\220\200\246\221\202\250\222" + "\204\251\223\206\253\223\211\254\224\214\255\225\216\257\226\220\260\227" + "\222\261\227\222\262\227\226\263\231\230\265\232\232\266\233\234\267\233" + "\236\271\234\240\272\235\242\273\236\245\275\237\247\276\237\251\277\240" + "\253\300\241\255\300\242\255\303\243\260\304\243\261\305\244\261\307\245" + "\265\310\246\267\311\246\271\311\247\273\313\250\275\314\251\276\315\252" + "\300\316\252\302\317\253\304\317\254\306\321\255\307\323\256\311\324\256" + "\313\325\257\314\326\260\314\327\261\317\330\261\321\331\261\323\331\262" + "\324\332\262\326\334\264\326\335\264\332\335\265\333\336\266\335\336\266" + "\336\340\270\337\341\271\341\341\271\341\342\272\344\343\273\344\344\273" + "\350\345\274\350\345\275\351\346\276\354\347\277\355\347\300\355\350\300" + "\360\351\301\361\352\301\363\353\303\364\353\304\365\354\304\367\354\305" + "\370\354\305\370\355\307\371\355\310\373\356\310\374\356\311\375\357\312" + "\376\360\313\377\360\314\377\360\314\377\361\314\377\362\315\377\362\315" + "\377\363\316\377\363\317\377\364\320\377\364\321\377\365\322\377\365\322" + "\377\365\322\377\366\324\377\366\324\377\367\326\377\367\326\377\367\327" + "\377\367\330\377\370\331\377\371\332\377\371\332\377\371\332\377\371\334" + "\377\371\334\377\371\335\377\372\335\377\372\336\377\373\337\377\373\340" + "\377\373\340\377\374\341\377\374\342\377\374\343\377\374\344\377\374\344" + "\377\375\344\377\375\345\377\376\347\377\376\350\377\376\350\377\377\351", +}; + +#endif + +#endif diff --git a/gst/gl/effects/gstgleffectssources.c b/gst/gl/effects/gstgleffectssources.c index 77485a46fb..45a671e138 100644 --- a/gst/gl/effects/gstgleffectssources.c +++ b/gst/gl/effects/gstgleffectssources.c @@ -143,3 +143,16 @@ const gchar *sum_fragment_source = " vec4 blendcolor = texture2DRect (blend, gl_TexCoord[0].st);" " gl_FragColor = alpha * basecolor + beta * blendcolor;" "}"; + +const gchar *luma_to_curve_fragment_source = +"#extension GL_ARB_texture_rectangle : enable\n" +"uniform sampler2DRect tex;" +"uniform sampler1D curve;" +"void main () {" +" vec2 texturecoord = gl_TexCoord[0].st;" +" vec4 color = texture2DRect (tex, texturecoord);" +" float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));" +" vec4 outcolor;" +" color = texture1D(curve, luma);" +" gl_FragColor = color;" +"}"; diff --git a/gst/gl/effects/gstgleffectssources.h b/gst/gl/effects/gstgleffectssources.h index aba2c0c7df..253b11390a 100644 --- a/gst/gl/effects/gstgleffectssources.h +++ b/gst/gl/effects/gstgleffectssources.h @@ -30,5 +30,6 @@ const gchar *luma_threshold_fragment_source; const gchar *hconv9_fragment_source; const gchar *vconv9_fragment_source; const gchar *sum_fragment_source; +const gchar *luma_to_curve_fragment_source; #endif /* __GST_GL_EFFECTS_SOURCES_H__ */ diff --git a/gst/gl/gstgleffects.c b/gst/gl/gstgleffects.c index d6c19161d5..b25d903346 100644 --- a/gst/gl/gstgleffects.c +++ b/gst/gl/gstgleffects.c @@ -59,6 +59,8 @@ typedef enum { GST_GL_EFFECT_MIRROR, GST_GL_EFFECT_SQUEEZE, GST_GL_EFFECT_STRETCH, + GST_GL_EFFECT_HEAT, + GST_GL_EFFECT_SEPIA, GST_GL_EFFECT_GLOW, GST_GL_N_EFFECTS } GstGLEffectsEffect; @@ -73,6 +75,8 @@ gst_gl_effects_effect_get_type (void) { GST_GL_EFFECT_MIRROR, "Mirror Effect", "mirror" }, { GST_GL_EFFECT_SQUEEZE, "Squeeze Effect", "squeeze" }, { GST_GL_EFFECT_STRETCH, "Stretch Effect", "stretch" }, + { GST_GL_EFFECT_HEAT, "Heat Signature Effect", "heat" }, + { GST_GL_EFFECT_SEPIA, "Sepia Toning Effect", "sepia" }, { GST_GL_EFFECT_GLOW, "Glow Lighting Effect", "glow" }, { 0, NULL, NULL } }; @@ -100,6 +104,12 @@ gst_gl_effects_set_effect (GstGLEffects *effects, gint effect_type) { case GST_GL_EFFECT_STRETCH: effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_stretch; break; + case GST_GL_EFFECT_HEAT: + effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_heat; + break; + case GST_GL_EFFECT_SEPIA: + effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_sepia; + break; case GST_GL_EFFECT_GLOW: effects->effect = (GstGLEffectProcessFunc) gst_gl_effects_glow; break; @@ -139,6 +149,10 @@ gst_gl_effects_reset_gl_resources (GstGLFilter *filter) glDeleteTextures (1, &effects->midtexture[i]); effects->midtexture[i] = 0; } + for (i=0; icurve[i]); + effects->curve[i] = 0; + } } static void @@ -217,10 +231,15 @@ gst_gl_effects_draw_texture (GstGLEffects * effects, GLuint tex) static void gst_gl_effects_init (GstGLEffects * effects, GstGLEffectsClass * klass) { + gint i; effects->shaderstable = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref); + for (i=0; icurve[i] = 0; + } + effects->effect = gst_gl_effects_identity; } diff --git a/gst/gl/gstgleffects.h b/gst/gl/gstgleffects.h index f59f9f43fe..b5844474e5 100644 --- a/gst/gl/gstgleffects.h +++ b/gst/gl/gstgleffects.h @@ -45,6 +45,12 @@ typedef void (* GstGLEffectProcessFunc) (GstGLEffects *effects); #define NEEDED_TEXTURES 4 +enum { + GST_GL_EFFECTS_CURVE_HEAT, + GST_GL_EFFECTS_CURVE_SEPIA, + GST_GL_EFFECTS_N_CURVES +}; + struct _GstGLEffects { GstGLFilter filter; @@ -56,6 +62,8 @@ struct _GstGLEffects GLuint midtexture[NEEDED_TEXTURES]; GLuint outtexture; + GLuint curve[GST_GL_EFFECTS_N_CURVES]; + GHashTable *shaderstable; }; @@ -79,6 +87,8 @@ void gst_gl_effects_identity (GstGLEffects *effects); void gst_gl_effects_mirror (GstGLEffects *effects); 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_glow (GstGLEffects *effects); G_END_DECLS