summaryrefslogtreecommitdiff
path: root/ext/gl
diff options
context:
space:
mode:
authorMatthew Waters <matthew@centricular.com>2017-01-13 11:06:39 +1100
committerMatthew Waters <matthew@centricular.com>2017-01-13 11:20:51 +1100
commit4de388278a0430eae4eb7612d83f5084e48dad62 (patch)
treedcc723fe1f2b442d642ec8397dee2295ecfc41a4 /ext/gl
parent4315a4b54d9c830d9380e3d5c9413601f9a136fe (diff)
downloadgstreamer-plugins-bad-4de388278a0430eae4eb7612d83f5084e48dad62.tar.gz
glutils: privatise matrix multiplication/videoaffinetransformation retrieval
Diffstat (limited to 'ext/gl')
-rw-r--r--ext/gl/gstglutils.c60
-rw-r--r--ext/gl/gstglutils.h3
2 files changed, 63 insertions, 0 deletions
diff --git a/ext/gl/gstglutils.c b/ext/gl/gstglutils.c
index ca5e8ab06..224923c15 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 ee7d4c698..5c9de83d6 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