Post

Replies

Boosts

Views

Activity

Convert a .3dl file to Metal Texture
I am trying to convert .3dl and .cube to Metal Texture on iOS device in Swift language, recently I have found the answer for .cube file in this question and answer: Init a Metal texture with the type of 3D class AdobeLUTParser { static func texture(withContentsOf url: URL, device: MTLDevice) -> MTLTexture? { let lutString = try! NSString(contentsOf: url, encoding: String.Encoding.utf8.rawValue) let lines = lutString.components(separatedBy: "\r\n") as [NSString] var dim = 2 var values: UnsafeMutablePointer<Float>? = nil var index = 0 for line in lines { if line.length == 0 { continue; } // skip blanks let firstChar = line.character(at: 0) if firstChar < 58 /*':'*/ { if values == nil { print("Error: Got data before size in LUT") break; } let numbers = line.components(separatedBy: " ") as [NSString] if numbers.count == 3 { let r = numbers[0].floatValue let g = numbers[1].floatValue let b = numbers[2].floatValue let a = Float(1) values![index * 4 + 0] = r values![index * 4 + 1] = g values![index * 4 + 2] = b values![index * 4 + 3] = a index += 1 } } else { if line.hasPrefix("LUT_3D_SIZE") { let sizeString = line.components(separatedBy: " ")[1] as NSString dim = Int(sizeString.intValue) if dim < 2 || dim > 512 { print("Error: insane LUT size: \(dim)") } let rawPointer = malloc(dim * dim * dim * 4 * MemoryLayout<Float>.size) values = rawPointer!.bindMemory(to: Float.self, capacity: dim * dim * dim * 4) } else if line.hasPrefix("LUT_1D_SIZE") { print("Error: 1D LUTs not supported") break } } } if values == nil { print("Did not parse LUT successfully") return nil } let textureDescriptor = MTLTextureDescriptor() textureDescriptor.textureType = .type3D textureDescriptor.pixelFormat = .rgba32Float textureDescriptor.width = dim textureDescriptor.height = dim textureDescriptor.depth = dim textureDescriptor.usage = .shaderRead let texture = device.makeTexture(descriptor: textureDescriptor) texture.replace(region: MTLRegionMake3D(0, 0, 0, dim, dim, dim), mipmapLevel:0, slice:0, withBytes:values!, bytesPerRow:dim * MemoryLayout<Float>.size * 4, bytesPerImage:dim * dim * MemoryLayout<Float>.size * 4) return texture } } But .3dl is different from .cube, I still don't know how to parse the .3dl file and how to Convert .3dl, any one know how to parse .3dl file?
0
0
730
Jan ’23
Save 48MP ProRaw to PhotoLibrary may fail
After took 48MP ProRaw photo, captureOutput:(AVCapturePhotoOutput *)output didFinishProcessingPhoto write to photo library use [PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait: or [PHPhotoLibrary sharedPhotoLibrary] performChanges There is a high probability of failure No matter use fileURL or [photo fileDataRepresentation] failure info below 2022-09-28 10:43:57.353815+0800 LUTCamera[2031:218103] [GatekeeperXPC] Error received from proxy factory <PLAssetsdServiceProxyFactory: 0x28190b300> in sendChangesRequest:usingProxyFactory:error:: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.photos.service was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid." UserInfo={NSDebugDescription=The connection to service named com.apple.photos.service was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid.} 2022-09-28 10:43:57.354114+0800 LUTCamera[2031:218103] [PhotoKit] PhotoKit XPC proxy is invalid. Dropping request on the floor and returning an error: Error Domain=PHPhotosErrorDomain Code=3301 "(null)" (underlying error Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.photos.service was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid." UserInfo={NSDebugDescription=The connection to service named com.apple.photos.service was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid.}) 2022-09-28 10:43:57.359493+0800 LUTCamera[2031:218100] [error] error: XPC: synchronousRemoteObjectProxyWithErrorHandler encountered error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service created from an endpoint was invalidated: failed to check-in, peer may have been unloaded: mach_error=10000003." UserInfo={NSDebugDescription=The connection to service created from an endpoint was invalidated: failed to check-in, peer may have been unloaded: mach_error=10000003.} 2022-09-28 10:43:57.359508+0800 LUTCamera[2031:218257] CoreData: XPC: XPC connection was invalidated CoreData: error: XPC: synchronousRemoteObjectProxyWithErrorHandler encountered error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service created from an endpoint was invalidated: failed to check-in, peer may have been unloaded: mach_error=10000003." UserInfo={NSDebugDescription=The connection to service created from an endpoint was invalidated: failed to check-in, peer may have been unloaded: mach_error=10000003.} 2022-09-28 10:43:57.473207+0800 LUTCamera[2031:218100] CoreData: XPC: sendMessage: failed #0
1
0
1.3k
Sep ’22