diff options
author | der richter <der.richter@gmx.de> | 2024-04-28 19:21:01 +0200 |
---|---|---|
committer | der richter <der.richter@gmx.de> | 2024-05-05 19:02:50 +0200 |
commit | 8a61929eb8e62097cf8ef0764dba233000fd1e5f (patch) | |
tree | 6d32a34e7ce5d2cb0c4b02b830823e2d3c093d44 /video | |
parent | cb75ecf19f28cfa00ecd348da13bca2550e85963 (diff) | |
download | mpv-8a61929eb8e62097cf8ef0764dba233000fd1e5f.tar.bz2 mpv-8a61929eb8e62097cf8ef0764dba233000fd1e5f.tar.xz |
cocoa-cb: add support for macOS color space transformation (EDR/HDR)
by default utilises the color space of the screen on which the window is
located. if a specific value is defined, it will instead be utilised.
depending on the chosen color space the macOS EDR (HDR) support is
activated and that OS's transformation (tone mapping) is used.
Fixes #7341
Diffstat (limited to 'video')
-rw-r--r-- | video/out/cocoa_cb_common.swift | 50 | ||||
-rw-r--r-- | video/out/mac/common.swift | 2 | ||||
-rw-r--r-- | video/out/mac/gl_layer.swift | 1 | ||||
-rw-r--r-- | video/out/mac/view.swift | 1 |
4 files changed, 53 insertions, 1 deletions
diff --git a/video/out/cocoa_cb_common.swift b/video/out/cocoa_cb_common.swift index 38c47a19a2..b2910dba85 100644 --- a/video/out/cocoa_cb_common.swift +++ b/video/out/cocoa_cb_common.swift @@ -120,7 +120,55 @@ class CocoaCB: Common, EventSubscriber { } libmpv.setRenderICCProfile(colorSpace) - layer?.colorspace = colorSpace.cgColorSpace + layer?.colorspace = getColorSpace() + } + + func getColorSpace() -> CGColorSpace? { + guard let colorSpace = window?.screen?.colorSpace?.cgColorSpace else { + log.warning("Couldn't retrieve ICC Profile, no color space available") + return nil + } + + let outputCsp = Int(option.mac.cocoa_cb_output_csp) + + switch outputCsp { + case MAC_CSP_AUTO: return colorSpace + case MAC_CSP_DISPLAY_P3: return CGColorSpace(name: CGColorSpace.displayP3) + case MAC_CSP_DISPLAY_P3_HLG: return CGColorSpace(name: CGColorSpace.displayP3_HLG) + case MAC_CSP_DISPLAY_P3_PQ: return CGColorSpace(name: CGColorSpace.displayP3_PQ) + case MAC_CSP_DCI_P3: return CGColorSpace(name: CGColorSpace.dcip3) + case MAC_CSP_BT_2020: return CGColorSpace(name: CGColorSpace.itur_2020) + case MAC_CSP_BT_709: return CGColorSpace(name: CGColorSpace.itur_709) + case MAC_CSP_SRGB: return CGColorSpace(name: CGColorSpace.sRGB) + case MAC_CSP_SRGB_LINEAR: return CGColorSpace(name: CGColorSpace.linearSRGB) + case MAC_CSP_RGB_LINEAR: return CGColorSpace(name: CGColorSpace.genericRGBLinear) + case MAC_CSP_ADOBE: return CGColorSpace(name: CGColorSpace.adobeRGB1998) + default: break + } + +#if HAVE_MACOS_11_FEATURES + if #available(macOS 11.0, *) { + switch outputCsp { + case MAC_CSP_BT_2100_HLG: return CGColorSpace(name: CGColorSpace.itur_2100_HLG) + case MAC_CSP_BT_2100_PQ: return CGColorSpace(name: CGColorSpace.itur_2100_PQ) + default: break + } + } +#endif + +#if HAVE_MACOS_12_FEATURES + if #available(macOS 12.0, *) { + switch outputCsp { + case MAC_CSP_DISPLAY_P3_LINEAR: return CGColorSpace(name: CGColorSpace.linearDisplayP3) + case MAC_CSP_BT_2020_LINEAR: return CGColorSpace(name: CGColorSpace.linearITUR_2020) + default: break + } + } +#endif + + log.warning("Couldn't retrieve configured color space, falling back to auto") + + return colorSpace } override func windowDidEndAnimation() { diff --git a/video/out/mac/common.swift b/video/out/mac/common.swift index 50a508e872..9fd7dbc9ea 100644 --- a/video/out/mac/common.swift +++ b/video/out/mac/common.swift @@ -668,6 +668,8 @@ class Common: NSObject { titleBar?.set(material: Int(option.mac.macos_title_bar_material)) case TypeHelper.toPointer(&option.macPtr.pointee.macos_title_bar_color): titleBar?.set(color: option.mac.macos_title_bar_color) + case TypeHelper.toPointer(&option.macPtr.pointee.cocoa_cb_output_csp): + updateICCProfile() default: break } diff --git a/video/out/mac/gl_layer.swift b/video/out/mac/gl_layer.swift index eba6f1a2d4..6a98f3dbec 100644 --- a/video/out/mac/gl_layer.swift +++ b/video/out/mac/gl_layer.swift @@ -106,6 +106,7 @@ class GLLayer: CAOpenGLLayer { super.init() autoresizingMask = [.layerWidthSizable, .layerHeightSizable] backgroundColor = NSColor.black.cgColor + wantsExtendedDynamicRangeContent = true if bufferDepth > 8 { contentsFormat = .RGBA16Float diff --git a/video/out/mac/view.swift b/video/out/mac/view.swift index 4921b7512c..b82151ba96 100644 --- a/video/out/mac/view.swift +++ b/video/out/mac/view.swift @@ -32,6 +32,7 @@ class View: NSView, CALayerDelegate { super.init(frame: frame) autoresizingMask = [.width, .height] wantsBestResolutionOpenGLSurface = true + wantsExtendedDynamicRangeOpenGLSurface = true registerForDraggedTypes([ .fileURL, .URL, .string ]) } |