Add MAX function with scale in `SDImageScaleFactorForKey`

This commit is contained in:
kinarob 2019-04-26 16:46:37 +08:00
parent 806e228867
commit 2dd9fe4d9b
3 changed files with 5 additions and 5 deletions

View File

@ -17,7 +17,7 @@ UIImage * _Nullable SDImageCacheDecodeImageData(NSData * _Nonnull imageData, NSS
BOOL decodeFirstFrame = options & SDWebImageDecodeFirstFrameOnly; BOOL decodeFirstFrame = options & SDWebImageDecodeFirstFrameOnly;
NSNumber *scaleValue = context[SDWebImageContextImageScaleFactor]; NSNumber *scaleValue = context[SDWebImageContextImageScaleFactor];
CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey); CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey);
SDImageCoderOptions *coderOptions = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(MAX(scale, 1))}; SDImageCoderOptions *coderOptions = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)};
if (context) { if (context) {
SDImageCoderMutableOptions *mutableCoderOptions = [coderOptions mutableCopy]; SDImageCoderMutableOptions *mutableCoderOptions = [coderOptions mutableCopy];
[mutableCoderOptions setValue:context forKey:SDImageCoderWebImageContext]; [mutableCoderOptions setValue:context forKey:SDImageCoderWebImageContext];

View File

@ -31,7 +31,7 @@ UIImage * _Nullable SDImageLoaderDecodeImageData(NSData * _Nonnull imageData, NS
BOOL decodeFirstFrame = options & SDWebImageDecodeFirstFrameOnly; BOOL decodeFirstFrame = options & SDWebImageDecodeFirstFrameOnly;
NSNumber *scaleValue = context[SDWebImageContextImageScaleFactor]; NSNumber *scaleValue = context[SDWebImageContextImageScaleFactor];
CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey); CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey);
SDImageCoderOptions *coderOptions = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(MAX(scale, 1))}; SDImageCoderOptions *coderOptions = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)};
if (context) { if (context) {
SDImageCoderMutableOptions *mutableCoderOptions = [coderOptions mutableCopy]; SDImageCoderMutableOptions *mutableCoderOptions = [coderOptions mutableCopy];
[mutableCoderOptions setValue:context forKey:SDImageCoderWebImageContext]; [mutableCoderOptions setValue:context forKey:SDImageCoderWebImageContext];
@ -90,7 +90,7 @@ UIImage * _Nullable SDImageLoaderDecodeProgressiveImageData(NSData * _Nonnull im
BOOL decodeFirstFrame = options & SDWebImageDecodeFirstFrameOnly; BOOL decodeFirstFrame = options & SDWebImageDecodeFirstFrameOnly;
NSNumber *scaleValue = context[SDWebImageContextImageScaleFactor]; NSNumber *scaleValue = context[SDWebImageContextImageScaleFactor];
CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey); CGFloat scale = scaleValue.doubleValue >= 1 ? scaleValue.doubleValue : SDImageScaleFactorForKey(cacheKey);
SDImageCoderOptions *coderOptions = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(MAX(scale, 1))}; SDImageCoderOptions *coderOptions = @{SDImageCoderDecodeFirstFrameOnly : @(decodeFirstFrame), SDImageCoderDecodeScaleFactor : @(scale)};
if (context) { if (context) {
SDImageCoderMutableOptions *mutableCoderOptions = [coderOptions mutableCopy]; SDImageCoderMutableOptions *mutableCoderOptions = [coderOptions mutableCopy];
[mutableCoderOptions setValue:context forKey:SDImageCoderWebImageContext]; [mutableCoderOptions setValue:context forKey:SDImageCoderWebImageContext];

View File

@ -39,14 +39,14 @@ inline CGFloat SDImageScaleFactorForKey(NSString * _Nullable key) {
NSString *fileScale = [NSString stringWithFormat:@"@%@x.", scaleFactor]; NSString *fileScale = [NSString stringWithFormat:@"@%@x.", scaleFactor];
if ([key containsString:fileScale]) { if ([key containsString:fileScale]) {
scale = scaleFactor.doubleValue; scale = scaleFactor.doubleValue;
return scale; return MAX(scale, 1);
} }
if (isURL) { if (isURL) {
// %402x. for url encode // %402x. for url encode
NSString *urlScale = [NSString stringWithFormat:@"%%40%@x.", scaleFactor]; NSString *urlScale = [NSString stringWithFormat:@"%%40%@x.", scaleFactor];
if ([key containsString:urlScale]) { if ([key containsString:urlScale]) {
scale = scaleFactor.doubleValue; scale = scaleFactor.doubleValue;
return scale; return MAX(scale, 1);
} }
} }
} }