Commit 2cc1db80 authored by Felix Paul Kühne's avatar Felix Paul Kühne

windowsless Mac: best-effort color space support

Will need a re-iteration once libvlc API advanced
parent 792e7f77
......@@ -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],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment