From 498ad7ba573b80ac8740886b46f9f8e660647858 Mon Sep 17 00:00:00 2001 From: reimar Date: Thu, 31 Dec 2009 19:59:58 +0000 Subject: First steps to supporting different YUV->RGB conversion definitions. The numbers are possibly still wrong though. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30151 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libvo/csputils.c | 46 ++++++++++++++++++++++++++++++++++++++-------- libvo/csputils.h | 10 ++++++++++ libvo/vo_gl.c | 2 +- libvo/vo_gl2.c | 2 +- 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/libvo/csputils.c b/libvo/csputils.c index 55ef66d7d4..b31d9416a8 100644 --- a/libvo/csputils.c +++ b/libvo/csputils.c @@ -56,20 +56,50 @@ void mp_gen_gamma_map(uint8_t *map, int size, float gamma) { 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; - float uv_coeffs[3][2] = { - { 0.000, 1.596}, - {-0.391, -0.813}, - { 2.018, 0.000} + 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] = { + [MP_CSP_DEFAULT] = { + { 0.000, 1.596}, + {-0.391, -0.813}, + { 2.018, 0.000} + }, + [MP_CSP_BT_601] = { + { 0.000, 1.403}, + {-0.344, -0.714}, + { 1.773, 0.000} + }, + [MP_CSP_BT_709] = { + { 0.0000, 1.5701}, + {-0.1870, -0.4664}, + { 1.8556, 0.0000} + }, + [MP_CSP_SMPTE_240M] = { + { 0.0000, 1.5756}, + {-0.2253, -0.5000}, + { 1.8270, 0.0000} + }, + [MP_CSP_EBU] = { + { 0.000, 1.140}, + {-0.396, -0.581}, + { 2.029, 0.000} + }, }; + + if (format < 0 || format >= MP_CSP_COUNT) + format = MP_CSP_DEFAULT; + uv_coeffs = uv_coeffs_table[format]; + for (i = 0; i < 3; i++) { yuv2rgb[i][COL_C] = params->brightness; - yuv2rgb[i][COL_Y] = 1.164 * params->contrast; - yuv2rgb[i][COL_C] += (-16 / 255.0) * yuv2rgb[i][COL_Y]; + yuv2rgb[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_C] += (-128 / 255.0) * yuv2rgb[i][COL_U]; + 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_C] += (-128 / 255.0) * yuv2rgb[i][COL_V]; + 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 yuv2rgb[i][COL_C] += 0.5 - params->contrast / 2.0; diff --git a/libvo/csputils.h b/libvo/csputils.h index 1218b1a473..29760fd872 100644 --- a/libvo/csputils.h +++ b/libvo/csputils.h @@ -21,7 +21,17 @@ #include +enum mp_csp_standard { + MP_CSP_DEFAULT, + MP_CSP_BT_601, + MP_CSP_BT_709, + MP_CSP_SMPTE_240M, + MP_CSP_EBU, + MP_CSP_COUNT +}; + struct mp_csp_params { + enum mp_csp_standard format; float brightness; float contrast; float hue; diff --git a/libvo/vo_gl.c b/libvo/vo_gl.c index 53ddbad977..eb71149bbb 100644 --- a/libvo/vo_gl.c +++ b/libvo/vo_gl.c @@ -216,7 +216,7 @@ static void update_yuvconv(void) { float ggamma = exp(log(8.0) * eq_ggamma / 100.0); float bgamma = exp(log(8.0) * eq_bgamma / 100.0); gl_conversion_params_t params = {gl_target, yuvconvtype, - {bri, cont, hue, sat, rgamma, ggamma, bgamma}, + {MP_CSP_DEFAULT, bri, cont, hue, sat, rgamma, ggamma, bgamma}, texture_width, texture_height, 0, 0, filter_strength}; mp_get_chroma_shift(image_format, &xs, &ys); params.chrom_texw = params.texw >> xs; diff --git a/libvo/vo_gl2.c b/libvo/vo_gl2.c index bbf850b827..1cdf7bf83f 100644 --- a/libvo/vo_gl2.c +++ b/libvo/vo_gl2.c @@ -571,7 +571,7 @@ static int initGl(uint32_t d_width, uint32_t d_height) if (is_yuv) { int xs, ys; gl_conversion_params_t params = {GL_TEXTURE_2D, use_yuv, - {0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0}, + {MP_CSP_DEFAULT, 0.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0}, texture_width, texture_height, 0, 0, 0}; switch (use_yuv) { case YUV_CONVERSION_FRAGMENT_LOOKUP: -- cgit v1.2.3