mirror of
https://github.com/zhigang1992/PINRemoteImage.git
synced 2026-05-20 04:11:08 +08:00
Allow maximum progressive render size to be set
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
- (void)updateProgressiveImageWithData:(nonnull NSData *)data expectedNumberOfBytes:(int64_t)expectedNumberOfBytes;
|
||||
|
||||
//Returns the latest image based on thresholds, returns nil if no new image is generated
|
||||
- (nullable UIImage *)currentImageBlurred:(BOOL)blurred;
|
||||
- (UIImage *)currentImageBlurred:(BOOL)blurred maxProgressiveRenderSize:(CGSize)maxBlurSize;
|
||||
|
||||
- (nullable NSData *)data;
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@
|
||||
[self.lock unlock];
|
||||
}
|
||||
|
||||
- (UIImage *)currentImageBlurred:(BOOL)blurred
|
||||
- (UIImage *)currentImageBlurred:(BOOL)blurred maxProgressiveRenderSize:(CGSize)maxProgressiveRenderSize
|
||||
{
|
||||
[self.lock lock];
|
||||
if (self.imageSource == nil) {
|
||||
@@ -204,6 +204,11 @@
|
||||
NSNumber *isProgressive = jpegProperties[(NSString *)kCGImagePropertyJFIFIsProgressive];
|
||||
self.isProgressiveJPEG = jpegProperties && [isProgressive boolValue];
|
||||
}
|
||||
|
||||
if (self.size.width > maxProgressiveRenderSize.width || self.size.height > maxProgressiveRenderSize.height) {
|
||||
[self.lock unlock];
|
||||
return nil;
|
||||
}
|
||||
|
||||
float progress = 0;
|
||||
if (self.expectedNumberOfBytes > 0) {
|
||||
@@ -314,12 +319,9 @@
|
||||
return nil;
|
||||
}
|
||||
|
||||
CGSize maxSize = CGSizeMake(1024, 1024);
|
||||
CGSize inputSize = inputImage.size;
|
||||
if (inputSize.width < 1 ||
|
||||
inputSize.height < 1 ||
|
||||
maxSize.height < inputSize.height ||
|
||||
maxSize.width < inputSize.width) {
|
||||
inputSize.height < 1) {
|
||||
CGImageRelease(inputImageRef);
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -223,6 +223,15 @@ typedef void(^PINRemoteImageManagerAuthenticationChallenge)(NSURLSessionTask * _
|
||||
- (void)setProgressiveRendersShouldBlur:(BOOL)shouldBlur
|
||||
completion:(nullable dispatch_block_t)completion;
|
||||
|
||||
/**
|
||||
Sets the maximum size of an image that PINRemoteImage will blur. If the image is too large, blurring is skipped
|
||||
|
||||
@param maxProgressiveRenderSize A CGSize which indicates the max size PINRemoteImage will render a progressive image. If an image is larger in either dimension, progressive rendering will be skipped
|
||||
@param completion Completion to be called once maxProgressiveRenderSize is set.
|
||||
*/
|
||||
- (void)setProgressiveRendersMaxProgressiveRenderSize:(CGSize)maxProgressiveRenderSize
|
||||
completion:(nullable dispatch_block_t)completion;
|
||||
|
||||
/**
|
||||
Prefetch an image at the given URL.
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ typedef void (^PINRemoteImageManagerDataCompletion)(NSData *data, NSError *error
|
||||
@property (nonatomic, strong) NSMutableSet *canceledTasks;
|
||||
@property (nonatomic, strong) NSArray *progressThresholds;
|
||||
@property (nonatomic, assign) BOOL shouldBlurProgressive;
|
||||
@property (nonatomic, assign) CGSize maxProgressiveRenderSize;
|
||||
@property (nonatomic, assign) NSTimeInterval estimatedRemainingTimeThreshold;
|
||||
@property (nonatomic, strong) dispatch_queue_t callbackQueue;
|
||||
@property (nonatomic, strong) NSOperationQueue *concurrentOperationQueue;
|
||||
@@ -184,6 +185,7 @@ static dispatch_once_t sharedDispatchToken;
|
||||
_lowQualityBPSThreshold = 50000; // approximately edge speeds
|
||||
_shouldUpgradeLowQualityImages = NO;
|
||||
_shouldBlurProgressive = YES;
|
||||
_maxProgressiveRenderSize = CGSizeMake(1024, 1024);
|
||||
self.tasks = [[NSMutableDictionary alloc] init];
|
||||
self.canceledTasks = [[NSMutableSet alloc] init];
|
||||
self.taskQOS = [[NSMutableArray alloc] initWithCapacity:5];
|
||||
@@ -295,6 +297,20 @@ static dispatch_once_t sharedDispatchToken;
|
||||
});
|
||||
}
|
||||
|
||||
- (void)setProgressiveRendersMaxProgressiveRenderSize:(CGSize)maxProgressiveRenderSize completion:(nullable dispatch_block_t)completion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
typeof(self) strongSelf = weakSelf;
|
||||
[strongSelf lock];
|
||||
strongSelf.maxProgressiveRenderSize = maxProgressiveRenderSize;
|
||||
[strongSelf unlock];
|
||||
if (completion) {
|
||||
completion();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)setHighQualityBPSThreshold:(float)highQualityBPSThreshold completion:(dispatch_block_t)completion
|
||||
{
|
||||
__weak typeof(self) weakSelf = self;
|
||||
@@ -1077,6 +1093,7 @@ static dispatch_once_t sharedDispatchToken;
|
||||
PINProgressiveImage *progressiveImage = task.progressImage;
|
||||
BOOL hasProgressBlocks = task.hasProgressBlocks;
|
||||
BOOL shouldBlur = self.shouldBlurProgressive;
|
||||
CGSize maxProgressiveRenderSize = self.maxProgressiveRenderSize;
|
||||
[self unlock];
|
||||
|
||||
[progressiveImage updateProgressiveImageWithData:data expectedNumberOfBytes:[dataTask countOfBytesExpectedToReceive]];
|
||||
@@ -1085,7 +1102,7 @@ static dispatch_once_t sharedDispatchToken;
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[_concurrentOperationQueue pin_addOperationWithQueuePriority:PINRemoteImageManagerPriorityLow block:^{
|
||||
typeof(self) strongSelf = weakSelf;
|
||||
UIImage *progressImage = [progressiveImage currentImageBlurred:shouldBlur];
|
||||
UIImage *progressImage = [progressiveImage currentImageBlurred:shouldBlur maxProgressiveRenderSize:maxProgressiveRenderSize];
|
||||
if (progressImage) {
|
||||
[strongSelf lock];
|
||||
NSString *cacheKey = [strongSelf cacheKeyForURL:[[dataTask originalRequest] URL] processorKey:nil];
|
||||
|
||||
Reference in New Issue
Block a user