summaryrefslogtreecommitdiffstats
path: root/libvo/csputils.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-10-08 00:14:51 +0200
committerwm4 <wm4@nowhere>2012-10-24 21:56:33 +0200
commitf6197249a783f00ae583e67d113ed737d677f12c (patch)
tree3fb6af12aca6403bddf06c1c4e06f597a5019078 /libvo/csputils.c
parentfd5c4a19849b768986a0e652bb2f398c922f42dd (diff)
downloadmpv-f6197249a783f00ae583e67d113ed737d677f12c.tar.bz2
mpv-f6197249a783f00ae583e67d113ed737d677f12c.tar.xz
spudec: use csputils for color conversion
Just to get rid of that conversion copy&pasted from the internet. R and G are swapped for unknown reasons. Testing various subtitles seem to yield the same results as VLC. The sub-bitmap renderers output the correct colors. The colorspace conversion is used without problems for vo_gl, vo_gl3 and vo_vdpau. The problem is most likely that apparently, the DVD palette read from the subtitle track extradata is converted to YUV using vobsub_palette_to_yuv(), and swapped in the process. Or in other words, the YUV colors spu->global_palette are encoded with R and G swapped. Add some utility definition to csputils.c/h to make converting single color values easier.
Diffstat (limited to 'libvo/csputils.c')
-rw-r--r--libvo/csputils.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libvo/csputils.c b/libvo/csputils.c
index b894a2f869..b0255a00dc 100644
--- a/libvo/csputils.c
+++ b/libvo/csputils.c
@@ -361,3 +361,17 @@ void mp_invert_yuv2rgb(float out[3][4], float in[3][4])
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);
}
+
+// Multiply the color in c with the given matrix.
+// c is {R, G, B} or {Y, U, V} (depending on input/output and matrix).
+void mp_map_color(float matrix[3][4], uint8_t c[3])
+{
+ uint8_t in[3] = {c[0], c[1], c[2]};
+ for (int i = 0; i < 3; i++) {
+ double val = matrix[i][3] * 255;
+ for (int x = 0; x < 3; x++)
+ val += matrix[i][x] * in[x];
+ int ival = lrint(val);
+ c[i] = FFMIN(FFMAX(ival, 0), 255);
+ }
+}