Add the support for animated coder for thumbnail images

This commit is contained in:
DreamPiggy 2020-01-05 20:37:20 +08:00
parent 80c6454495
commit 0b0c0d2840
1 changed files with 21 additions and 16 deletions

View File

@ -431,6 +431,22 @@
scale = MAX([scaleFactor doubleValue], 1); scale = MAX([scaleFactor doubleValue], 1);
} }
_scale = scale; _scale = scale;
CGSize thumbnailSize = CGSizeZero;
NSValue *thumbnailSizeValue = options[SDImageCoderDecodeThumbnailPixelSize];
if (thumbnailSizeValue != nil) {
#if SD_MAC
thumbnailSize = thumbnailSizeValue.sizeValue;
#else
thumbnailSize = thumbnailSizeValue.CGSizeValue;
#endif
}
_thumbnailSize = thumbnailSize;
BOOL preserveAspectRatio = NO;
NSNumber *preserveAspectRatioValue = options[SDImageCoderDecodePreserveAspectRatio];
if (preserveAspectRatioValue != nil) {
preserveAspectRatio = preserveAspectRatioValue.boolValue;
}
_preserveAspectRatio = preserveAspectRatio;
_imageSource = imageSource; _imageSource = imageSource;
_imageData = data; _imageData = data;
#if SD_UIKIT #if SD_UIKIT
@ -482,24 +498,13 @@
} }
- (UIImage *)animatedImageFrameAtIndex:(NSUInteger)index { - (UIImage *)animatedImageFrameAtIndex:(NSUInteger)index {
CGImageRef imageRef = CGImageSourceCreateImageAtIndex(_imageSource, index, NULL); UIImage *image = [self.class createFrameAtIndex:index source:_imageSource scale:_scale preserveAspectRatio:_preserveAspectRatio thumbnailSize:_thumbnailSize];
if (!imageRef) {
return nil;
}
// Image/IO create CGImage does not decode, so we do this because this is called background queue, this can avoid main queue block when rendering(especially when one more imageViews use the same image instance) // Image/IO create CGImage does not decode, so we do this because this is called background queue, this can avoid main queue block when rendering(especially when one more imageViews use the same image instance)
CGImageRef newImageRef = [SDImageCoderHelper CGImageCreateDecoded:imageRef]; UIImage *decodedImage = [SDImageCoderHelper decodedImageWithImage:image];
if (!newImageRef) { if (!decodedImage) {
newImageRef = imageRef;
} else {
CGImageRelease(imageRef);
}
#if SD_MAC
UIImage *image = [[UIImage alloc] initWithCGImage:newImageRef scale:_scale orientation:kCGImagePropertyOrientationUp];
#else
UIImage *image = [[UIImage alloc] initWithCGImage:newImageRef scale:_scale orientation:UIImageOrientationUp];
#endif
CGImageRelease(newImageRef);
return image; return image;
}
return decodedImage;
} }
@end @end