changeset 29727:3c1645511249

Add colorspace option to vo_vdpau. Allows to use ITU-R BT.709 instead of the default ITU-R BT.601. Patch by Lauri Myll¸«£ri, lauri D myllari gmail
author cehoyos
date Sat, 10 Oct 2009 20:53:42 +0000
parents 0d05687720a9
children af460532dd3a
files DOCS/man/en/mplayer.1 libvo/vo_vdpau.c
diffstat 2 files changed, 55 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/man/en/mplayer.1	Sat Oct 10 10:39:05 2009 +0000
+++ b/DOCS/man/en/mplayer.1	Sat Oct 10 20:53:42 2009 +0000
@@ -3493,6 +3493,22 @@
 Useful with slow video memory.
 .IPs pullup
 Try to apply inverse telecine, needs motion adaptive temporal deinterlacing.
+.IPs colorspace
+Select the color space for YUV to RGB conversion (default: 1, BT.601).
+In general BT.601 should be used for standard definition (SD) content and
+BT.709 for high definition (HD) content.
+Using incorrect color space results in slightly under or over saturated and
+shifted colors.
+.RSss
+.IPs 0
+Guess the color space based on video resolution.
+Video with width >= 1280 or height > 576 is assumed to be HD and BT.709 color
+space will be used.
+.IPs 1
+Use ITU-R BT.601 color space (default).
+.IPs 2
+Use ITU-R BT.709 color space.
+.RE
 .RE
 .PD 1
 .
--- a/libvo/vo_vdpau.c	Sat Oct 10 10:39:05 2009 +0000
+++ b/libvo/vo_vdpau.c	Sat Oct 10 20:53:42 2009 +0000
@@ -159,6 +159,7 @@
 static int                                pullup;
 static float                              denoise;
 static float                              sharpen;
+static int                                colorspace;
 static int                                chroma_deint;
 static int                                top_field_first;
 
@@ -403,6 +404,31 @@
     return 0;
 }
 
+static int update_csc_matrix(void)
+{
+    VdpStatus vdp_st;
+    VdpCSCMatrix matrix;
+    static const VdpVideoMixerAttribute attributes[] = {VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX};
+    const void *attribute_values[] = {&matrix};
+    static const VdpColorStandard vdp_colors[] = {0, VDP_COLOR_STANDARD_ITUR_BT_601, VDP_COLOR_STANDARD_ITUR_BT_709};
+    static const char * const vdp_names[] = {NULL, "BT.601", "BT.709"};
+    int csp = colorspace;
+
+    if (!csp)
+        csp = vid_width >= 1280 || vid_height > 576 ? 2 : 1;
+
+    mp_msg(MSGT_VO, MSGL_V, "[vdpau] Updating CSC matrix for %s\n",
+           vdp_names[csp]);
+
+    vdp_st = vdp_generate_csc_matrix(&procamp, vdp_colors[csp], &matrix);
+    CHECK_ST_WARNING("Error when generating CSC matrix")
+
+    vdp_st = vdp_video_mixer_set_attribute_values(video_mixer, 1, attributes,
+                                                  attribute_values);
+    CHECK_ST_WARNING("Error when setting CSC matrix")
+    return VO_TRUE;
+}
+
 static int create_vdp_mixer(VdpChromaType vdp_chroma_type)
 {
 #define VDP_NUM_MIXER_PARAMETER 3
@@ -458,6 +484,7 @@
     if (!chroma_deint)
         vdp_video_mixer_set_attribute_values(video_mixer, 1, skip_chroma_attrib, skip_chroma_value_ptr);
 
+    update_csc_matrix();
     return 0;
 }
 
@@ -1040,6 +1067,7 @@
     {"pullup",  OPT_ARG_BOOL,  &pullup,  NULL},
     {"denoise", OPT_ARG_FLOAT, &denoise, NULL},
     {"sharpen", OPT_ARG_FLOAT, &sharpen, NULL},
+    {"colorspace", OPT_ARG_INT, &colorspace, NULL},
     {NULL}
 };
 
@@ -1062,6 +1090,10 @@
     "    Apply denoising, argument is strength from 0.0 to 1.0\n"
     "  sharpen\n"
     "    Apply sharpening or softening, argument is strength from -1.0 to 1.0\n"
+    "  colorspace\n"
+    "    0: guess based on video resolution\n"
+    "    1: ITU-R BT.601 (default)\n"
+    "    2: ITU-R BT.709\n"
     ;
 
 static int preinit(const char *arg)
@@ -1079,6 +1111,7 @@
     pullup  = 0;
     denoise = 0;
     sharpen = 0;
+    colorspace = 1;
     if (subopt_parse(arg, subopts) != 0) {
         mp_msg(MSGT_VO, MSGL_FATAL, help_msg);
         return -1;
@@ -1087,6 +1120,11 @@
         deint_type = deint;
     if (deint > 1)
         deint_buffer_past_frames = 1;
+    if (colorspace < 0 || colorspace > 2) {
+        mp_msg(MSGT_VO, MSGL_WARN, "[vdpau] Invalid color space specified, "
+               "using BT.601\n");
+        colorspace = 1;
+    }
 
     vdpau_lib_handle = dlopen(vdpaulibrary, RTLD_LAZY);
     if (!vdpau_lib_handle) {
@@ -1148,11 +1186,6 @@
 
 static int set_equalizer(char *name, int value)
 {
-    VdpStatus vdp_st;
-    VdpCSCMatrix matrix;
-    static const VdpVideoMixerAttribute attributes[] = {VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX};
-    const void *attribute_values[] = {&matrix};
-
     if (!strcasecmp(name, "brightness"))
         procamp.brightness = value / 100.0;
     else if (!strcasecmp(name, "contrast"))
@@ -1164,13 +1197,7 @@
     else
         return VO_NOTIMPL;
 
-    vdp_st = vdp_generate_csc_matrix(&procamp, VDP_COLOR_STANDARD_ITUR_BT_601,
-                                     &matrix);
-    CHECK_ST_WARNING("Error when generating CSC matrix")
-    vdp_st = vdp_video_mixer_set_attribute_values(video_mixer, 1, attributes,
-                                                  attribute_values);
-    CHECK_ST_WARNING("Error when setting CSC matrix")
-    return VO_TRUE;
+    return update_csc_matrix();
 }
 
 static int control(uint32_t request, void *data, ...)