glutils: Export affine transformation functions for gtkglsink
Also remove duplicated copy of those functions from the gl plugin With contributions from Bastien Nocera Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1088>
This commit is contained in:
parent
9b75628101
commit
fdd7f9be23
@ -2409,10 +2409,10 @@ gst_glimage_sink_on_draw (GstGLImageSink * gl_sink)
|
|||||||
if (gl_sink->transform_matrix) {
|
if (gl_sink->transform_matrix) {
|
||||||
gfloat tmp[16];
|
gfloat tmp[16];
|
||||||
|
|
||||||
gst_gl_get_affine_transformation_meta_as_ndc_ext (af_meta, tmp);
|
gst_gl_get_affine_transformation_meta_as_ndc (af_meta, tmp);
|
||||||
gst_gl_multiply_matrix4 (tmp, gl_sink->transform_matrix, matrix);
|
gst_gl_multiply_matrix4 (tmp, gl_sink->transform_matrix, matrix);
|
||||||
} else {
|
} else {
|
||||||
gst_gl_get_affine_transformation_meta_as_ndc_ext (af_meta, matrix);
|
gst_gl_get_affine_transformation_meta_as_ndc (af_meta, matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_gl_shader_set_uniform_matrix_4fv (gl_sink->redisplay_shader,
|
gst_gl_shader_set_uniform_matrix_4fv (gl_sink->redisplay_shader,
|
||||||
|
@ -807,7 +807,7 @@ gst_gl_transformation_prepare_output_buffer (GstBaseTransform * trans,
|
|||||||
GST_LOG_OBJECT (trans, "applying transformation to existing affine "
|
GST_LOG_OBJECT (trans, "applying transformation to existing affine "
|
||||||
"transformation meta");
|
"transformation meta");
|
||||||
|
|
||||||
gst_gl_get_affine_transformation_meta_as_ndc_ext (af_meta, upstream);
|
gst_gl_get_affine_transformation_meta_as_ndc (af_meta, upstream);
|
||||||
|
|
||||||
/* apply the transformation to the existing affine meta */
|
/* apply the transformation to the existing affine meta */
|
||||||
graphene_matrix_init_from_float (&upstream_matrix, upstream);
|
graphene_matrix_init_from_float (&upstream_matrix, upstream);
|
||||||
@ -822,7 +822,7 @@ gst_gl_transformation_prepare_output_buffer (GstBaseTransform * trans,
|
|||||||
graphene_matrix_multiply (&tmp, &yflip, &tmp2);
|
graphene_matrix_multiply (&tmp, &yflip, &tmp2);
|
||||||
|
|
||||||
graphene_matrix_to_float (&tmp2, downstream);
|
graphene_matrix_to_float (&tmp2, downstream);
|
||||||
gst_gl_set_affine_transformation_meta_from_ndc_ext (af_meta, downstream);
|
gst_gl_set_affine_transformation_meta_from_ndc (af_meta, downstream);
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
@ -106,73 +106,3 @@ gst_gl_context_gen_shader (GstGLContext * context, const gchar * vert_src,
|
|||||||
|
|
||||||
return *shader != NULL;
|
return *shader != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const gfloat identity_matrix[] = {
|
|
||||||
1.0, 0.0, 0.0, 0.0,
|
|
||||||
0.0, 1.0, 0.0, 0.0,
|
|
||||||
0.0, 0.0, 1.0, 0.0,
|
|
||||||
0.0, 0.0, 0.0, 1.0,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const gfloat from_ndc_matrix[] = {
|
|
||||||
0.5, 0.0, 0.0, 0.0,
|
|
||||||
0.0, 0.5, 0.0, 0.0,
|
|
||||||
0.0, 0.0, 0.5, 0.0,
|
|
||||||
0.5, 0.5, 0.5, 1.0,
|
|
||||||
};
|
|
||||||
|
|
||||||
static const gfloat to_ndc_matrix[] = {
|
|
||||||
2.0, 0.0, 0.0, 0.0,
|
|
||||||
0.0, 2.0, 0.0, 0.0,
|
|
||||||
0.0, 0.0, 2.0, 0.0,
|
|
||||||
-1.0, -1.0, -1.0, 1.0,
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result)
|
|
||||||
{
|
|
||||||
int i, j, k;
|
|
||||||
gfloat tmp[16] = { 0.0f };
|
|
||||||
|
|
||||||
if (!a || !b || !result)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) { /* column */
|
|
||||||
for (j = 0; j < 4; j++) { /* row */
|
|
||||||
for (k = 0; k < 4; k++) {
|
|
||||||
tmp[j + (i * 4)] += a[k + (i * 4)] * b[j + (k * 4)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < 16; i++)
|
|
||||||
result[i] = tmp[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
void gst_gl_get_affine_transformation_meta_as_ndc_ext
|
|
||||||
(GstVideoAffineTransformationMeta * meta, gfloat * matrix)
|
|
||||||
{
|
|
||||||
if (!meta) {
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < 16; i++) {
|
|
||||||
matrix[i] = identity_matrix[i];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
float tmp[16];
|
|
||||||
|
|
||||||
gst_gl_multiply_matrix4 (from_ndc_matrix, meta->matrix, tmp);
|
|
||||||
gst_gl_multiply_matrix4 (tmp, to_ndc_matrix, matrix);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void gst_gl_set_affine_transformation_meta_from_ndc_ext
|
|
||||||
(GstVideoAffineTransformationMeta * meta, const gfloat * matrix)
|
|
||||||
{
|
|
||||||
float tmp[16];
|
|
||||||
|
|
||||||
g_return_if_fail (meta != NULL);
|
|
||||||
|
|
||||||
gst_gl_multiply_matrix4 (to_ndc_matrix, matrix, tmp);
|
|
||||||
gst_gl_multiply_matrix4 (tmp, from_ndc_matrix, meta->matrix);
|
|
||||||
}
|
|
||||||
|
@ -28,10 +28,6 @@ G_BEGIN_DECLS
|
|||||||
gboolean gst_gl_context_gen_shader (GstGLContext * context,
|
gboolean gst_gl_context_gen_shader (GstGLContext * context,
|
||||||
const gchar * shader_vertex_source,
|
const gchar * shader_vertex_source,
|
||||||
const gchar * shader_fragment_source, GstGLShader ** shader);
|
const gchar * shader_fragment_source, GstGLShader ** shader);
|
||||||
void gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result);
|
|
||||||
void gst_gl_get_affine_transformation_meta_as_ndc_ext (GstVideoAffineTransformationMeta *
|
|
||||||
meta, gfloat * matrix);
|
|
||||||
void gst_gl_set_affine_transformation_meta_from_ndc_ext (GstVideoAffineTransformationMeta * meta, const gfloat * matrix);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@ -1616,7 +1616,7 @@ gst_gl_video_mixer_callback (gpointer stuff)
|
|||||||
gst_video_aggregator_pad_get_current_buffer (vagg_pad);
|
gst_video_aggregator_pad_get_current_buffer (vagg_pad);
|
||||||
|
|
||||||
af_meta = gst_buffer_get_video_affine_transformation_meta (buffer);
|
af_meta = gst_buffer_get_video_affine_transformation_meta (buffer);
|
||||||
gst_gl_get_affine_transformation_meta_as_ndc_ext (af_meta, af_matrix);
|
gst_gl_get_affine_transformation_meta_as_ndc (af_meta, af_matrix);
|
||||||
gst_gl_multiply_matrix4 (af_matrix, pad->m_matrix, matrix);
|
gst_gl_multiply_matrix4 (af_matrix, pad->m_matrix, matrix);
|
||||||
gst_gl_shader_set_uniform_matrix_4fv (video_mixer->shader,
|
gst_gl_shader_set_uniform_matrix_4fv (video_mixer->shader,
|
||||||
"u_transformation", 1, FALSE, matrix);
|
"u_transformation", 1, FALSE, matrix);
|
||||||
|
@ -810,17 +810,28 @@ static const gfloat to_ndc_matrix[] = {
|
|||||||
-1.0, -1.0, -1.0, 1.0,
|
-1.0, -1.0, -1.0, 1.0,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* multiplies two 4x4 matrices, @a X @b, and stores the result in @result
|
/**
|
||||||
* https://en.wikipedia.org/wiki/Matrix_multiplication
|
* gst_gl_multiply_matrix4:
|
||||||
|
* @a: (array fixed-size=16): a 2-dimensional 4x4 array of #gfloat
|
||||||
|
* @b: (array fixed-size=16): another 2-dimensional 4x4 array of #gfloat
|
||||||
|
* @result: (out) (array fixed-size=16): the result of the multiplication
|
||||||
|
*
|
||||||
|
* Multiplies two 4x4 matrices, @a and @b, and stores the result, a
|
||||||
|
* 2-dimensional array of #gfloat, in @result.
|
||||||
|
*
|
||||||
|
* Since: 1.20
|
||||||
*/
|
*/
|
||||||
static void
|
/* https://en.wikipedia.org/wiki/Matrix_multiplication */
|
||||||
|
void
|
||||||
gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result)
|
gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result)
|
||||||
{
|
{
|
||||||
int i, j, k;
|
int i, j, k;
|
||||||
gfloat tmp[16] = { 0.0f };
|
gfloat tmp[16] = { 0.0f };
|
||||||
|
|
||||||
if (!a || !b || !result)
|
g_return_if_fail (a != NULL);
|
||||||
return;
|
g_return_if_fail (b != NULL);
|
||||||
|
g_return_if_fail (result != NULL);
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) { /* column */
|
for (i = 0; i < 4; i++) { /* column */
|
||||||
for (j = 0; j < 4; j++) { /* row */
|
for (j = 0; j < 4; j++) { /* row */
|
||||||
for (k = 0; k < 4; k++) {
|
for (k = 0; k < 4; k++) {
|
||||||
@ -833,7 +844,7 @@ gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result)
|
|||||||
result[i] = tmp[i];
|
result[i] = tmp[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* gst_gl_get_affine_transformation_meta_as_ndc:
|
* gst_gl_get_affine_transformation_meta_as_ndc:
|
||||||
* @meta: (nullable): a #GstVideoAffineTransformationMeta
|
* @meta: (nullable): a #GstVideoAffineTransformationMeta
|
||||||
* @matrix: (out): result of the 4x4 matrix
|
* @matrix: (out): result of the 4x4 matrix
|
||||||
@ -845,11 +856,15 @@ gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result)
|
|||||||
* - x - [-1, 1] - +ve X moves right
|
* - x - [-1, 1] - +ve X moves right
|
||||||
* - y - [-1, 1] - +ve Y moves up
|
* - y - [-1, 1] - +ve Y moves up
|
||||||
* - z - [-1, 1] - +ve Z moves into
|
* - z - [-1, 1] - +ve Z moves into
|
||||||
|
*
|
||||||
|
* Since: 1.20
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta *
|
gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta *
|
||||||
meta, gfloat * matrix)
|
meta, gfloat * matrix)
|
||||||
{
|
{
|
||||||
|
g_return_if_fail (matrix != NULL);
|
||||||
|
|
||||||
if (!meta) {
|
if (!meta) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -865,12 +880,23 @@ gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_gl_set_affine_transformation_meta_from_ndc:
|
||||||
|
* @meta: a #GstVideoAffineTransformationMeta
|
||||||
|
* @matrix: a 4x4 matrix
|
||||||
|
*
|
||||||
|
* Set the 4x4 affine transformation matrix stored in @meta from the
|
||||||
|
* NDC coordinates in @matrix.
|
||||||
|
*
|
||||||
|
* Since: 1.20
|
||||||
|
*/
|
||||||
void gst_gl_set_affine_transformation_meta_from_ndc
|
void gst_gl_set_affine_transformation_meta_from_ndc
|
||||||
(GstVideoAffineTransformationMeta * meta, const gfloat * matrix)
|
(GstVideoAffineTransformationMeta * meta, const gfloat * matrix)
|
||||||
{
|
{
|
||||||
float tmp[16];
|
float tmp[16];
|
||||||
|
|
||||||
g_return_if_fail (meta != NULL);
|
g_return_if_fail (meta != NULL);
|
||||||
|
g_return_if_fail (matrix != NULL);
|
||||||
|
|
||||||
/* change of basis multiplications */
|
/* change of basis multiplications */
|
||||||
gst_gl_multiply_matrix4 (to_ndc_matrix, matrix, tmp);
|
gst_gl_multiply_matrix4 (to_ndc_matrix, matrix, tmp);
|
||||||
|
@ -59,6 +59,15 @@ gboolean gst_gl_value_set_texture_target (GValue * value, GstGLTextureTarget tar
|
|||||||
GST_GL_API
|
GST_GL_API
|
||||||
GstGLTextureTarget gst_gl_value_get_texture_target_mask (const GValue * value);
|
GstGLTextureTarget gst_gl_value_get_texture_target_mask (const GValue * value);
|
||||||
|
|
||||||
|
GST_GL_API
|
||||||
|
void gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta * meta, gfloat * matrix);
|
||||||
|
GST_GL_API
|
||||||
|
void gst_gl_set_affine_transformation_meta_from_ndc (GstVideoAffineTransformationMeta * meta, const gfloat * matrix);
|
||||||
|
|
||||||
|
GST_GL_API
|
||||||
|
void gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result);
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_GL_UTILS_H__ */
|
#endif /* __GST_GL_UTILS_H__ */
|
||||||
|
@ -26,8 +26,6 @@
|
|||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
G_GNUC_INTERNAL gboolean gst_gl_run_query (GstElement * element, GstQuery * query, GstPadDirection direction);
|
G_GNUC_INTERNAL gboolean gst_gl_run_query (GstElement * element, GstQuery * query, GstPadDirection direction);
|
||||||
G_GNUC_INTERNAL void gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta * meta, gfloat * matrix);
|
|
||||||
G_GNUC_INTERNAL void gst_gl_set_affine_transformation_meta_from_ndc (GstVideoAffineTransformationMeta * meta, const gfloat * matrix);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user