Lossy option has no effect when exporting PNG/TIFF to HEIF
Originator: | xhruso00 | ||
Number: | rdar://FB13685221 | Date Originated: | 13/3/2024 |
Status: | Open | Resolved: | |
Product: | macOS | Product Version: | 14.4 |
Classification: | Bug | Reproducible: | Always |
kCGImageDestinationLossyCompressionQuality has no effect when exporting PNG or TIFF to HEIF using CGImageDestination. JPG to HEIF works with compression option. HEIF to HEIF works with compression option. func heifImageDataUsingDestination(at url: URL, compressionQuality : CGFloat) -> Data? { guard let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil) else { return nil } guard let cgImage = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) else { return nil } var mutableData = NSMutableData() guard let imageDestination = CGImageDestinationCreateWithData(mutableData, "public.heic" as CFString, 1, nil) else { return nil } let options = [ kCGImageDestinationLossyCompressionQuality: compressionQuality ] as CFDictionary CGImageDestinationAddImage(imageDestination, cgImage, options) let success = CGImageDestinationFinalize(imageDestination) if success { return mutableData as Data } return nil } 1. Get URL of any PNG image 2. Use CGImageDestination to export new HEIC image with kCGImageDestinationLossyCompressionQuality parameter of 0.01 3. Use CGImageDestination to export new HEIC image with kCGImageDestinationLossyCompressionQuality parameter of 0.9 4. Compare these images Expected results: Image from step 2 smaller than image from step 3 Current results: Image from step 2 is the same as step 3 14.4 (23E214) Version 15.3 (15E204a)
Comments
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!