Added `SDImageCoder.defaultDecodeSolution` to control the force decode solution, defaults to CoreGraphics (the same as 5.12)
For user who want new UIKit solution, you can opt-in to change the `defaultDecodeSolution` case
This commit is contained in:
parent
ff6b3b9bb5
commit
213a8b8def
|
@ -55,6 +55,9 @@ typedef NS_OPTIONS(NSUInteger, SDImageCacheOptions) {
|
|||
SDImageCacheMatchAnimatedImageClass = 1 << 7,
|
||||
};
|
||||
|
||||
/**
|
||||
* A token associated with each cache query. Can be used to cancel a cache query
|
||||
*/
|
||||
@interface SDImageCacheToken : NSObject <SDWebImageOperation>
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,6 +10,13 @@
|
|||
#import "SDWebImageCompat.h"
|
||||
#import "SDImageFrame.h"
|
||||
|
||||
typedef NS_ENUM(NSUInteger, SDImageCoderDecodeSolution) {
|
||||
/// always use the CoreGraphics to redraw on bitmap context, best compatibility
|
||||
SDImageCoderDecodeSolutionCoreGraphics,
|
||||
/// available on iOS/tvOS 15+, use UIKit's new CGImageDecompressor, best performance. If failed, will fallback to CoreGraphics as well
|
||||
SDImageCoderDecodeSolutionUIKit
|
||||
};
|
||||
|
||||
/**
|
||||
Provide some common helper methods for building the image decoder/encoder.
|
||||
*/
|
||||
|
@ -111,6 +118,12 @@
|
|||
*/
|
||||
+ (UIImage * _Nullable)decodedAndScaledDownImageWithImage:(UIImage * _Nullable)image limitBytes:(NSUInteger)bytes;
|
||||
|
||||
/** Control the default force decode solution. Available solutions in `SDImageCoderDecodeSolution`.
|
||||
@note Defaults to `SDImageCoderDecodeSolutionCoreGraphics`
|
||||
@note You can opt-in to use `SDImageCoderDecodeSolutionUIKit`, which will prefer to use UIKit on iOS 15, and fallback to CoreGraphics instead.
|
||||
*/
|
||||
@property (class, readwrite) SDImageCoderDecodeSolution defaultDecodeSolution;
|
||||
|
||||
/**
|
||||
Control the default limit bytes to scale down largest images.
|
||||
This value must be larger than 4 Bytes (at least 1x1 pixel). Defaults to 60MB on iOS/tvOS, 90MB on macOS, 30MB on watchOS.
|
||||
|
|
|
@ -22,6 +22,8 @@ static inline size_t SDByteAlign(size_t size, size_t alignment) {
|
|||
return ((size + (alignment - 1)) / alignment) * alignment;
|
||||
}
|
||||
|
||||
static SDImageCoderDecodeSolution kDefaultDecodeSolution = SDImageCoderDecodeSolutionCoreGraphics;
|
||||
|
||||
static const size_t kBytesPerPixel = 4;
|
||||
static const size_t kBitsPerComponent = 8;
|
||||
|
||||
|
@ -370,12 +372,14 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|||
#if SD_UIKIT
|
||||
// See: https://developer.apple.com/documentation/uikit/uiimage/3750834-imagebypreparingfordisplay
|
||||
// Need CGImage-based
|
||||
if (@available(iOS 15, tvOS 15, *)) {
|
||||
UIImage *decodedImage = [image imageByPreparingForDisplay];
|
||||
if (decodedImage) {
|
||||
SDImageCopyAssociatedObject(image, decodedImage);
|
||||
decodedImage.sd_isDecoded = YES;
|
||||
return decodedImage;
|
||||
if (self.defaultDecodeSolution == SDImageCoderDecodeSolutionUIKit) {
|
||||
if (@available(iOS 15, tvOS 15, *)) {
|
||||
UIImage *decodedImage = [image imageByPreparingForDisplay];
|
||||
if (decodedImage) {
|
||||
SDImageCopyAssociatedObject(image, decodedImage);
|
||||
decodedImage.sd_isDecoded = YES;
|
||||
return decodedImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -435,15 +439,17 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|||
#if SD_UIKIT
|
||||
// See: https://developer.apple.com/documentation/uikit/uiimage/3750835-imagebypreparingthumbnailofsize
|
||||
// Need CGImage-based
|
||||
if (@available(iOS 15, tvOS 15, *)) {
|
||||
// Calculate thumbnail point size
|
||||
CGFloat scale = image.scale ?: 1;
|
||||
CGSize thumbnailSize = CGSizeMake(destResolution.width / scale, destResolution.height / scale);
|
||||
UIImage *decodedImage = [image imageByPreparingThumbnailOfSize:thumbnailSize];
|
||||
if (decodedImage) {
|
||||
SDImageCopyAssociatedObject(image, decodedImage);
|
||||
decodedImage.sd_isDecoded = YES;
|
||||
return decodedImage;
|
||||
if (self.defaultDecodeSolution == SDImageCoderDecodeSolutionUIKit) {
|
||||
if (@available(iOS 15, tvOS 15, *)) {
|
||||
// Calculate thumbnail point size
|
||||
CGFloat scale = image.scale ?: 1;
|
||||
CGSize thumbnailSize = CGSizeMake(destResolution.width / scale, destResolution.height / scale);
|
||||
UIImage *decodedImage = [image imageByPreparingThumbnailOfSize:thumbnailSize];
|
||||
if (decodedImage) {
|
||||
SDImageCopyAssociatedObject(image, decodedImage);
|
||||
decodedImage.sd_isDecoded = YES;
|
||||
return decodedImage;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -557,6 +563,14 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|||
}
|
||||
}
|
||||
|
||||
+ (SDImageCoderDecodeSolution)defaultDecodeSolution {
|
||||
return kDefaultDecodeSolution;
|
||||
}
|
||||
|
||||
+ (void)setDefaultDecodeSolution:(SDImageCoderDecodeSolution)defaultDecodeSolution {
|
||||
kDefaultDecodeSolution = defaultDecodeSolution;
|
||||
}
|
||||
|
||||
+ (NSUInteger)defaultScaleDownLimitBytes {
|
||||
return kDestImageLimitBytes;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
- (BOOL)sd_isDecoded {
|
||||
NSNumber *value = objc_getAssociatedObject(self, @selector(sd_isDecoded));
|
||||
if (value) {
|
||||
if (value != nil) {
|
||||
return value.boolValue;
|
||||
} else {
|
||||
// Assume only CGImage based can use lazy decoding
|
||||
|
|
Loading…
Reference in New Issue