HEIC format is not supported in modifying Image Metadata Without Recompressing Image

Originator:simonwjw
Number:rdar://47433272 Date Originated:22/1/2019
Status:submitted Resolved:
Product:iOS Image I/O Product Version:
Classification: Reproducible:Always
 
Area:
Image I/O

Summary:
In our app, we need to strip off GPS data from HEIC photos. The `CGImageDestinationFinalize` method in Image I/O will re-encode the HEIC photos, which is very slow and the threads get stuck if I run multiple tasks (>=3 on iPhone XS Max) concurrently. 

After some research, I found this Technical Q&A QA1895. https://developer.apple.com/library/archive/qa/qa1895/_index.html. Here it suggests "CGImageDestinationCopyImageSource" to copy image source without recompressing the image data. However, apparently, HEIC format is not supported in "CGImageDestinationCopyImageSource". 

Here is the error I got:
Error Domain=kCFErrorDomainCGImageMetadata Code=1 "image type 'public.heic' is not supported for lossless metadata modification at this time.

Given HEIC is the default option on iPhone, and gets more and more popular, please add the support in "CGImageDestinationCopyImageSource".

Steps to Reproduce:

1, Given a HEIC image data source created from local device
2, Run the following code to strip off GPS metadata

        CGImageDestinationRef destination = CGImageDestinationCreateWithURL((__bridge CFURLRef)URL, AVFileTypeHEIC, size, NULL);
        if (destination) {
                CFErrorRef errorRef = NULL;
                CGImageMetadataRef sourceMetadata = CGImageSourceCopyMetadataAtIndex(source, 0, NULL);
                NSDictionary *options = @{(__bridge NSString *)kCGImageMetadataShouldExcludeGPS : @(YES)
                                          (__bridge NSString *)kCGImageDestinationMergeMetadata : @(YES);
                                          (__bridge NSString *)kCGImageDestinationMetadata, (__bridge id)sourceMetadata};
                isExportedSuccessfully = CGImageDestinationCopyImageSource(destination, source, (__bridge CFDictionaryRef)options, &errorRef);
                
            }
            
            CFRelease(destination);
        }

Expected Results:
The HEIC format photo should be Losslessly copied (without re-encoding) along with the new options/metadatas

Actual Results:
It fails with the following error:

Error Domain=kCFErrorDomainCGImageMetadata Code=1 "image type 'public.heic' is not supported for lossless metadata modification at this time.
Version/Build:

Configuration:
iOS 11 and above

Comments

Did you ever figure this out?

By stormychel at Feb. 16, 2021, 6:14 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!