-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix colormanagement broken in 1.3.0, #3929 #5213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,6 +347,44 @@ class ViewLayer: CAOpenGLLayer { | |
return ctx | ||
} | ||
|
||
// MARK: - ICC Profile | ||
|
||
/// Set an ICC profile for use with the mpv [icc-profile-auto](https://mpv.io/manual/stable/#options-icc-profile-auto) | ||
/// option. | ||
/// | ||
/// This method fulfills the mpv requirement that applications using libmpv with the render API provide the ICC profile via | ||
/// `MPV_RENDER_PARAM_ICC_PROFILE` in order for the `--icc-profile-auto` option to work. The ICC profile data will not | ||
/// be used by mpv unless the option is enabled. | ||
/// | ||
/// The IINA `Load ICC profile` setting is tied to the `--icc-profile-auto` option. This allows users to override IINA using | ||
/// the [--icc-profile](https://mpv.io/manual/stable/#options-icc-profile) option. | ||
func setRenderICCProfile(_ profile: NSColorSpace) { | ||
// The OpenGL context must always be locked before locking the isUninited lock to avoid | ||
// deadlocks. | ||
videoView.player.mpv.lockAndSetOpenGLContext() | ||
defer { videoView.player.mpv.unlockOpenGLContext() } | ||
videoView.$isUninited.withLock() { isUninited in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I merged this PR into my own code yesterday and have since been getting frequent crashes at startup when using the Xcode debugger, coming from inside
I did some experiments and it looks like I fixed it by locking the OpenGL context around the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will make this a draft and look into this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that was it. I added the code to lock the OpenGL context. |
||
guard !isUninited else { return } | ||
|
||
guard let renderContext = videoView.player.mpv.mpvRenderContext else { return } | ||
guard var iccData = profile.iccProfileData else { | ||
let name = profile.localizedName ?? "unnamed" | ||
Logger.log("Color space \(name) does not contain ICC profile data", level: .warning) | ||
return | ||
} | ||
iccData.withUnsafeMutableBytes { (ptr: UnsafeMutableRawBufferPointer) in | ||
guard let baseAddress = ptr.baseAddress, ptr.count > 0 else { return } | ||
|
||
let u8Ptr = baseAddress.assumingMemoryBound(to: UInt8.self) | ||
var icc = mpv_byte_array(data: u8Ptr, size: ptr.count) | ||
withUnsafeMutableBytes(of: &icc) { (ptr: UnsafeMutableRawBufferPointer) in | ||
let params = mpv_render_param(type: MPV_RENDER_PARAM_ICC_PROFILE, data: ptr.baseAddress) | ||
mpv_render_context_set_parameter(renderContext, params) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Utils | ||
|
||
/** Check OpenGL error (for debug only). */ | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this put in
ViewLayer
? Looks like it would fit better inMPVController
(or even justVideoView
). You could pull out thevideoView.$isUninited.withLock
into the calling method to keep it insideVideoView
and reduce level of nested code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I'm slow in responding. Been focused on the JPEG XL problems.
The plan is to put it in
MPVRenderer
, along with all the render related code currently inMPVController
, similar to how mpv structures the code. But I got interrupted doing that refactoring. As we are now looking to freeze changes, test and release the first beta, this refactoring will have to wait for a future release. So this method is here temporarily.