summaryrefslogtreecommitdiffstats
path: root/libvo
diff options
context:
space:
mode:
authorreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2010-01-01 12:54:09 +0000
committerreimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2>2010-01-01 12:54:09 +0000
commit5f684e1b32cc052edf33d8c0ff5ead106e98e680 (patch)
treed5e8bc8b70f7254a9070b6528c40b0e47e6872fb /libvo
parent85344073fa9d45db689dc2529f1c48c889d84cc1 (diff)
downloadmpv-5f684e1b32cc052edf33d8c0ff5ead106e98e680.tar.bz2
mpv-5f684e1b32cc052edf33d8c0ff5ead106e98e680.tar.xz
Slightly generalize code to generate YUV->RGB conversion table and add
XYZ->RGB conversion as an example for that. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30163 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libvo')
-rw-r--r--libvo/csputils.c56
-rw-r--r--libvo/csputils.h1
-rw-r--r--libvo/vo_gl.c1
3 files changed, 37 insertions, 21 deletions
diff --git a/libvo/csputils.c b/libvo/csputils.c
index b31d9416a8..6f69ec4212 100644
--- a/libvo/csputils.c
+++ b/libvo/csputils.c
@@ -52,53 +52,67 @@ void mp_gen_gamma_map(uint8_t *map, int size, float gamma) {
* \brief get the coefficients of the yuv -> rgb conversion matrix
* \param params struct specifying the properties of the conversion like brightness, ...
* \param yuv2rgb array to store coefficients into
+ *
+ * Note: contrast, hue and saturation will only work as expected with YUV formats,
+ * not with e.g. MP_CSP_XYZ
*/
void mp_get_yuv2rgb_coeffs(struct mp_csp_params *params, float yuv2rgb[3][4]) {
float uvcos = params->saturation * cos(params->hue);
float uvsin = params->saturation * sin(params->hue);
int format = params->format;
int i;
- const float (*uv_coeffs)[2];
- static const float level_adjust[4] = {-16 / 255.0, -128 / 255.0, -128 / 255.0, 1.164};
- static const float uv_coeffs_table[MP_CSP_COUNT][3][2] = {
+ const float (*uv_coeffs)[3];
+ const float *level_adjust;
+ static const float yuv_pc_level_adjust[4] = {-16 / 255.0, -128 / 255.0, -128 / 255.0, 1.164};
+ static const float yuv_tv_level_adjust[4] = {0, -128 / 255.0, -128 / 255.0, 0};
+ static const float xyz_level_adjust[4] = {0, 0, 0, 0};
+ static const float uv_coeffs_table[MP_CSP_COUNT][3][3] = {
[MP_CSP_DEFAULT] = {
- { 0.000, 1.596},
- {-0.391, -0.813},
- { 2.018, 0.000}
+ {1, 0.000, 1.596},
+ {1, -0.391, -0.813},
+ {1, 2.018, 0.000}
},
[MP_CSP_BT_601] = {
- { 0.000, 1.403},
- {-0.344, -0.714},
- { 1.773, 0.000}
+ {1, 0.000, 1.403},
+ {1, -0.344, -0.714},
+ {1, 1.773, 0.000}
},
[MP_CSP_BT_709] = {
- { 0.0000, 1.5701},
- {-0.1870, -0.4664},
- { 1.8556, 0.0000}
+ {1, 0.0000, 1.5701},
+ {1, -0.1870, -0.4664},
+ {1, 1.8556, 0.0000}
},
[MP_CSP_SMPTE_240M] = {
- { 0.0000, 1.5756},
- {-0.2253, -0.5000},
- { 1.8270, 0.0000}
+ {1, 0.0000, 1.5756},
+ {1, -0.2253, -0.5000},
+ {1, 1.8270, 0.0000}
},
[MP_CSP_EBU] = {
- { 0.000, 1.140},
- {-0.396, -0.581},
- { 2.029, 0.000}
+ {1, 0.000, 1.140},
+ {1, -0.396, -0.581},
+ {1, 2.029, 0.000}
+ },
+ [MP_CSP_XYZ] = {
+ { 3.2404542, -1.5371385, -0.4985314},
+ {-0.9692660, 1.8760108, 0.0415560},
+ { 0.0556434, -0.2040259, 1.0572252}
},
};
if (format < 0 || format >= MP_CSP_COUNT)
format = MP_CSP_DEFAULT;
uv_coeffs = uv_coeffs_table[format];
+ level_adjust = yuv_pc_level_adjust;
+ if (format == MP_CSP_XYZ)
+ level_adjust = xyz_level_adjust;
for (i = 0; i < 3; i++) {
yuv2rgb[i][COL_C] = params->brightness;
- yuv2rgb[i][COL_Y] = level_adjust[COL_C] * params->contrast;
+ yuv2rgb[i][COL_Y] = uv_coeffs[i][COL_Y] * level_adjust[COL_C] * params->contrast;
yuv2rgb[i][COL_C] += level_adjust[COL_Y] * yuv2rgb[i][COL_Y];
- yuv2rgb[i][COL_U] = uv_coeffs[i][0] * uvcos + uv_coeffs[i][1] * uvsin;
+ yuv2rgb[i][COL_U] = uv_coeffs[i][COL_U] * uvcos + uv_coeffs[i][COL_V] * uvsin;
yuv2rgb[i][COL_C] += level_adjust[COL_U] * yuv2rgb[i][COL_U];
- yuv2rgb[i][COL_V] = uv_coeffs[i][0] * uvsin + uv_coeffs[i][1] * uvcos;
+ yuv2rgb[i][COL_V] = uv_coeffs[i][COL_U] * uvsin + uv_coeffs[i][COL_V] * uvcos;
yuv2rgb[i][COL_C] += level_adjust[COL_V] * yuv2rgb[i][COL_V];
// this "centers" contrast control so that e.g. a contrast of 0
// leads to a grey image, not a black one
diff --git a/libvo/csputils.h b/libvo/csputils.h
index 29760fd872..4723c7006d 100644
--- a/libvo/csputils.h
+++ b/libvo/csputils.h
@@ -27,6 +27,7 @@ enum mp_csp_standard {
MP_CSP_BT_709,
MP_CSP_SMPTE_240M,
MP_CSP_EBU,
+ MP_CSP_XYZ,
MP_CSP_COUNT
};
diff --git a/libvo/vo_gl.c b/libvo/vo_gl.c
index 3f37c301c7..51e5b0fb03 100644
--- a/libvo/vo_gl.c
+++ b/libvo/vo_gl.c
@@ -1108,6 +1108,7 @@ static int preinit(const char *arg)
" 2: YUV to RGB according to BT.709\n"
" 3: YUV to RGB according to SMPT-240M\n"
" 4: YUV to RGB according to EBU\n"
+ " 5: XYZ to RGB\n"
" lscale=<n>\n"
" 0: use standard bilinear scaling for luma.\n"
" 1: use improved bicubic scaling for luma.\n"