From: Olivier CrĂȘte Date: Tue, 29 Aug 2017 21:21:05 +0000 (-0400) Subject: glutils: Export affine transformation functions for gtkglsink X-Git-Tag: 1.19.3~270 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fdd7f9be23bf3ec34f2f676ecdc2d36b76189104;p=platform%2Fupstream%2Fgstreamer.git 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: --- diff --git a/subprojects/gst-plugins-base/ext/gl/gstglimagesink.c b/subprojects/gst-plugins-base/ext/gl/gstglimagesink.c index 35f24afef3..26b729e67f 100644 --- a/subprojects/gst-plugins-base/ext/gl/gstglimagesink.c +++ b/subprojects/gst-plugins-base/ext/gl/gstglimagesink.c @@ -2409,10 +2409,10 @@ gst_glimage_sink_on_draw (GstGLImageSink * gl_sink) if (gl_sink->transform_matrix) { 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); } 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, diff --git a/subprojects/gst-plugins-base/ext/gl/gstgltransformation.c b/subprojects/gst-plugins-base/ext/gl/gstgltransformation.c index a5ca2005b7..3a03b992b0 100644 --- a/subprojects/gst-plugins-base/ext/gl/gstgltransformation.c +++ b/subprojects/gst-plugins-base/ext/gl/gstgltransformation.c @@ -807,7 +807,7 @@ gst_gl_transformation_prepare_output_buffer (GstBaseTransform * trans, GST_LOG_OBJECT (trans, "applying transformation to existing affine " "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 */ 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_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; } diff --git a/subprojects/gst-plugins-base/ext/gl/gstglutils.c b/subprojects/gst-plugins-base/ext/gl/gstglutils.c index 12209a6998..bbbcb0fbfa 100644 --- a/subprojects/gst-plugins-base/ext/gl/gstglutils.c +++ b/subprojects/gst-plugins-base/ext/gl/gstglutils.c @@ -106,73 +106,3 @@ gst_gl_context_gen_shader (GstGLContext * context, const gchar * vert_src, 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); -} diff --git a/subprojects/gst-plugins-base/ext/gl/gstglutils.h b/subprojects/gst-plugins-base/ext/gl/gstglutils.h index bf567f603a..ee7d4c6982 100644 --- a/subprojects/gst-plugins-base/ext/gl/gstglutils.h +++ b/subprojects/gst-plugins-base/ext/gl/gstglutils.h @@ -28,10 +28,6 @@ G_BEGIN_DECLS gboolean gst_gl_context_gen_shader (GstGLContext * context, const gchar * shader_vertex_source, 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 diff --git a/subprojects/gst-plugins-base/ext/gl/gstglvideomixer.c b/subprojects/gst-plugins-base/ext/gl/gstglvideomixer.c index a08016b54a..14dabcbb2b 100644 --- a/subprojects/gst-plugins-base/ext/gl/gstglvideomixer.c +++ b/subprojects/gst-plugins-base/ext/gl/gstglvideomixer.c @@ -1616,7 +1616,7 @@ gst_gl_video_mixer_callback (gpointer stuff) gst_video_aggregator_pad_get_current_buffer (vagg_pad); 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_shader_set_uniform_matrix_4fv (video_mixer->shader, "u_transformation", 1, FALSE, matrix); diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils.c b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils.c index 52fa7d8360..5e4f92e7da 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils.c @@ -810,17 +810,28 @@ static const gfloat to_ndc_matrix[] = { -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) { int i, j, k; gfloat tmp[16] = { 0.0f }; - if (!a || !b || !result) - return; + g_return_if_fail (a != NULL); + g_return_if_fail (b != NULL); + g_return_if_fail (result != NULL); + for (i = 0; i < 4; i++) { /* column */ for (j = 0; j < 4; j++) { /* row */ 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]; } -/* +/** * gst_gl_get_affine_transformation_meta_as_ndc: * @meta: (nullable): a #GstVideoAffineTransformationMeta * @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 * - y - [-1, 1] - +ve Y moves up * - z - [-1, 1] - +ve Z moves into + * + * Since: 1.20 */ void gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta * meta, gfloat * matrix) { + g_return_if_fail (matrix != NULL); + if (!meta) { 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 (GstVideoAffineTransformationMeta * meta, const gfloat * matrix) { float tmp[16]; g_return_if_fail (meta != NULL); + g_return_if_fail (matrix != NULL); /* change of basis multiplications */ gst_gl_multiply_matrix4 (to_ndc_matrix, matrix, tmp); diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils.h b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils.h index bbae73e6db..b27145489f 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils.h @@ -59,6 +59,15 @@ gboolean gst_gl_value_set_texture_target (GValue * value, GstGLTextureTarget tar GST_GL_API 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 #endif /* __GST_GL_UTILS_H__ */ diff --git a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils_private.h b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils_private.h index 5a314e37b8..9bc652dcb9 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils_private.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/gl/gstglutils_private.h @@ -26,8 +26,6 @@ G_BEGIN_DECLS 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