[vlc-commits] windowsless Mac: best-effort color space support

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


npapi-vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Sat Apr 16 17:48:36 2016 +0300| [2cc1db80654371a574027c0502cc87a60c984229] | committer: Felix Paul Kühne

windowsless Mac: best-effort color space support

Will need a re-iteration once libvlc API advanced

> https://code.videolan.org/videolan/npapi-vlc/commit/2cc1db80654371a574027c0502cc87a60c984229
---

 npapi/vlcwindowless_mac.cpp | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/npapi/vlcwindowless_mac.cpp b/npapi/vlcwindowless_mac.cpp
index f8c992c..6f09021 100644
--- a/npapi/vlcwindowless_mac.cpp
+++ b/npapi/vlcwindowless_mac.cpp
@@ -25,6 +25,7 @@
 #include "vlcwindowless_mac.h"
 
 #define SHOW_BRANDING 1
+#define OSX_EL_CAPITAN (NSAppKitVersionNumber >= 1404)
 
 CGImageRef createImageNamed(CFStringRef);
 
@@ -51,8 +52,6 @@ CGImageRef createImageNamed(CFStringRef name)
 VlcWindowlessMac::VlcWindowlessMac(NPP instance, NPuint16_t mode) :
     VlcWindowlessBase(instance, mode)
 {
-    colorspace = CGColorSpaceCreateDeviceRGB();
-
     const char *userAgent = NPN_UserAgent(this->getBrowser());
     if (strstr(userAgent, "Safari") && strstr(userAgent, "Version/5")) {
         legacy_drawing_mode = true;
@@ -64,7 +63,8 @@ VlcWindowlessMac::~VlcWindowlessMac()
 {
     if (lastFrame)
         CGImageRelease(lastFrame);
-    CGColorSpaceRelease(colorspace);
+    if (colorspace != nil)
+        CGColorSpaceRelease(colorspace);
 }
 
 void VlcWindowlessMac::drawNoPlayback(CGContextRef cgContext)
@@ -274,6 +274,28 @@ bool VlcWindowlessMac::handle_event(void *event)
             left = (npwindow.width  - m_media_width) / 2.;
             top = (npwindow.height - m_media_height) / 2.;
 
+            if (colorspace == nil) {
+               /* 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) {
+                   fprintf(stderr, "Guessing color space based on video dimensions (height: %i)", cached_height);
+
+                   if (cached_height >= 2000 || cached_width >= 3800) {
+                       fprintf(stderr, "Should use BT.2020 color space, but in reality it's BT.709");
+                       colorspace = CGColorSpaceCreateWithName(kCGColorSpaceITUR_709);
+                   } else if (cached_height > 576) {
+                       fprintf(stderr, "Using BT.709 color space");
+                       colorspace = CGColorSpaceCreateWithName(kCGColorSpaceITUR_709);
+                   } else {
+                       fprintf(stderr, "SD content, using linear RGB color space");
+                       colorspace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
+                   }
+               } else {
+                   fprintf(stderr, "OS does not support BT.709 or BT.2020 color spaces, output may vary");
+                   colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGBLinear);
+               }
+            }
+
             /* fetch frame */
             CFDataRef dataRef = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
                                                             (const uint8_t *)&m_frame_buf[0],



More information about the vlc-commits mailing list