[vlc-commits] vout-macosx: prepare color space handling

Felix Paul Kühne git at videolan.org
Sat Apr 16 14:15:14 CEST 2016


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Sat Apr 16 15:03:07 2016 +0300| [5c28f702503a67c60f6e0c6cc3799bc0b846e038] | committer: Felix Paul Kühne

vout-macosx: prepare color space handling

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5c28f702503a67c60f6e0c6cc3799bc0b846e038
---

 modules/video_output/macosx.m |   41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/modules/video_output/macosx.m b/modules/video_output/macosx.m
index 4279f79..b67172c 100644
--- a/modules/video_output/macosx.m
+++ b/modules/video_output/macosx.m
@@ -60,6 +60,8 @@
 
 #endif
 
+#define OSX_EL_CAPITAN (NSAppKitVersionNumber >= 1404)
+
 /**
  * Forward declarations
  */
@@ -115,6 +117,9 @@ struct vout_display_sys_t
     VLCOpenGLVideoView *glView;
     id<VLCOpenGLVideoViewEmbedding> container;
 
+    CGColorSpaceRef cgColorSpace;
+    NSColorSpace *nsColorSpace;
+
     vout_window_t *embed;
     vlc_gl_t gl;
     vout_display_opengl_t *vgl;
@@ -170,6 +175,27 @@ static int Open (vlc_object_t *this)
          * main thread, after we are done using it. */
         sys->container = [container retain];
 
+        /* support for BT.709 and BT.2020 color spaces was introduced with OS X 10.11
+         * on older OS versions, we can't show correct colors, so we fallback on linear RGB */
+        if (OSX_EL_CAPITAN) {
+            msg_Warn(vd, "Guessing color space based on video dimensions (height: %i", vd->fmt.i_height);
+
+            if (vd->fmt.i_height >= 2000 || vd->fmt.i_width >= 3800) {
+                msg_Dbg(vd, "Should use BT.2020 color space, but in reality it's BT.709");
+                sys->cgColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceITUR_709);
+            } else if (vd->fmt.i_height > 576) {
+                msg_Dbg(vd, "Using BT.709 color space");
+                sys->cgColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceITUR_709);
+            } else {
+                msg_Dbg(vd, "SD content, using linear RGB color space");
+                sys->cgColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+            }
+        } else {
+            msg_Dbg(vd, "OS does not support BT.709 or BT.2020 color spaces, output may vary");
+            sys->cgColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+        }
+        sys->nsColorSpace = [[NSColorSpace alloc] initWithCGColorSpace:sys->cgColorSpace];
+
         /* Get our main view*/
         [VLCOpenGLVideoView performSelectorOnMainThread:@selector(getNewView:)
                                              withObject:[NSValue valueWithPointer:&sys->glView]
@@ -270,6 +296,12 @@ void Close (vlc_object_t *this)
 
         [sys->glView release];
 
+        if (sys->cgColorSpace != nil)
+            CGColorSpaceRelease(sys->cgColorSpace);
+
+        if (sys->nsColorSpace != nil)
+            [sys->nsColorSpace release];
+
         if (sys->embed)
             vout_display_DeleteWindow (vd, sys->embed);
         free (sys);
@@ -789,4 +821,13 @@ static void OpenglSwap (vlc_gl_t *gl)
     return YES;
 }
 
+- (void)viewWillMoveToWindow:(nullable NSWindow *)newWindow
+{
+    [super viewWillMoveToWindow:newWindow];
+
+    if (newWindow != nil) {
+        [newWindow setColorSpace:vd->sys->nsColorSpace];
+    }
+}
+
 @end



More information about the vlc-commits mailing list