Merge pull request #2399 from zhongwuzw/replace-valueforkey
Replace valueForKey with objectForKey when access NSDictionary
This commit is contained in:
commit
5ea8074bad
|
@ -81,8 +81,9 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
|
|||
return nil;
|
||||
}
|
||||
CGFloat scale = 1;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
@ -139,9 +140,9 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
|
|||
- (NSUInteger)sd_imageLoopCountWithSource:(CGImageSourceRef)source {
|
||||
NSUInteger loopCount = 0;
|
||||
NSDictionary *imageProperties = (__bridge_transfer NSDictionary *)CGImageSourceCopyProperties(source, nil);
|
||||
NSDictionary *pngProperties = [imageProperties valueForKey:(__bridge NSString *)kCGImagePropertyPNGDictionary];
|
||||
NSDictionary *pngProperties = imageProperties[(__bridge NSString *)kCGImagePropertyPNGDictionary];
|
||||
if (pngProperties) {
|
||||
NSNumber *apngLoopCount = [pngProperties valueForKey:(__bridge NSString *)kCGImagePropertyAPNGLoopCount];
|
||||
NSNumber *apngLoopCount = pngProperties[(__bridge NSString *)kCGImagePropertyAPNGLoopCount];
|
||||
if (apngLoopCount != nil) {
|
||||
loopCount = apngLoopCount.unsignedIntegerValue;
|
||||
}
|
||||
|
@ -199,10 +200,10 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
|
|||
}
|
||||
NSMutableDictionary *properties = [NSMutableDictionary dictionary];
|
||||
double compressionQuality = 1;
|
||||
if ([options valueForKey:SDImageCoderEncodeCompressionQuality]) {
|
||||
compressionQuality = [[options valueForKey:SDImageCoderEncodeCompressionQuality] doubleValue];
|
||||
if (options[SDImageCoderEncodeCompressionQuality]) {
|
||||
compressionQuality = [options[SDImageCoderEncodeCompressionQuality] doubleValue];
|
||||
}
|
||||
[properties setValue:@(compressionQuality) forKey:(__bridge NSString *)kCGImageDestinationLossyCompressionQuality];
|
||||
properties[(__bridge NSString *)kCGImageDestinationLossyCompressionQuality] = @(compressionQuality);
|
||||
|
||||
BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue];
|
||||
if (encodeFirstFrame || frames.count == 0) {
|
||||
|
@ -212,7 +213,7 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
|
|||
// for animated APNG images
|
||||
NSUInteger loopCount = image.sd_imageLoopCount;
|
||||
NSDictionary *pngProperties = @{(__bridge NSString *)kCGImagePropertyAPNGLoopCount : @(loopCount)};
|
||||
[properties setValue:pngProperties forKey:(__bridge NSString *)kCGImagePropertyPNGDictionary];
|
||||
properties[(__bridge NSString *)kCGImagePropertyPNGDictionary] = pngProperties;
|
||||
CGImageDestinationSetProperties(imageDestination, (__bridge CFDictionaryRef)properties);
|
||||
|
||||
for (size_t i = 0; i < frames.count; i++) {
|
||||
|
@ -246,8 +247,9 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
|
|||
CFStringRef imageUTType = [NSData sd_UTTypeFromImageFormat:SDImageFormatPNG];
|
||||
_imageSource = CGImageSourceCreateIncremental((__bridge CFDictionaryRef)@{(__bridge NSString *)kCGImageSourceTypeIdentifierHint : (__bridge NSString *)imageUTType});
|
||||
CGFloat scale = 1;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
@ -297,8 +299,9 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
|
|||
|
||||
if (partialImageRef) {
|
||||
CGFloat scale = _scale;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
@ -334,8 +337,9 @@ const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef
|
|||
return nil;
|
||||
}
|
||||
CGFloat scale = 1;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
|
|
@ -371,9 +371,9 @@
|
|||
return nil;
|
||||
}
|
||||
|
||||
if ([context valueForKey:SDWebImageContextImageTransformer]) {
|
||||
id<SDImageTransformer> transformer = context[SDWebImageContextImageTransformer];
|
||||
if (transformer) {
|
||||
// grab the transformed disk image if transformer provided
|
||||
id<SDImageTransformer> transformer = [context valueForKey:SDWebImageContextImageTransformer];
|
||||
NSString *transformerKey = [transformer transformerKey];
|
||||
key = SDTransformedKeyForKey(key, transformerKey);
|
||||
}
|
||||
|
|
|
@ -15,20 +15,18 @@
|
|||
UIImage * _Nullable SDImageCacheDecodeImageData(NSData * _Nonnull imageData, NSString * _Nonnull cacheKey, SDWebImageOptions options, SDWebImageContext * _Nullable context) {
|
||||
UIImage *image;
|
||||
BOOL decodeFirstFrame = options & SDWebImageDecodeFirstFrameOnly;
|
||||
NSNumber *scaleValue = [context valueForKey:SDWebImageContextImageScaleFactor];
|
||||
NSNumber *scaleValue = context[SDWebImageContextImageScaleFactor];
|
||||
CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey);
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
if (!decodeFirstFrame) {
|
||||
Class animatedImageClass = context[SDWebImageContextAnimatedImageClass];
|
||||
// check whether we should use `SDAnimatedImage`
|
||||
if ([context valueForKey:SDWebImageContextAnimatedImageClass]) {
|
||||
Class animatedImageClass = [context valueForKey:SDWebImageContextAnimatedImageClass];
|
||||
if ([animatedImageClass isSubclassOfClass:[UIImage class]] && [animatedImageClass conformsToProtocol:@protocol(SDAnimatedImage)]) {
|
||||
image = [[animatedImageClass alloc] initWithData:imageData scale:scale];
|
||||
if (options & SDWebImagePreloadAllFrames && [image respondsToSelector:@selector(preloadAllFrames)]) {
|
||||
[((id<SDAnimatedImage>)image) preloadAllFrames];
|
||||
}
|
||||
if ([animatedImageClass isSubclassOfClass:[UIImage class]] && [animatedImageClass conformsToProtocol:@protocol(SDAnimatedImage)]) {
|
||||
image = [[animatedImageClass alloc] initWithData:imageData scale:scale];
|
||||
if (options & SDWebImagePreloadAllFrames && [image respondsToSelector:@selector(preloadAllFrames)]) {
|
||||
[((id<SDAnimatedImage>)image) preloadAllFrames];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,8 +74,9 @@
|
|||
return nil;
|
||||
}
|
||||
CGFloat scale = 1;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
@ -132,9 +133,9 @@
|
|||
- (NSUInteger)sd_imageLoopCountWithSource:(CGImageSourceRef)source {
|
||||
NSUInteger loopCount = 1;
|
||||
NSDictionary *imageProperties = (__bridge_transfer NSDictionary *)CGImageSourceCopyProperties(source, nil);
|
||||
NSDictionary *gifProperties = [imageProperties valueForKey:(__bridge NSString *)kCGImagePropertyGIFDictionary];
|
||||
NSDictionary *gifProperties = imageProperties[(__bridge NSString *)kCGImagePropertyGIFDictionary];
|
||||
if (gifProperties) {
|
||||
NSNumber *gifLoopCount = [gifProperties valueForKey:(__bridge NSString *)kCGImagePropertyGIFLoopCount];
|
||||
NSNumber *gifLoopCount = gifProperties[(__bridge NSString *)kCGImagePropertyGIFLoopCount];
|
||||
if (gifLoopCount != nil) {
|
||||
loopCount = gifLoopCount.unsignedIntegerValue;
|
||||
}
|
||||
|
@ -186,8 +187,9 @@
|
|||
CFStringRef imageUTType = [NSData sd_UTTypeFromImageFormat:SDImageFormatGIF];
|
||||
_imageSource = CGImageSourceCreateIncremental((__bridge CFDictionaryRef)@{(__bridge NSString *)kCGImageSourceTypeIdentifierHint : (__bridge NSString *)imageUTType});
|
||||
CGFloat scale = 1;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
@ -237,8 +239,9 @@
|
|||
|
||||
if (partialImageRef) {
|
||||
CGFloat scale = _scale;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
@ -282,10 +285,10 @@
|
|||
}
|
||||
NSMutableDictionary *properties = [NSMutableDictionary dictionary];
|
||||
double compressionQuality = 1;
|
||||
if ([options valueForKey:SDImageCoderEncodeCompressionQuality]) {
|
||||
compressionQuality = [[options valueForKey:SDImageCoderEncodeCompressionQuality] doubleValue];
|
||||
if (options[SDImageCoderEncodeCompressionQuality]) {
|
||||
compressionQuality = [options[SDImageCoderEncodeCompressionQuality] doubleValue];
|
||||
}
|
||||
[properties setValue:@(compressionQuality) forKey:(__bridge NSString *)kCGImageDestinationLossyCompressionQuality];
|
||||
properties[(__bridge NSString *)kCGImageDestinationLossyCompressionQuality] = @(compressionQuality);
|
||||
|
||||
BOOL encodeFirstFrame = [options[SDImageCoderEncodeFirstFrameOnly] boolValue];
|
||||
if (encodeFirstFrame || frames.count == 0) {
|
||||
|
@ -295,7 +298,7 @@
|
|||
// for animated GIF images
|
||||
NSUInteger loopCount = image.sd_imageLoopCount;
|
||||
NSDictionary *gifProperties = @{(__bridge NSString *)kCGImagePropertyGIFLoopCount : @(loopCount)};
|
||||
[properties setValue:gifProperties forKey:(__bridge NSString *)kCGImagePropertyGIFDictionary];
|
||||
properties[(__bridge NSString *)kCGImagePropertyGIFDictionary] = gifProperties;
|
||||
CGImageDestinationSetProperties(imageDestination, (__bridge CFDictionaryRef)properties);
|
||||
|
||||
for (size_t i = 0; i < frames.count; i++) {
|
||||
|
@ -335,8 +338,9 @@
|
|||
return nil;
|
||||
}
|
||||
CGFloat scale = 1;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
|
|
@ -68,8 +68,9 @@
|
|||
return nil;
|
||||
}
|
||||
CGFloat scale = 1;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
@ -103,8 +104,9 @@
|
|||
if (self) {
|
||||
_imageSource = CGImageSourceCreateIncremental(NULL);
|
||||
CGFloat scale = 1;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
@ -159,8 +161,9 @@
|
|||
|
||||
if (partialImageRef) {
|
||||
CGFloat scale = _scale;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
@ -227,12 +230,12 @@
|
|||
#else
|
||||
CGImagePropertyOrientation exifOrientation = kCGImagePropertyOrientationUp;
|
||||
#endif
|
||||
[properties setValue:@(exifOrientation) forKey:(__bridge NSString *)kCGImagePropertyOrientation];
|
||||
properties[(__bridge NSString *)kCGImagePropertyOrientation] = @(exifOrientation);
|
||||
double compressionQuality = 1;
|
||||
if ([options valueForKey:SDImageCoderEncodeCompressionQuality]) {
|
||||
compressionQuality = [[options valueForKey:SDImageCoderEncodeCompressionQuality] doubleValue];
|
||||
if (options[SDImageCoderEncodeCompressionQuality]) {
|
||||
compressionQuality = [options[SDImageCoderEncodeCompressionQuality] doubleValue];
|
||||
}
|
||||
[properties setValue:@(compressionQuality) forKey:(__bridge NSString *)kCGImageDestinationLossyCompressionQuality];
|
||||
properties[(__bridge NSString *)kCGImageDestinationLossyCompressionQuality] = @(compressionQuality);
|
||||
|
||||
// Add your image to the destination.
|
||||
CGImageDestinationAddImage(imageDestination, image.CGImage, (__bridge CFDictionaryRef)properties);
|
||||
|
|
|
@ -21,7 +21,7 @@ UIImage * _Nullable SDImageLoaderDecodeImageData(NSData * _Nonnull imageData, NS
|
|||
NSCParameterAssert(imageURL);
|
||||
|
||||
UIImage *image;
|
||||
id<SDWebImageCacheKeyFilter> cacheKeyFilter = [context valueForKey:SDWebImageContextCacheKeyFilter];
|
||||
id<SDWebImageCacheKeyFilter> cacheKeyFilter = context[SDWebImageContextCacheKeyFilter];
|
||||
NSString *cacheKey;
|
||||
if (cacheKeyFilter) {
|
||||
cacheKey = [cacheKeyFilter cacheKeyForURL:imageURL];
|
||||
|
@ -29,20 +29,18 @@ UIImage * _Nullable SDImageLoaderDecodeImageData(NSData * _Nonnull imageData, NS
|
|||
cacheKey = imageURL.absoluteString;
|
||||
}
|
||||
BOOL decodeFirstFrame = options & SDWebImageDecodeFirstFrameOnly;
|
||||
NSNumber *scaleValue = [context valueForKey:SDWebImageContextImageScaleFactor];
|
||||
NSNumber *scaleValue = context[SDWebImageContextImageScaleFactor];
|
||||
CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey);
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
if (!decodeFirstFrame) {
|
||||
// check whether we should use `SDAnimatedImage`
|
||||
if ([context valueForKey:SDWebImageContextAnimatedImageClass]) {
|
||||
Class animatedImageClass = [context valueForKey:SDWebImageContextAnimatedImageClass];
|
||||
if ([animatedImageClass isSubclassOfClass:[UIImage class]] && [animatedImageClass conformsToProtocol:@protocol(SDAnimatedImage)]) {
|
||||
image = [[animatedImageClass alloc] initWithData:imageData scale:scale];
|
||||
if (options & SDWebImagePreloadAllFrames && [image respondsToSelector:@selector(preloadAllFrames)]) {
|
||||
[((id<SDAnimatedImage>)image) preloadAllFrames];
|
||||
}
|
||||
Class animatedImageClass = context[SDWebImageContextAnimatedImageClass];
|
||||
if ([animatedImageClass isSubclassOfClass:[UIImage class]] && [animatedImageClass conformsToProtocol:@protocol(SDAnimatedImage)]) {
|
||||
image = [[animatedImageClass alloc] initWithData:imageData scale:scale];
|
||||
if (options & SDWebImagePreloadAllFrames && [image respondsToSelector:@selector(preloadAllFrames)]) {
|
||||
[((id<SDAnimatedImage>)image) preloadAllFrames];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +82,7 @@ UIImage * _Nullable SDImageLoaderDecodeProgressiveImageData(NSData * _Nonnull im
|
|||
NSCParameterAssert(operation);
|
||||
|
||||
UIImage *image;
|
||||
id<SDWebImageCacheKeyFilter> cacheKeyFilter = [context valueForKey:SDWebImageContextCacheKeyFilter];
|
||||
id<SDWebImageCacheKeyFilter> cacheKeyFilter = context[SDWebImageContextCacheKeyFilter];
|
||||
NSString *cacheKey;
|
||||
if (cacheKeyFilter) {
|
||||
cacheKey = [cacheKeyFilter cacheKeyForURL:imageURL];
|
||||
|
@ -92,7 +90,7 @@ UIImage * _Nullable SDImageLoaderDecodeProgressiveImageData(NSData * _Nonnull im
|
|||
cacheKey = imageURL.absoluteString;
|
||||
}
|
||||
BOOL decodeFirstFrame = options & SDWebImageDecodeFirstFrameOnly;
|
||||
NSNumber *scaleValue = [context valueForKey:SDWebImageContextImageScaleFactor];
|
||||
NSNumber *scaleValue = context[SDWebImageContextImageScaleFactor];
|
||||
CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey);
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
|
@ -117,11 +115,9 @@ UIImage * _Nullable SDImageLoaderDecodeProgressiveImageData(NSData * _Nonnull im
|
|||
[progressiveCoder updateIncrementalData:imageData finished:finished];
|
||||
if (!decodeFirstFrame) {
|
||||
// check whether we should use `SDAnimatedImage`
|
||||
if ([context valueForKey:SDWebImageContextAnimatedImageClass]) {
|
||||
Class animatedImageClass = [context valueForKey:SDWebImageContextAnimatedImageClass];
|
||||
if ([animatedImageClass isSubclassOfClass:[UIImage class]] && [animatedImageClass conformsToProtocol:@protocol(SDAnimatedImage)] && [progressiveCoder conformsToProtocol:@protocol(SDAnimatedImageCoder)]) {
|
||||
image = [[animatedImageClass alloc] initWithAnimatedCoder:(id<SDAnimatedImageCoder>)progressiveCoder scale:scale];
|
||||
}
|
||||
Class animatedImageClass = context[SDWebImageContextAnimatedImageClass];
|
||||
if ([animatedImageClass isSubclassOfClass:[UIImage class]] && [animatedImageClass conformsToProtocol:@protocol(SDAnimatedImage)] && [progressiveCoder conformsToProtocol:@protocol(SDAnimatedImageCoder)]) {
|
||||
image = [[animatedImageClass alloc] initWithAnimatedCoder:(id<SDAnimatedImageCoder>)progressiveCoder scale:scale];
|
||||
}
|
||||
}
|
||||
if (!image) {
|
||||
|
|
|
@ -159,11 +159,7 @@ static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
|
|||
return;
|
||||
}
|
||||
NSMutableDictionary *mutableHTTPHeaders = [self.HTTPHeaders mutableCopy];
|
||||
if (value) {
|
||||
[mutableHTTPHeaders setObject:value forKey:field];
|
||||
} else {
|
||||
[mutableHTTPHeaders removeObjectForKey:field];
|
||||
}
|
||||
[mutableHTTPHeaders setValue:value forKey:field];
|
||||
self.HTTPHeaders = [mutableHTTPHeaders copy];
|
||||
}
|
||||
|
||||
|
@ -215,7 +211,7 @@ static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
|
|||
[sself.URLOperations removeObjectForKey:url];
|
||||
UNLOCK(sself.operationsLock);
|
||||
};
|
||||
[self.URLOperations setObject:operation forKey:url];
|
||||
self.URLOperations[url] = operation;
|
||||
// Add operation to operation queue only after all configuration done according to Apple's doc.
|
||||
// `addOperation:` does not synchronously execute the `operation.completionBlock` so this will not cause deadlock.
|
||||
[self.downloadQueue addOperation:operation];
|
||||
|
@ -502,10 +498,8 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
}
|
||||
|
||||
- (id<SDWebImageOperation>)loadImageWithURL:(NSURL *)url options:(SDWebImageOptions)options context:(SDWebImageContext *)context progress:(SDImageLoaderProgressBlock)progressBlock completed:(SDImageLoaderCompletedBlock)completedBlock {
|
||||
UIImage *cachedImage;
|
||||
if ([context valueForKey:SDWebImageContextLoaderCachedImage]) {
|
||||
cachedImage = [context valueForKey:SDWebImageContextLoaderCachedImage];
|
||||
}
|
||||
UIImage *cachedImage = context[SDWebImageContextLoaderCachedImage];
|
||||
|
||||
SDWebImageDownloaderOptions downloaderOptions = 0;
|
||||
if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
|
||||
if (options & SDWebImageProgressiveLoad) downloaderOptions |= SDWebImageDownloaderProgressiveLoad;
|
||||
|
|
|
@ -189,7 +189,7 @@ static id<SDImageLoader> _defaultImageLoader;
|
|||
// Check whether we should query cache
|
||||
BOOL shouldQueryCache = (options & SDWebImageFromLoaderOnly) == 0;
|
||||
if (shouldQueryCache) {
|
||||
id<SDWebImageCacheKeyFilter> cacheKeyFilter = [context valueForKey:SDWebImageContextCacheKeyFilter];
|
||||
id<SDWebImageCacheKeyFilter> cacheKeyFilter = context[SDWebImageContextCacheKeyFilter];
|
||||
NSString *key = [self cacheKeyForURL:url cacheKeyFilter:cacheKeyFilter];
|
||||
__weak SDWebImageCombinedOperation *weakOperation = operation;
|
||||
operation.cacheOperation = [self.imageCache queryImageForKey:key options:options context:context completion:^(UIImage * _Nullable cachedImage, NSData * _Nullable cachedData, SDImageCacheType cacheType) {
|
||||
|
@ -233,7 +233,7 @@ static id<SDImageLoader> _defaultImageLoader;
|
|||
} else {
|
||||
mutableContext = [NSMutableDictionary dictionary];
|
||||
}
|
||||
[mutableContext setValue:cachedImage forKey:SDWebImageContextLoaderCachedImage];
|
||||
mutableContext[SDWebImageContextLoaderCachedImage] = cachedImage;
|
||||
context = [mutableContext copy];
|
||||
}
|
||||
|
||||
|
@ -277,13 +277,13 @@ static id<SDImageLoader> _defaultImageLoader;
|
|||
}
|
||||
|
||||
SDImageCacheType storeCacheType = SDImageCacheTypeAll;
|
||||
if ([context valueForKey:SDWebImageContextStoreCacheType]) {
|
||||
storeCacheType = [[context valueForKey:SDWebImageContextStoreCacheType] unsignedIntegerValue];
|
||||
if (context[SDWebImageContextStoreCacheType]) {
|
||||
storeCacheType = [context[SDWebImageContextStoreCacheType] integerValue];
|
||||
}
|
||||
id<SDWebImageCacheKeyFilter> cacheKeyFilter = [context valueForKey:SDWebImageContextCacheKeyFilter];
|
||||
id<SDWebImageCacheKeyFilter> cacheKeyFilter = context[SDWebImageContextCacheKeyFilter];
|
||||
NSString *key = [self cacheKeyForURL:url cacheKeyFilter:cacheKeyFilter];
|
||||
id<SDImageTransformer> transformer = [context valueForKey:SDWebImageContextImageTransformer];
|
||||
id<SDWebImageCacheSerializer> cacheSerializer = [context valueForKey:SDWebImageContextCacheKeyFilter];
|
||||
id<SDImageTransformer> transformer = context[SDWebImageContextImageTransformer];
|
||||
id<SDWebImageCacheSerializer> cacheSerializer = context[SDWebImageContextCacheKeyFilter];
|
||||
if (downloadedImage && (!downloadedImage.sd_isAnimated || (options & SDWebImageTransformAnimatedImage)) && transformer) {
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
|
||||
UIImage *transformedImage = [transformer transformedImageWithImage:downloadedImage forKey:key];
|
||||
|
@ -369,17 +369,17 @@ static id<SDImageLoader> _defaultImageLoader;
|
|||
SDWebImageMutableContext *mutableContext = [SDWebImageMutableContext dictionary];
|
||||
|
||||
// Image Transformer from manager
|
||||
if (![context valueForKey:SDWebImageContextImageTransformer]) {
|
||||
if (!context[SDWebImageContextImageTransformer]) {
|
||||
id<SDImageTransformer> transformer = self.transformer;
|
||||
[mutableContext setValue:transformer forKey:SDWebImageContextImageTransformer];
|
||||
}
|
||||
// Cache key filter from manager
|
||||
if (![context valueForKey:SDWebImageContextCacheKeyFilter]) {
|
||||
if (!context[SDWebImageContextCacheKeyFilter]) {
|
||||
id<SDWebImageCacheKeyFilter> cacheKeyFilter = self.cacheKeyFilter;
|
||||
[mutableContext setValue:cacheKeyFilter forKey:SDWebImageContextCacheKeyFilter];
|
||||
}
|
||||
// Cache serializer from manager
|
||||
if (![context valueForKey:SDWebImageContextCacheSerializer]) {
|
||||
if (!context[SDWebImageContextCacheSerializer]) {
|
||||
id<SDWebImageCacheSerializer> cacheSerializer = self.cacheSerializer;
|
||||
[mutableContext setValue:cacheSerializer forKey:SDWebImageContextCacheSerializer];
|
||||
}
|
||||
|
|
|
@ -44,10 +44,8 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
|
|||
progress:(nullable SDImageLoaderProgressBlock)progressBlock
|
||||
completed:(nullable SDInternalCompletionBlock)completedBlock {
|
||||
context = [context copy]; // copy to avoid mutable object
|
||||
NSString *validOperationKey = nil;
|
||||
if ([context valueForKey:SDWebImageContextSetImageOperationKey]) {
|
||||
validOperationKey = [context valueForKey:SDWebImageContextSetImageOperationKey];
|
||||
} else {
|
||||
NSString *validOperationKey = context[SDWebImageContextSetImageOperationKey];
|
||||
if (!validOperationKey) {
|
||||
validOperationKey = NSStringFromClass([self class]);
|
||||
}
|
||||
[self sd_cancelImageLoadOperationWithKey:validOperationKey];
|
||||
|
@ -70,10 +68,8 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL;
|
|||
id<SDWebImageIndicator> imageIndicator = self.sd_imageIndicator;
|
||||
#endif
|
||||
|
||||
SDWebImageManager *manager;
|
||||
if ([context valueForKey:SDWebImageContextCustomManager]) {
|
||||
manager = (SDWebImageManager *)[context valueForKey:SDWebImageContextCustomManager];
|
||||
} else {
|
||||
SDWebImageManager *manager = context[SDWebImageContextCustomManager];
|
||||
if (!manager) {
|
||||
manager = [SDWebImageManager sharedManager];
|
||||
}
|
||||
|
||||
|
|
|
@ -112,10 +112,11 @@
|
|||
|
||||
uint32_t flags = WebPDemuxGetI(demuxer, WEBP_FF_FORMAT_FLAGS);
|
||||
BOOL hasAnimation = flags & ANIMATION_FLAG;
|
||||
BOOL decodeFirstFrame = [[options valueForKey:SDImageCoderDecodeFirstFrameOnly] boolValue];
|
||||
BOOL decodeFirstFrame = [options[SDImageCoderDecodeFirstFrameOnly] boolValue];
|
||||
CGFloat scale = 1;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
@ -212,8 +213,9 @@
|
|||
// Progressive images need transparent, so always use premultiplied BGRA
|
||||
_idec = WebPINewRGB(MODE_bgrA, NULL, 0, 0);
|
||||
CGFloat scale = 1;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
@ -284,8 +286,9 @@
|
|||
return nil;
|
||||
}
|
||||
CGFloat scale = _scale;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
@ -425,8 +428,8 @@
|
|||
NSData *data;
|
||||
|
||||
double compressionQuality = 1;
|
||||
if ([options valueForKey:SDImageCoderEncodeCompressionQuality]) {
|
||||
compressionQuality = [[options valueForKey:SDImageCoderEncodeCompressionQuality] doubleValue];
|
||||
if (options[SDImageCoderEncodeCompressionQuality]) {
|
||||
compressionQuality = [options[SDImageCoderEncodeCompressionQuality] doubleValue];
|
||||
}
|
||||
NSArray<SDImageFrame *> *frames = [SDImageCoderHelper framesFromAnimatedImage:image];
|
||||
|
||||
|
@ -633,8 +636,9 @@ static void FreeImageData(void *info, const void *data, size_t size) {
|
|||
return nil;
|
||||
}
|
||||
CGFloat scale = 1;
|
||||
if ([options valueForKey:SDImageCoderDecodeScaleFactor]) {
|
||||
scale = [[options valueForKey:SDImageCoderDecodeScaleFactor] doubleValue];
|
||||
NSNumber *scaleFactor = options[SDImageCoderDecodeScaleFactor];
|
||||
if (scaleFactor != nil) {
|
||||
scale = [scaleFactor doubleValue];
|
||||
if (scale < 1) {
|
||||
scale = 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue