in SAM2-Demo/Common/CoreImageExtensions.swift [56:63]
func writePNG(_ image: CIImage, to url: URL) {
let outputCGImage = createCGImage(image, from: image.extent, format: .BGRA8, colorSpace: nil)!
guard let destination = CGImageDestinationCreateWithURL(url as CFURL, UTType.png.identifier as CFString, 1, nil) else {
fatalError("Failed to create an image destination.")
}
CGImageDestinationAddImage(destination, outputCGImage, nil)
CGImageDestinationFinalize(destination)
}