From ab99912e7ded1b1cf4561b0ef35e8f424e162291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 1 Mar 2023 16:20:46 +0800 Subject: [PATCH] HDR: use `ReferencePeakHDRLuminance` for tone mapping `--target-peak` --- iina.xcodeproj/project.pbxproj | 4 ++ iina/Base.lproj/PrefCodecViewController.xib | 46 ++++++++++----------- iina/VideoView.swift | 5 ++- iina/iina-Bridging-Header.h | 2 + 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/iina.xcodeproj/project.pbxproj b/iina.xcodeproj/project.pbxproj index fd19e2ceeb..78ac95d01f 100644 --- a/iina.xcodeproj/project.pbxproj +++ b/iina.xcodeproj/project.pbxproj @@ -171,6 +171,7 @@ AD63BF8429AEF1A100A63251 /* libavcodec.60.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = AD63BF7A29AEF1A000A63251 /* libavcodec.60.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; AD70988927E0DD9200BD7795 /* libmpv.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = AD70988827E0DD9200BD7795 /* libmpv.2.dylib */; }; AD70988A27E0DD9200BD7795 /* libmpv.2.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = AD70988827E0DD9200BD7795 /* libmpv.2.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; }; + ADD4287F29AF39450057386F /* CoreDisplay.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ADD4287E29AF39450057386F /* CoreDisplay.framework */; }; B206FFD92415439600E3B8B7 /* FourCharCode+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B206FFD82415439600E3B8B7 /* FourCharCode+Extensions.swift */; }; B2133D6A240D8FDA001B6095 /* IINA.sdef in Resources */ = {isa = PBXBuildFile; fileRef = B2133D69240D8FDA001B6095 /* IINA.sdef */; }; B2133D6D240E07AC001B6095 /* AppDelegate+Scripting.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2133D6C240E07AC001B6095 /* AppDelegate+Scripting.swift */; }; @@ -946,6 +947,7 @@ AD63BF7929AEF1A000A63251 /* libswscale.7.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libswscale.7.dylib; path = deps/lib/libswscale.7.dylib; sourceTree = ""; }; AD63BF7A29AEF1A000A63251 /* libavcodec.60.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libavcodec.60.dylib; path = deps/lib/libavcodec.60.dylib; sourceTree = ""; }; AD70988827E0DD9200BD7795 /* libmpv.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libmpv.2.dylib; path = deps/lib/libmpv.2.dylib; sourceTree = ""; }; + ADD4287E29AF39450057386F /* CoreDisplay.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreDisplay.framework; path = ../../../System/Library/Frameworks/CoreDisplay.framework; sourceTree = ""; }; B206FFD82415439600E3B8B7 /* FourCharCode+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FourCharCode+Extensions.swift"; sourceTree = ""; }; B2133D69240D8FDA001B6095 /* IINA.sdef */ = {isa = PBXFileReference; lastKnownFileType = text; path = IINA.sdef; sourceTree = ""; }; B2133D6C240E07AC001B6095 /* AppDelegate+Scripting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AppDelegate+Scripting.swift"; sourceTree = ""; }; @@ -1249,6 +1251,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + ADD4287F29AF39450057386F /* CoreDisplay.framework in Frameworks */, B4E4470125CE3F930069F06E /* Sparkle in Frameworks */, AD63BF7B29AEF1A000A63251 /* libavformat.60.dylib in Frameworks */, 8451E6D92604AEFC009A15D7 /* Just in Frameworks */, @@ -1373,6 +1376,7 @@ 848290731D95978100C3C76C /* Frameworks */ = { isa = PBXGroup; children = ( + ADD4287E29AF39450057386F /* CoreDisplay.framework */, AD63BF7A29AEF1A000A63251 /* libavcodec.60.dylib */, AD63BF7829AEF1A000A63251 /* libavfilter.9.dylib */, AD63BF7629AEF1A000A63251 /* libavformat.60.dylib */, diff --git a/iina/Base.lproj/PrefCodecViewController.xib b/iina/Base.lproj/PrefCodecViewController.xib index b228afa719..e3d65b7892 100644 --- a/iina/Base.lproj/PrefCodecViewController.xib +++ b/iina/Base.lproj/PrefCodecViewController.xib @@ -1,8 +1,8 @@ - + - + @@ -30,11 +30,11 @@ - + - + @@ -42,7 +42,7 @@ - + @@ -50,7 +50,7 @@ - + @@ -71,7 +71,7 @@ - + @@ -79,7 +79,7 @@ - + @@ -100,7 +100,7 @@ - + @@ -108,7 +108,7 @@ - + @@ -116,7 +116,7 @@ - + @@ -134,7 +134,7 @@ - + @@ -152,7 +152,7 @@ - + @@ -160,7 +160,7 @@ - + @@ -178,7 +178,7 @@ - + @@ -199,7 +199,7 @@ - + @@ -240,7 +240,7 @@ - + Map one set of colors to another to approximate the appearance of high-dynamic-range images in a medium that has a more limited dynamic range. ( From Wikipedia ) @@ -262,10 +262,10 @@ Use tone mapping algorithm if you want gamut reduction. For example: playing HDR - + - Maximum luminance supported by your screen + Maximum luminance supported by your screen
if set to 0, IINA will try to detect the maximum luminance of current monitor Ref: https://mpv.io/manual/master/#options-target-peak diff --git a/iina/VideoView.swift b/iina/VideoView.swift index 24a8d5d118..abb8ad9cc4 100644 --- a/iina/VideoView.swift +++ b/iina/VideoView.swift @@ -372,7 +372,10 @@ extension VideoView { mpv.setFlag(MPVOption.Screenshot.screenshotTagColorspace, true) if Preference.bool(for: .enableToneMapping) { - let targetPeak = Preference.integer(for: .toneMappingTargetPeak) + var targetPeak = Preference.integer(for: .toneMappingTargetPeak) + if targetPeak == 0, let displayInfo = CoreDisplay_DisplayCreateInfoDictionary(currentDisplay!)?.takeRetainedValue() as? [String: AnyObject], let hdrLuminance = displayInfo["ReferencePeakHDRLuminance"] as? Int { + targetPeak = hdrLuminance + } let algorithm = Preference.ToneMappingAlgorithmOption(rawValue: Preference.integer(for: .toneMappingAlgorithm))!.mpvString Logger.log("Will enable tone mapping target-peak=\(targetPeak) algorithm=\(algorithm)", subsystem: hdrSubsystem); diff --git a/iina/iina-Bridging-Header.h b/iina/iina-Bridging-Header.h index 41aa291018..56db709f87 100644 --- a/iina/iina-Bridging-Header.h +++ b/iina/iina-Bridging-Header.h @@ -19,6 +19,8 @@ #import +extern CFDictionaryRef _Nullable CoreDisplay_DisplayCreateInfoDictionary(CGDirectDisplayID display); + #pragma mark - PIP.framework NS_ASSUME_NONNULL_BEGIN