From 892267af74bd2e04edd451d218b56ae4b880486a Mon Sep 17 00:00:00 2001 From: DreamPiggy Date: Thu, 2 Aug 2018 11:07:53 +0800 Subject: [PATCH] Fix that downloader options about image decoding is not correctly set --- SDWebImage/SDImageCacheDefine.m | 10 +++++----- SDWebImage/SDImageLoader.m | 20 ++++++++++---------- SDWebImage/SDWebImageDownloader.m | 3 +++ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/SDWebImage/SDImageCacheDefine.m b/SDWebImage/SDImageCacheDefine.m index a729d7ad..68e9165b 100644 --- a/SDWebImage/SDImageCacheDefine.m +++ b/SDWebImage/SDImageCacheDefine.m @@ -33,13 +33,13 @@ UIImage * _Nullable SDImageCacheDecodeImageData(NSData * _Nonnull imageData, NSS } } if (!image) { - SDImageCoderOptions *options = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}; + SDImageCoderOptions *coderOptions = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}; if (context) { - SDImageCoderMutableOptions *mutableOptions = [options mutableCopy]; - [mutableOptions setValue:context forKey:SDImageCoderWebImageContext]; - options = [mutableOptions copy]; + SDImageCoderMutableOptions *mutableCoderOptions = [coderOptions mutableCopy]; + [mutableCoderOptions setValue:context forKey:SDImageCoderWebImageContext]; + coderOptions = [mutableCoderOptions copy]; } - image = [[SDImageCodersManager sharedManager] decodedImageWithData:imageData options:options]; + image = [[SDImageCodersManager sharedManager] decodedImageWithData:imageData options:coderOptions]; } if (image) { BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0; diff --git a/SDWebImage/SDImageLoader.m b/SDWebImage/SDImageLoader.m index 4fe35e0f..97f51686 100644 --- a/SDWebImage/SDImageLoader.m +++ b/SDWebImage/SDImageLoader.m @@ -47,13 +47,13 @@ UIImage * _Nullable SDImageLoaderDecodeImageData(NSData * _Nonnull imageData, NS } } if (!image) { - SDImageCoderOptions *options = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}; + SDImageCoderOptions *coderOptions = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}; if (context) { - SDImageCoderMutableOptions *mutableOptions = [options mutableCopy]; - [mutableOptions setValue:context forKey:SDImageCoderWebImageContext]; - options = [mutableOptions copy]; + SDImageCoderMutableOptions *mutableCoderOptions = [coderOptions mutableCopy]; + [mutableCoderOptions setValue:context forKey:SDImageCoderWebImageContext]; + coderOptions = [mutableCoderOptions copy]; } - image = [[SDImageCodersManager sharedManager] decodedImageWithData:imageData options:options]; + image = [[SDImageCodersManager sharedManager] decodedImageWithData:imageData options:coderOptions]; } if (image) { BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0; @@ -125,13 +125,13 @@ UIImage * _Nullable SDImageLoaderDecodeProgressiveImageData(NSData * _Nonnull im } } if (!image) { - SDImageCoderOptions *options = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}; + SDImageCoderOptions *coderOptions = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}; if (context) { - SDImageCoderMutableOptions *mutableOptions = [options mutableCopy]; - [mutableOptions setValue:context forKey:SDImageCoderWebImageContext]; - options = [mutableOptions copy]; + SDImageCoderMutableOptions *mutableCoderOptions = [coderOptions mutableCopy]; + [mutableCoderOptions setValue:context forKey:SDImageCoderWebImageContext]; + coderOptions = [mutableCoderOptions copy]; } - image = [progressiveCoder incrementalDecodedImageWithOptions:options]; + image = [progressiveCoder incrementalDecodedImageWithOptions:coderOptions]; } if (image) { BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0; diff --git a/SDWebImage/SDWebImageDownloader.m b/SDWebImage/SDWebImageDownloader.m index 7dd3c7aa..0350f7ac 100644 --- a/SDWebImage/SDWebImageDownloader.m +++ b/SDWebImage/SDWebImageDownloader.m @@ -488,6 +488,9 @@ didReceiveResponse:(NSURLResponse *)response if (options & SDWebImageAllowInvalidSSLCertificates) downloaderOptions |= SDWebImageDownloaderAllowInvalidSSLCertificates; if (options & SDWebImageHighPriority) downloaderOptions |= SDWebImageDownloaderHighPriority; if (options & SDWebImageScaleDownLargeImages) downloaderOptions |= SDWebImageDownloaderScaleDownLargeImages; + if (options & SDWebImageAvoidDecodeImage) downloaderOptions |= SDWebImageDownloaderAvoidDecodeImage; + if (options & SDWebImageDecodeFirstFrameOnly) downloaderOptions |= SDWebImageDownloaderDecodeFirstFrameOnly; + if (options & SDWebImagePreloadAllFrames) downloaderOptions |= SDWebImageDownloaderPreloadAllFrames; if (cachedImage && options & SDWebImageRefreshCached) { // force progressive off if image already cached but forced refreshing