History

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

der richter committed 2 years ago

Commit 8a619291 parent cb75ecf10 files · +143 −2Browse files

Unified · Split

10 files
  1. DOCS/man/options.rst +31 −0
  2. meson.build +12 −0
  3. meson_options.txt +2 −0
  4. osdep/mac/app_bridge.h +19 −0
  5. osdep/mac/app_bridge.m +18 −1
  6. osdep/mac/meson.build +8 −0
  7. video/out/cocoa_cb_common.swift +49 −1
  8. video/out/mac/common.swift +2 −0
  9. video/out/mac/gl_layer.swift +1 −0
  10. video/out/mac/view.swift +1 −0
DOCS/man/options.rst+31−0
@@ -6285,6 +6285,37 @@ them. · 6284 unmodified lines
62856285
62866286 macOS and cocoa-cb only.
62876287
6288+``--cocoa-cb-output-csp=<csp>``
6289+ This sets the color space of the layer to activate the macOS color
6290+ transformation. Depending on the color space used the system's EDR (HDR)
6291+ support will be activated. To get correct results, this needs to be set to
6292+ the color primaries/transfer characteristics of the VO target. It is recommended
6293+ to use this switch together with ``--target-trc`` and ``--target-prim``.
6294+
6295+ ``<csp>`` can be one of the following:
6296+
6297+ :auto: Sets the color space to the icc profile of the
6298+ screen (default).
6299+ :display-p3: DCI P3 primaries, a D65 white point and the sRGB
6300+ transfer function.
6301+ :display-p3-hlg: DCI P3 primaries, a D65 white point and the Hybrid
6302+ Log-Gamma (HLG) transfer function.
6303+ :display-p3-pq: DCI P3 primaries, a D65 white point and the Perceptual
6304+ Quantizer (PQ) transfer function.
6305+ :display-p3-linear: DCI P3 primaries, a D65 white point and linear transfer function.
6306+ :dci-p3: DCI P3 color space.
6307+ :bt.2020: ITU BT.2020 color space.
6308+ :bt.2020-linear: ITU BT.2020 color space and linear transfer function.
6309+ :bt.2100-hlg: ITU BT.2100 and the Hybrid Log-Gamma (HLG) transfer function.
6310+ :bt.2100-pq: ITU BT.2100 and the Perceptual Quantizer (PQ) transfer function.
6311+ :bt.709: ITU BT.709 color space.
6312+ :srgb: sRGB colorimetry and non-linear transfer function.
6313+ :srgb-linear: Same as sRGB but linear transfer function.
6314+ :rgb-linear: RGB and linear transfer function.
6315+ :adobe: Adobe RGB (1998) color space.
6316+
6317+ macOS and cocoa-cb only.
6318+
62886319 ``--macos-title-bar-appearance=<appearance>``
62896320 Sets the appearance of the title bar (default: auto). Not all combinations
62906321 of appearances and ``--macos-title-bar-material`` materials make sense or
meson.build+12−0
@@ -1570,6 +1570,18 @@ if features['cocoa'] and features['swift'] · 1569 unmodified lines
15701570 'video/out/mac/window.swift')
15711571 endif
15721572
1573+macos_11_features = get_option('macos-11-features').require(
1574+ macos_sdk_version.version_compare('>= 11'),
1575+ error_message: 'A macos sdk version >= 11 could not be found!',
1576+)
1577+features += {'macos-11-features': macos_11_features.allowed()}
1578+
1579+macos_12_features = get_option('macos-12-features').require(
1580+ macos_sdk_version.version_compare('>= 12'),
1581+ error_message: 'A macos sdk version >= 12 could not be found!',
1582+)
1583+features += {'macos-12-features': macos_12_features.allowed()}
1584+
15731585 macos_cocoa_cb = get_option('macos-cocoa-cb').require(
15741586 features['cocoa'] and features['gl-cocoa'] and features['swift'],
15751587 error_message: 'Either cocoa, gl-cocoa or swift could not be found!',
meson_options.txt+2−0
@@ -106,6 +106,8 @@ option('videotoolbox-pl', type: 'feature', value: 'auto', description: 'Videotoo · 105 unmodified lines
106106 option('vulkan-interop', type: 'feature', value: 'auto', description: 'Vulkan graphics interop')
107107
108108 # macOS features
109+option('macos-11-features', type: 'feature', value: 'auto', description: 'macOS 11 SDK Features')
110+option('macos-12-features', type: 'feature', value: 'auto', description: 'macOS 12 SDK Features')
109111 option('macos-cocoa-cb', type: 'feature', value: 'auto', description: 'macOS libmpv backend')
110112 option('macos-media-player', type: 'feature', value: 'auto', description: 'macOS Media Player support')
111113 option('macos-touchbar', type: 'feature', value: 'auto', description: 'macOS Touch Bar support')
osdep/mac/app_bridge.h+19−0
@@ -35,6 +35,24 @@ enum { · 34 unmodified lines
3535 RENDER_TIMER_PRECISE,
3636 };
3737
38+enum {
39+ MAC_CSP_AUTO = -1,
40+ MAC_CSP_DISPLAY_P3,
41+ MAC_CSP_DISPLAY_P3_HLG,
42+ MAC_CSP_DISPLAY_P3_PQ,
43+ MAC_CSP_DISPLAY_P3_LINEAR,
44+ MAC_CSP_DCI_P3,
45+ MAC_CSP_BT_2020,
46+ MAC_CSP_BT_2020_LINEAR,
47+ MAC_CSP_BT_2100_HLG,
48+ MAC_CSP_BT_2100_PQ,
49+ MAC_CSP_BT_709,
50+ MAC_CSP_SRGB,
51+ MAC_CSP_SRGB_LINEAR,
52+ MAC_CSP_RGB_LINEAR,
53+ MAC_CSP_ADOBE,
54+};
55+
3856 struct macos_opts {
3957 int macos_title_bar_appearance;
4058 int macos_title_bar_material;
@@ -46,6 +64,7 @@ struct macos_opts { · 5 unmodified lines
4664 int macos_render_timer;
4765 int cocoa_cb_sw_renderer;
4866 bool cocoa_cb_10bit_context;
67+ int cocoa_cb_output_csp;
4968 };
5069
5170 void cocoa_init_media_keys(void);
osdep/mac/app_bridge.m+18−1
@@ -55,6 +55,22 @@ const struct m_sub_options macos_conf = { · 54 unmodified lines
5555 {"cocoa-cb-sw-renderer", OPT_CHOICE(cocoa_cb_sw_renderer,
5656 {"auto", -1}, {"no", 0}, {"yes", 1})},
5757 {"cocoa-cb-10bit-context", OPT_BOOL(cocoa_cb_10bit_context)},
58+ {"cocoa-cb-output-csp", OPT_CHOICE(cocoa_cb_output_csp,
59+ {"auto", MAC_CSP_AUTO},
60+ {"display-p3", MAC_CSP_DISPLAY_P3},
61+ {"display-p3-hlg", MAC_CSP_DISPLAY_P3_HLG},
62+ {"display-p3-pq", MAC_CSP_DISPLAY_P3_PQ},
63+ {"display-p3-linear", MAC_CSP_DISPLAY_P3_LINEAR},
64+ {"dci-p3", MAC_CSP_DCI_P3},
65+ {"bt.2020", MAC_CSP_BT_2020},
66+ {"bt.2020-linear", MAC_CSP_BT_2020_LINEAR},
67+ {"bt.2100-hlg", MAC_CSP_BT_2100_HLG},
68+ {"bt.2100-pq", MAC_CSP_BT_2100_PQ},
69+ {"bt.709", MAC_CSP_BT_709},
70+ {"srgb", MAC_CSP_SRGB},
71+ {"srgb-linear", MAC_CSP_SRGB_LINEAR},
72+ {"rgb-linear", MAC_CSP_RGB_LINEAR},
73+ {"adobe", MAC_CSP_ADOBE})},
5874 {0}
5975 },
6076 .size = sizeof(struct macos_opts),
@@ -63,7 +79,8 @@ const struct m_sub_options macos_conf = { · 2 unmodified lines
6379 .macos_fs_animation_duration = -1,
6480 .macos_render_timer = RENDER_TIMER_CALLBACK,
6581 .cocoa_cb_sw_renderer = -1,
66− .cocoa_cb_10bit_context = true
82+ .cocoa_cb_10bit_context = true,
83+ .cocoa_cb_output_csp = MAC_CSP_AUTO,
6784 },
6885 };
6986
osdep/mac/meson.build+8−0
@@ -19,6 +19,14 @@ if get_option('optimization') != '0' · 18 unmodified lines
1919 swift_flags += '-O'
2020 endif
2121
22+if macos_11_features.allowed()
23+ swift_flags += ['-D', 'HAVE_MACOS_11_FEATURES']
24+endif
25+
26+if macos_12_features.allowed()
27+ swift_flags += ['-D', 'HAVE_MACOS_12_FEATURES']
28+endif
29+
2230 if macos_cocoa_cb.allowed()
2331 swift_flags += ['-D', 'HAVE_MACOS_COCOA_CB']
2432 endif
video/out/cocoa_cb_common.swift+49−1
@@ -120,7 +120,55 @@ class CocoaCB: Common, EventSubscriber { · 119 unmodified lines
120120 }
121121
122122 libmpv.setRenderICCProfile(colorSpace)
123− layer?.colorspace = colorSpace.cgColorSpace
123+ layer?.colorspace = getColorSpace()
124+ }
125+
126+ func getColorSpace() -> CGColorSpace? {
127+ guard let colorSpace = window?.screen?.colorSpace?.cgColorSpace else {
128+ log.warning("Couldn't retrieve ICC Profile, no color space available")
129+ return nil
130+ }
131+
132+ let outputCsp = Int(option.mac.cocoa_cb_output_csp)
133+
134+ switch outputCsp {
135+ case MAC_CSP_AUTO: return colorSpace
136+ case MAC_CSP_DISPLAY_P3: return CGColorSpace(name: CGColorSpace.displayP3)
137+ case MAC_CSP_DISPLAY_P3_HLG: return CGColorSpace(name: CGColorSpace.displayP3_HLG)
138+ case MAC_CSP_DISPLAY_P3_PQ: return CGColorSpace(name: CGColorSpace.displayP3_PQ)
139+ case MAC_CSP_DCI_P3: return CGColorSpace(name: CGColorSpace.dcip3)
140+ case MAC_CSP_BT_2020: return CGColorSpace(name: CGColorSpace.itur_2020)
141+ case MAC_CSP_BT_709: return CGColorSpace(name: CGColorSpace.itur_709)
142+ case MAC_CSP_SRGB: return CGColorSpace(name: CGColorSpace.sRGB)
143+ case MAC_CSP_SRGB_LINEAR: return CGColorSpace(name: CGColorSpace.linearSRGB)
144+ case MAC_CSP_RGB_LINEAR: return CGColorSpace(name: CGColorSpace.genericRGBLinear)
145+ case MAC_CSP_ADOBE: return CGColorSpace(name: CGColorSpace.adobeRGB1998)
146+ default: break
147+ }
148+
149+#if HAVE_MACOS_11_FEATURES
150+ if #available(macOS 11.0, *) {
151+ switch outputCsp {
152+ case MAC_CSP_BT_2100_HLG: return CGColorSpace(name: CGColorSpace.itur_2100_HLG)
153+ case MAC_CSP_BT_2100_PQ: return CGColorSpace(name: CGColorSpace.itur_2100_PQ)
154+ default: break
155+ }
156+ }
157+#endif
158+
159+#if HAVE_MACOS_12_FEATURES
160+ if #available(macOS 12.0, *) {
161+ switch outputCsp {
162+ case MAC_CSP_DISPLAY_P3_LINEAR: return CGColorSpace(name: CGColorSpace.linearDisplayP3)
163+ case MAC_CSP_BT_2020_LINEAR: return CGColorSpace(name: CGColorSpace.linearITUR_2020)
164+ default: break
165+ }
166+ }
167+#endif
168+
169+ log.warning("Couldn't retrieve configured color space, falling back to auto")
170+
171+ return colorSpace
124172 }
125173
126174 override func windowDidEndAnimation() {
video/out/mac/common.swift+2−0
@@ -668,6 +668,8 @@ class Common: NSObject { · 667 unmodified lines
668668 titleBar?.set(material: Int(option.mac.macos_title_bar_material))
669669 case TypeHelper.toPointer(&option.macPtr.pointee.macos_title_bar_color):
670670 titleBar?.set(color: option.mac.macos_title_bar_color)
671+ case TypeHelper.toPointer(&option.macPtr.pointee.cocoa_cb_output_csp):
672+ updateICCProfile()
671673 default:
672674 break
673675 }
video/out/mac/gl_layer.swift+1−0
@@ -106,6 +106,7 @@ class GLLayer: CAOpenGLLayer { · 105 unmodified lines
106106 super.init()
107107 autoresizingMask = [.layerWidthSizable, .layerHeightSizable]
108108 backgroundColor = NSColor.black.cgColor
109+ wantsExtendedDynamicRangeContent = true
109110
110111 if bufferDepth > 8 {
111112 contentsFormat = .RGBA16Float
video/out/mac/view.swift+1−0
@@ -32,6 +32,7 @@ class View: NSView, CALayerDelegate { · 31 unmodified lines
3232 super.init(frame: frame)
3333 autoresizingMask = [.width, .height]
3434 wantsBestResolutionOpenGLSurface = true
35+ wantsExtendedDynamicRangeOpenGLSurface = true
3536 registerForDraggedTypes([ .fileURL, .URL, .string ])
3637 }
3738

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t