Skip to content

Commit f6b6a88

Browse files
committed
Support libavif loop count
This requires libavif 1.0.0+
1 parent 1c25e7a commit f6b6a88

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
github "SDWebImage/SDWebImage" ~> 5.10
2-
github "SDWebImage/libavif-Xcode" >= 0.11.2-rc1
2+
github "SDWebImage/libavif-Xcode" >= 1.0.0

Example/Podfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
source 'https://github.com/CocoaPods/Specs.git'
12
install! 'cocoapods', :generate_multiple_pod_projects => true
23

34
target 'SDWebImageAVIFCoder_Example' do
45
platform :ios, '9.0'
56
pod 'SDWebImageAVIFCoder', :path => '../'
6-
pod 'libavif', :subspecs => ['core', 'librav1e', 'libdav1d']
7+
pod 'libavif', '1.0.0', :subspecs => ['core', 'librav1e', 'libdav1d']
78

89
target 'SDWebImageAVIFCoder_Tests' do
910
inherit! :search_paths
@@ -13,11 +14,11 @@ end
1314
target 'SDWebImageAVIFCoder_Example macOS' do
1415
platform :osx, '10.11'
1516
pod 'SDWebImageAVIFCoder', :path => '../'
16-
pod 'libavif', :subspecs => ['core', 'librav1e', 'libdav1d']
17+
pod 'libavif', '1.0.0', :subspecs => ['core', 'librav1e', 'libdav1d']
1718
end
1819

1920
target 'SDWebImageAVIFCoder_Example CLI' do
2021
platform :osx, '10.11'
2122
pod 'SDWebImageAVIFCoder', :path => '../'
22-
pod 'libavif', :subspecs => ['core', 'librav1e', 'libdav1d']
23+
pod 'libavif', '1.0.0', :subspecs => ['core', 'librav1e', 'libdav1d']
2324
end

Package.resolved

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let package = Package(
1818
// Dependencies declare other packages that this package depends on.
1919
// .package(url: /* package url */, from: "1.0.0"),
2020
.package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.10.0"),
21-
.package(url: "https://github.com/SDWebImage/libavif-Xcode.git", from: "0.11.0")
21+
.package(url: "https://github.com/SDWebImage/libavif-Xcode.git", from: "1.0.0")
2222
],
2323
targets: [
2424
// Targets are the basic building blocks of a package. A target can define a module or a test suite.

SDWebImageAVIFCoder.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'SDWebImageAVIFCoder'
11-
s.version = '0.11.1'
11+
s.version = '0.12.0'
1212
s.summary = 'A SDWebImage coder plugin to support AVIF(AV1 Image File Format) image'
1313

1414
# This description is used to generate tags and improve search results.
@@ -40,6 +40,6 @@ Which is built based on the open-sourced libavif codec.
4040
}
4141

4242
s.dependency 'SDWebImage', '~> 5.10'
43-
s.dependency 'libavif/core', '>= 0.11.0'
43+
s.dependency 'libavif/core', '>= 1.0.0'
4444
s.libraries = 'c++'
4545
end

SDWebImageAVIFCoder/Classes/SDImageAVIFCoder.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ - (UIImage *)decodedImageWithData:(NSData *)data options:(SDImageCoderOptions *)
182182

183183
// Animated image
184184
NSMutableArray<SDImageFrame *> *frames = [NSMutableArray array];
185+
NSUInteger loopCount = decoder->repetitionCount;
185186
while (avifDecoderNextImage(decoder) == AVIF_RESULT_OK) {
186187
@autoreleasepool {
187188
CGImageRef originImageRef = SDCreateCGImageFromAVIF(decoder->image);
@@ -209,7 +210,7 @@ - (UIImage *)decodedImageWithData:(NSData *)data options:(SDImageCoderOptions *)
209210
avifDecoderDestroy(decoder);
210211

211212
UIImage *animatedImage = [SDImageCoderHelper animatedImageWithFrames:frames];
212-
animatedImage.sd_imageLoopCount = 0;
213+
animatedImage.sd_imageLoopCount = loopCount;
213214
animatedImage.sd_imageFormat = SDImageFormatAVIF;
214215

215216
return animatedImage;
@@ -361,7 +362,7 @@ - (instancetype)initWithAnimatedImageData:(NSData *)data options:(SDImageCoderOp
361362
}
362363
// TODO: Optimize the performance like WebPCoder (frame meta cache, etc)
363364
_frameCount = decoder->imageCount;
364-
_loopCount = 0;
365+
_loopCount = decoder->repetitionCount;
365366
_hasAnimation = decoder->imageCount > 1;
366367
CGFloat scale = 1;
367368
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];

0 commit comments

Comments
 (0)