Add SDImageCoderWebImageContext coder option, which allow custom coder plugin, to receive the context option from top-level API (Cache/Downloader/View Category)
This commit is contained in:
parent
919751f2de
commit
ef3123984f
|
@ -33,7 +33,13 @@ UIImage * _Nullable SDImageCacheDecodeImageData(NSData * _Nonnull imageData, NSS
|
|||
}
|
||||
}
|
||||
if (!image) {
|
||||
image = [[SDImageCodersManager sharedManager] decodedImageWithData:imageData options:@{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}];
|
||||
SDImageCoderOptions *options = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)};
|
||||
if (context) {
|
||||
SDImageCoderMutableOptions *mutableOptions = [options mutableCopy];
|
||||
[mutableOptions setValue:context forKey:SDImageCoderWebImageContext];
|
||||
options = [mutableOptions copy];
|
||||
}
|
||||
image = [[SDImageCodersManager sharedManager] decodedImageWithData:imageData options:options];
|
||||
}
|
||||
if (image) {
|
||||
BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
typedef NSString * SDImageCoderOption NS_STRING_ENUM;
|
||||
typedef NSDictionary<SDImageCoderOption, id> SDImageCoderOptions;
|
||||
typedef NSMutableDictionary<SDImageCoderOption, id> SDImageCoderMutableOptions;
|
||||
|
||||
#pragma mark - Coder Options
|
||||
// These options are for image decoding
|
||||
|
@ -38,6 +39,14 @@ FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeFirstFrame
|
|||
*/
|
||||
FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderEncodeCompressionQuality;
|
||||
|
||||
/**
|
||||
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 inforamtion only.
|
||||
See `SDWebImageContext` for more detailed information.
|
||||
*/
|
||||
FOUNDATION_EXPORT SDImageCoderOption _Nonnull const SDImageCoderWebImageContext;
|
||||
|
||||
#pragma mark - Coder
|
||||
/**
|
||||
This is the image coder protocol to provide custom image decoding/encoding.
|
||||
|
|
|
@ -13,3 +13,5 @@ SDImageCoderOption const SDImageCoderDecodeScaleFactor = @"decodeScaleFactor";
|
|||
|
||||
SDImageCoderOption const SDImageCoderEncodeFirstFrameOnly = @"encodeFirstFrameOnly";
|
||||
SDImageCoderOption const SDImageCoderEncodeCompressionQuality = @"encodeCompressionQuality";
|
||||
|
||||
SDImageCoderOption const SDImageCoderWebImageContext = @"webImageContext";
|
||||
|
|
|
@ -47,7 +47,13 @@ UIImage * _Nullable SDImageLoaderDecodeImageData(NSData * _Nonnull imageData, NS
|
|||
}
|
||||
}
|
||||
if (!image) {
|
||||
image = [[SDImageCodersManager sharedManager] decodedImageWithData:imageData options:@{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}];
|
||||
SDImageCoderOptions *options = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)};
|
||||
if (context) {
|
||||
SDImageCoderMutableOptions *mutableOptions = [options mutableCopy];
|
||||
[mutableOptions setValue:context forKey:SDImageCoderWebImageContext];
|
||||
options = [mutableOptions copy];
|
||||
}
|
||||
image = [[SDImageCodersManager sharedManager] decodedImageWithData:imageData options:options];
|
||||
}
|
||||
if (image) {
|
||||
BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0;
|
||||
|
@ -119,7 +125,13 @@ UIImage * _Nullable SDImageLoaderDecodeProgressiveImageData(NSData * _Nonnull im
|
|||
}
|
||||
}
|
||||
if (!image) {
|
||||
image = [progressiveCoder incrementalDecodedImageWithOptions:@{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)}];
|
||||
SDImageCoderOptions *options = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)};
|
||||
if (context) {
|
||||
SDImageCoderMutableOptions *mutableOptions = [options mutableCopy];
|
||||
[mutableOptions setValue:context forKey:SDImageCoderWebImageContext];
|
||||
options = [mutableOptions copy];
|
||||
}
|
||||
image = [progressiveCoder incrementalDecodedImageWithOptions:options];
|
||||
}
|
||||
if (image) {
|
||||
BOOL shouldDecode = (options & SDWebImageAvoidDecodeImage) == 0;
|
||||
|
|
Loading…
Reference in New Issue