Skip to content

Commit 634f480

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

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
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

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: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ - (UIImage *)decodedImageWithData:(NSData *)data options:(SDImageCoderOptions *)
182182

183183
// Animated image
184184
NSMutableArray<SDImageFrame *> *frames = [NSMutableArray array];
185+
// if repetitionCount is a non-negative integer `n`, then the image sequence should be played back `n + 1` times.
186+
int loopCount = decoder->repetitionCount + 1;
187+
if (loopCount < 0) {
188+
loopCount = 0;
189+
}
185190
while (avifDecoderNextImage(decoder) == AVIF_RESULT_OK) {
186191
@autoreleasepool {
187192
CGImageRef originImageRef = SDCreateCGImageFromAVIF(decoder->image);
@@ -209,7 +214,7 @@ - (UIImage *)decodedImageWithData:(NSData *)data options:(SDImageCoderOptions *)
209214
avifDecoderDestroy(decoder);
210215

211216
UIImage *animatedImage = [SDImageCoderHelper animatedImageWithFrames:frames];
212-
animatedImage.sd_imageLoopCount = 0;
217+
animatedImage.sd_imageLoopCount = loopCount;
213218
animatedImage.sd_imageFormat = SDImageFormatAVIF;
214219

215220
return animatedImage;
@@ -361,7 +366,11 @@ - (instancetype)initWithAnimatedImageData:(NSData *)data options:(SDImageCoderOp
361366
}
362367
// TODO: Optimize the performance like WebPCoder (frame meta cache, etc)
363368
_frameCount = decoder->imageCount;
364-
_loopCount = 0;
369+
int loopCount = decoder->repetitionCount + 1;
370+
if (loopCount < 0) {
371+
loopCount = 0;
372+
}
373+
_loopCount = loopCount;
365374
_hasAnimation = decoder->imageCount > 1;
366375
CGFloat scale = 1;
367376
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];

0 commit comments

Comments
 (0)