comparison libvo/csputils.c @ 30109:0f25d3062987

First steps to supporting different YUV->RGB conversion definitions. The numbers are possibly still wrong though.
author reimar
date Thu, 31 Dec 2009 19:59:58 +0000
parents 0898adc64a6f
children 28cbec606cbb
comparison
equal deleted inserted replaced
30108:0898adc64a6f 30109:0f25d3062987
54 * \param yuv2rgb array to store coefficients into 54 * \param yuv2rgb array to store coefficients into
55 */ 55 */
56 void mp_get_yuv2rgb_coeffs(struct mp_csp_params *params, float yuv2rgb[3][4]) { 56 void mp_get_yuv2rgb_coeffs(struct mp_csp_params *params, float yuv2rgb[3][4]) {
57 float uvcos = params->saturation * cos(params->hue); 57 float uvcos = params->saturation * cos(params->hue);
58 float uvsin = params->saturation * sin(params->hue); 58 float uvsin = params->saturation * sin(params->hue);
59 int format = params->format;
59 int i; 60 int i;
60 float uv_coeffs[3][2] = { 61 const float (*uv_coeffs)[2];
61 { 0.000, 1.596}, 62 static const float level_adjust[4] = {-16 / 255.0, -128 / 255.0, -128 / 255.0, 1.164};
62 {-0.391, -0.813}, 63 static const float uv_coeffs_table[MP_CSP_COUNT][3][2] = {
63 { 2.018, 0.000} 64 [MP_CSP_DEFAULT] = {
65 { 0.000, 1.596},
66 {-0.391, -0.813},
67 { 2.018, 0.000}
68 },
69 [MP_CSP_BT_601] = {
70 { 0.000, 1.403},
71 {-0.344, -0.714},
72 { 1.773, 0.000}
73 },
74 [MP_CSP_BT_709] = {
75 { 0.0000, 1.5701},
76 {-0.1870, -0.4664},
77 { 1.8556, 0.0000}
78 },
79 [MP_CSP_SMPTE_240M] = {
80 { 0.0000, 1.5756},
81 {-0.2253, -0.5000},
82 { 1.8270, 0.0000}
83 },
84 [MP_CSP_EBU] = {
85 { 0.000, 1.140},
86 {-0.396, -0.581},
87 { 2.029, 0.000}
88 },
64 }; 89 };
90
91 if (format < 0 || format >= MP_CSP_COUNT)
92 format = MP_CSP_DEFAULT;
93 uv_coeffs = uv_coeffs_table[format];
94
65 for (i = 0; i < 3; i++) { 95 for (i = 0; i < 3; i++) {
66 yuv2rgb[i][COL_C] = params->brightness; 96 yuv2rgb[i][COL_C] = params->brightness;
67 yuv2rgb[i][COL_Y] = 1.164 * params->contrast; 97 yuv2rgb[i][COL_Y] = level_adjust[COL_C] * params->contrast;
68 yuv2rgb[i][COL_C] += (-16 / 255.0) * yuv2rgb[i][COL_Y]; 98 yuv2rgb[i][COL_C] += level_adjust[COL_Y] * yuv2rgb[i][COL_Y];
69 yuv2rgb[i][COL_U] = uv_coeffs[i][0] * uvcos + uv_coeffs[i][1] * uvsin; 99 yuv2rgb[i][COL_U] = uv_coeffs[i][0] * uvcos + uv_coeffs[i][1] * uvsin;
70 yuv2rgb[i][COL_C] += (-128 / 255.0) * yuv2rgb[i][COL_U]; 100 yuv2rgb[i][COL_C] += level_adjust[COL_U] * yuv2rgb[i][COL_U];
71 yuv2rgb[i][COL_V] = uv_coeffs[i][0] * uvsin + uv_coeffs[i][1] * uvcos; 101 yuv2rgb[i][COL_V] = uv_coeffs[i][0] * uvsin + uv_coeffs[i][1] * uvcos;
72 yuv2rgb[i][COL_C] += (-128 / 255.0) * yuv2rgb[i][COL_V]; 102 yuv2rgb[i][COL_C] += level_adjust[COL_V] * yuv2rgb[i][COL_V];
73 // this "centers" contrast control so that e.g. a contrast of 0 103 // this "centers" contrast control so that e.g. a contrast of 0
74 // leads to a grey image, not a black one 104 // leads to a grey image, not a black one
75 yuv2rgb[i][COL_C] += 0.5 - params->contrast / 2.0; 105 yuv2rgb[i][COL_C] += 0.5 - params->contrast / 2.0;
76 } 106 }
77 } 107 }