[MPlayer-cvslog] r30151 - in trunk/libvo: csputils.c csputils.h vo_gl.c vo_gl2.c

reimar subversion at mplayerhq.hu
Thu Dec 31 20:59:58 CET 2009


Author: reimar
Date: Thu Dec 31 20:59:58 2009
New Revision: 30151

Log:
First steps to supporting different YUV->RGB conversion definitions.
The numbers are possibly still wrong though.

Modified:
   trunk/libvo/csputils.c
   trunk/libvo/csputils.h
   trunk/libvo/vo_gl.c
   trunk/libvo/vo_gl2.c

Modified: trunk/libvo/csputils.c
==============================================================================
--- trunk/libvo/csputils.c	Thu Dec 31 19:25:35 2009	(r30150)
+++ trunk/libvo/csputils.c	Thu Dec 31 20:59:58 2009	(r30151)
@@ -56,20 +56,50 @@ void mp_gen_gamma_map(uint8_t *map, int 
 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;

Modified: trunk/libvo/csputils.h
==============================================================================
--- trunk/libvo/csputils.h	Thu Dec 31 19:25:35 2009	(r30150)
+++ trunk/libvo/csputils.h	Thu Dec 31 20:59:58 2009	(r30151)
@@ -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;

Modified: trunk/libvo/vo_gl.c
==============================================================================
--- trunk/libvo/vo_gl.c	Thu Dec 31 19:25:35 2009	(r30150)
+++ trunk/libvo/vo_gl.c	Thu Dec 31 20:59:58 2009	(r30151)
@@ -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;

Modified: trunk/libvo/vo_gl2.c
==============================================================================
--- trunk/libvo/vo_gl2.c	Thu Dec 31 19:25:35 2009	(r30150)
+++ trunk/libvo/vo_gl2.c	Thu Dec 31 20:59:58 2009	(r30151)
@@ -571,7 +571,7 @@ static int initGl(uint32_t d_width, uint
   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:


More information about the MPlayer-cvslog mailing list