[vlc-devel] [PATCH] decoder: adjust the unknown colorimetry values because getting a vout

Steve Lhomme robux4 at videolabs.io
Sat Apr 16 16:00:55 CEST 2016


replaces https://patches.videolan.org/patch/12965/
---
 src/input/decoder.c | 43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/src/input/decoder.c b/src/input/decoder.c
index a1d7414..43b445e 100644
--- a/src/input/decoder.c
+++ b/src/input/decoder.c
@@ -134,6 +134,11 @@ struct decoder_owner_sys_t
 /* */
 #define DECODER_SPU_VOUT_WAIT_DURATION ((int)(0.200*CLOCK_FREQ))
 
+#define UHD_MIN_WIDTH    3800
+#define UHD_MIN_HEIGHT   2000
+#define HD_MIN_HEIGHT     576
+#define NTSC_HEIGHT       525
+
 /**
  * Load a decoder module
  */
@@ -394,6 +399,44 @@ static int vout_update_format( decoder_t *p_dec )
         vlc_ureduce( &fmt.i_sar_num, &fmt.i_sar_den,
                      fmt.i_sar_num, fmt.i_sar_den, 50000 );
 
+        if ( fmt.primaries == COLOR_PRIMARIES_UNDEF )
+        {
+            if ( ( fmt.i_bits_per_pixel == 0 || fmt.i_bits_per_pixel >= 10) &&
+                 ( fmt.i_visible_height >= UHD_MIN_HEIGHT || fmt.i_visible_width >= UHD_MIN_WIDTH ) )
+                fmt.primaries = COLOR_PRIMARIES_BT2020;
+            else if ( fmt.i_visible_height > HD_MIN_HEIGHT )
+                fmt.primaries = COLOR_PRIMARIES_BT709;
+            else if ( fmt.i_visible_height <= NTSC_HEIGHT )
+                fmt.primaries = COLOR_PRIMARIES_BT601_525;
+            else
+                fmt.primaries = COLOR_PRIMARIES_BT601_625;
+            msg_Info( p_dec, "Forcing color primaries to %d", fmt.primaries  );
+        }
+
+        if ( fmt.transfer == TRANSFER_FUNC_UNDEF )
+        {
+            if ( ( fmt.i_bits_per_pixel == 0 || fmt.i_bits_per_pixel >= 10) &&
+                 ( fmt.i_visible_height >= UHD_MIN_HEIGHT || fmt.i_visible_width >= UHD_MIN_WIDTH ) )
+                fmt.transfer = TRANSFER_FUNC_BT2020;
+            else if ( fmt.i_visible_height > HD_MIN_HEIGHT )
+                fmt.transfer = TRANSFER_FUNC_BT709;
+            else
+                fmt.transfer = TRANSFER_FUNC_SRGB;
+            msg_Info( p_dec, "Forcing color transfer curve to %d", fmt.transfer  );
+        }
+
+        if ( fmt.space == COLOR_SPACE_UNDEF )
+        {
+            if ( ( fmt.i_bits_per_pixel == 0 || fmt.i_bits_per_pixel >= 10) &&
+                 ( fmt.i_visible_height >= UHD_MIN_HEIGHT || fmt.i_visible_width >= UHD_MIN_WIDTH ) )
+                fmt.space = COLOR_SPACE_BT2020_LIMITED;
+            else if ( fmt.i_visible_height > HD_MIN_HEIGHT )
+                fmt.space = COLOR_SPACE_BT709_LIMITED;
+            else
+                fmt.space = COLOR_SPACE_BT601_LIMITED;
+            msg_Info( p_dec, "Forcing color range to %d", fmt.space  );
+        }
+
         vlc_mutex_lock( &p_owner->lock );
 
         p_vout = p_owner->p_vout;
-- 
2.7.0



More information about the vlc-devel mailing list