Authored by Matej Bukovinski
Committed by Olivier Poitrey

Disk cache now uses the raw image data returned from the server.

This preserves the image quality and retains some image attributes, such as the alpha channel (for non-jpeg images).
... ... @@ -20,7 +20,7 @@ extern NSString *const SDWebImageDownloadStartNotification;
extern NSString *const SDWebImageDownloadStopNotification;
typedef void(^SDWebImageDownloaderProgressBlock)(NSUInteger receivedSize, long long expectedSize);
typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSError *error, BOOL finished);
typedef void(^SDWebImageDownloaderCompletedBlock)(UIImage *image, NSData *data, NSError *error, BOOL finished);
/**
* Asynchronous downloader dedicated and optimized for image loading.
... ...
... ... @@ -91,7 +91,7 @@ NSString *const kCompletedCallbackKey = @"completed";
return _downloadQueue.maxConcurrentOperationCount;
}
- (id<SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSUInteger, long long))progressBlock completed:(void (^)(UIImage *, NSError *, BOOL))completedBlock
- (id<SDWebImageOperation>)downloadImageWithURL:(NSURL *)url options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSUInteger, long long))progressBlock completed:(void (^)(UIImage *, NSData *, NSError *, BOOL))completedBlock
{
__block SDWebImageDownloaderOperation *operation;
__weak SDWebImageDownloader *wself = self;
... ... @@ -114,7 +114,7 @@ NSString *const kCompletedCallbackKey = @"completed";
if (callback) callback(receivedSize, expectedSize);
}
}
completed:^(UIImage *image, NSError *error, BOOL finished)
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished)
{
if (!wself) return;
SDWebImageDownloader *sself = wself;
... ... @@ -122,7 +122,7 @@ NSString *const kCompletedCallbackKey = @"completed";
for (NSDictionary *callbacks in callbacksForURL)
{
SDWebImageDownloaderCompletedBlock callback = callbacks[kCompletedCallbackKey];
if (callback) callback(image, error, finished);
if (callback) callback(image, data, error, finished);
}
}
cancelled:^
... ... @@ -137,7 +137,7 @@ NSString *const kCompletedCallbackKey = @"completed";
return operation;
}
- (void)addProgressCallback:(void (^)(NSUInteger, long long))progressBlock andCompletedBlock:(void (^)(UIImage *, NSError *, BOOL))completedBlock forURL:(NSURL *)url createCallback:(void (^)())createCallback
- (void)addProgressCallback:(void (^)(NSUInteger, long long))progressBlock andCompletedBlock:(void (^)(UIImage *, NSData *data, NSError *, BOOL))completedBlock forURL:(NSURL *)url createCallback:(void (^)())createCallback
{
dispatch_barrier_sync(self.barrierQueue, ^
{
... ...
... ... @@ -30,7 +30,7 @@
size_t width, height;
}
- (id)initWithRequest:(NSURLRequest *)request queue:(dispatch_queue_t)queue options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSUInteger, long long))progressBlock completed:(void (^)(UIImage *, NSError *, BOOL))completedBlock cancelled:(void (^)())cancelBlock
- (id)initWithRequest:(NSURLRequest *)request queue:(dispatch_queue_t)queue options:(SDWebImageDownloaderOptions)options progress:(void (^)(NSUInteger, long long))progressBlock completed:(void (^)(UIImage *, NSData *, NSError *, BOOL))completedBlock cancelled:(void (^)())cancelBlock
{
if ((self = [super init]))
{
... ... @@ -77,7 +77,7 @@
{
if (self.completedBlock)
{
self.completedBlock(nil, [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey: @"Connection can't be initialized"}], YES);
self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey: @"Connection can't be initialized"}], YES);
}
}
});
... ... @@ -158,7 +158,7 @@
if (self.completedBlock)
{
self.completedBlock(nil, [NSError errorWithDomain:NSURLErrorDomain code:[((NSHTTPURLResponse *)response) statusCode] userInfo:nil], YES);
self.completedBlock(nil, nil, [NSError errorWithDomain:NSURLErrorDomain code:[((NSHTTPURLResponse *)response) statusCode] userInfo:nil], YES);
}
[self done];
... ... @@ -228,7 +228,7 @@
{
UIImage *image = [UIImage decodedImageWithImage:SDScaledImageForPath(self.request.URL.absoluteString, [UIImage imageWithCGImage:partialImageRef])];
CGImageRelease(partialImageRef);
if (self.completedBlock) self.completedBlock(image, nil, NO);
if (self.completedBlock) self.completedBlock(image, nil, nil, NO);
}
}
... ... @@ -251,7 +251,7 @@
UIImage *image = [UIImage decodedImageWithImage:SDScaledImageForPath(self.request.URL.absoluteString, self.imageData)];
dispatch_async(dispatch_get_main_queue(), ^
{
completionBlock(image, nil, YES);
completionBlock(image, self.imageData, nil, YES);
completionBlock = nil;
});
}
... ... @@ -266,7 +266,7 @@
if (self.completedBlock)
{
self.completedBlock(nil, error, YES);
self.completedBlock(nil, nil, error, YES);
}
[self done];
... ...
... ... @@ -97,7 +97,7 @@
SDWebImageDownloaderOptions downloaderOptions = 0;
if (options & SDWebImageLowPriority) downloaderOptions |= SDWebImageDownloaderLowPriority;
if (options & SDWebImageProgressiveDownload) downloaderOptions |= SDWebImageDownloaderProgressiveDownload;
__block id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSError *error, BOOL finished)
__block id<SDWebImageOperation> subOperation = [self.imageDownloader downloadImageWithURL:url options:downloaderOptions progress:progressBlock completed:^(UIImage *downloadedImage, NSData *data, NSError *error, BOOL finished)
{
dispatch_async(dispatch_get_main_queue(), ^
{
... ... @@ -109,7 +109,7 @@
}
else if (downloadedImage && finished)
{
[self.imageCache storeImage:downloadedImage forKey:key];
[self.imageCache storeImage:downloadedImage imageData:data forKey:key toDisk:YES];
}
if (finished)
... ...