From de6c39189f4b3fc615a6778984a60e895e9d18cb Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Fri, 13 Jan 2017 11:06:39 +1100 Subject: [PATCH] glutils: privatise matrix multiplication/videoaffinetransformation retrieval --- ext/gl/gstglutils.c | 60 ++++++++++++++++++++++++++++ ext/gl/gstglutils.h | 3 ++ gst-libs/gst/gl/gstglutils.c | 2 +- gst-libs/gst/gl/gstglutils.h | 6 --- gst-libs/gst/gl/gstglutils_private.h | 1 + gst-libs/gst/gl/gstglviewconvert.c | 1 + 6 files changed, 66 insertions(+), 7 deletions(-) diff --git a/ext/gl/gstglutils.c b/ext/gl/gstglutils.c index ca5e8ab06c..224923c15b 100644 --- a/ext/gl/gstglutils.c +++ b/ext/gl/gstglutils.c @@ -105,3 +105,63 @@ gst_gl_context_gen_shader (GstGLContext * context, const gchar * vert_src, return *shader != NULL; } + +static const gfloat identity_matrix[] = { + 1.0f, 0.0f, 0.0, 0.0f, + 0.0f, 1.0f, 0.0, 0.0f, + 0.0f, 0.0f, 1.0, 0.0f, + 0.0f, 0.0f, 0.0, 1.0f, +}; + +static const gfloat from_ndc_matrix[] = { + 0.5f, 0.0f, 0.0, 0.5f, + 0.0f, 0.5f, 0.0, 0.5f, + 0.0f, 0.0f, 0.5, 0.5f, + 0.0f, 0.0f, 0.0, 1.0f, +}; + +static const gfloat to_ndc_matrix[] = { + 2.0f, 0.0f, 0.0, -1.0f, + 0.0f, 2.0f, 0.0, -1.0f, + 0.0f, 0.0f, 2.0, -1.0f, + 0.0f, 0.0f, 0.0, 1.0f, +}; + +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++) { + for (j = 0; j < 4; j++) { + for (k = 0; k < 4; k++) { + tmp[i + (j * 4)] += a[i + (k * 4)] * b[k + (j * 4)]; + } + } + } + + for (i = 0; i < 16; i++) + result[i] = tmp[i]; +} + +void +gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta * + meta, gfloat * matrix) +{ + if (!meta) { + int i; + + for (i = 0; i < 16; i++) { + matrix[i] = identity_matrix[i]; + } + } else { + gfloat tmp[16] = { 0.0f }; + + gst_gl_multiply_matrix4 (from_ndc_matrix, meta->matrix, tmp); + gst_gl_multiply_matrix4 (tmp, to_ndc_matrix, matrix); + } +} diff --git a/ext/gl/gstglutils.h b/ext/gl/gstglutils.h index ee7d4c6982..5c9de83d64 100644 --- a/ext/gl/gstglutils.h +++ b/ext/gl/gstglutils.h @@ -28,6 +28,9 @@ 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 (GstVideoAffineTransformationMeta * + meta, gfloat * matrix); G_END_DECLS diff --git a/gst-libs/gst/gl/gstglutils.c b/gst-libs/gst/gl/gstglutils.c index b41ed8f4fd..fb19156507 100644 --- a/gst-libs/gst/gl/gstglutils.c +++ b/gst-libs/gst/gl/gstglutils.c @@ -722,7 +722,7 @@ static const gfloat to_ndc_matrix[] = { 0.0f, 0.0f, 0.0, 1.0f, }; -void +static void gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result) { int i, j, k; diff --git a/gst-libs/gst/gl/gstglutils.h b/gst-libs/gst/gl/gstglutils.h index e1207aafa7..4139302c2b 100644 --- a/gst-libs/gst/gl/gstglutils.h +++ b/gst-libs/gst/gl/gstglutils.h @@ -56,12 +56,6 @@ gboolean gst_gl_value_set_texture_target (GValue * value, GstGLTextureTarget tar GST_EXPORT GstGLTextureTarget gst_gl_value_get_texture_target_mask (const GValue * value); -GST_EXPORT -void gst_gl_multiply_matrix4 (const gfloat * a, const gfloat * b, gfloat * result); -GST_EXPORT -void gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta * - meta, gfloat * matrix); - G_END_DECLS #endif /* __GST_GL_UTILS_H__ */ diff --git a/gst-libs/gst/gl/gstglutils_private.h b/gst-libs/gst/gl/gstglutils_private.h index 9321d8d7af..008fcc6dcb 100644 --- a/gst-libs/gst/gl/gstglutils_private.h +++ b/gst-libs/gst/gl/gstglutils_private.h @@ -26,6 +26,7 @@ G_BEGIN_DECLS gboolean gst_gl_run_query (GstElement * element, GstQuery * query, GstPadDirection direction); +void gst_gl_get_affine_transformation_meta_as_ndc (GstVideoAffineTransformationMeta * meta, gfloat * matrix); G_END_DECLS diff --git a/gst-libs/gst/gl/gstglviewconvert.c b/gst-libs/gst/gl/gstglviewconvert.c index 11a98f2ae9..64c64f7ed9 100644 --- a/gst-libs/gst/gl/gstglviewconvert.c +++ b/gst-libs/gst/gl/gstglviewconvert.c @@ -34,6 +34,7 @@ #include "gstglviewconvert.h" #include "gstglsl_private.h" +#include "gstglutils_private.h" #include #define USING_OPENGL(context) (gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL, 1, 0))