mirror of
https://github.com/mpv-player/mpv
synced 2025-03-11 08:37:59 +00:00
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
This commit is contained in:
parent
0ecf324ac5
commit
498ad7ba57
@ -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;
|
||||
|
@ -21,7 +21,17 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
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;
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user