Use `SDWebImageAvoidDecodeImage` to allow user to control force decode feature for individual image request. Replace all the central control for `decompressImages`
This commit is contained in:
parent
1367b18b89
commit
781c079a3a
|
@ -40,14 +40,19 @@ typedef NS_OPTIONS(NSUInteger, SDImageCacheOptions) {
|
|||
* Use this flag to transform them anyway.
|
||||
*/
|
||||
SDImageCacheTransformAnimatedImage = 1 << 2,
|
||||
/**
|
||||
* By default, we will decode the image in the background during cache query and download from the network. This can help to improve performance because when rendering image on the screen, it need to be firstly decoded. But this happen on the main queue by Core Animation.
|
||||
* However, this process may increase the memory usage as well. If you are experiencing a issue due to excessive memory consumption, This flag can prevent decode the image.
|
||||
*/
|
||||
SDImageCacheAvoidDecodeImage = 1 << 3,
|
||||
/**
|
||||
* By default, we decode the animated image. This flag can force decode the first frame only and produece the static image.
|
||||
*/
|
||||
SDImageCacheDecodeFirstFrameOnly = 1 << 3,
|
||||
SDImageCacheDecodeFirstFrameOnly = 1 << 4,
|
||||
/**
|
||||
* By default, for `SDAnimatedImage`, we decode the animated image frame during rendering to reduce memory usage. This flag actually trigger `preloadAllAnimatedImageFrames = YES` after image load from disk cache
|
||||
*/
|
||||
SDImageCachePreloadAllFrames = 1 << 4
|
||||
SDImageCachePreloadAllFrames = 1 << 5
|
||||
};
|
||||
|
||||
typedef void(^SDCacheQueryCompletedBlock)(UIImage * _Nullable image, NSData * _Nullable data, SDImageCacheType cacheType);
|
||||
|
|
|
@ -473,7 +473,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
|||
if (!image) {
|
||||
image = [[SDWebImageCodersManager sharedManager] decodedImageWithData:data options:@{SDWebImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDWebImageCoderDecodeScaleFactor : @(scale)}];
|
||||
}
|
||||
BOOL shouldDecode = YES;
|
||||
BOOL shouldDecode = (options & SDImageCacheAvoidDecodeImage) == 0;
|
||||
if ([image conformsToProtocol:@protocol(SDAnimatedImage)]) {
|
||||
// `SDAnimatedImage` do not decode
|
||||
shouldDecode = NO;
|
||||
|
@ -482,9 +482,7 @@ FOUNDATION_STATIC_INLINE NSUInteger SDCacheCostForImage(UIImage *image) {
|
|||
shouldDecode = NO;
|
||||
}
|
||||
if (shouldDecode) {
|
||||
if (self.config.shouldDecompressImages) {
|
||||
image = [SDWebImageCoderHelper decodedImageWithImage:image];
|
||||
}
|
||||
image = [SDWebImageCoderHelper decodedImageWithImage:image];
|
||||
}
|
||||
return image;
|
||||
} else {
|
||||
|
|
|
@ -11,12 +11,6 @@
|
|||
|
||||
@interface SDImageCacheConfig : NSObject
|
||||
|
||||
/**
|
||||
* Decompressing images means pre-decoding the image that are downloaded and cached on background queue. This can avoid image view decode it on main queue when rendering. This can improve performance but can consume more memory.
|
||||
* Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
|
||||
*/
|
||||
@property (assign, nonatomic) BOOL shouldDecompressImages;
|
||||
|
||||
/**
|
||||
* Whether or not to disable iCloud backup
|
||||
* Defaults to YES.
|
||||
|
|
|
@ -14,7 +14,6 @@ static const NSInteger kDefaultCacheMaxCacheAge = 60 * 60 * 24 * 7; // 1 week
|
|||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_shouldDecompressImages = YES;
|
||||
_shouldDisableiCloud = YES;
|
||||
_shouldCacheImagesInMemory = YES;
|
||||
_diskCacheReadingOptions = 0;
|
||||
|
|
|
@ -128,7 +128,7 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
|
|||
/**
|
||||
* By default, images are decoded respecting their original size. On iOS, this flag will scale down the
|
||||
* images to a size compatible with the constrained memory of devices.
|
||||
* If `SDWebImageProgressiveDownload` flag is set the scale down is deactivated.
|
||||
* This flag take no effect if `SDWebImageAvoidDecodeImage` is set. And it will be ignored if `SDWebImageProgressiveDownload` is set.
|
||||
*/
|
||||
SDWebImageScaleDownLargeImages = 1 << 12,
|
||||
|
||||
|
@ -154,6 +154,12 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageOptions) {
|
|||
*/
|
||||
SDWebImageForceTransition = 1 << 16,
|
||||
|
||||
/**
|
||||
* By default, we will decode the image in the background during cache query and download from the network. This can help to improve performance because when rendering image on the screen, it need to be firstly decoded. But this happen on the main queue by Core Animation.
|
||||
* However, this process may increase the memory usage as well. If you are experiencing a issue due to excessive memory consumption, This flag can prevent decode the image.
|
||||
*/
|
||||
SDWebImageAvoidDecodeImage = 1 << 17,
|
||||
|
||||
/**
|
||||
* By default, we decode the animated image. This flag can force decode the first frame only and produece the static image.
|
||||
*/
|
||||
|
|
|
@ -60,19 +60,27 @@ typedef NS_OPTIONS(NSUInteger, SDWebImageDownloaderOptions) {
|
|||
SDWebImageDownloaderHighPriority = 1 << 7,
|
||||
|
||||
/**
|
||||
* Scale down the image
|
||||
* By default, images are decoded respecting their original size. On iOS, this flag will scale down the
|
||||
* images to a size compatible with the constrained memory of devices.
|
||||
* This flag take no effect if `SDWebImageDownloaderAvoidDecodeImage` is set. And it will be ignored if `SDWebImageDownloaderProgressiveDownload` is set.
|
||||
*/
|
||||
SDWebImageDownloaderScaleDownLargeImages = 1 << 8,
|
||||
|
||||
/**
|
||||
* By default, we will decode the image in the background during cache query and download from the network. This can help to improve performance because when rendering image on the screen, it need to be firstly decoded. But this happen on the main queue by Core Animation.
|
||||
* However, this process may increase the memory usage as well. If you are experiencing a issue due to excessive memory consumption, This flag can prevent decode the image.
|
||||
*/
|
||||
SDWebImageDownloaderAvoidDecodeImage = 1 << 9,
|
||||
|
||||
/**
|
||||
* By default, we decode the animated image. This flag can force decode the first frame only and produece the static image.
|
||||
*/
|
||||
SDWebImageDownloaderDecodeFirstFrameOnly = 1 << 9,
|
||||
SDWebImageDownloaderDecodeFirstFrameOnly = 1 << 10,
|
||||
|
||||
/**
|
||||
* By default, for `SDAnimatedImage`, we decode the animated image frame during rendering to reduce memory usage. This flag actually trigger `preloadAllAnimatedImageFrames = YES` after image load from network
|
||||
*/
|
||||
SDWebImageDownloaderPreloadAllFrames = 1 << 10
|
||||
SDWebImageDownloaderPreloadAllFrames = 1 << 11
|
||||
};
|
||||
|
||||
FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadStartNotification;
|
||||
|
|
|
@ -198,7 +198,6 @@ static void * SDWebImageDownloaderContext = &SDWebImageDownloaderContext;
|
|||
operationClass = [SDWebImageDownloaderOperation class];
|
||||
}
|
||||
NSOperation<SDWebImageDownloaderOperation> *operation = [[operationClass alloc] initWithRequest:request inSession:sself.session options:options context:context];
|
||||
operation.shouldDecompressImages = sself.config.shouldDecompressImages;
|
||||
|
||||
if (sself.config.urlCredential) {
|
||||
operation.credential = sself.config.urlCredential;
|
||||
|
|
|
@ -30,12 +30,6 @@ typedef NS_ENUM(NSInteger, SDWebImageDownloaderExecutionOrder) {
|
|||
*/
|
||||
@property (nonatomic, class, nonnull) SDWebImageDownloaderConfig *defaultDownloaderConfig;
|
||||
|
||||
/**
|
||||
* Decompressing images that are downloaded and cached can improve performance but can consume lot of memory.
|
||||
* Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
|
||||
*/
|
||||
@property (nonatomic, assign) BOOL shouldDecompressImages;
|
||||
|
||||
/**
|
||||
* The maximum number of concurrent downloads.
|
||||
* Defaults to 6.
|
||||
|
|
|
@ -29,7 +29,6 @@ static SDWebImageDownloaderConfig * _defaultDownloaderConfig;
|
|||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_shouldDecompressImages = YES;
|
||||
_maxConcurrentDownloads = 6;
|
||||
_downloadTimeout = 15.0;
|
||||
_executionOrder = SDWebImageDownloaderFIFOExecutionOrder;
|
||||
|
@ -39,7 +38,6 @@ static SDWebImageDownloaderConfig * _defaultDownloaderConfig;
|
|||
|
||||
- (id)copyWithZone:(NSZone *)zone {
|
||||
SDWebImageDownloaderConfig *config = [[[self class] allocWithZone:zone] init];
|
||||
config.shouldDecompressImages = self.shouldDecompressImages;
|
||||
config.maxConcurrentDownloads = self.maxConcurrentDownloads;
|
||||
config.downloadTimeout = self.downloadTimeout;
|
||||
config.sessionConfiguration = [self.sessionConfiguration copyWithZone:zone];
|
||||
|
|
|
@ -36,9 +36,6 @@ FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadFinishNotification
|
|||
- (nullable id)addHandlersForProgress:(nullable SDWebImageDownloaderProgressBlock)progressBlock
|
||||
completed:(nullable SDWebImageDownloaderCompletedBlock)completedBlock;
|
||||
|
||||
- (BOOL)shouldDecompressImages;
|
||||
- (void)setShouldDecompressImages:(BOOL)value;
|
||||
|
||||
- (nullable NSURLCredential *)credential;
|
||||
- (void)setCredential:(nullable NSURLCredential *)value;
|
||||
|
||||
|
@ -70,12 +67,6 @@ FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadFinishNotification
|
|||
*/
|
||||
@property (strong, nonatomic, readonly, nullable) NSURLSessionTask *dataTask;
|
||||
|
||||
/**
|
||||
* Decompressing images that are downloaded and cached can improve performance but can consume lot of memory.
|
||||
* Defaults to YES. Set this to NO if you are experiencing a crash due to excessive memory consumption.
|
||||
*/
|
||||
@property (assign, nonatomic) BOOL shouldDecompressImages;
|
||||
|
||||
/**
|
||||
* The credential used for authentication challenges in `-URLSession:task:didReceiveChallenge:completionHandler:`.
|
||||
*
|
||||
|
|
|
@ -87,7 +87,6 @@ typedef NSMutableDictionary<NSString *, id> SDCallbacksDictionary;
|
|||
context:(nullable SDWebImageContext *)context {
|
||||
if ((self = [super init])) {
|
||||
_request = [request copy];
|
||||
_shouldDecompressImages = YES;
|
||||
_options = options;
|
||||
_context = [context copy];
|
||||
_callbackBlocks = [NSMutableArray new];
|
||||
|
@ -379,7 +378,7 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
image = [self.progressiveCoder incrementalDecodedImageWithOptions:@{SDWebImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDWebImageCoderDecodeScaleFactor : @(scale)}];
|
||||
}
|
||||
if (image) {
|
||||
BOOL shouldDecode = self.shouldDecompressImages;
|
||||
BOOL shouldDecode = (self.options & SDWebImageDownloaderAvoidDecodeImage) == 0;
|
||||
if ([image conformsToProtocol:@protocol(SDAnimatedImage)]) {
|
||||
// `SDAnimatedImage` do not decode
|
||||
shouldDecode = NO;
|
||||
|
@ -479,7 +478,7 @@ didReceiveResponse:(NSURLResponse *)response
|
|||
image = [[SDWebImageCodersManager sharedManager] decodedImageWithData:imageData options:@{SDWebImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDWebImageCoderDecodeScaleFactor : @(scale)}];
|
||||
}
|
||||
|
||||
BOOL shouldDecode = self.shouldDecompressImages;
|
||||
BOOL shouldDecode = (self.options & SDWebImageDownloaderAvoidDecodeImage) == 0;
|
||||
if ([image conformsToProtocol:@protocol(SDAnimatedImage)]) {
|
||||
// `SDAnimatedImage` do not decode
|
||||
shouldDecode = NO;
|
||||
|
|
|
@ -16,27 +16,27 @@
|
|||
@property (nonatomic, assign) BOOL sd_isDecoded;
|
||||
|
||||
/**
|
||||
Decompress (force decode before rendering) the provided image
|
||||
Decode the provided image. This is useful if you want to force decode the image before rendering to improve performance.
|
||||
|
||||
@param image The image to be decompressed
|
||||
@return The decompressed image
|
||||
@param image The image to be decoded
|
||||
@return The decoded image
|
||||
*/
|
||||
+ (nullable UIImage *)sd_decodedImageWithImage:(nullable UIImage *)image;
|
||||
|
||||
/**
|
||||
Decompress and scale down the provided image
|
||||
Decode and scale down the provided image
|
||||
|
||||
@param image The image to be decompressed
|
||||
@return The decompressed and scaled down image
|
||||
@param image The image to be decoded
|
||||
@return The decoded and scaled down image
|
||||
*/
|
||||
+ (nullable UIImage *)sd_decodedAndScaledDownImageWithImage:(nullable UIImage *)image;
|
||||
|
||||
/**
|
||||
Decompress and scale down the provided image and limit bytes
|
||||
Decode and scale down the provided image with limit bytes
|
||||
|
||||
@param image The image to be decompressed
|
||||
@param image The image to be decoded
|
||||
@param bytes The limit bytes size. Provide 0 to use the build-in limit.
|
||||
@return The decompressed and scaled down image
|
||||
@return The decoded and scaled down image
|
||||
*/
|
||||
+ (nullable UIImage *)sd_decodedAndScaledDownImageWithImage:(nullable UIImage *)image limitBytes:(NSUInteger)bytes;
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
*/
|
||||
@interface SDWebImageTestDownloadOperation : NSOperation <SDWebImageDownloaderOperation>
|
||||
|
||||
@property (nonatomic, assign) BOOL shouldDecompressImages;
|
||||
@property (nonatomic, strong, nullable) NSURLCredential *credential;
|
||||
@property (nonatomic, strong, nullable) NSURLRequest *request;
|
||||
@property (nonatomic, strong, nullable) NSURLResponse *response;
|
||||
|
|
Loading…
Reference in New Issue