[MPlayer-dev-eng] [Patch] Use Rec709 for YUV->RGB conversion in vo_gl when playing HD content

Zhou Zongyi zhouzy at os.pku.edu.cn
Thu Oct 22 15:42:53 CEST 2009


Hi all,

Currently mplayer's OpenGL output always uses Rec601 for YUV -> RGB conversion and it produces incorrect color when displaying HD content.

This patch makes mplayer switch to Rec709 when width >= 1280 or height >= 720

Index: libvo/gl_common.c
===================================================================
--- libvo/gl_common.c (revision 29789)
+++ libvo/gl_common.c (working copy)
@@ -916,19 +919,22 @@
 static void get_yuv2rgb_coeffs(gl_conversion_params_t *params, float yuv2rgb[3][4]) {
   float uvcos = params->saturation * cos(params->hue);
   float uvsin = params->saturation * sin(params->hue);
-  int i;
-  float uv_coeffs[3][2] = {
-    { 0.000,  1.596},
-    {-0.391, -0.813},
-    { 2.018,  0.000}
+  int i; int j = params->ishd? 3:0;
+  static const float uv_coeffs[6][2] = {
+    { 0.0000,  1.5960},
+    {-0.3918, -0.8130},
+    { 2.0172,  0.0000},
+    { 0.0000,  1.7930},
+    {-0.2129, -0.5326},
+    { 2.1126,  0.0000}
   };
   for (i = 0; i < 3; i++) {
     yuv2rgb[i][COL_C]  = params->brightness;
-    yuv2rgb[i][COL_Y]  = 1.164 * params->contrast;
+    yuv2rgb[i][COL_Y]  = 1.1644 * params->contrast;
     yuv2rgb[i][COL_C] += (-16 / 255.0) * 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+j][0] * uvcos + uv_coeffs[i+j][1] * uvsin;
     yuv2rgb[i][COL_C] += (-128 / 255.0) * 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+j][0] * uvsin + uv_coeffs[i+j][1] * uvcos;
     yuv2rgb[i][COL_C] += (-128 / 255.0) * 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
Index: libvo/gl_common.h
===================================================================
--- libvo/gl_common.h (revision 29789)
+++ libvo/gl_common.h (working copy)
@@ -336,6 +336,7 @@
   int texw;
   int texh;
   float filter_strength;
+  int ishd;
 } gl_conversion_params_t;
 
 void glSetupYUVConversion(gl_conversion_params_t *params);
Index: libvo/vo_gl.c
===================================================================
--- libvo/vo_gl.c (revision 29789)
+++ libvo/vo_gl.c (working copy)
@@ -219,7 +224,8 @@
   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,
-      texture_width, texture_height, filter_strength};
+      texture_width, texture_height, filter_strength,
+      (image_width>=1280 || image_height>=720)? 1:0};
   glSetupYUVConversion(&params);
   if (custom_prog) {
     FILE *f = fopen(custom_prog, "r");



Zhou Zongyi
2009-10-22


More information about the MPlayer-dev-eng mailing list