From 16365d5d094f2a4bab91f9cb04dce8eff4b0b818 Mon Sep 17 00:00:00 2001 From: CMK Date: Tue, 24 May 2022 16:04:04 +0800 Subject: [PATCH] fix: ICC profile losing during media compression issue --- .../Sources/MastodonUI/Vendor/ItemProviderLoader.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/MastodonSDK/Sources/MastodonUI/Vendor/ItemProviderLoader.swift b/MastodonSDK/Sources/MastodonUI/Vendor/ItemProviderLoader.swift index ef0c36f1b..e3622f3cd 100644 --- a/MastodonSDK/Sources/MastodonUI/Vendor/ItemProviderLoader.swift +++ b/MastodonSDK/Sources/MastodonUI/Vendor/ItemProviderLoader.swift @@ -41,7 +41,7 @@ extension ItemProviderLoader { guard let source = CGImageSourceCreateWithURL(url as CFURL, sourceOptions) else { return } - + #if APP_EXTENSION let maxPixelSize: Int = 4096 // not limit but may upload fail #else @@ -87,8 +87,11 @@ extension ItemProviderLoader { return (utType as String) == UTType.png.identifier }() + let sourceProperties = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as NSDictionary? let destinationProperties = [ - kCGImageDestinationLossyCompressionQuality: isPNG ? 1.0 : 0.75 + kCGImageDestinationLossyCompressionQuality: isPNG ? 1.0 : 0.75, + kCGImagePropertyProfileName: sourceProperties?[kCGImagePropertyProfileName], + kCGImagePropertyColorModel: sourceProperties?[kCGImagePropertyColorModel] ] as CFDictionary CGImageDestinationAddImage(imageDestination, cgImage, destinationProperties)