glcolorconvert: expose the YUV->RGB glsl function

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5109>
This commit is contained in:
Matthew Waters 2023-07-20 20:56:34 +10:00 committed by GStreamer Marge Bot
parent b32e2cd9dd
commit bff5d6d725
3 changed files with 61 additions and 14 deletions

View file

@ -1569,6 +1569,27 @@ The glcolorconvertelement provides a GStreamer element that uses
</parameter>
</parameters>
</function>
<function name="yuv_to_rgb_shader_string" c:identifier="gst_gl_color_convert_yuv_to_rgb_shader_string" version="1.24">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.c">The returned glsl function has declaration:
`vec3 yuv_to_rgb (vec3 rgb, vec3 offset, vec3 ycoeff, vec3 ucoeff, vec3 vcoeff);`
The Y component is placed in the 0th index of the returned value, The U component in the
1st, and the V component in the 2nd. offset, ycoeff, ucoeff, and vcoeff are the
specific coefficients and offset used for the conversion.</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.h"/>
<return-value transfer-ownership="full">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.c">a glsl function that can be used to convert from
yuv to rgb</doc>
<type name="utf8" c:type="gchar*"/>
</return-value>
<parameters>
<parameter name="context" transfer-ownership="none">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.c">a #GstGLContext</doc>
<type name="GLContext" c:type="GstGLContext*"/>
</parameter>
</parameters>
</function>
<method name="decide_allocation" c:identifier="gst_gl_color_convert_decide_allocation" version="1.8">
<doc xml:space="preserve" filename="../subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.c">Provides an implementation of #GstBaseTransformClass.decide_allocation()</doc>
<source-position filename="../subprojects/gst-plugins-base/gst-libs/gst/gl/gstglcolorconvert.h"/>

View file

@ -158,25 +158,25 @@ struct shader_templ
GstGLTextureTarget target;
};
#define glsl_func_yuv_to_rgb \
"vec3 yuv_to_rgb (vec3 val, vec3 offset, vec3 ycoeff, vec3 ucoeff, vec3 vcoeff) {\n" \
static const char glsl_func_yuv_to_rgb[] = \
"vec3 yuv_to_rgb (vec3 yuv, vec3 offset, vec3 ycoeff, vec3 ucoeff, vec3 vcoeff) {\n" \
" vec3 rgb;\n" \
" val += offset;\n" \
" rgb.r = dot(val, ycoeff);\n" \
" rgb.g = dot(val, ucoeff);\n" \
" rgb.b = dot(val, vcoeff);\n" \
" yuv += offset;\n" \
" rgb.r = dot(yuv, ycoeff);\n" \
" rgb.g = dot(yuv, ucoeff);\n" \
" rgb.b = dot(yuv, vcoeff);\n" \
" return rgb;\n" \
"}\n"
"}\n";
#define glsl_func_rgb_to_yuv \
"vec3 rgb_to_yuv (vec3 val, vec3 offset, vec3 rcoeff, vec3 gcoeff, vec3 bcoeff) {\n" \
static const char glsl_func_rgb_to_yuv[] = \
"vec3 rgb_to_yuv (vec3 rgb, vec3 offset, vec3 rcoeff, vec3 gcoeff, vec3 bcoeff) {\n" \
" vec3 yuv;\n" \
" yuv.r = dot(val.rgb, rcoeff);\n" \
" yuv.g = dot(val.rgb, gcoeff);\n" \
" yuv.b = dot(val.rgb, bcoeff);\n" \
" yuv.r = dot(rgb.rgb, rcoeff);\n" \
" yuv.g = dot(rgb.rgb, gcoeff);\n" \
" yuv.b = dot(rgb.rgb, bcoeff);\n" \
" yuv += offset;\n" \
" return yuv;\n" \
"}\n"
"}\n";
static const char glsl_func_swizzle[] = "vec4 swizzle(vec4 texel, int[4] components) {\n" \
" return vec4(texel[components[0]], texel[components[1]], texel[components[2]], texel[components[3]]);\n" \
@ -190,7 +190,7 @@ static const char glsl_func_swizzle[] = "vec4 swizzle(vec4 texel, int[4] compone
"vec2 swizzle2(vec3 texel, int[3] components) {\n" \
" return vec2(texel[components[0]], texel[components[1]]);\n" \
"}\n" \
"vec2 swizzle2(vec4 texel, int[3] components) {\n" \
"vec2 swizzle2(vec4 texel, int[4] components) {\n" \
" return vec2(texel[components[0]], texel[components[1]]);\n" \
"}\n" \
"vec3 swizzle3(vec4 texel, int[4] components) {\n" \
@ -3257,3 +3257,26 @@ _do_convert_draw (GstGLContext * context, GstGLColorConvert * convert)
return ret;
}
/**
* gst_gl_color_convert_yuv_to_rgb_shader_string:
* @context: a #GstGLContext
*
* The returned glsl function has declaration:
*
* `vec3 yuv_to_rgb (vec3 rgb, vec3 offset, vec3 ycoeff, vec3 ucoeff, vec3 vcoeff);`
*
* The Y component is placed in the 0th index of the returned value, The U component in the
* 1st, and the V component in the 2nd. offset, ycoeff, ucoeff, and vcoeff are the
* specific coefficients and offset used for the conversion.
*
* Returns: (transfer full): a glsl function that can be used to convert from
* yuv to rgb
*
* Since: 1.24
*/
gchar *
gst_gl_color_convert_yuv_to_rgb_shader_string (GstGLContext * context)
{
return g_strdup (glsl_func_yuv_to_rgb);
}

View file

@ -151,6 +151,9 @@ gboolean gst_gl_color_convert_decide_allocation (GstGLColorConvert * conver
GST_GL_API
GstBuffer * gst_gl_color_convert_perform (GstGLColorConvert * convert, GstBuffer * inbuf);
GST_GL_API
gchar * gst_gl_color_convert_yuv_to_rgb_shader_string (GstGLContext * context);
G_END_DECLS
#endif /* __GST_GL_COLOR_CONVERT_H__ */