summaryrefslogtreecommitdiffstats
path: root/libvo
diff options
context:
space:
mode:
authorRudolf Polzer <divverent@xonotic.org>2012-10-24 19:11:42 +0200
committerwm4 <wm4@nowhere>2012-10-24 21:56:29 +0200
commitaa1047a35a98606c972cc35e566178703b1f2bff (patch)
treee757c045aee158cbe4bf56f3d142f80e0ef62cb0 /libvo
parent1282f9d79e09160af67ec13c05c0eed1ae02bd46 (diff)
downloadmpv-aa1047a35a98606c972cc35e566178703b1f2bff.tar.bz2
mpv-aa1047a35a98606c972cc35e566178703b1f2bff.tar.xz
sub: add helper to draw sub-bitmaps into an image
Merged by wm4 from commits 93978f17b76d..13211ef5fc20. Changed copyright header in draw_bmp.c to "mpv", and removed the one in draw_bmp.h.
Diffstat (limited to 'libvo')
-rw-r--r--libvo/csputils.c54
-rw-r--r--libvo/csputils.h10
2 files changed, 64 insertions, 0 deletions
diff --git a/libvo/csputils.c b/libvo/csputils.c
index ed74b9ae74..58b29bfeaa 100644
--- a/libvo/csputils.c
+++ b/libvo/csputils.c
@@ -29,6 +29,7 @@
#include <math.h>
#include <assert.h>
#include <libavutil/common.h>
+#include "mp_msg.h"
#include "csputils.h"
@@ -317,3 +318,56 @@ int mp_csp_equalizer_set(struct mp_csp_equalizer *eq, const char *property,
return 1;
}
+
+void mp_invert_yuv2rgb(float out[3][4], float in[3][4])
+{
+ // this is from the DarkPlaces engine, reduces to 3x3. Original code
+ // released under GPL2 or any later version.
+ float det;
+
+ // this seems to help gcc's common subexpression elimination, and also makes the code look nicer
+ float m00 = in[0][0], m01 = in[0][1], m02 = in[0][2], m03 = in[0][3],
+ m10 = in[1][0], m11 = in[1][1], m12 = in[1][2], m13 = in[1][3],
+ m20 = in[2][0], m21 = in[2][1], m22 = in[2][2], m23 = in[2][3];
+
+ // calculate the adjoint
+ out[0][0] = (m11 * m22 - m21 * m12);
+ out[0][1] = -(m01 * m22 - m21 * m02);
+ out[0][2] = (m01 * m12 - m11 * m02);
+ out[1][0] = -(m10 * m22 - m20 * m12);
+ out[1][1] = (m00 * m22 - m20 * m02);
+ out[1][2] = -(m00 * m12 - m10 * m02);
+ out[2][0] = (m10 * m21 - m20 * m11);
+ out[2][1] = -(m00 * m21 - m20 * m01);
+ out[2][2] = (m00 * m11 - m10 * m01);
+
+ // calculate the determinant (as inverse == 1/det * adjoint, adjoint * m == identity * det, so this calculates the det)
+ det = m00 * out[0][0] + m10 * out[0][1] + m20 * out[0][2];
+ if (det == 0.0f) {
+ //mp_msg(MSGT_VO, MSGL_ERR, "cannot invert yuv2rgb matrix\n");
+ return;
+ }
+
+ // multiplications are faster than divisions, usually
+ det = 1.0f / det;
+
+ // manually unrolled loop to multiply all matrix elements by 1/det
+ out[0][0] *= det;
+ out[0][1] *= det;
+ out[0][2] *= det;
+ out[1][0] *= det;
+ out[1][1] *= det;
+ out[1][2] *= det;
+ out[2][0] *= det;
+ out[2][1] *= det;
+ out[2][2] *= det;
+
+ // fix the constant coefficient
+ // rgb = M * yuv + C
+ // M^-1 * rgb = yuv + M^-1 * C
+ // yuv = M^-1 * rgb - M^-1 * C
+ // ^^^^^^^^^^
+ out[0][3] = -(out[0][0] * m03 + out[0][1] * m13 + out[0][2] * m23);
+ out[1][3] = -(out[1][0] * m03 + out[1][1] * m13 + out[1][2] * m23);
+ out[2][3] = -(out[2][0] * m03 + out[2][1] * m13 + out[2][2] * m23);
+}
diff --git a/libvo/csputils.h b/libvo/csputils.h
index 4ec0f14ba2..0dd75b0549 100644
--- a/libvo/csputils.h
+++ b/libvo/csputils.h
@@ -133,4 +133,14 @@ void mp_gen_gamma_map(unsigned char *map, int size, float gamma);
void mp_get_yuv2rgb_coeffs(struct mp_csp_params *params, float yuv2rgb[3][4]);
void mp_gen_yuv2rgb_map(struct mp_csp_params *params, uint8_t *map, int size);
+#define MP_MAP_YUV2RGB_COLOR(m, y, u, v, scale, c) ((m)[c][0] * (y) + \
+ (m)[c][1] * (u) + \
+ (m)[c][2] * (v) + \
+ (m)[c][3] * (scale))
+#define MP_MAP_RGB2YUV_COLOR(minv, r, g, b, scale, c) ((minv)[c][0] * (r) + \
+ (minv)[c][1] * (g) + \
+ (minv)[c][2] * (b) + \
+ (minv)[c][3] * (scale))
+void mp_invert_yuv2rgb(float out[3][4], float in[3][4]);
+
#endif /* MPLAYER_CSPUTILS_H */