mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 00:06:36 +00:00
glcolorconvert: merge shaders for AYUV and VUYA formats
The shaders can be used for AYUV and varieties.
This commit is contained in:
parent
289d8e53e2
commit
56de495f0e
1 changed files with 12 additions and 39 deletions
|
@ -200,11 +200,12 @@ static const struct shader_templ templ_COMPOSE =
|
||||||
GST_GL_TEXTURE_TARGET_2D
|
GST_GL_TEXTURE_TARGET_2D
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Shaders for AYUV and varieties */
|
||||||
static const gchar templ_AYUV_to_RGB_BODY[] =
|
static const gchar templ_AYUV_to_RGB_BODY[] =
|
||||||
"vec4 texel, rgba;\n"
|
"vec4 texel, rgba;\n"
|
||||||
"texel = texture2D(tex, texcoord * tex_scale0);\n"
|
"texel = texture2D(tex, texcoord * tex_scale0);\n"
|
||||||
"rgba.rgb = yuv_to_rgb (texel.yzw, offset, coeff1, coeff2, coeff3);\n"
|
"rgba.rgb = yuv_to_rgb (texel.%s, offset, coeff1, coeff2, coeff3);\n"
|
||||||
"rgba.a = texel.r;\n"
|
"rgba.a = texel.%c;\n"
|
||||||
"gl_FragColor=vec4(rgba.%c,rgba.%c,rgba.%c,rgba.%c);\n";
|
"gl_FragColor=vec4(rgba.%c,rgba.%c,rgba.%c,rgba.%c);\n";
|
||||||
|
|
||||||
static const struct shader_templ templ_AYUV_to_RGB =
|
static const struct shader_templ templ_AYUV_to_RGB =
|
||||||
|
@ -217,8 +218,8 @@ static const struct shader_templ templ_AYUV_to_RGB =
|
||||||
static const gchar templ_RGB_to_AYUV_BODY[] =
|
static const gchar templ_RGB_to_AYUV_BODY[] =
|
||||||
"vec4 texel, ayuv;\n"
|
"vec4 texel, ayuv;\n"
|
||||||
"texel = texture2D(tex, texcoord).%c%c%c%c;\n"
|
"texel = texture2D(tex, texcoord).%c%c%c%c;\n"
|
||||||
"ayuv.yzw = rgb_to_yuv (texel.rgb, offset, coeff1, coeff2, coeff3);\n"
|
"ayuv.%s = rgb_to_yuv (texel.rgb, offset, coeff1, coeff2, coeff3);\n"
|
||||||
"ayuv.x = %s;\n"
|
"ayuv.%c = %s;\n"
|
||||||
"gl_FragColor = ayuv;\n";
|
"gl_FragColor = ayuv;\n";
|
||||||
|
|
||||||
static const struct shader_templ templ_RGB_to_AYUV =
|
static const struct shader_templ templ_RGB_to_AYUV =
|
||||||
|
@ -228,34 +229,6 @@ static const struct shader_templ templ_RGB_to_AYUV =
|
||||||
GST_GL_TEXTURE_TARGET_2D
|
GST_GL_TEXTURE_TARGET_2D
|
||||||
};
|
};
|
||||||
|
|
||||||
static const gchar templ_VUYA_to_RGB_BODY[] =
|
|
||||||
"vec4 texel, rgba;\n"
|
|
||||||
"texel = texture2D(tex, texcoord * tex_scale0);\n"
|
|
||||||
"rgba.rgb = yuv_to_rgb (texel.zyx, offset, coeff1, coeff2, coeff3);\n"
|
|
||||||
"rgba.a = texel.w;\n"
|
|
||||||
"gl_FragColor=vec4(rgba.%c,rgba.%c,rgba.%c,rgba.%c);\n";
|
|
||||||
|
|
||||||
static const struct shader_templ templ_VUYA_to_RGB =
|
|
||||||
{ NULL,
|
|
||||||
DEFAULT_UNIFORMS YUV_TO_RGB_COEFFICIENTS "uniform sampler2D tex;\n",
|
|
||||||
{ glsl_func_yuv_to_rgb, NULL, },
|
|
||||||
GST_GL_TEXTURE_TARGET_2D
|
|
||||||
};
|
|
||||||
|
|
||||||
static const gchar templ_RGB_to_VUYA_BODY[] =
|
|
||||||
"vec4 texel, ayuv;\n"
|
|
||||||
"texel = texture2D(tex, texcoord).%c%c%c%c;\n"
|
|
||||||
"ayuv.zyx = rgb_to_yuv (texel.rgb, offset, coeff1, coeff2, coeff3);\n"
|
|
||||||
"ayuv.w = %s;\n"
|
|
||||||
"gl_FragColor = ayuv;\n";
|
|
||||||
|
|
||||||
static const struct shader_templ templ_RGB_to_VUYA =
|
|
||||||
{ NULL,
|
|
||||||
DEFAULT_UNIFORMS RGB_TO_YUV_COEFFICIENTS "uniform sampler2D tex;\n",
|
|
||||||
{ glsl_func_rgb_to_yuv, NULL, },
|
|
||||||
GST_GL_TEXTURE_TARGET_2D
|
|
||||||
};
|
|
||||||
|
|
||||||
/* YUV to RGB conversion */
|
/* YUV to RGB conversion */
|
||||||
static const gchar templ_PLANAR_YUV_to_RGB_BODY[] =
|
static const gchar templ_PLANAR_YUV_to_RGB_BODY[] =
|
||||||
"vec4 texel, rgba;\n"
|
"vec4 texel, rgba;\n"
|
||||||
|
@ -1642,13 +1615,13 @@ _YUV_to_RGB (GstGLColorConvert * convert)
|
||||||
switch (GST_VIDEO_INFO_FORMAT (&convert->in_info)) {
|
switch (GST_VIDEO_INFO_FORMAT (&convert->in_info)) {
|
||||||
case GST_VIDEO_FORMAT_AYUV:
|
case GST_VIDEO_FORMAT_AYUV:
|
||||||
info->templ = &templ_AYUV_to_RGB;
|
info->templ = &templ_AYUV_to_RGB;
|
||||||
info->frag_body = g_strdup_printf (templ_AYUV_to_RGB_BODY,
|
info->frag_body = g_strdup_printf (templ_AYUV_to_RGB_BODY, "yzw", 'x',
|
||||||
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3]);
|
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3]);
|
||||||
info->shader_tex_names[0] = "tex";
|
info->shader_tex_names[0] = "tex";
|
||||||
break;
|
break;
|
||||||
case GST_VIDEO_FORMAT_VUYA:
|
case GST_VIDEO_FORMAT_VUYA:
|
||||||
info->templ = &templ_VUYA_to_RGB;
|
info->templ = &templ_AYUV_to_RGB;
|
||||||
info->frag_body = g_strdup_printf (templ_VUYA_to_RGB_BODY,
|
info->frag_body = g_strdup_printf (templ_AYUV_to_RGB_BODY, "zyx", 'w',
|
||||||
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3]);
|
pixel_order[0], pixel_order[1], pixel_order[2], pixel_order[3]);
|
||||||
info->shader_tex_names[0] = "tex";
|
info->shader_tex_names[0] = "tex";
|
||||||
break;
|
break;
|
||||||
|
@ -1771,14 +1744,14 @@ _RGB_to_YUV (GstGLColorConvert * convert)
|
||||||
alpha = _is_RGBx (in_format) ? "1.0" : "texel.a";
|
alpha = _is_RGBx (in_format) ? "1.0" : "texel.a";
|
||||||
info->templ = &templ_RGB_to_AYUV;
|
info->templ = &templ_RGB_to_AYUV;
|
||||||
info->frag_body = g_strdup_printf (templ_RGB_to_AYUV_BODY, pixel_order[0],
|
info->frag_body = g_strdup_printf (templ_RGB_to_AYUV_BODY, pixel_order[0],
|
||||||
pixel_order[1], pixel_order[2], pixel_order[3], alpha);
|
pixel_order[1], pixel_order[2], pixel_order[3], "yzw", 'x', alpha);
|
||||||
info->out_n_textures = 1;
|
info->out_n_textures = 1;
|
||||||
break;
|
break;
|
||||||
case GST_VIDEO_FORMAT_VUYA:
|
case GST_VIDEO_FORMAT_VUYA:
|
||||||
alpha = _is_RGBx (in_format) ? "1.0" : "texel.a";
|
alpha = _is_RGBx (in_format) ? "1.0" : "texel.a";
|
||||||
info->templ = &templ_RGB_to_VUYA;
|
info->templ = &templ_RGB_to_AYUV;
|
||||||
info->frag_body = g_strdup_printf (templ_RGB_to_VUYA_BODY, pixel_order[0],
|
info->frag_body = g_strdup_printf (templ_RGB_to_AYUV_BODY, pixel_order[0],
|
||||||
pixel_order[1], pixel_order[2], pixel_order[3], alpha);
|
pixel_order[1], pixel_order[2], pixel_order[3], "zyx", 'w', alpha);
|
||||||
info->out_n_textures = 1;
|
info->out_n_textures = 1;
|
||||||
break;
|
break;
|
||||||
case GST_VIDEO_FORMAT_I420:
|
case GST_VIDEO_FORMAT_I420:
|
||||||
|
|
Loading…
Reference in a new issue