Merge branch '5.13.x' of github.com:SDWebImage/SDWebImage

# Conflicts:
#	SDWebImage/Core/SDImageCacheDefine.m
This commit is contained in:
DreamPiggy 2022-10-29 20:40:00 +08:00
commit b014808ddd
7 changed files with 60 additions and 25 deletions

View File

@ -1,3 +1,9 @@
## [5.13.5 - 5.13 Fix, on Oct 29th, 2022](https://github.com/rs/SDWebImage/releases/tag/5.13.5)
See [all tickets marked for the 5.13.4 release](https://github.com/SDWebImage/SDWebImage/milestone/103)
### Fixes
- Quick fix the issue that UIImage.sd_decodeOptions cause retain cycle when pass custom cache in context option #3420 #3371
## [5.13.4 - 5.13 Crash Fix, on Sep 26th, 2022](https://github.com/rs/SDWebImage/releases/tag/5.13.4)
See [all tickets marked for the 5.13.4 release](https://github.com/SDWebImage/SDWebImage/milestone/101)

View File

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SDWebImage'
s.version = '5.13.4'
s.version = '5.13.5'
s.osx.deployment_target = '10.11'
s.ios.deployment_target = '9.0'

View File

@ -13,6 +13,37 @@
#import "UIImage+Metadata.h"
#import "SDInternalMacros.h"
static NSArray<NSString *>* GetKnownContextOptions(void) {
static NSArray<NSString *> *knownContextOptions;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
knownContextOptions =
[NSArray arrayWithObjects:
SDWebImageContextSetImageOperationKey,
SDWebImageContextCustomManager,
SDWebImageContextImageCache,
SDWebImageContextImageLoader,
SDWebImageContextImageCoder,
SDWebImageContextImageTransformer,
SDWebImageContextImageScaleFactor,
SDWebImageContextImagePreserveAspectRatio,
SDWebImageContextImageThumbnailPixelSize,
SDWebImageContextQueryCacheType,
SDWebImageContextStoreCacheType,
SDWebImageContextOriginalQueryCacheType,
SDWebImageContextOriginalStoreCacheType,
SDWebImageContextOriginalImageCache,
SDWebImageContextAnimatedImageClass,
SDWebImageContextDownloadRequestModifier,
SDWebImageContextDownloadResponseModifier,
SDWebImageContextDownloadDecryptor,
SDWebImageContextCacheKeyFilter,
SDWebImageContextCacheSerializer
, nil];
});
return knownContextOptions;
}
SDImageCoderOptions * _Nonnull SDGetDecodeOptionsFromContext(SDWebImageContext * _Nullable context, SDWebImageOptions options, NSString * _Nonnull cacheKey) {
BOOL decodeFirstFrame = SD_OPTIONS_CONTAINS(options, SDWebImageDecodeFirstFrameOnly);
NSNumber *scaleValue = context[SDWebImageContextImageScaleFactor];
@ -38,7 +69,10 @@ SDImageCoderOptions * _Nonnull SDGetDecodeOptionsFromContext(SDWebImageContext *
mutableCoderOptions[SDImageCoderDecodeThumbnailPixelSize] = thumbnailSizeValue;
mutableCoderOptions[SDImageCoderDecodeTypeIdentifierHint] = typeIdentifierHint;
mutableCoderOptions[SDImageCoderDecodeFileExtensionHint] = fileExtensionHint;
mutableCoderOptions[SDImageCoderWebImageContext] = context;
// Hack to remove all known context options before SDWebImage 5.14.0
SDImageCoderMutableOptions *mutableContext = [NSMutableDictionary dictionaryWithDictionary:context];
[mutableContext removeObjectsForKeys:GetKnownContextOptions()];
mutableCoderOptions[SDImageCoderWebImageContext] = [mutableContext copy];
SDImageCoderOptions *coderOptions = [mutableCoderOptions copy];
return coderOptions;

View File

@ -107,7 +107,9 @@ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeEmbedThumb
A SDWebImageContext object which hold the original context options from top-level API. (SDWebImageContext)
This option is ignored for all built-in coders and take no effect.
But this may be useful for some custom coders, because some business logic may dependent on things other than image or image data information only.
Only the unknown context from top-level API (See SDWebImageDefine.h) may be passed in during image loading.
See `SDWebImageContext` for more detailed information.
@warning This option will be removed in 5.14.0
*/
FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderWebImageContext API_DEPRECATED("The coder component will be seperated from Core subspec in the future. Update your code to not rely on this context option.", macos(10.10, API_TO_BE_DEPRECATED), ios(8.0, API_TO_BE_DEPRECATED), tvos(9.0, API_TO_BE_DEPRECATED), watchos(2.0, API_TO_BE_DEPRECATED));

View File

@ -108,28 +108,9 @@ UIImage * _Nullable SDImageLoaderDecodeProgressiveImageData(NSData * _Nonnull im
} else {
cacheKey = imageURL.absoluteString;
}
SDImageCoderOptions *coderOptions = SDGetDecodeOptionsFromContext(context, options, cacheKey);
BOOL decodeFirstFrame = SD_OPTIONS_CONTAINS(options, SDWebImageDecodeFirstFrameOnly);
NSNumber *scaleValue = context[SDWebImageContextImageScaleFactor];
CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey);
NSNumber *preserveAspectRatioValue = context[SDWebImageContextImagePreserveAspectRatio];
NSValue *thumbnailSizeValue;
BOOL shouldScaleDown = SD_OPTIONS_CONTAINS(options, SDWebImageScaleDownLargeImages);
if (shouldScaleDown) {
CGFloat thumbnailPixels = SDImageCoderHelper.defaultScaleDownLimitBytes / 4;
CGFloat dimension = ceil(sqrt(thumbnailPixels));
thumbnailSizeValue = @(CGSizeMake(dimension, dimension));
}
if (context[SDWebImageContextImageThumbnailPixelSize]) {
thumbnailSizeValue = context[SDWebImageContextImageThumbnailPixelSize];
}
SDImageCoderMutableOptions *mutableCoderOptions = [NSMutableDictionary dictionaryWithCapacity:2];
mutableCoderOptions[SDImageCoderDecodeFirstFrameOnly] = @(decodeFirstFrame);
mutableCoderOptions[SDImageCoderDecodeScaleFactor] = @(scale);
mutableCoderOptions[SDImageCoderDecodePreserveAspectRatio] = preserveAspectRatioValue;
mutableCoderOptions[SDImageCoderDecodeThumbnailPixelSize] = thumbnailSizeValue;
mutableCoderOptions[SDImageCoderWebImageContext] = context;
SDImageCoderOptions *coderOptions = [mutableCoderOptions copy];
CGFloat scale = [coderOptions[SDImageCoderDecodeScaleFactor] doubleValue];
// Grab the progressive image coder
id<SDProgressiveImageCoder> progressiveCoder = SDImageLoaderGetProgressiveCoder(operation);

View File

@ -538,6 +538,18 @@
[self waitForExpectationsWithTimeout:kAsyncTestTimeout * 5 handler:nil];
}
- (void)test20ThatContextPassedToLoaderDoesNotContainsBuiltIn {
XCTestExpectation *expectation = [self expectationWithDescription:@"The SDImageCoderWebImageContext should contains only unknown context to avoid retain cycle"];
NSURL *url = [NSURL URLWithString:@"http://via.placeholder.com/502x502.png"];
[SDWebImageManager.sharedManager loadImageWithURL:url options:0 context:@{SDWebImageContextImageScaleFactor : @(2), @"Foo": @"Bar"} progress:nil completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, SDImageCacheType cacheType, BOOL finished, NSURL * _Nullable imageURL) {
SDImageCoderOptions *decodeOptions = image.sd_decodeOptions;
SDWebImageContext *retrievedContext = decodeOptions[SDImageCoderWebImageContext];
expect(retrievedContext[@"Foo"]).equal(@"Bar");
[expectation fulfill];
}];
[self waitForExpectationsWithCommonTimeout];
}
- (NSString *)testJPEGPath {
NSBundle *testBundle = [NSBundle bundleForClass:[self class]];
return [testBundle pathForResource:@"TestImage" ofType:@"jpg"];

View File

@ -15,11 +15,11 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>5.13.4</string>
<string>5.13.5</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>5.13.4</string>
<string>5.13.5</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>