changeset 30121:28cbec606cbb

Slightly generalize code to generate YUV->RGB conversion table and add XYZ->RGB conversion as an example for that.
author reimar
date Fri, 01 Jan 2010 12:54:09 +0000
parents f02090c2a62e
children 1772a5171ac7
files libvo/csputils.c libvo/csputils.h libvo/vo_gl.c
diffstat 3 files changed, 37 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/csputils.c	Fri Jan 01 12:53:28 2010 +0000
+++ b/libvo/csputils.c	Fri Jan 01 12:54:09 2010 +0000
@@ -52,53 +52,67 @@
  * \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
--- a/libvo/csputils.h	Fri Jan 01 12:53:28 2010 +0000
+++ b/libvo/csputils.h	Fri Jan 01 12:54:09 2010 +0000
@@ -27,6 +27,7 @@
   MP_CSP_BT_709,
   MP_CSP_SMPTE_240M,
   MP_CSP_EBU,
+  MP_CSP_XYZ,
   MP_CSP_COUNT
 };
 
--- a/libvo/vo_gl.c	Fri Jan 01 12:53:28 2010 +0000
+++ b/libvo/vo_gl.c	Fri Jan 01 12:54:09 2010 +0000
@@ -1108,6 +1108,7 @@
               "    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"