I've found it! You need to setup metalLayer.edrMetadata to something like this:
metalLayer.edrMetadata = CAEDRMetadata.hdr10(minLuminance: 0, maxLuminance: 1000, opticalOutputScale: 1000)
I still have to figure out the parameters and how to use all that (I see problems after app switching for example), but it works!
Post
Replies
Boosts
Views
Activity
Tried all pixel formats. Can make photo "lighter" or "darker", but no HDR in any way. Even tried "hack from the internet" with AVPlayer, playing HDR video.
Next option is to convert image into video and try to play it instead :)
Tried that. No luck :–(
Here's some more code. Maybe my mistake will be visible somewhere here.
PHPickerConfiguration configuration
var configuration = PHPickerConfiguration(photoLibrary: .shared())
configuration.filter = PHPickerFilter.images
configuration.preferredAssetRepresentationMode = .current
configuration.selection = .default
configuration.selectionLimit = 1
configuration.preselectedAssetIdentifiers = []
Here I get result from the Picker
let provider = pickerResult.itemProvider
guard provider.hasItemConformingToTypeIdentifier(UTType.image.identifier) else { throw Problem.noAssetForPickerResult }
provider.loadFileRepresentation(forTypeIdentifier: UTType.image.identifier, completionHandler: convertAndExtractEXIF)
Copying file to avoid any changes
// inside convertAndExtractEXIF
let originalUrl = Storage.documentsDirectoryUrl.appendingPathComponent("\(UUID().uuidString).heic", isDirectory: false)
try! FileManager.default.copyItem(at: url, to: originalUrl)
Configuring MTKView-based view
private func setup() {
device = MTLCreateSystemDefaultDevice()
clearColor = MTLClearColorMake(0.0, 0.0, 0.0, 0.0)
preferredFramesPerSecond = 1
framebufferOnly = false
enableSetNeedsDisplay = true
delegate = renderer
if let metalLayer = layer as? CAMetalLayer {
if #available(iOS 16, *) {
metalLayer.wantsExtendedDynamicRangeContent = true
}
metalLayer.pixelFormat = .rgba16Float
metalLayer.colorspace = CGColorSpace(name: CGColorSpace.extendedLinearDisplayP3)
}
}
Drawing image from imageURL in the delegate:
func draw(in view: MTKView) {
guard let imageUrl else { return }
Task { @MainActor [imageUrl, view] in
guard let commandQueue = view.device?.makeCommandQueue() else { return print("CommandQueue problem") }
guard let commandBuffer = commandQueue.makeCommandBuffer() else { return print("CommandBuffer problem") }
guard let drawable = view.currentDrawable else { return print("Drawable problem") }
guard let originalImage = CIImage(data: try! Data(contentsOf: imageUrl)) else { return print("Original image problem") }
let originalSize = originalImage.extent.size
let drawableSize = view.drawableSize
let scale = min(CGFloat(drawableSize.width / originalSize.width), CGFloat(drawableSize.height / originalSize.height))
let ciImage = originalImage
.transformed(by: CGAffineTransform(scaleX: scale, y: scale))
let contextOptions: [CIContextOption: Any] = [
.useSoftwareRenderer: false,
]
let ciContext = CIContext(mtlCommandQueue: commandQueue, options: contextOptions)
let destination = CIRenderDestination(
width: Int(view.drawableSize.width),
height: Int(view.drawableSize.height),
pixelFormat: .bgra10_xr_srgb,
commandBuffer: commandBuffer,
mtlTextureProvider: { drawable.texture }
)
try! ciContext.startTask(toRender: ciImage, to: destination)
commandBuffer.present(drawable)
commandBuffer.commit()
}
}
I managed to get this command line utility from previous version of macOS and alter Xcode build script to use that. Seems to work, but for release builds I will have to use 10.14.
I have the same problem. In fact, when Xcode (11.3.1) builds application distributions, it uses this utility too. This results in pretty obscure build error messages, like this:ipatool failed with an exception: #<CmdSpec::NonZeroExitException: $ /Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/bitcode-build-tool -v -t /Applications/Xcode.11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin --sdk /Applications/Xcode.11.3.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk -o /var/folders/gg/sn34249n0l53vhc0_36r3y3h0000gn/T/ipatool20200211-26412-6iu957/thinned-out/arm64/Payload/[APP.app]/Frameworks/libswiftCore.dylib --generate-dsym /var/folders/gg/sn34249n0l53vhc0_36r3y3h0000gn/T/ipatool20200211-26412-6iu957/thinned-out/arm64/Payload/[APP.app]/Frameworks/libswiftCore.dylib.dSYM --strip-swift-symbols /var/folders/gg/sn34249n0l53vhc0_36r3y3h0000gn/T/ipatool20200211-26412-6iu957/thinned-in/arm64/Payload/[APP.app]/Frameworks/libswiftCore.dylib
Status: pid 26742 exit 2
Stdout:
Debug: SDK path: /Applications/Xcode.11.3.1.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk
Debug: SDK version: 13.2
Debug: PATH: ['/Applications/Xcode.11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin', '/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin']
Debug: Using: /Applications/Xcode.11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo
MachoInfo: cd /
"/Applications/Xcode.11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo" "-info" "/var/folders/gg/sn34249n0l53vhc0_36r3y3h0000gn/T/ipatool20200211-26412-6iu957/thinned-in/arm64/Payload/[APP.app]/Frameworks/libswiftCore.dylib"
-= Output =-
Non-fat file: /var/folders/gg/sn34249n0l53vhc0_36r3y3h0000gn/T/ipatool20200211-26412-6iu957/thinned-in/arm64/Payload/[APP.app]/Frameworks/libswiftCore.dylib is architecture: arm64
Exited with 0
Debug: Command took 0 seconds
Debug: Using: /Applications/Xcode.11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dwarfdump
GetUUID: cd /
"/Applications/Xcode.11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/dwarfdump" "-u" "/var/folders/gg/sn34249n0l53vhc0_36r3y3h0000gn/T/ipatool20200211-26412-6iu957/thinned-in/arm64/Payload/[APP.app]/Frameworks/libswiftCore.dylib"
-= Output =-
UUID: AD0CAD3B-1B51-3327-8644-8BE1FF1F0AE9 (arm64) /var/folders/gg/sn34249n0l53vhc0_36r3y3h0000gn/T/ipatool20200211-26412-6iu957/thinned-in/arm64/Payload/[APP.app]/Frameworks/libswiftCore.dylib
Exited with 0
Debug: Command took 0 seconds
Debug: Using: /Applications/Xcode.11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/segedit
ExtractXAR: cd /
"/Applications/Xcode.11.3.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/segedit" "/var/folders/gg/sn34249n0l53vhc0_36r3y3h0000gn/T/ipatool20200211-26412-6iu957/thinned-in/arm64/Payload/[APP.app]/Frameworks/libswiftCore.dylib" "-extract" "__LLVM" "__bundle" "/var/folders/gg/sn34249n0l53vhc0_36r3y3h0000gn/T/libswiftCore.dylibsf1ejW/libswiftCore.dylib.arm64.xar"
-= Output =-
Exited with 0
Debug: Command took 0 seconds
Stderr:
bitcode-build-tool internal error
Traceback (most recent call last):
File "/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/bitcode-build-tool", line 10, in <module>
bitcode_build_tool_main(sys.argv)
File "/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/../lib/bitcode_build_tool/main.py", line 83, in main
map(input_macho.buildBitcode, input_macho.getArchs())
File "/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/../lib/bitcode_build_tool/macho.py", line 130, in buildBitcode
bitcode_bundle = BitcodeBundle(arch, bundle, output_path).run()
File "/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/../lib/bitcode_build_tool/bundle.py", line 67, in __init__
super(BitcodeBundle, self).__init__(input_xar)
File "/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/../lib/bitcode_build_tool/bundle.py", line 26, in __init__
out = subprocess.check_output(cmd)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 216, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 394, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1047, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
>
/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/ipatool:297:in `run'
/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/ipatool:2703:in `block in CompileOrStripBitcodeInBundle'
/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/ipatool:2642:in `each'
/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/ipatool:2642:in `CompileOrStripBitcodeInBundle'
/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/ipatool:2902:in `block in ProcessIPA'
/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/ipatool:2864:in `each'
/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/ipatool:2864:in `ProcessIPA'
/Applications/Xcode.11.3.1.app/Contents/Developer/usr/bin/ipatool:3811:in `<main>'Hope this will be fixed soon.