Adopt SDAnimatedImage for `sd_imageFrameCount`

This commit is contained in:
DreamPiggy 2021-05-25 16:05:42 +08:00
parent 4ae33983e0
commit 7f078d21ba
3 changed files with 7 additions and 7 deletions

View File

@ -314,6 +314,10 @@ static CGFloat SDImageScaleFromPath(NSString *string) {
return;
}
- (NSUInteger)sd_imageFrameCount {
return self.animatedImageFrameCount;
}
- (SDImageFormat)sd_imageFormat {
return self.animatedImageFormat;
}

View File

@ -21,7 +21,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDMemoryCacheCostForImage(UIImage *image) {
frameCount = 1;
#elif SD_UIKIT || SD_WATCH
// Filter the same frame in `_UIAnimatedImage`.
frameCount = image.images.count > 0 ? [NSSet setWithArray:image.images].count : 1;
frameCount = image.images.count > 1 ? [NSSet setWithArray:image.images].count : 1;
#endif
NSUInteger cost = bytesPerFrame * frameCount;
return cost;

View File

@ -410,9 +410,7 @@ withLocalImageURL:(NSURL *)imageUrl
UIImage *outputImage = [coder decodedImageWithData:outputImageData options:nil];
expect(outputImage.size).to.equal(inputImage.size);
expect(outputImage.scale).to.equal(inputImage.scale);
#if SD_UIKIT
expect(outputImage.images.count).to.equal(inputImage.images.count);
#endif
expect(outputImage.sd_imageLoopCount).to.equal(inputImage.sd_imageLoopCount);
// check max pixel size encoding with scratch
CGFloat maxWidth = 50;
@ -429,9 +427,7 @@ withLocalImageURL:(NSURL *)imageUrl
// Image/IO's thumbnail API does not always use round to preserve precision, we check ABS <= 1
expect(ABS(outputMaxImage.size.width - maxPixelSize.width)).beLessThanOrEqualTo(1);
expect(ABS(outputMaxImage.size.height - maxPixelSize.height)).beLessThanOrEqualTo(1);
#if SD_UIKIT
expect(outputMaxImage.images.count).to.equal(inputImage.images.count);
#endif
expect(outputMaxImage.sd_imageLoopCount).to.equal(inputImage.sd_imageLoopCount);
}
}