Writing AVDepthData to file fails on macOS

I'm trying to save a Portrait Mode photo on macOS (10.14.1) with embedded depth data.

The finalize function to write to a jpg file fails on macOS.

The following code works on iOS, but fails on macOS.

This will work on macOS if I comment out CGImageDestinationAddAuxiliaryDataInfo, so it appears to be the depth data.


guard let data = CFDataCreateMutable(kCFAllocatorDefault, 0) else {
  // error
}

guard let cgImageDestination = CGImageDestinationCreateWithData(data, AVFileType.jpg as CFString, 1, nil) else {
    // error
}

CGImageDestinationAddImage(cgImageDestination, cgImage, attachments)


//*******************************************************************
// add depth data - this section works on iOS but fails on macOS
var auxDataType :NSString?
let auxData = depthData.dictionaryRepresentation(forAuxiliaryDataType: &auxDataType)
let auxDataTemp = NSMutableDictionary(dictionary: auxData!)
CGImageDestinationAddAuxiliaryDataInfo(cgImageDestination, auxDataType!, auxDataTemp as CFDictionary)
//*******************************************************************


if CGImageDestinationFinalize(cgImageDestination) {
    // success
    return
} else {
  // error ***************
    print("Finalizing CGImageDestination error!")
    return
}


Are the specs or requirements different on macOS for writing depth data?

Thanks,

James

Accepted Reply

Just to follow up, I got this to work. I'm able to save a Portrait Mode photo on macOS.


I found an unrelated bug in my code that was causing my error in CGImageDestinationFinalize.

Here is what I found out: Setting the image colorspace to CGColorSpace.sRGB appears to be incompatible with a Portrait Mode photo with embedded depth data. I'm looking into this to see if this is a bug, or I had an implementation bug.

Replies

Saving depth to a file with CGImageDestination should work on macos. Could you please file a bug at bugreport.apple.com and include sample code (and a sample image) that reproduce the problem?


Thanks.

Just to follow up, I got this to work. I'm able to save a Portrait Mode photo on macOS.


I found an unrelated bug in my code that was causing my error in CGImageDestinationFinalize.

Here is what I found out: Setting the image colorspace to CGColorSpace.sRGB appears to be incompatible with a Portrait Mode photo with embedded depth data. I'm looking into this to see if this is a bug, or I had an implementation bug.

Are you creating the depth data manually with a custom depth or are you using the one obtained by a dual camera phone?