From ae82c2d5092e2a36ed6a71f5286659d7f6d40da8 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Sat, 6 Apr 2019 02:25:06 +0800 Subject: [PATCH 1/2] Add the preview code for AVIF (AV1 based HEIF) format support --- Example/Podfile | 11 +++++- Example/Podfile.lock | 38 ++++++++++++++----- .../project.pbxproj | 8 +++- SDWebImageHEIFCoder.podspec | 9 +++++ .../Classes/SDImageHEIFCoder.h | 2 + .../Classes/SDImageHEIFCoder.m | 16 +++++++- 6 files changed, 71 insertions(+), 13 deletions(-) diff --git a/Example/Podfile b/Example/Podfile index b42dc1c..a04afac 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -5,7 +5,12 @@ target 'SDWebImageHEIFCoder_Example' do platform :ios, '8.0' pod 'SDWebImageHEIFCoder', :path => '../', :subspecs => [ 'libde265', - 'libx265' + 'libx265', + 'libaom' + ] + pod 'libheif', :git => 'https://github.com/dreampiggy/libheif.git', :branch => 'cocoapods_avif', :subspecs => [ + 'libde265', + 'libaom' ] target 'SDWebImageHEIFCoder_Tests' do @@ -21,4 +26,8 @@ target 'SDWebImageHEIFCoder_Example macOS' do 'libde265', 'libx265' ] + pod 'libheif', :git => 'https://github.com/dreampiggy/libheif.git', :branch => 'cocoapods_avif', :subspecs => [ + 'libde265', + 'libaom' + ] end \ No newline at end of file diff --git a/Example/Podfile.lock b/Example/Podfile.lock index f5f7b8c..524aa7e 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -1,5 +1,9 @@ PODS: + - libaom (1.0.1) - libde265 (1.0.3) + - libheif/libaom (1.4.0): + - libaom (>= 1.0.1) + - libheif/libheif - libheif/libde265 (1.4.0): - libde265 - libheif/libheif @@ -29,41 +33,57 @@ PODS: - libx265/encoder - libx265/input - libx265/output - - SDWebImage/Core (5.0.1) - - SDWebImageHEIFCoder/libde265 (0.5.1): + - SDWebImage/Core (5.0.2) + - SDWebImageHEIFCoder/libaom (0.5.2): + - libheif/libaom + - SDWebImage/Core (~> 5.0) + - SDWebImageHEIFCoder/libheif + - SDWebImageHEIFCoder/libde265 (0.5.2): - libheif/libde265 - SDWebImage/Core (~> 5.0) - SDWebImageHEIFCoder/libheif - - SDWebImageHEIFCoder/libheif (0.5.1): + - SDWebImageHEIFCoder/libheif (0.5.2): - libheif/libheif (>= 1.4.0) - SDWebImage/Core (~> 5.0) - - SDWebImageHEIFCoder/libx265 (0.5.1): + - SDWebImageHEIFCoder/libx265 (0.5.2): - libheif/libx265 - SDWebImage/Core (~> 5.0) - SDWebImageHEIFCoder/libheif DEPENDENCIES: + - libheif/libaom (from `https://github.com/dreampiggy/libheif.git`, branch `cocoapods_avif`) + - libheif/libde265 (from `https://github.com/dreampiggy/libheif.git`, branch `cocoapods_avif`) + - SDWebImageHEIFCoder/libaom (from `../`) - SDWebImageHEIFCoder/libde265 (from `../`) - SDWebImageHEIFCoder/libx265 (from `../`) SPEC REPOS: https://github.com/cocoapods/specs.git: + - libaom - libde265 - - libheif - libx265 - SDWebImage EXTERNAL SOURCES: + libheif: + :branch: cocoapods_avif + :git: https://github.com/dreampiggy/libheif.git SDWebImageHEIFCoder: :path: "../" +CHECKOUT OPTIONS: + libheif: + :commit: 5f8f74a913abc4e91a495326d4c5f535efe8b240 + :git: https://github.com/dreampiggy/libheif.git + SPEC CHECKSUMS: + libaom: 1e48c68559b8d6191c1a9f266e0bee83b2dd21fd libde265: b2a0cc3d2aeaafb792b43fcf2a122f42e1de107c - libheif: e79ed1935019556d3b7a5b8926dcbaa478cb4180 + libheif: 0f7d3e215560d92234acfaad89ca1e7306d4a3d0 libx265: 23ab716aae3eff1e6b68b3db6ace8883867691c4 - SDWebImage: 27dd2c9ea07a2252f94557c9fbb6105ee94b74c9 - SDWebImageHEIFCoder: 8e078eff3c4dab7d4031331a225948aab396bfa7 + SDWebImage: 6764b5fa0f73c203728052955dbefa2bf1f33282 + SDWebImageHEIFCoder: 8b02ef1fc782606c28d51ed48bb91983edc7ad8e -PODFILE CHECKSUM: ed097a0e3cb0df40f8e18e8e1e8b396ec38d29ff +PODFILE CHECKSUM: 7798feb2c1491ee12d239e4590ffcc49be98a342 COCOAPODS: 1.6.1 diff --git a/Example/SDWebImageHEIFCoder.xcodeproj/project.pbxproj b/Example/SDWebImageHEIFCoder.xcodeproj/project.pbxproj index b37e60b..30a38ad 100644 --- a/Example/SDWebImageHEIFCoder.xcodeproj/project.pbxproj +++ b/Example/SDWebImageHEIFCoder.xcodeproj/project.pbxproj @@ -396,7 +396,8 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-SDWebImageHEIFCoder_Example macOS/Pods-SDWebImageHEIFCoder_Example macOS-frameworks.sh", "${BUILT_PRODUCTS_DIR}/SDWebImage-macOS/SDWebImage.framework", - "${BUILT_PRODUCTS_DIR}/SDWebImageHEIFCoder-macOS/SDWebImageHEIFCoder.framework", + "${BUILT_PRODUCTS_DIR}/SDWebImageHEIFCoder-libde265-libheif-libx265/SDWebImageHEIFCoder.framework", + "${BUILT_PRODUCTS_DIR}/libaom-macOS/libaom.framework", "${BUILT_PRODUCTS_DIR}/libde265-macOS/libde265.framework", "${BUILT_PRODUCTS_DIR}/libheif-macOS/libheif.framework", "${BUILT_PRODUCTS_DIR}/libx265-macOS/libx265.framework", @@ -407,6 +408,7 @@ outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImageHEIFCoder.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libaom.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libde265.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libheif.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libx265.framework", @@ -488,7 +490,8 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-SDWebImageHEIFCoder_Example/Pods-SDWebImageHEIFCoder_Example-frameworks.sh", "${BUILT_PRODUCTS_DIR}/SDWebImage-iOS/SDWebImage.framework", - "${BUILT_PRODUCTS_DIR}/SDWebImageHEIFCoder-iOS/SDWebImageHEIFCoder.framework", + "${BUILT_PRODUCTS_DIR}/SDWebImageHEIFCoder-libaom-libde265-libheif-libx265/SDWebImageHEIFCoder.framework", + "${BUILT_PRODUCTS_DIR}/libaom-iOS/libaom.framework", "${BUILT_PRODUCTS_DIR}/libde265-iOS/libde265.framework", "${BUILT_PRODUCTS_DIR}/libheif-iOS/libheif.framework", "${BUILT_PRODUCTS_DIR}/libx265-iOS/libx265.framework", @@ -499,6 +502,7 @@ outputPaths = ( "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImageHEIFCoder.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libaom.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libde265.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libheif.framework", "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libx265.framework", diff --git a/SDWebImageHEIFCoder.podspec b/SDWebImageHEIFCoder.podspec index 8fda168..92de445 100644 --- a/SDWebImageHEIFCoder.podspec +++ b/SDWebImageHEIFCoder.podspec @@ -52,6 +52,15 @@ Which is built based on the open-sourced libheif codec. 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) HAVE_X265=1' } end + + # AVIF Decoding and Encoding need libaom + s.subspec 'libaom' do |ss| + ss.dependency 'libheif/libaom' + ss.dependency 'SDWebImageHEIFCoder/libheif' + ss.xcconfig = { + 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) HAVE_AOM=1' + } + end s.dependency 'SDWebImage/Core', '~> 5.0' end diff --git a/SDWebImageHEIFCoder/Classes/SDImageHEIFCoder.h b/SDWebImageHEIFCoder/Classes/SDImageHEIFCoder.h index 38e4a18..aef6c82 100644 --- a/SDWebImageHEIFCoder/Classes/SDImageHEIFCoder.h +++ b/SDWebImageHEIFCoder/Classes/SDImageHEIFCoder.h @@ -7,6 +7,8 @@ #import +static const SDImageFormat SDImageFormatAVIF = 15; // AV1-codec based HEIF + @interface SDImageHEIFCoder : NSObject @property (nonatomic, class, readonly, nonnull) SDImageHEIFCoder *sharedCoder; diff --git a/SDWebImageHEIFCoder/Classes/SDImageHEIFCoder.m b/SDWebImageHEIFCoder/Classes/SDImageHEIFCoder.m index 65f9b94..ff04539 100644 --- a/SDWebImageHEIFCoder/Classes/SDImageHEIFCoder.m +++ b/SDWebImageHEIFCoder/Classes/SDImageHEIFCoder.m @@ -50,7 +50,7 @@ + (instancetype)sharedCoder { } - (BOOL)canDecodeFromData:(NSData *)data { -#if HAVE_LIBDE265 +#if HAVE_LIBDE265 || HAVE_AOM return [[self class] isHEIFFormatForData:data]; #else return NO; @@ -174,6 +174,12 @@ - (BOOL)canEncodeToFormat:(SDImageFormat)format { return YES; #else return NO; +#endif + } else if (format == SDImageFormatAVIF) { +#if HAVE_AOM + return YES; +#else + return NO; #endif } return NO; @@ -363,6 +369,7 @@ + (BOOL)isHEIFFormatForData:(NSData *)data if (data.length >= 12) { //....ftypmif1 ....ftypmsf1 ....ftypheic ....ftypheix ....ftyphevc ....ftyphevx NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(4, 8)] encoding:NSASCIIStringEncoding]; +#if HAVE_LIBDE265 if ([testString isEqualToString:@"ftypmif1"] || [testString isEqualToString:@"ftypmsf1"] || [testString isEqualToString:@"ftypheic"] @@ -371,6 +378,13 @@ + (BOOL)isHEIFFormatForData:(NSData *)data || [testString isEqualToString:@"ftyphevx"]) { return YES; } +#endif +#if HAVE_AOM + if ([testString isEqualToString:@"ftypavif"] + || [testString isEqualToString:@"ftypavis"]) { + return YES; + } +#endif } return NO; From 641e8b63d4e3d46013576e633b7df65648bf3946 Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Mon, 15 Apr 2019 01:12:10 +0800 Subject: [PATCH 2/2] Support the AVIF subspec and decoding --- Example/Podfile | 3 +- Example/Podfile.lock | 2 +- .../project.pbxproj | 166 +++++++++++++----- .../ViewController.m | 19 +- .../Classes/SDImageHEIFCoder.m | 16 +- 5 files changed, 142 insertions(+), 64 deletions(-) diff --git a/Example/Podfile b/Example/Podfile index a04afac..f45f12b 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -24,7 +24,8 @@ target 'SDWebImageHEIFCoder_Example macOS' do platform :osx, '10.10' pod 'SDWebImageHEIFCoder', :path => '../', :subspecs => [ 'libde265', - 'libx265' + 'libx265', + 'libaom' ] pod 'libheif', :git => 'https://github.com/dreampiggy/libheif.git', :branch => 'cocoapods_avif', :subspecs => [ 'libde265', diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 524aa7e..a8cc218 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -84,6 +84,6 @@ SPEC CHECKSUMS: SDWebImage: 6764b5fa0f73c203728052955dbefa2bf1f33282 SDWebImageHEIFCoder: 8b02ef1fc782606c28d51ed48bb91983edc7ad8e -PODFILE CHECKSUM: 7798feb2c1491ee12d239e4590ffcc49be98a342 +PODFILE CHECKSUM: 0f40ba831206c927189586a2cdcee53c9767475e COCOAPODS: 1.6.1 diff --git a/Example/SDWebImageHEIFCoder.xcodeproj/project.pbxproj b/Example/SDWebImageHEIFCoder.xcodeproj/project.pbxproj index 30a38ad..10b2530 100644 --- a/Example/SDWebImageHEIFCoder.xcodeproj/project.pbxproj +++ b/Example/SDWebImageHEIFCoder.xcodeproj/project.pbxproj @@ -7,12 +7,14 @@ objects = { /* Begin PBXBuildFile section */ - 02611B7015E8FA9225C7A277 /* Pods_SDWebImageHEIFCoder_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C56612731812E8C66FD75D78 /* Pods_SDWebImageHEIFCoder_Tests.framework */; }; + 0588EFAB441E2AFF647BF1A3 /* Pods_SDWebImageHEIFCoder_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 88BDED79F5466CB6ED3CD2F7 /* Pods_SDWebImageHEIFCoder_Tests.framework */; }; + 16263553CB3C63517F94AE8A /* Pods_SDWebImageHEIFCoder_Example_macOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C952E92B45A3C574F1D15EEF /* Pods_SDWebImageHEIFCoder_Example_macOS.framework */; }; 32DE7FAC2261EA5400CF1A88 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 32DE7FAB2261EA5400CF1A88 /* AppDelegate.m */; }; 32DE7FAF2261EA5400CF1A88 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 32DE7FAE2261EA5400CF1A88 /* ViewController.m */; }; 32DE7FB12261EA5400CF1A88 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 32DE7FB02261EA5400CF1A88 /* Assets.xcassets */; }; 32DE7FB42261EA5400CF1A88 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 32DE7FB22261EA5400CF1A88 /* Main.storyboard */; }; 32DE7FB72261EA5400CF1A88 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 32DE7FB62261EA5400CF1A88 /* main.m */; }; + 3A7AB3D0FB478EE5A12C5502 /* Pods_SDWebImageHEIFCoder_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0AF991D3E0118CD0FFB0ACCD /* Pods_SDWebImageHEIFCoder_Example.framework */; }; 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; }; 6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58F195388D20070C39A /* CoreGraphics.framework */; }; 6003F592195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; }; @@ -28,8 +30,6 @@ 6003F5BC195388D20070C39A /* Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5BB195388D20070C39A /* Tests.m */; }; 71719F9F1E33DC2100824A3D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 71719F9D1E33DC2100824A3D /* LaunchScreen.storyboard */; }; 873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; }; - C8FC400702982DCE3137FF1E /* Pods_SDWebImageHEIFCoder_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AAB362D312C46B9817266DAB /* Pods_SDWebImageHEIFCoder_Example.framework */; }; - EF9F662659DA33FEAF30A93A /* Pods_SDWebImageHEIFCoder_Example_macOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2AF860EE1234E07BC0DB72D /* Pods_SDWebImageHEIFCoder_Example_macOS.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -43,6 +43,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 0AF991D3E0118CD0FFB0ACCD /* Pods_SDWebImageHEIFCoder_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SDWebImageHEIFCoder_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 3223E81322623D46004129E9 /* libaom.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libaom.a; path = ../../../../../../usr/local/Cellar/aom/1.0.0/lib/libaom.a; sourceTree = ""; }; 32DE7FA82261EA5300CF1A88 /* SDWebImageHEIFCoder_Example macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SDWebImageHEIFCoder_Example macOS.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 32DE7FAA2261EA5300CF1A88 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 32DE7FAB2261EA5400CF1A88 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; @@ -77,14 +79,13 @@ 71719F9E1E33DC2100824A3D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 7B8FAB679E1472168E8617DA /* SDWebImageHEIFCoder.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = SDWebImageHEIFCoder.podspec; path = ../SDWebImageHEIFCoder.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Main.storyboard; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 88BDED79F5466CB6ED3CD2F7 /* Pods_SDWebImageHEIFCoder_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SDWebImageHEIFCoder_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8AE65D38B3BF6E4CCAFAF73D /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; A1EC1B641EF75BEA2475590E /* Pods-SDWebImageHEIFCoder_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SDWebImageHEIFCoder_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-SDWebImageHEIFCoder_Example/Pods-SDWebImageHEIFCoder_Example.release.xcconfig"; sourceTree = ""; }; A67B84CEC3645A0A997486A2 /* Pods-SDWebImageHEIFCoder_Example macOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SDWebImageHEIFCoder_Example macOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SDWebImageHEIFCoder_Example macOS/Pods-SDWebImageHEIFCoder_Example macOS.debug.xcconfig"; sourceTree = ""; }; - AAB362D312C46B9817266DAB /* Pods_SDWebImageHEIFCoder_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SDWebImageHEIFCoder_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; AB0B536057FCDF0347F3135D /* Pods-SDWebImageHEIFCoder_Example macOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SDWebImageHEIFCoder_Example macOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-SDWebImageHEIFCoder_Example macOS/Pods-SDWebImageHEIFCoder_Example macOS.release.xcconfig"; sourceTree = ""; }; AD1FAB2DFC3830F2A4ADBB8B /* Pods-SDWebImageHEIFCoder_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SDWebImageHEIFCoder_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SDWebImageHEIFCoder_Tests/Pods-SDWebImageHEIFCoder_Tests.release.xcconfig"; sourceTree = ""; }; - B2AF860EE1234E07BC0DB72D /* Pods_SDWebImageHEIFCoder_Example_macOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SDWebImageHEIFCoder_Example_macOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - C56612731812E8C66FD75D78 /* Pods_SDWebImageHEIFCoder_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SDWebImageHEIFCoder_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + C952E92B45A3C574F1D15EEF /* Pods_SDWebImageHEIFCoder_Example_macOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SDWebImageHEIFCoder_Example_macOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E246A920ED516D3F3B26DB31 /* Pods-SDWebImageHEIFCoder_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SDWebImageHEIFCoder_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SDWebImageHEIFCoder_Tests/Pods-SDWebImageHEIFCoder_Tests.debug.xcconfig"; sourceTree = ""; }; EDAAE4F3946D0D53727C85E0 /* Pods-SDWebImageHEIFCoder_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SDWebImageHEIFCoder_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SDWebImageHEIFCoder_Example/Pods-SDWebImageHEIFCoder_Example.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -94,7 +95,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - EF9F662659DA33FEAF30A93A /* Pods_SDWebImageHEIFCoder_Example_macOS.framework in Frameworks */, + 16263553CB3C63517F94AE8A /* Pods_SDWebImageHEIFCoder_Example_macOS.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -105,7 +106,7 @@ 6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */, 6003F592195388D20070C39A /* UIKit.framework in Frameworks */, 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */, - C8FC400702982DCE3137FF1E /* Pods_SDWebImageHEIFCoder_Example.framework in Frameworks */, + 3A7AB3D0FB478EE5A12C5502 /* Pods_SDWebImageHEIFCoder_Example.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -116,7 +117,7 @@ 6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */, 6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */, 6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */, - 02611B7015E8FA9225C7A277 /* Pods_SDWebImageHEIFCoder_Tests.framework in Frameworks */, + 0588EFAB441E2AFF647BF1A3 /* Pods_SDWebImageHEIFCoder_Tests.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -166,13 +167,14 @@ 6003F58C195388D20070C39A /* Frameworks */ = { isa = PBXGroup; children = ( + 3223E81322623D46004129E9 /* libaom.a */, 6003F58D195388D20070C39A /* Foundation.framework */, 6003F58F195388D20070C39A /* CoreGraphics.framework */, 6003F591195388D20070C39A /* UIKit.framework */, 6003F5AF195388D20070C39A /* XCTest.framework */, - AAB362D312C46B9817266DAB /* Pods_SDWebImageHEIFCoder_Example.framework */, - C56612731812E8C66FD75D78 /* Pods_SDWebImageHEIFCoder_Tests.framework */, - B2AF860EE1234E07BC0DB72D /* Pods_SDWebImageHEIFCoder_Example_macOS.framework */, + 0AF991D3E0118CD0FFB0ACCD /* Pods_SDWebImageHEIFCoder_Example.framework */, + C952E92B45A3C574F1D15EEF /* Pods_SDWebImageHEIFCoder_Example_macOS.framework */, + 88BDED79F5466CB6ED3CD2F7 /* Pods_SDWebImageHEIFCoder_Tests.framework */, ); name = Frameworks; sourceTree = ""; @@ -257,7 +259,7 @@ 32DE7FA42261EA5300CF1A88 /* Sources */, 32DE7FA52261EA5300CF1A88 /* Frameworks */, 32DE7FA62261EA5300CF1A88 /* Resources */, - 96669B7112262C063F62EA79 /* [CP] Embed Pods Frameworks */, + 781E680B77F04382301DB64D /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -276,7 +278,7 @@ 6003F586195388D20070C39A /* Sources */, 6003F587195388D20070C39A /* Frameworks */, 6003F588195388D20070C39A /* Resources */, - F39A86DB2BA8E836FE67CC7B /* [CP] Embed Pods Frameworks */, + 8C9773534A2E22BB787E77C5 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -386,7 +388,7 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 96669B7112262C063F62EA79 /* [CP] Embed Pods Frameworks */ = { + 781E680B77F04382301DB64D /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -396,7 +398,7 @@ inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-SDWebImageHEIFCoder_Example macOS/Pods-SDWebImageHEIFCoder_Example macOS-frameworks.sh", "${BUILT_PRODUCTS_DIR}/SDWebImage-macOS/SDWebImage.framework", - "${BUILT_PRODUCTS_DIR}/SDWebImageHEIFCoder-libde265-libheif-libx265/SDWebImageHEIFCoder.framework", + "${BUILT_PRODUCTS_DIR}/SDWebImageHEIFCoder-macOS/SDWebImageHEIFCoder.framework", "${BUILT_PRODUCTS_DIR}/libaom-macOS/libaom.framework", "${BUILT_PRODUCTS_DIR}/libde265-macOS/libde265.framework", "${BUILT_PRODUCTS_DIR}/libheif-macOS/libheif.framework", @@ -418,7 +420,7 @@ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-SDWebImageHEIFCoder_Example macOS/Pods-SDWebImageHEIFCoder_Example macOS-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - A2C66F452A1B40946E468D96 /* [CP] Check Pods Manifest.lock */ = { + 8C9773534A2E22BB787E77C5 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -426,21 +428,31 @@ inputFileListPaths = ( ); inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", + "${PODS_ROOT}/Target Support Files/Pods-SDWebImageHEIFCoder_Example/Pods-SDWebImageHEIFCoder_Example-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/SDWebImage-iOS/SDWebImage.framework", + "${BUILT_PRODUCTS_DIR}/SDWebImageHEIFCoder-iOS/SDWebImageHEIFCoder.framework", + "${BUILT_PRODUCTS_DIR}/libaom-iOS/libaom.framework", + "${BUILT_PRODUCTS_DIR}/libde265-iOS/libde265.framework", + "${BUILT_PRODUCTS_DIR}/libheif-iOS/libheif.framework", + "${BUILT_PRODUCTS_DIR}/libx265-iOS/libx265.framework", ); - name = "[CP] Check Pods Manifest.lock"; + name = "[CP] Embed Pods Frameworks"; outputFileListPaths = ( ); outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-SDWebImageHEIFCoder_Example macOS-checkManifestLockResult.txt", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImageHEIFCoder.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libaom.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libde265.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libheif.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libx265.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-SDWebImageHEIFCoder_Example/Pods-SDWebImageHEIFCoder_Example-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - AC57DECD759D1FC135D8AF3F /* [CP] Check Pods Manifest.lock */ = { + A2C66F452A1B40946E468D96 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -455,61 +467,51 @@ outputFileListPaths = ( ); outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-SDWebImageHEIFCoder_Tests-checkManifestLockResult.txt", + "$(DERIVED_FILE_DIR)/Pods-SDWebImageHEIFCoder_Example macOS-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - DC2568C50939AE9524F8F271 /* [CP] Check Pods Manifest.lock */ = { + AC57DECD759D1FC135D8AF3F /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); + inputFileListPaths = ( + ); inputPaths = ( "${PODS_PODFILE_DIR_PATH}/Podfile.lock", "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-SDWebImageHEIFCoder_Example-checkManifestLockResult.txt", + "$(DERIVED_FILE_DIR)/Pods-SDWebImageHEIFCoder_Tests-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - F39A86DB2BA8E836FE67CC7B /* [CP] Embed Pods Frameworks */ = { + DC2568C50939AE9524F8F271 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); - inputFileListPaths = ( - ); inputPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-SDWebImageHEIFCoder_Example/Pods-SDWebImageHEIFCoder_Example-frameworks.sh", - "${BUILT_PRODUCTS_DIR}/SDWebImage-iOS/SDWebImage.framework", - "${BUILT_PRODUCTS_DIR}/SDWebImageHEIFCoder-libaom-libde265-libheif-libx265/SDWebImageHEIFCoder.framework", - "${BUILT_PRODUCTS_DIR}/libaom-iOS/libaom.framework", - "${BUILT_PRODUCTS_DIR}/libde265-iOS/libde265.framework", - "${BUILT_PRODUCTS_DIR}/libheif-iOS/libheif.framework", - "${BUILT_PRODUCTS_DIR}/libx265-iOS/libx265.framework", - ); - name = "[CP] Embed Pods Frameworks"; - outputFileListPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); + name = "[CP] Check Pods Manifest.lock"; outputPaths = ( - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImageHEIFCoder.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libaom.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libde265.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libheif.framework", - "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/libx265.framework", + "$(DERIVED_FILE_DIR)/Pods-SDWebImageHEIFCoder_Example-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-SDWebImageHEIFCoder_Example/Pods-SDWebImageHEIFCoder_Example-frameworks.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -607,6 +609,42 @@ COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = dwarf; GCC_C_LANGUAGE_STANDARD = gnu11; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "\"${PODS_CONFIGURATION_BUILD_DIR}/SDWebImage-macOS/SDWebImage.framework/Headers\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/SDWebImageHEIFCoder-macOS/SDWebImageHEIFCoder.framework/Headers\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/libaom-macOS/libaom.framework/Headers\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/libavif-macOS/libavif.framework/Headers\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/libde265-macOS/libde265.framework/Headers\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/libheif-macOS/libheif.framework/Headers\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/libx265-macOS/libx265.framework/Headers\"", + "$(inherited)", + "${PODS_ROOT}/libaom", + "${PODS_TARGET_SRCROOT}/", + "${PODS_ROOT}/libaom/generate", + "${PODS_TARGET_SRCROOT}/generate", + "$(inherited)", + "$(PODS_ROOT)/libavif/include", + "$(PODS_TARGET_SRCROOT)/include", + "${PODS_ROOT}/libaom/", + "$(inherited)", + "${PODS_ROOT}/libde265/", + "${PODS_TARGET_SRCROOT}/", + "${PODS_ROOT}/libde265/libde265", + "${PODS_TARGET_SRCROOT}/libde265", + "$(inherited)", + "${PODS_ROOT}/libheif/", + "${PODS_TARGET_SRCROOT}/", + "${PODS_ROOT}/libaom/", + "$(inherited)", + "${PODS_ROOT}/libheif/", + "${PODS_TARGET_SRCROOT}/", + "$(inherited)", + "${PODS_ROOT}/libheif/", + "${PODS_TARGET_SRCROOT}/", + "${PODS_ROOT}/libx265/source/", + /usr/local/include, + ); INFOPLIST_FILE = "SDWebImageHEIFCoder_Example macOS/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; @@ -637,6 +675,42 @@ COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_C_LANGUAGE_STANDARD = gnu11; + HEADER_SEARCH_PATHS = ( + "$(inherited)", + "\"${PODS_CONFIGURATION_BUILD_DIR}/SDWebImage-macOS/SDWebImage.framework/Headers\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/SDWebImageHEIFCoder-macOS/SDWebImageHEIFCoder.framework/Headers\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/libaom-macOS/libaom.framework/Headers\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/libavif-macOS/libavif.framework/Headers\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/libde265-macOS/libde265.framework/Headers\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/libheif-macOS/libheif.framework/Headers\"", + "\"${PODS_CONFIGURATION_BUILD_DIR}/libx265-macOS/libx265.framework/Headers\"", + "$(inherited)", + "${PODS_ROOT}/libaom", + "${PODS_TARGET_SRCROOT}/", + "${PODS_ROOT}/libaom/generate", + "${PODS_TARGET_SRCROOT}/generate", + "$(inherited)", + "$(PODS_ROOT)/libavif/include", + "$(PODS_TARGET_SRCROOT)/include", + "${PODS_ROOT}/libaom/", + "$(inherited)", + "${PODS_ROOT}/libde265/", + "${PODS_TARGET_SRCROOT}/", + "${PODS_ROOT}/libde265/libde265", + "${PODS_TARGET_SRCROOT}/libde265", + "$(inherited)", + "${PODS_ROOT}/libheif/", + "${PODS_TARGET_SRCROOT}/", + "${PODS_ROOT}/libaom/", + "$(inherited)", + "${PODS_ROOT}/libheif/", + "${PODS_TARGET_SRCROOT}/", + "$(inherited)", + "${PODS_ROOT}/libheif/", + "${PODS_TARGET_SRCROOT}/", + "${PODS_ROOT}/libx265/source/", + /usr/local/include, + ); INFOPLIST_FILE = "SDWebImageHEIFCoder_Example macOS/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; diff --git a/Example/SDWebImageHEIFCoder_Example macOS/ViewController.m b/Example/SDWebImageHEIFCoder_Example macOS/ViewController.m index 25fd446..639057a 100644 --- a/Example/SDWebImageHEIFCoder_Example macOS/ViewController.m +++ b/Example/SDWebImageHEIFCoder_Example macOS/ViewController.m @@ -17,8 +17,8 @@ - (void)viewDidLoad { SDImageHEIFCoder *HEIFCoder = [SDImageHEIFCoder sharedCoder]; [[SDImageCodersManager sharedManager] addCoder:HEIFCoder]; - NSURL *staticHEIFURL = [NSURL URLWithString:@"http://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic"]; - NSURL *animatedHEIFURL = [NSURL URLWithString:@"http://nokiatech.github.io/heif/content/image_sequences/starfield_animation.heic"]; + NSURL *HEICURL = [NSURL URLWithString:@"http://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic"]; + NSURL *AVIFURL = [NSURL URLWithString:@"https://raw.githubusercontent.com/AOMediaCodec/av1-avif/master/testFiles/Microsoft/Chimera_10bit_cropped_to_1920x1008.avif"]; CGSize screenSize = self.view.bounds.size; @@ -31,7 +31,7 @@ - (void)viewDidLoad { [self.view addSubview:imageView1]; [self.view addSubview:imageView2]; - [imageView1 sd_setImageWithURL:staticHEIFURL completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { + [imageView1 sd_setImageWithURL:HEICURL completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { if (image) { NSLog(@"Static HEIF load success"); dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ @@ -42,16 +42,9 @@ - (void)viewDidLoad { }); } }]; - [imageView2 sd_setImageWithURL:animatedHEIFURL completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { - if (image.sd_isAnimated) { - NSLog(@"Animated HEIF load success"); - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - // Animated HEIF encoding is really slow, specify the lowest quality with fast speed - NSData *HEIFData = [SDImageHEIFCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatHEIF options:@{SDImageCoderEncodeCompressionQuality : @(0)}]; - if (HEIFData) { - NSLog(@"Animated HEIF encode success"); - } - }); + [imageView2 sd_setImageWithURL:AVIFURL completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) { + if (image) { + NSLog(@"AVIF load success"); } }]; } diff --git a/SDWebImageHEIFCoder/Classes/SDImageHEIFCoder.m b/SDWebImageHEIFCoder/Classes/SDImageHEIFCoder.m index ff04539..714b098 100644 --- a/SDWebImageHEIFCoder/Classes/SDImageHEIFCoder.m +++ b/SDWebImageHEIFCoder/Classes/SDImageHEIFCoder.m @@ -22,6 +22,7 @@ typedef enum heif_chroma heif_chroma; typedef enum heif_channel heif_channel; typedef enum heif_colorspace heif_colorspace; +typedef enum heif_compression_format heif_compression_format; static heif_error WriteImageData(heif_context * ctx, const void * data, size_t size, void * userdata) { NSMutableData *imageData = (__bridge NSMutableData *)userdata; @@ -197,12 +198,12 @@ - (NSData *)encodedDataWithImage:(UIImage *)image format:(SDImageFormat)format o compressionQuality = [[options valueForKey:SDImageCoderEncodeCompressionQuality] doubleValue]; } - data = [self sd_encodedHEIFDataWithImage:image quality:compressionQuality]; + data = [self sd_encodedHEIFDataWithImage:image format:format quality:compressionQuality]; return data; } -- (nullable NSData *)sd_encodedHEIFDataWithImage:(nonnull UIImage *)image quality:(double)quality { +- (nullable NSData *)sd_encodedHEIFDataWithImage:(nonnull UIImage *)image format:(SDImageFormat)format quality:(double)quality { CGImageRef imageRef = image.CGImage; if (!imageRef) { return nil; @@ -237,9 +238,18 @@ - (nullable NSData *)sd_encodedHEIFDataWithImage:(nonnull UIImage *)image qualit } heif_error error; + heif_compression_format compression_format; + if (format == SDImageFormatHEIF || format == SDImageFormatHEIC) { + compression_format = heif_compression_HEVC; + } else if (format == SDImageFormatAVIF) { + compression_format = heif_compression_AV1; + } else { + return nil; + } + // get the default encoder heif_encoder* encoder; - error = heif_context_get_encoder_for_format(ctx, heif_compression_HEVC, &encoder); + error = heif_context_get_encoder_for_format(ctx, compression_format, &encoder); if (error.code != heif_error_Ok) { heif_context_free(ctx); return nil;