mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-19 16:21:17 +00:00
[166/906] add rgb_to_luma_fragment source and correspondent effect. use the latter for a cross processing effect.
This commit is contained in:
parent
e009d7b400
commit
5b1f62a079
7 changed files with 158 additions and 0 deletions
|
@ -35,6 +35,7 @@ libgstopengl_la_SOURCES = \
|
|||
effects/gstgleffectsqueeze.c \
|
||||
effects/gstgleffectstretch.c \
|
||||
effects/gstgleffectlumatocurve.c \
|
||||
effects/gstgleffectrgbtocurve.c \
|
||||
effects/gstgleffectglow.c
|
||||
|
||||
|
||||
|
|
91
gst/gl/effects/gstgleffectrgbtocurve.c
Normal file
91
gst/gl/effects/gstgleffectrgbtocurve.c
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
||||
*
|
||||
* 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 <gstgleffects.h>
|
||||
#include <gstgleffectscurves.h>
|
||||
|
||||
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);
|
||||
}
|
|
@ -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\35<X\36>Y\36?Z\37A[\40"
|
||||
"B[\"D\\#E]#G_$G_%J`&Ka(La(Ob*Oc*Qd+Rd-Te.Ug/Vh0Yh1Zi3[j4]k5_k6am9bm;dn;h"
|
||||
"n<ho?jq?mrAmrBnsDqtFstJuuKvvKxwMzwO|xQ\177yS\200zU\204zX\204{Z\206|\\\210"
|
||||
"~_\212~a\216\177c\216\200e\217\201h\221\201j\225\202m\225\203o\227\204r\231"
|
||||
"\204u\233\205w\235\206y\237\207|\240\207\177\242\211\201\244\211\204\246"
|
||||
"\211\206\250\212\211\252\213\213\253\214\216\254\214\220\256\215\223\260"
|
||||
"\216\225\262\217\230\264\217\232\265\220\235\267\221\237\271\222\241\273"
|
||||
"\222\243\273\223\246\275\224\250\277\225\253\301\225\254\302\226\256\303"
|
||||
"\227\261\305\230\263\306\230\265\310\231\267\311\232\271\313\233\273\314"
|
||||
"\233\275\315\234\277\317\235\301\320\236\302\321\236\304\323\237\306\324"
|
||||
"\237\307\325\237\311\326\240\313\327\241\313\331\241\316\331\242\320\333"
|
||||
"\243\321\334\244\322\335\245\324\335\245\325\337\246\327\340\247\330\341"
|
||||
"\250\331\341\250\333\342\251\335\343\252\335\343\253\335\345\253\341\345"
|
||||
"\253\341\346\254\341\347\255\344\350\255\345\350\256\347\350\257\350\351"
|
||||
"\260\350\352\260\352\353\261\353\354\262\354\354\262\355\354\263\356\355"
|
||||
"\264\357\356\264\360\356\264\361\357\265\362\357\266\362\357\267\364\360"
|
||||
"\267\365\361\270\366\361\271\366\361\271\367\362\272\367\363\272\370\363"
|
||||
"\273\371\363\274\372\363\274\372\364\275\372\365\276\373\365\277\373\365"
|
||||
"\277\374\366\300\374\366\300\375\366\301\375\366\301\375\367\302\376\367"
|
||||
"\303\376\367\303\376\370\304\377\370\305\377\371\305\377\371\306\377\371"
|
||||
"\306\377\372\307\377\372\310\377\372\310\377\372\311\377\372\312\377\372"
|
||||
"\313\377\372\313\377\373\313\377\373\314\377\373\315\377\373\315\377\373"
|
||||
"\316\377\374\317\377\374\317\377\374\320\377\374\320\377\374\321\377\375"
|
||||
"\322\377\375\322\377\375\323\377\375\323\377\375\325\377\375\325\377\375"
|
||||
"\325\377\375\325\377\375\326\377\375\327\377\375\330\377\375\331\377\375"
|
||||
"\331\377\375\331\377\376\332\377\376\332\377\376\333\377\376\334\377\376"
|
||||
"\335\377\376\335\377\376\335\377\376\335\377\376\337\377\376\340\377\376"
|
||||
"\340\377\376\341\377\376\341\377\377\341\377\377\342\377\377\343\377\377"
|
||||
"\344\377\377\345\377\377\345",
|
||||
};
|
||||
|
||||
/* CURVE for the cross processing effect */
|
||||
static const GstGLEffectsCurve cross_curve = {
|
||||
256, 1, 3,
|
||||
|
|
|
@ -144,6 +144,7 @@ const gchar *sum_fragment_source =
|
|||
" gl_FragColor = alpha * basecolor + beta * blendcolor;"
|
||||
"}";
|
||||
|
||||
/* lut operations, map luma to tex1d, see orange book (chapter 19) */
|
||||
const gchar *luma_to_curve_fragment_source =
|
||||
"#extension GL_ARB_texture_rectangle : enable\n"
|
||||
"uniform sampler2DRect tex;"
|
||||
|
@ -156,3 +157,21 @@ const gchar *luma_to_curve_fragment_source =
|
|||
" color = texture1D(curve, luma);"
|
||||
" gl_FragColor = color;"
|
||||
"}";
|
||||
|
||||
/* lut operations, map rgb to tex1d, see orange book (chapter 19) */
|
||||
const gchar *rgb_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);"
|
||||
" vec4 outcolor;"
|
||||
" outcolor.r = texture1D(curve, color.r).r;"
|
||||
" outcolor.g = texture1D(curve, color.g).g;"
|
||||
" outcolor.b = texture1D(curve, color.b).b;"
|
||||
" outcolor.a = color.a;"
|
||||
" gl_FragColor = outcolor;"
|
||||
"}";
|
||||
|
||||
|
||||
|
|
|
@ -31,5 +31,6 @@ const gchar *hconv9_fragment_source;
|
|||
const gchar *vconv9_fragment_source;
|
||||
const gchar *sum_fragment_source;
|
||||
const gchar *luma_to_curve_fragment_source;
|
||||
const gchar *rgb_to_curve_fragment_source;
|
||||
|
||||
#endif /* __GST_GL_EFFECTS_SOURCES_H__ */
|
||||
|
|
|
@ -61,6 +61,7 @@ typedef enum {
|
|||
GST_GL_EFFECT_STRETCH,
|
||||
GST_GL_EFFECT_HEAT,
|
||||
GST_GL_EFFECT_SEPIA,
|
||||
GST_GL_EFFECT_XPRO,
|
||||
GST_GL_EFFECT_GLOW,
|
||||
GST_GL_N_EFFECTS
|
||||
} GstGLEffectsEffect;
|
||||
|
@ -77,6 +78,7 @@ gst_gl_effects_effect_get_type (void)
|
|||
{ 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_XPRO, "Cross Processing Effect", "xpro" },
|
||||
{ GST_GL_EFFECT_GLOW, "Glow Lighting Effect", "glow" },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
@ -110,6 +112,9 @@ gst_gl_effects_set_effect (GstGLEffects *effects, gint effect_type) {
|
|||
case GST_GL_EFFECT_SEPIA:
|
||||
effects->effect = (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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue