Skip to content

Instantly share code, notes, and snippets.

@andsimakov
Created June 2, 2022 18:36
Show Gist options
  • Save andsimakov/3d29305b0ab5d05dac3ed8092d4df92e to your computer and use it in GitHub Desktop.
Save andsimakov/3d29305b0ab5d05dac3ed8092d4df92e to your computer and use it in GitHub Desktop.
import CoreImage
import CoreGraphics
import Foundation
extension CIImageRepresentationOption {
@available(iOS 14.1, macOS 11.0, macCatalyst 14.1, *)
static var hdrGainMapImage: Self { .init(rawValue: "kCIImageRepresentationHDRGainMapImage") } // not public, but should work
}
let image = CIImage(data: FileManager.default.contents(atPath: " /Users/miric/Downloads/hdr/IMG_1727.jpg")!)! // your input image
let gainMap = CIImage(data: FileManager.default.contents(atPath: "/Users/miric/Downloads/hdr/IMG_1727-hdrgainmap.jpg")!)! // your HDR gain map
let ciContext = CIContext()
let outputPath = URL(fileURLWithPath: "/Users/miric/Downloads/hdr/IMG_1727.heic") // path of the output image
try! ciContext.writeHEIFRepresentation(of: image,
to: outputPath,
format: .RGBA8,
colorSpace: CGColorSpace(name: CGColorSpace.displayP3)!,
options: [.hdrGainMapImage: gainMap])
@andsimakov
Copy link
Author

Still crashes:

assemble_image_file/assemble_image_file.swift:11: Fatal error: Unexpectedly found nil while unwrapping an Optional value
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.	Program arguments: /Library/Developer/CommandLineTools/usr/bin/swift-frontend -frontend -interpret assemble_image_file.swift -enable-objc-interop -sdk /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -color-diagnostics -target-sdk-version 12.1 -module-name assemble_image_file
1.	Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)
2.
3.	While running user code "assemble_image_file.swift"
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000109290c27 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  swift-frontend           0x000000010928fbb8 llvm::sys::RunSignalHandlers() + 248
2  swift-frontend           0x0000000109291236 SignalHandler(int) + 278
3  libsystem_platform.dylib 0x00007fff205ead7d _sigtramp + 29
4  libsystem_notify.dylib   0x00007fff22e0e625 notify_register_plain + 882
5  libswiftCore.dylib       0x00007fff2c986b69 $ss17_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_A2HSus6UInt32VtFySRys5UInt8VGXEfU_yAMXEfU_ + 105
6  libswiftCore.dylib       0x00007fff2c986909 $ss17_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_A2HSus6UInt32VtFySRys5UInt8VGXEfU_ + 121
7  libswiftCore.dylib       0x00007fff2c9865bc $ss17_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_A2HSus6UInt32VtF + 428
8  libswiftCore.dylib       0x000000010f10a518 $ss17_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_A2HSus6UInt32VtF + 18446603344315695368
9  swift-frontend           0x000000010449d220 llvm::orc::runAsMain(int (*)(int, char**), llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::Optional<llvm::StringRef>) + 1408
10 swift-frontend           0x00000001043fe017 swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions const&, swift::SILOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >&&) + 12871
11 swift-frontend           0x00000001043ad700 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2656
12 swift-frontend           0x000000010439f6d7 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 14743
13 swift-frontend           0x00000001042dfb08 main + 1032
14 libdyld.dylib            0x00007fff205c0f3d start + 1
15 libdyld.dylib            0x000000000000000c start + 18446603339973259472
[1]    77906 illegal hardware instruction  swift assemble_image_file.swift

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment