changeset 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 19414a605695
files libvo/csputils.c libvo/csputils.h libvo/vo_gl.c libvo/vo_gl2.c
diffstat 4 files changed, 50 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/csputils.c	Thu Dec 31 18:25:35 2009 +0000
+++ b/libvo/csputils.c	Thu Dec 31 19:59:58 2009 +0000
@@ -56,20 +56,50 @@
 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;
--- a/libvo/csputils.h	Thu Dec 31 18:25:35 2009 +0000
+++ b/libvo/csputils.h	Thu Dec 31 19:59:58 2009 +0000
@@ -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;
--- a/libvo/vo_gl.c	Thu Dec 31 18:25:35 2009 +0000
+++ b/libvo/vo_gl.c	Thu Dec 31 19:59:58 2009 +0000
@@ -216,7 +216,7 @@
   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;
--- a/libvo/vo_gl2.c	Thu Dec 31 18:25:35 2009 +0000
+++ b/libvo/vo_gl2.c	Thu Dec 31 19:59:58 2009 +0000
@@ -571,7 +571,7 @@
   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: